docs/tests
Peter Bengtsson 7acccdac9b
load webhook versions at runtime instead of import-time (#24788)
* load webhook versions at runtime instead of import-time

* fix tests
2022-01-28 18:27:00 +00:00
..
browser test that youtube embeds work (#24726) 2022-01-27 17:18:33 +00:00
content load webhook versions at runtime instead of import-time (#24788) 2022-01-28 18:27:00 +00:00
fixtures hardcode popular redirect tests (#24602) 2022-01-25 16:16:24 +00:00
graphql Remove `import x` statements (#20594) 2021-07-29 20:28:30 +00:00
helpers improve test debugging and loading of cached redirects json file (#23584) 2021-12-13 16:20:05 +00:00
javascripts React Cleanup: Documentation (#20517) 2021-07-27 09:07:18 -07:00
linting move test/utils.js to where it belongs (#23586) 2021-12-11 19:58:34 +00:00
meta Adding Codespace prebuilds to docs-internal (#23952) 2022-01-11 00:23:08 -06:00
rendering Merge branch 'jules-4800' of github.com:github/docs-internal into jules-4800 2022-01-25 12:43:38 +01:00
routing hardcode popular redirect tests (#24602) 2022-01-25 16:16:24 +00:00
translations Prevent creation of empty source files (#23634) 2021-12-13 16:57:38 +00:00
unit delete customRanking (#24659) 2022-01-27 13:02:13 +00:00
README.md Update README.md (#21137) 2021-08-25 16:19:50 -07:00
package.json

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

Running individual tests

You can run specific tests in one of these two ways:

# The TEST_NAME can be a filename, partial filename, or path to a file or directory
npm test -- <TEST_NAME>

NODE_OPTIONS=--experimental-vm-modules npx jest tests/unit

Failed Local Tests

If the tests fail locally with an error like this:

Could not find a production build in the '/Users/username/repos/docs-internal/.next' directory.

You may need to run this before every test run:

npx next build

Linting

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

npm run lint