docs/tests
James M. Greene f388a3d550
Deploy to staging manually using a script (#19769)
* Add 'script/deploy' to enable manual deploys to Heroku

* Pass API tokens into 'deploy-to-staging' module usage

* Construct Octokit instance to pass in

* Get PR branch name and verify state

* Reorganize

* Rename option to 'octokit'

* Add missing option

* Actually use the convenience methods for convenience

* Simplify top-level script

* Top-level script revisions

* Add parse-pr-url module

* Add create-staging-app-name module

* Remove misplaced comment

* Pass in owner

* Use owner param

* More variables

* Pass owner along more

* Correct prNumber param reference

* Add WIP deploy-to-staging module

* Prevent 'scripts/' and '.github/actions-scripts/' files from being modified in open source repo

* Extract PR author earlier

* Add note about optionally supplying DOCUBOT_REPO_PAT env var

* Override Heroku env var during AppSetup creation instead of later to avoid triggering a second deploy

* Updates to deploy-to-staging module

* Lots of updates

* Add dyno start-up monitoring and warmup requests

* Ignore 'script/deploy' in the repository-references test

* Correct path to Octokit helper

* Temporarily add a 'gha-' prefix to environment names

* Log whole error if terminal. Good for Octokit errors!

* Correct Octokit preview configuration

* Add more logging around Heroku build and release

* Added more timings to log messages

* Monitor dyno states specifically from the dyno list view to avoid 404 oddities when Free dynos are dropped and non-Free dynos are added

* Don't wait for AppSetup status as it includes the Build time

* Updating logging since we don't see DeploymentStatus update messages in the UI =(

* Remove commented out code

* Refactor to extract more properties from the PR object

* Fix reference to pull request number

* Increase Heroku polling intervals from 2.5 seconds to 5 seconds

* Remove unhelpful createDeploymentStatus API calls

* Workaround Heroku's secondary release upon app creation
2021-06-14 22:32:07 +00:00
..
browser React: remove expose (#19771) 2021-06-10 16:53:43 +00:00
content lint 2021-05-26 15:18:26 -04:00
fixtures
graphql
helpers Update tests/helpers/supertest.js 2021-06-07 12:52:50 -07:00
javascripts
linting Add Code security landing and guides pages (#19650) 2021-06-10 20:14:56 +00:00
meta Deploy to staging manually using a script (#19769) 2021-06-14 22:32:07 +00:00
rendering update test 2021-06-10 09:43:32 -07:00
routing Rename "helpfulness" to survey (#19727) 2021-06-04 12:22:31 -07:00
unit updating headers of fixture 2021-06-14 14:25:14 -07: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.