docs/tests
James M. Greene 2dbae93c53
Try to prevent late/duplicate response errors (#20077)
* Ensure all Express 'next' calls include 'return's

* Add headersSent checks during archived versions flow

* Return a 404 earlier if archived resource fetch fails

* Short-circuit responses for archived stuff

* Be more careful about responding to and short-circuiting after search requests

* Fix tests
2021-06-28 19:31:54 +00:00
..
browser Disable client-side link transitions (#20141) 2021-06-24 14:35:23 -07:00
content Address goofy exports (#20113) 2021-06-24 14:59:06 +00:00
fixtures write tests to ensure that ghes versioning in a feature gets combined with ghes versioning frontmatter, and does NOT overwrite it 2021-06-23 15:03:12 -04:00
graphql Remove remaining JSON requires (#20110) 2021-06-23 14:57:50 -07:00
helpers Address goofy exports (#20113) 2021-06-24 14:59:06 +00:00
javascripts Create a user agent parser for analytics (#15915) 2020-10-21 07:43:09 -07:00
linting Merge branch 'main' of github.com:github/docs-internal into script-to-use-short-versions 2021-06-24 10:14:50 -04:00
meta Deploy to staging manually using a script (#19769) 2021-06-14 22:32:07 +00:00
rendering add short titles to frontmatter (#20131) 2021-06-24 11:02:53 -07:00
routing Try to prevent late/duplicate response errors (#20077) 2021-06-28 19:31:54 +00:00
unit Merge branch 'main' into revert-20087-revert-20069-fix-homepage-versions-dropdown 2021-06-24 12:40:17 -04:00
README.md Performance testing NextJS / React (#19540) 2021-05-27 15:17:27 -07:00

README.md

Tests

It's not strictly necessary to run tests locally while developing: You can always open a pull request and rely on the CI service to run tests for you, but sometimes it's helpful to run tests locally before pushing your changes to GitHub.

Test are written using jest, a framework maintained by Facebook and used by many teams at GitHub. Jest is convenient in that it provides everything: a test runner, an assertion library, code coverage analysis, custom reporters for different types of test output, etc.

Install optional dependencies

We typically rely on CI to run our tests, so we consider some large test-only dependencies optional (for example, puppeteer). In order to run the tests locally you'll need to make sure optional dependencies are installed by running:

npm ci --include=optional

If you run into the error "Could not find expected browser (chrome) locally" you may need to manually install the expected chromium version with:

node node_modules/puppeteer/install.js

Running all the tests

Once you've followed the development instructions above, you can run the entire test suite locally:

script/test # or `npm test`

Watching all the tests

You can also run a script that will continually watch for changes and re-run the tests any time a change is made. This command will notify you when tests change to and from a passing or failing state, and will also print out a test coverage report, so you can see what files are in need of tests.

npm run test-watch

Testing individual files

If you're making changes to a specific file and don't want to run the entire test suite, you can pass an argument to the jest testing tool:

jest __tests__/page.js

The argument doesn't have to be a fully qualified file path. It can also be a portion of a filename:

jest page # runs tests on __tests__/page.js and __tests__/pages.js

Linting

To validate all your JavaScript code (and auto-format some easily reparable mistakes), run the linter:

npm run lint

This test checks all internal links and image references in the English site. To run it locally (takes about 60 seconds):

npx jest links-and-images

It checks images, anchors, and links for every version of every page.

It reports five types of problems:

  1. Broken image references
    • Example: /assets/images/foo.png where foo.png doesn't exist.
  2. Broken same-page anchors
    • Example: #foo where the page does not have a heading Foo.
  3. Broken links due to page not found
    • Example: /github/using-git/foo where there is no foo.md file at that path.
  4. Broken links due to versioning
    • Example: an unversioned link to a Dotcom-only article in a page that has Enterprise versions.
  5. Broken anchors on links
    • Example: /some/valid/link#bar where the linked page can be found but it does not have a heading Bar.