From f73d5f6372a2570b7a38255bc0a69e0deacf67f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 11 Mar 2021 17:57:06 +0100 Subject: [PATCH] Jest Website v2 (#11149) --- .circleci/config.yml | 16 - .circleci/website.sh | 35 - .eslintignore | 2 +- .eslintrc.js | 8 + .gitignore | 4 +- CONTRIBUTING.md | 2 +- crowdin.yaml | 92 +- docs/CLI.md | 4 +- docs/Configuration.md | 144 +- docs/ExpectAPI.md | 6 +- docs/GlobalAPI.md | 4 +- docs/JestObjectAPI.md | 2 +- docs/MockFunctionAPI.md | 10 +- docs/SnapshotTesting.md | 4 +- docs/Troubleshooting.md | 2 +- docs/TutorialAsync.md | 2 +- docs/TutorialReactNative.md | 8 +- docs/WatchPlugins.md | 30 +- netlify.toml | 18 + package.json | 7 +- website/.vscode/settings.json | 2 +- website/README.md | 33 +- website/archivedVersions.json | 5 + website/blog/2016-04-12-jest-11.md | 10 +- website/blog/2016-06-22-jest-13.md | 4 +- website/blog/2016-07-27-jest-14.md | 6 +- website/blog/2016-09-01-jest-15.md | 8 +- website/blog/2016-10-03-jest-16.md | 2 +- website/blog/2016-12-15-2016-in-jest.md | 2 +- ...2017-01-30-a-great-developer-experience.md | 10 +- ...e-watch-mode-test-platform-improvements.md | 14 +- ...delightful-testing-multi-project-runner.md | 10 +- website/blog/2017-12-18-jest-22.md | 8 +- ...jest-23-blazing-fast-delightful-testing.md | 16 +- ...refreshing-polished-typescript-friendly.md | 8 +- website/blog/2020-01-21-jest-25.md | 4 +- website/blog/2020-05-05-jest-26.md | 6 +- .../blog/2021-03-09-jest-website-upgrade.md | 49 + website/core/Footer.js | 108 - website/docusaurus.config.js | 261 + website/i18n.js | 44 + website/languages.js | 185 - website/package.json | 37 +- website/pages/en/help.js | 86 - website/sidebars.json | 22 +- website/siteConfig.js | 139 - website/src/components/v1/Container.js | 40 + website/src/components/v1/GridBlock.js | 95 + website/src/components/v1/MarkdownBlock.js | 43 + website/src/components/v1/legacyCSS.css | 282 + website/src/css/algoliaDocSearchTheme.scss | 46 + website/src/css/docusaurusTheme.scss | 72 + .../pages/animations/_landingAnimation.js} | 60 +- website/src/pages/help.js | 88 + website/{pages/en => src/pages}/index.js | 303 +- website/src/pages/index.module.scss | 55 + website/{pages/en => src/pages}/versions.js | 82 +- website/{pages/en => src/pages}/videos.js | 56 +- website/src/pages/videos.module.scss | 18 + website/src/prism/themeDark.js | 62 + website/src/prism/themeLight.js | 59 + website/static/CNAME | 1 + website/static/_redirects | 33 + website/static/css/code-block-buttons.css | 39 - .../static/css/{custom.css => custom.scss} | 55 +- website/static/css/hljs-jest.css | 112 - website/static/css/{jest.css => jest.scss} | 101 +- website/static/img/logos/nyt.png | Bin 12827 -> 22302 bytes website/static/img/oss_logo.png | Bin 4369 -> 4728 bytes website/static/js/code-block-buttons.js | 45 - website/static/manifest.json | 32 + website/translators.txt | 81 - website/users.json | 35 + website/versioned_docs/version-22.x/CLI.md | 300 - .../version-22.x/Configuration.md | 1000 -- .../versioned_docs/version-22.x/ExpectAPI.md | 992 -- .../version-22.x/GettingStarted.md | 149 - .../versioned_docs/version-22.x/GlobalAPI.md | 344 - .../version-22.x/JestObjectAPI.md | 643 -- .../version-22.x/MockFunctionAPI.md | 288 - .../version-22.x/Troubleshooting.md | 262 - .../version-22.x/TutorialReact.md | 343 - website/versioned_docs/version-23.x/CLI.md | 312 - .../version-23.x/Configuration.md | 1041 -- .../versioned_docs/version-23.x/GlobalAPI.md | 656 -- .../version-23.x/JestObjectAPI.md | 658 -- website/versioned_docs/version-24.x/CLI.md | 341 - .../version-24.x/Configuration.md | 1239 --- .../versioned_docs/version-24.x/GlobalAPI.md | 676 -- .../version-24.x/JestObjectAPI.md | 671 -- .../Architecture.md | 3 +- .../BypassingModuleMocks.md | 3 +- website/versioned_docs/version-25.x/CLI.md | 7 +- .../version-25.x/Configuration.md | 143 +- .../DynamoDB.md | 3 +- .../ECMAScriptModules.md | 3 +- .../EnvironmentVariables.md | 3 +- .../Es6ClassMocks.md | 3 +- .../versioned_docs/version-25.x/ExpectAPI.md | 46 +- .../GettingStarted.md | 3 +- .../versioned_docs/version-25.x/GlobalAPI.md | 7 +- .../JestCommunity.md | 3 +- .../version-25.x/JestObjectAPI.md | 3 +- .../JestPlatform.md | 3 +- .../ManualMocks.md | 3 +- .../MigrationGuide.md | 3 +- .../MockFunctionAPI.md | 11 +- .../MockFunctions.md | 7 +- .../{version-22.x => version-25.x}/MongoDB.md | 3 +- .../MoreResources.md | 5 +- .../Puppeteer.md | 3 +- .../SetupAndTeardown.md | 3 +- .../SnapshotTesting.md | 3 +- .../TestingAsyncCode.md | 3 +- .../TestingFrameworks.md | 3 +- .../TimerMocks.md | 3 +- .../version-25.x/Troubleshooting.md | 5 +- .../TutorialAsync.md | 3 +- .../TutorialReact.md | 3 +- .../version-25.x/TutorialReactNative.md | 13 +- .../TutorialjQuery.md | 3 +- .../UsingMatchers.md | 11 +- .../WatchPlugins.md | 33 +- .../{version-24.x => version-25.x}/Webpack.md | 3 +- website/versioned_docs/version-26.0/CLI.md | 347 - .../version-26.0/Configuration.md | 1276 --- website/versioned_docs/version-26.2/CLI.md | 351 - .../version-26.2/Configuration.md | 1290 --- .../version-26.4/Configuration.md | 1321 --- .../version-26.5/Configuration.md | 1339 --- .../version-26.x/Architecture.md | 8 + .../version-26.x/BypassingModuleMocks.md | 59 + .../{version-26.5 => version-26.x}/CLI.md | 7 +- .../Configuration.md | 145 +- .../versioned_docs/version-26.x/DynamoDB.md | 81 + .../version-26.x/ECMAScriptModules.md | 30 + .../version-26.x/EnvironmentVariables.md | 14 + .../Es6ClassMocks.md | 5 +- .../ExpectAPI.md | 47 +- .../GettingStarted.md | 104 +- .../GlobalAPI.md | 7 +- .../version-26.x/JestCommunity.md | 19 + .../JestObjectAPI.md | 3 +- .../JestPlatform.md | 3 +- .../ManualMocks.md | 3 +- .../version-26.x/MigrationGuide.md | 22 + .../MockFunctionAPI.md | 157 +- .../MockFunctions.md | 17 +- .../versioned_docs/version-26.x/MongoDB.md | 61 + .../version-26.x/MoreResources.md | 24 + .../Puppeteer.md | 43 +- .../version-26.x/SetupAndTeardown.md | 190 + .../SnapshotTesting.md | 137 +- .../version-26.x/TestingAsyncCode.md | 129 + .../version-26.x/TestingFrameworks.md | 45 + .../versioned_docs/version-26.x/TimerMocks.md | 163 + .../Troubleshooting.md | 9 +- .../TutorialAsync.md | 5 +- .../TutorialReact.md | 38 +- .../TutorialReactNative.md | 13 +- .../version-26.x/TutorialjQuery.md | 68 + .../version-26.x/UsingMatchers.md | 164 + .../WatchPlugins.md | 34 +- .../{version-22.x => version-26.x}/Webpack.md | 7 +- .../version-22.x-sidebars.json | 44 - .../version-23.x-sidebars.json | 45 - .../version-24.x-sidebars.json | 45 - .../version-25.x-sidebars.json | 156 + .../version-26.0-sidebars.json | 46 - .../version-26.x-sidebars.json | 160 + website/versions.json | 12 +- website/videos.json | 29 + yarn.lock | 8550 +++++++++++++---- 173 files changed, 10857 insertions(+), 19661 deletions(-) delete mode 100755 .circleci/website.sh create mode 100644 netlify.toml create mode 100644 website/archivedVersions.json create mode 100644 website/blog/2021-03-09-jest-website-upgrade.md delete mode 100644 website/core/Footer.js create mode 100644 website/docusaurus.config.js create mode 100644 website/i18n.js delete mode 100644 website/languages.js delete mode 100755 website/pages/en/help.js delete mode 100644 website/siteConfig.js create mode 100644 website/src/components/v1/Container.js create mode 100644 website/src/components/v1/GridBlock.js create mode 100644 website/src/components/v1/MarkdownBlock.js create mode 100644 website/src/components/v1/legacyCSS.css create mode 100644 website/src/css/algoliaDocSearchTheme.scss create mode 100644 website/src/css/docusaurusTheme.scss rename website/{static/landing.js => src/pages/animations/_landingAnimation.js} (84%) create mode 100755 website/src/pages/help.js rename website/{pages/en => src/pages}/index.js (68%) create mode 100644 website/src/pages/index.module.scss rename website/{pages/en => src/pages}/versions.js (53%) rename website/{pages/en => src/pages}/videos.js (65%) create mode 100644 website/src/pages/videos.module.scss create mode 100644 website/src/prism/themeDark.js create mode 100644 website/src/prism/themeLight.js create mode 100644 website/static/CNAME create mode 100644 website/static/_redirects delete mode 100644 website/static/css/code-block-buttons.css rename website/static/css/{custom.css => custom.scss} (87%) delete mode 100644 website/static/css/hljs-jest.css rename website/static/css/{jest.css => jest.scss} (72%) delete mode 100644 website/static/js/code-block-buttons.js create mode 100644 website/static/manifest.json delete mode 100644 website/translators.txt create mode 100644 website/users.json delete mode 100644 website/versioned_docs/version-22.x/CLI.md delete mode 100644 website/versioned_docs/version-22.x/Configuration.md delete mode 100644 website/versioned_docs/version-22.x/ExpectAPI.md delete mode 100644 website/versioned_docs/version-22.x/GettingStarted.md delete mode 100644 website/versioned_docs/version-22.x/GlobalAPI.md delete mode 100644 website/versioned_docs/version-22.x/JestObjectAPI.md delete mode 100644 website/versioned_docs/version-22.x/MockFunctionAPI.md delete mode 100644 website/versioned_docs/version-22.x/Troubleshooting.md delete mode 100644 website/versioned_docs/version-22.x/TutorialReact.md delete mode 100644 website/versioned_docs/version-23.x/CLI.md delete mode 100644 website/versioned_docs/version-23.x/Configuration.md delete mode 100644 website/versioned_docs/version-23.x/GlobalAPI.md delete mode 100644 website/versioned_docs/version-23.x/JestObjectAPI.md delete mode 100644 website/versioned_docs/version-24.x/CLI.md delete mode 100644 website/versioned_docs/version-24.x/Configuration.md delete mode 100644 website/versioned_docs/version-24.x/GlobalAPI.md delete mode 100644 website/versioned_docs/version-24.x/JestObjectAPI.md rename website/versioned_docs/{version-22.x => version-25.x}/Architecture.md (88%) rename website/versioned_docs/{version-22.x => version-25.x}/BypassingModuleMocks.md (96%) rename website/versioned_docs/{version-22.x => version-25.x}/DynamoDB.md (97%) rename website/versioned_docs/{version-26.0 => version-25.x}/ECMAScriptModules.md (96%) rename website/versioned_docs/{version-22.x => version-25.x}/EnvironmentVariables.md (82%) rename website/versioned_docs/{version-24.x => version-25.x}/Es6ClassMocks.md (99%) rename website/versioned_docs/{version-24.x => version-25.x}/GettingStarted.md (99%) rename website/versioned_docs/{version-22.x => version-25.x}/JestCommunity.md (95%) rename website/versioned_docs/{version-22.x => version-25.x}/JestPlatform.md (98%) rename website/versioned_docs/{version-22.x => version-25.x}/ManualMocks.md (99%) rename website/versioned_docs/{version-22.x => version-25.x}/MigrationGuide.md (96%) rename website/versioned_docs/{version-24.x => version-25.x}/MockFunctionAPI.md (97%) rename website/versioned_docs/{version-23.x => version-25.x}/MockFunctions.md (98%) rename website/versioned_docs/{version-22.x => version-25.x}/MongoDB.md (96%) rename website/versioned_docs/{version-22.x => version-25.x}/MoreResources.md (87%) rename website/versioned_docs/{version-23.x => version-25.x}/Puppeteer.md (98%) rename website/versioned_docs/{version-22.x => version-25.x}/SetupAndTeardown.md (99%) rename website/versioned_docs/{version-23.x => version-25.x}/SnapshotTesting.md (99%) rename website/versioned_docs/{version-22.x => version-25.x}/TestingAsyncCode.md (98%) rename website/versioned_docs/{version-22.x => version-25.x}/TestingFrameworks.md (97%) rename website/versioned_docs/{version-22.x => version-25.x}/TimerMocks.md (99%) rename website/versioned_docs/{version-24.x => version-25.x}/TutorialAsync.md (98%) rename website/versioned_docs/{version-24.x => version-25.x}/TutorialReact.md (99%) rename website/versioned_docs/{version-22.x => version-25.x}/TutorialjQuery.md (97%) rename website/versioned_docs/{version-22.x => version-25.x}/UsingMatchers.md (95%) rename website/versioned_docs/{version-24.x => version-25.x}/WatchPlugins.md (87%) rename website/versioned_docs/{version-24.x => version-25.x}/Webpack.md (99%) delete mode 100644 website/versioned_docs/version-26.0/CLI.md delete mode 100644 website/versioned_docs/version-26.0/Configuration.md delete mode 100644 website/versioned_docs/version-26.2/CLI.md delete mode 100644 website/versioned_docs/version-26.2/Configuration.md delete mode 100644 website/versioned_docs/version-26.4/Configuration.md delete mode 100644 website/versioned_docs/version-26.5/Configuration.md create mode 100644 website/versioned_docs/version-26.x/Architecture.md create mode 100644 website/versioned_docs/version-26.x/BypassingModuleMocks.md rename website/versioned_docs/{version-26.5 => version-26.x}/CLI.md (99%) rename website/versioned_docs/{version-26.6 => version-26.x}/Configuration.md (94%) create mode 100644 website/versioned_docs/version-26.x/DynamoDB.md create mode 100644 website/versioned_docs/version-26.x/ECMAScriptModules.md create mode 100644 website/versioned_docs/version-26.x/EnvironmentVariables.md rename website/versioned_docs/{version-22.x => version-26.x}/Es6ClassMocks.md (98%) rename website/versioned_docs/{version-23.x => version-26.x}/ExpectAPI.md (96%) rename website/versioned_docs/{version-23.x => version-26.x}/GettingStarted.md (56%) rename website/versioned_docs/{version-26.4 => version-26.x}/GlobalAPI.md (99%) create mode 100644 website/versioned_docs/version-26.x/JestCommunity.md rename website/versioned_docs/{version-26.0 => version-26.x}/JestObjectAPI.md (99%) rename website/versioned_docs/{version-26.0 => version-26.x}/JestPlatform.md (98%) rename website/versioned_docs/{version-26.0 => version-26.x}/ManualMocks.md (99%) create mode 100644 website/versioned_docs/version-26.x/MigrationGuide.md rename website/versioned_docs/{version-23.x => version-26.x}/MockFunctionAPI.md (59%) rename website/versioned_docs/{version-22.x => version-26.x}/MockFunctions.md (93%) create mode 100644 website/versioned_docs/version-26.x/MongoDB.md create mode 100644 website/versioned_docs/version-26.x/MoreResources.md rename website/versioned_docs/{version-22.x => version-26.x}/Puppeteer.md (80%) create mode 100644 website/versioned_docs/version-26.x/SetupAndTeardown.md rename website/versioned_docs/{version-22.x => version-26.x}/SnapshotTesting.md (76%) create mode 100644 website/versioned_docs/version-26.x/TestingAsyncCode.md create mode 100644 website/versioned_docs/version-26.x/TestingFrameworks.md create mode 100644 website/versioned_docs/version-26.x/TimerMocks.md rename website/versioned_docs/{version-23.x => version-26.x}/Troubleshooting.md (92%) rename website/versioned_docs/{version-22.x => version-26.x}/TutorialAsync.md (95%) rename website/versioned_docs/{version-23.x => version-26.x}/TutorialReact.md (94%) rename website/versioned_docs/{version-22.x => version-26.x}/TutorialReactNative.md (88%) create mode 100644 website/versioned_docs/version-26.x/TutorialjQuery.md create mode 100644 website/versioned_docs/version-26.x/UsingMatchers.md rename website/versioned_docs/{version-23.x => version-26.x}/WatchPlugins.md (86%) rename website/versioned_docs/{version-22.x => version-26.x}/Webpack.md (95%) delete mode 100644 website/versioned_sidebars/version-22.x-sidebars.json delete mode 100644 website/versioned_sidebars/version-23.x-sidebars.json delete mode 100644 website/versioned_sidebars/version-24.x-sidebars.json create mode 100644 website/versioned_sidebars/version-25.x-sidebars.json delete mode 100644 website/versioned_sidebars/version-26.0-sidebars.json create mode 100644 website/versioned_sidebars/version-26.x-sidebars.json create mode 100644 website/videos.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 378809c9ddea..f70ad7530d07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -83,20 +83,6 @@ jobs: - store_test_results: path: reports/junit - test-or-deploy-website: - working_directory: ~/jest - executor: node/default - resource_class: large - steps: - - checkout - - node/install: - lts: true - install-npm: false - - node/install-packages: *install - - run: - name: Test or Deploy Jest Website - command: ./.circleci/website.sh - # Workflows enables us to run multiple jobs in parallel workflows: version: 2 @@ -107,5 +93,3 @@ workflows: - test-node-14 - test-node-15 # current - test-jest-jasmine - - test-or-deploy-website: - filters: *filter-ignore-gh-pages diff --git a/.circleci/website.sh b/.circleci/website.sh deleted file mode 100755 index 01dfb8aa6af1..000000000000 --- a/.circleci/website.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -e - -git diff-tree --no-commit-id --name-only -r HEAD > files_changed.txt -if ! grep -E "(^docs\/.*)|(^website\/.*)|(^\.circleci/website\.sh$)" files_changed.txt; then - echo "Skipping deploy & test. No relevant website files have changed" -else - echo "Relevant website files have changed" - if [[ $CIRCLE_PROJECT_USERNAME == "facebook" && -z $CI_PULL_REQUEST && -z $CIRCLE_PR_USERNAME ]]; then - # configure Docusaurus bot - git config --global user.email "docusaurus-bot@users.noreply.github.com" - git config --global user.name "Website Deployment Script" - echo "machine github.com login docusaurus-bot password $DOCUSAURUS_PUBLISH_TOKEN" > ~/.netrc - # install Docusaurus and generate file of English strings - yarn --immutable && cd website && node fetchSupporters.js && yarn write-translations - # crowdin install - sudo apt-get update - sudo apt-get install default-jre rsync - wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb - sudo dpkg -i crowdin.deb - # translations upload/download - yarn crowdin-upload - # download only enabled languages - for lang in ja es-ES ro zh-CN pt-BR ru uk - do - yarn crowdin-download -l $lang - done - # build and publish website - GIT_USER=docusaurus-bot USE_SSH=false yarn publish-gh-pages - else - echo "Skipping deploy. Test website build" - yarn --immutable && cd website && node fetchSupporters.js && yarn build - fi -fi diff --git a/.eslintignore b/.eslintignore index be8072a6a850..0871961de1b7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,10 +4,10 @@ bin/ flow-typed/** packages/*/build/** packages/jest-diff/src/cleanupSemantic.ts +website/.docusaurus website/blog website/build website/node_modules website/i18n/*.js -website/translated_docs website/static !.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 4e8e4c5460a2..556de75aba05 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -152,6 +152,14 @@ module.exports = { 'sort-keys': 'off', }, }, + { + files: ['website/**/*'], + rules: { + 'import/order': 'off', + 'import/sort-keys': 'off', + 'sort-keys': 'off', + }, + }, { files: ['examples/**/*'], rules: { diff --git a/.gitignore b/.gitignore index 4e7db024f4c0..060a7e07c4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,11 +20,11 @@ /packages/*/coverage/ /packages/*/node_modules/ +/website/.docusaurus /website/build /website/backers.json /website/node_modules /website/yarn.lock -/website/translated_docs /website/i18n/* /benchmarks/*/node_modules/ @@ -48,3 +48,5 @@ package-lock.json !**/.yarn/sdks !**/.yarn/versions **/.pnp.* + +crowdin-cli.jar diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c254d07085e6..3810117d329f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -194,7 +194,7 @@ The best way to get your bug fixed is to provide a reduced test case. Please pro ### Docs translation -We get translations from crowdin, see https://crowdin.com/project/jest. Any and all help is very much appreciated! +We get translations from Crowdin, see https://crowdin.com/project/jest-v2. Any and all help is very much appreciated! ### Security Bugs diff --git a/crowdin.yaml b/crowdin.yaml index df82c39c103a..08424962ce6d 100644 --- a/crowdin.yaml +++ b/crowdin.yaml @@ -1,50 +1,48 @@ -project_identifier_env: CROWDIN_JEST_PROJECT_ID -api_key_env: CROWDIN_JEST_API_KEY -base_path: './' +# +# Your Crowdin credentials +# +project_id: '428892' +api_token_env: 'CROWDIN_PERSONAL_TOKEN' + +base_path: '.' +base_url: 'https://api.crowdin.com' preserve_hierarchy: true +# See Yaml anchors: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/ +languages_mapping: &languages_mapping + locale: + 'es-ES': 'es-ES' + 'ja': 'ja' + 'pt-BR': 'pt-BR' + 'ro': 'ro' + 'ru': 'ru' + 'uk': 'uk' + 'zh-CN': 'zh-Hans' + +# +# Files configuration +# see https://support.crowdin.com/configuration-file/ +# files: - - source: '/docs/*.md' - translation: '/website/translated_docs/%locale%/%original_file_name%' - languages_mapping: &anchor - locale: - 'af': 'af' - 'ar': 'ar' - 'bs-BA': 'bs-BA' - 'ca': 'ca' - 'cs': 'cs' - 'da': 'da' - 'de': 'de' - 'el': 'el' - 'es-ES': 'es-ES' - 'fa': 'fa-IR' - 'fi': 'fi' - 'fr': 'fr' - 'he': 'he' - 'hu': 'hu' - 'id': 'id-ID' - 'it': 'it' - 'ja': 'ja' - 'ko': 'ko' - 'mr': 'mr-IN' - 'nl': 'nl' - 'no': 'no-NO' - 'pl': 'pl' - 'pt-BR': 'pt-BR' - 'pt-PT': 'pt-PT' - 'ro': 'ro' - 'ru': 'ru' - 'sk': 'sk-SK' - 'sr': 'sr' - 'sv-SE': 'sv-SE' - 'tr': 'tr' - 'uk': 'uk' - 'vi': 'vi' - 'zh-CN': 'zh-Hans' - 'zh-TW': 'zh-Hant' - - source: '/website/versioned_docs/**/*.md' - translation: '/website/translated_docs/%locale%/**/%original_file_name%' - languages_mapping: *anchor - - source: '/website/i18n/en.json' - translation: '/website/i18n/%locale%.json' - languages_mapping: *anchor + [ + { + 'source': '/website/i18n/en/**/*', + 'translation': '/website/i18n/%locale%/**/%original_file_name%', + 'languages_mapping': *languages_mapping, + }, + { + 'source': '/docs/**/*', + 'translation': '/website/i18n/%locale%/docusaurus-plugin-content-docs/current/**/%original_file_name%', + 'languages_mapping': *languages_mapping, + }, + { + 'source': '/website/versioned_docs/**/*', + 'translation': '/website/i18n/%locale%/docusaurus-plugin-content-docs/**/%original_file_name%', + 'languages_mapping': *languages_mapping, + }, + { + 'source': '/website/blog/**/*', + 'translation': '/website/i18n/%locale%/docusaurus-plugin-content-blog/**/%original_file_name%', + 'languages_mapping': *languages_mapping, + }, + ] diff --git a/docs/CLI.md b/docs/CLI.md index b23f0d25871e..3814bca63c54 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -100,7 +100,9 @@ jest --update-snapshot --detectOpenHandles _Note: CLI options take precedence over values from the [Configuration](Configuration.md)._ - +import TOCInline from "@theme/TOCInline" + + --- diff --git a/docs/Configuration.md b/docs/Configuration.md index a9e23d965af5..9e4b813ce44d 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -80,13 +80,15 @@ module.exports = { }; ``` - +import TOCInline from "@theme/TOCInline" + + --- ## Reference -### `automock` [boolean] +### `automock` \[boolean] Default: `false` @@ -123,17 +125,17 @@ test('if utils mocked automatically', () => { }); ``` -_Note: Node modules are automatically mocked when you have a manual mock in place (e.g.: `__mocks__/lodash.js`). More info [here](manual-mocks.html#mocking-node-modules)._ +_Note: Node modules are automatically mocked when you have a manual mock in place (e.g.: `__mocks__/lodash.js`). More info [here](manual-mocks#mocking-node-modules)._ _Note: Core modules, like `fs`, are not mocked by default. They can be mocked explicitly, like `jest.mock('fs')`._ -### `bail` [number | boolean] +### `bail` \[number | boolean] Default: `0` By default, Jest runs all tests and produces all errors into the console upon completion. The bail config option can be used here to have Jest stop running tests after `n` failures. Setting bail to `true` is the same as setting bail to `1`. -### `cacheDirectory` [string] +### `cacheDirectory` \[string] Default: `"/tmp/"` @@ -141,19 +143,19 @@ The directory where Jest should store its cached dependency information. Jest attempts to scan your dependency tree once (up-front) and cache it in order to ease some of the filesystem raking that needs to happen while running tests. This config option lets you customize where Jest stores that cache data on disk. -### `clearMocks` [boolean] +### `clearMocks` \[boolean] Default: `false` Automatically clear mock calls and instances before every test. Equivalent to calling `jest.clearAllMocks()` before each test. This does not remove any mock implementation that may have been provided. -### `collectCoverage` [boolean] +### `collectCoverage` \[boolean] Default: `false` Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage collection statements, it may significantly slow down your tests. -### `collectCoverageFrom` [array] +### `collectCoverageFrom` \[array] Default: `undefined` @@ -193,13 +195,13 @@ Most likely your glob patterns are not matching any files. Refer to the [microma -### `coverageDirectory` [string] +### `coverageDirectory` \[string] Default: `undefined` The directory where Jest should output its coverage files. -### `coveragePathIgnorePatterns` [array\] +### `coveragePathIgnorePatterns` \[array<string>] Default: `["/node_modules/"]` @@ -207,13 +209,13 @@ An array of regexp pattern strings that are matched against all file paths befor These pattern strings match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/build/", "/node_modules/"]`. -### `coverageProvider` [string] +### `coverageProvider` \[string] Indicates which provider should be used to instrument code for coverage. Allowed values are `babel` (default) or `v8`. Note that using `v8` is considered experimental. This uses V8's builtin code coverage rather than one based on Babel. It is not as well tested, and it has also improved in the last few releases of Node. Using the latest versions of node (v14 at the time of this writing) will yield better results. -### `coverageReporters` [array\] +### `coverageReporters` \[array<string *| \[*string, options]>] Default: `["json", "lcov", "text", "clover"]` @@ -229,7 +231,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). -### `coverageThreshold` [object] +### `coverageThreshold` \[object] Default: `undefined` @@ -293,7 +295,7 @@ Jest will fail if: - The `./src/api/very-important-module.js` file has less than 100% coverage. - Every remaining file combined has less than 50% coverage (`global`). -### `dependencyExtractor` [string] +### `dependencyExtractor` \[string] Default: `undefined` @@ -322,7 +324,7 @@ The `extract` function should return an iterable (`Array`, `Set`, etc.) with the That module can also contain a `getCacheKey` function to generate a cache key to determine if the logic has changed and any cached artifacts relying on it should be discarded. -### `displayName` [string, object] +### `displayName` \[string, object] default: `undefined` @@ -347,13 +349,13 @@ module.exports = { As a secondary option, an object with the properties `name` and `color` can be passed. This allows for a custom configuration of the background color of the displayName. `displayName` defaults to white when its value is a string. Jest uses [chalk](https://github.com/chalk/chalk) to provide the color. As such, all of the valid options for colors supported by chalk are also supported by jest. -### `errorOnDeprecated` [boolean] +### `errorOnDeprecated` \[boolean] Default: `false` Make calling deprecated APIs throw helpful error messages. Useful for easing the upgrade process. -### `extensionsToTreatAsEsm` [array\] +### `extensionsToTreatAsEsm` \[array<string>] Default: `[]` @@ -370,7 +372,7 @@ Jest will run `.mjs` and `.js` files with nearest `package.json`'s `type` field } ``` -### `extraGlobals` [array\] +### `extraGlobals` \[array<string>] Default: `undefined` @@ -387,7 +389,7 @@ For example, if your tests call `Math` often, you can pass it by setting `extraG } ``` -### `forceCoverageMatch` [array\] +### `forceCoverageMatch` \[array<string>] Default: `['']` @@ -420,7 +422,7 @@ You can collect coverage from those files with setting `forceCoverageMatch`. } ``` -### `globals` [object] +### `globals` \[object] Default: `{}` @@ -441,7 +443,7 @@ For example, the following would create a global `__DEV__` variable set to `true Note that, if you specify a global reference value (like an object or array) here, and some code mutates that value in the midst of running a test, that mutation will _not_ be persisted across test runs for other test files. In addition, the `globals` object must be json-serializable, so it can't be used to specify global functions. For that, you should use `setupFiles`. -### `globalSetup` [string] +### `globalSetup` \[string] Default: `undefined` @@ -471,7 +473,7 @@ module.exports = async function () { }; ``` -### `globalTeardown` [string] +### `globalTeardown` \[string] Default: `undefined` @@ -481,7 +483,7 @@ _Note: A global teardown module configured in a project (using multi-project run _Note: The same caveat concerning transformation of `node_modules` as for `globalSetup` applies to `globalTeardown`._ -### `haste` [object] +### `haste` \[object] Default: `undefined` @@ -502,7 +504,7 @@ type HasteConfig = { }; ``` -### `injectGlobals` [boolean] +### `injectGlobals` \[boolean] Default: `true` @@ -520,19 +522,19 @@ test('some test', () => { _Note: This option is only supported using the default `jest-circus`. test runner_ -### `maxConcurrency` [number] +### `maxConcurrency` \[number] Default: `5` A number limiting the number of tests that are allowed to run at the same time when using `test.concurrent`. Any test above this limit will be queued and executed once a slot is released. -### `moduleDirectories` [array\] +### `moduleDirectories` \[array<string>] Default: `["node_modules"]` An array of directory names to be searched recursively up from the requiring module's location. Setting this option will _override_ the default, if you wish to still search `node_modules` for packages include it along with any other options: `["node_modules", "bower_components"]` -### `moduleFileExtensions` [array\] +### `moduleFileExtensions` \[array<string>] Default: `["js", "jsx", "ts", "tsx", "json", "node"]` @@ -540,7 +542,7 @@ An array of file extensions your modules use. If you require modules without spe We recommend placing the extensions most commonly used in your project on the left, so if you are using TypeScript, you may want to consider moving "ts" and/or "tsx" to the beginning of the array. -### `moduleNameMapper` [object\>] +### `moduleNameMapper` \[object<string, string | array<string>>] Default: `null` @@ -573,7 +575,7 @@ The order in which the mappings are defined matters. Patterns are checked one by _Note: If you provide module name without boundaries `^$` it may cause hard to spot errors. E.g. `relay` will replace all modules which contain `relay` as a substring in its name: `relay`, `react-relay` and `graphql-relay` will all be pointed to your stub._ -### `modulePathIgnorePatterns` [array\] +### `modulePathIgnorePatterns` \[array<string>] Default: `[]` @@ -581,13 +583,13 @@ An array of regexp pattern strings that are matched against all module paths bef These pattern strings match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/build/"]`. -### `modulePaths` [array\] +### `modulePaths` \[array<string>] Default: `[]` An alternative API to setting the `NODE_PATH` env variable, `modulePaths` is an array of absolute paths to additional locations to search when resolving modules. Use the `` string token to include the path to your project's root directory. Example: `["/app/"]`. -### `notify` [boolean] +### `notify` \[boolean] Default: `false` @@ -595,7 +597,7 @@ Activates notifications for test results. **Beware:** Jest uses [node-notifier](https://github.com/mikaelbr/node-notifier) to display desktop notifications. On Windows, it creates a new start menu entry on the first use and not display the notification. Notifications will be properly displayed on subsequent runs -### `notifyMode` [string] +### `notifyMode` \[string] Default: `failure-change` @@ -610,7 +612,7 @@ Specifies notification mode. Requires `notify: true`. - `success-change`: send a notification when tests pass or once when it fails. - `failure-change`: send a notification when tests fail or once when it passes. -### `preset` [string] +### `preset` \[string] Default: `undefined` @@ -632,13 +634,13 @@ Presets may also be relative to filesystem paths. } ``` -### `prettierPath` [string] +### `prettierPath` \[string] Default: `'prettier'` Sets the path to the [`prettier`](https://prettier.io/) node module used to update inline snapshots. -### `projects` [array\] +### `projects` \[array<string | ProjectConfig>] Default: `undefined` @@ -671,7 +673,7 @@ The projects feature can also be used to run multiple configurations or multiple _Note: When using multi-project runner, it's recommended to add a `displayName` for each project. This will show the `displayName` of a project next to its tests._ -### `reporters` [array\] +### `reporters` \[array<moduleName | \[moduleName, options]>] Default: `undefined` @@ -744,19 +746,19 @@ class MyCustomReporter { For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) -### `resetMocks` [boolean] +### `resetMocks` \[boolean] Default: `false` Automatically reset mock state before every test. Equivalent to calling `jest.resetAllMocks()` before each test. This will lead to any mocks having their fake implementations removed but does not restore their initial implementation. -### `resetModules` [boolean] +### `resetModules` \[boolean] Default: `false` By default, each test file gets its own independent module registry. Enabling `resetModules` goes a step further and resets the module registry before running each individual test. This is useful to isolate modules for every test so that the local module state doesn't conflict between tests. This can be done programmatically using [`jest.resetModules()`](JestObjectAPI.md#jestresetmodules). -### `resolver` [string] +### `resolver` \[string] Default: `undefined` @@ -826,13 +828,13 @@ module.exports = (request, options) => { }; ``` -### `restoreMocks` [boolean] +### `restoreMocks` \[boolean] Default: `false` Automatically restore mock state before every test. Equivalent to calling `jest.restoreAllMocks()` before each test. This will lead to any mocks having their fake implementations removed and restores their initial implementation. -### `rootDir` [string] +### `rootDir` \[string] Default: The root of the directory containing your Jest [config file](#) _or_ the `package.json` _or_ the [`pwd`](http://en.wikipedia.org/wiki/Pwd) if no `package.json` is found @@ -842,7 +844,7 @@ Oftentimes, you'll want to set this to `'src'` or `'lib'`, corresponding to wher _Note that using `''` as a string token in any other path-based config settings will refer back to this value. So, for example, if you want your [`setupFiles`](#setupfiles-array) config entry to point at the `env-setup.js` file at the root of your project, you could set its value to `["/env-setup.js"]`._ -### `roots` [array\] +### `roots` \[array<string>] Default: `[""]` @@ -854,7 +856,7 @@ _Note: While `rootDir` is mostly used as a token to be re-used in other configur _Note: By default, `roots` has a single entry `` but there are cases where you may want to have multiple roots within one project, for example `roots: ["/src/", "/tests/"]`._ -### `runner` [string] +### `runner` \[string] Default: `"jest-runner"` @@ -882,7 +884,7 @@ async runTests( If you need to restrict your test-runner to only run in serial rather than being executed in parallel your class should have the property `isSerial` to be set as `true`. -### `setupFiles` [array] +### `setupFiles` \[array] Default: `[]` @@ -890,7 +892,7 @@ A list of paths to modules that run some code to configure or set up the testing It's also worth noting that `setupFiles` will execute _before_ [`setupFilesAfterEnv`](#setupfilesafterenv-array). -### `setupFilesAfterEnv` [array] +### `setupFilesAfterEnv` \[array] Default: `[]` @@ -916,13 +918,13 @@ Example `jest.setup.js` file jest.setTimeout(10000); // in milliseconds ``` -### `slowTestThreshold` [number] +### `slowTestThreshold` \[number] Default: `5` The number of seconds after which a test is considered as slow and reported as such in the results. -### `snapshotResolver` [string] +### `snapshotResolver` \[string] Default: `undefined` @@ -947,7 +949,7 @@ module.exports = { }; ``` -### `snapshotSerializers` [array\] +### `snapshotSerializers` \[array<string>] Default: `[]` @@ -1011,7 +1013,7 @@ To make a dependency explicit instead of implicit, you can call [`expect.addSnap More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). -### `testEnvironment` [string] +### `testEnvironment` \[string] Default: `"node"` @@ -1102,13 +1104,13 @@ beforeAll(() => { }); ``` -### `testEnvironmentOptions` [Object] +### `testEnvironmentOptions` \[Object] Default: `{}` Test environment options that will be passed to the `testEnvironment`. The relevant options depend on the environment. For example, you can override options given to [jsdom](https://github.com/jsdom/jsdom) such as `{userAgent: "Agent/007"}`. -### `testFailureExitCode` [number] +### `testFailureExitCode` \[number] Default: `1` @@ -1116,7 +1118,7 @@ The exit code Jest returns on test failure. _Note: This does not change the exit code in the case of Jest errors (e.g. invalid configuration)._ -### `testMatch` [array\] +### `testMatch` \[array<string>] (default: `[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]`) @@ -1124,9 +1126,9 @@ The glob patterns Jest uses to detect test files. By default it looks for `.js`, See the [micromatch](https://github.com/jonschlinkert/micromatch) package for details of the patterns you can specify. -See also [`testRegex` [string | array\]](#testregex-string--arraystring), but note that you cannot specify both options. +See also [`testRegex` [string | array<string>]](#testregex-string--arraystring), but note that you cannot specify both options. -### `testPathIgnorePatterns` [array\] +### `testPathIgnorePatterns` \[array<string>] Default: `["/node_modules/"]` @@ -1134,11 +1136,11 @@ An array of regexp pattern strings that are matched against all test paths befor These pattern strings match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/build/", "/node_modules/"]`. -### `testRegex` [string | array\] +### `testRegex` \[string | array<string>] Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$` -The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array\]](#testmatch-arraystring), but note that you cannot specify both options. +The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array<string>]](#testmatch-arraystring), but note that you cannot specify both options. The following is a visualization of the default regex: @@ -1154,7 +1156,7 @@ The following is a visualization of the default regex: _Note: `testRegex` will try to detect test files using the **absolute file path**, therefore, having a folder with a name that matches it will run all the files as tests_ -### `testResultsProcessor` [string] +### `testResultsProcessor` \[string] Default: `undefined` @@ -1203,7 +1205,7 @@ This option allows the use of a custom results processor. This processor must be } ``` -### `testRunner` [string] +### `testRunner` \[string] Default: `jest-circus/runner` @@ -1223,7 +1225,7 @@ function testRunner( An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). -### `testSequencer` [string] +### `testSequencer` \[string] Default: `@jest/test-sequencer` @@ -1257,19 +1259,19 @@ Use it in your Jest config file like this: } ``` -### `testTimeout` [number] +### `testTimeout` \[number] Default: `5000` Default timeout of a test in milliseconds. -### `testURL` [string] +### `testURL` \[string] Default: `http://localhost` This option sets the URL for the jsdom environment. It is reflected in properties such as `location.href`. -### `timers` [string] +### `timers` \[string] Default: `real` @@ -1277,7 +1279,7 @@ Setting this value to `legacy` or `fake` allows the use of fake timers for funct If the value is `modern`, [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers) will be used as implementation instead of Jest's own legacy implementation. This will be the default fake implementation in Jest 27. -### `transform` [object\] +### `transform` \[object<string, pathToTransformer | \[pathToTransformer, object]>] Default: `{"\\.[jt]sx?$": "babel-jest"}` @@ -1297,7 +1299,7 @@ _Note: when adding additional code transformers, this will overwrite the default A transformer must be an object with at least a `process` function, and it's also recommended to include a `getCacheKey` function. If your transformer is written in ESM you should have a default export with that object. -### `transformIgnorePatterns` [array\] +### `transformIgnorePatterns` \[array<string>] Default: `["/node_modules/", "\\.pnp\\.[^\\\/]+$"]` @@ -1307,9 +1309,9 @@ These pattern strings match against the full path. Use the `` string to Example: `["/bower_components/", "/node_modules/"]`. -Sometimes it happens (especially in React Native or TypeScript projects) that 3rd party modules are published as untranspiled. Since all files inside `node_modules` are not transformed by default, Jest will not understand the code in these modules, resulting in syntax errors. To overcome this, you may use `transformIgnorePatterns` to allow transpiling such modules. You'll find a good example of this use case in [React Native Guide](https://jestjs.io/docs/en/tutorial-react-native#transformignorepatterns-customization). +Sometimes it happens (especially in React Native or TypeScript projects) that 3rd party modules are published as untranspiled. Since all files inside `node_modules` are not transformed by default, Jest will not understand the code in these modules, resulting in syntax errors. To overcome this, you may use `transformIgnorePatterns` to allow transpiling such modules. You'll find a good example of this use case in [React Native Guide](/docs/tutorial-react-native#transformignorepatterns-customization). -### `unmockedModulePathPatterns` [array\] +### `unmockedModulePathPatterns` \[array<string>] Default: `[]` @@ -1319,13 +1321,13 @@ This is useful for some commonly used 'utility' modules that are almost always u It is possible to override this setting in individual tests by explicitly calling `jest.mock()` at the top of the test file. -### `verbose` [boolean] +### `verbose` \[boolean] Default: `false` Indicates whether each individual test should be reported during the run. All errors will also still be shown on the bottom after execution. Note that if there is only one test file being run it will default to `true`. -### `watchPathIgnorePatterns` [array\] +### `watchPathIgnorePatterns` \[array<string>] Default: `[]` @@ -1335,7 +1337,7 @@ These patterns match against the full path. Use the `` string token to Even if nothing is specified here, the watcher will ignore changes to any hidden files and directories, i.e. files and folders that begin with a dot (`.`). -### `watchPlugins` [array\] +### `watchPlugins` \[array<string | \[string, Object]>] Default: `[]` @@ -1351,13 +1353,13 @@ Examples of watch plugins include: _Note: The values in the `watchPlugins` property value can omit the `jest-watch-` prefix of the package name._ -### `watchman` [boolean] +### `watchman` \[boolean] Default: `true` Whether to use [`watchman`](https://facebook.github.io/watchman/) for file crawling. -### `//` [string] +### `//` \[string] No default diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index d1ce4d6dbf84..21c11f7ea80e 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -9,7 +9,9 @@ For additional Jest matchers maintained by the Jest Community check out [`jest-e ## Methods - +import TOCInline from "@theme/TOCInline" + + --- @@ -1319,7 +1321,7 @@ And it will generate the following snapshot: exports[`drinking flavors throws on octopus 1`] = `"yuck, octopus flavor"`; ``` -Check out [React Tree Snapshot Testing](https://jestjs.io/blog/2016/07/27/jest-14.html) for more information on snapshot testing. +Check out [React Tree Snapshot Testing](/blog/2016/07/27/jest-14) for more information on snapshot testing. ### `.toThrowErrorMatchingInlineSnapshot(inlineSnapshot)` diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 220985c9053e..fa9d01f6b6ae 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -7,7 +7,9 @@ In your test files, Jest puts each of these methods and objects into the global ## Methods - +import TOCInline from "@theme/TOCInline" + + --- diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 71fcdd67f051..a7b45df77980 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -127,7 +127,7 @@ This is how `createMockFromModule` will mock the following data types: #### `Function` -Creates a new [mock function](https://jestjs.io/docs/en/mock-functions.html). The new function has no formal parameters and when called will return `undefined`. This functionality also applies to `async` functions. +Creates a new [mock function](mock-functions). The new function has no formal parameters and when called will return `undefined`. This functionality also applies to `async` functions. #### `Class` diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index 5bb9002d4069..e068e0409894 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -7,7 +7,9 @@ Mock functions are also known as "spies", because they let you spy on the behavi ## Methods - +import TOCInline from "@theme/TOCInline" + + --- @@ -85,7 +87,7 @@ Often this is useful when you want to clean up a mock's usage data between two a Beware that `mockClear` will replace `mockFn.mock`, not just [`mockFn.mock.calls`](#mockfnmockcalls) and [`mockFn.mock.instances`](#mockfnmockinstances). You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. -The [`clearMocks`](configuration.html#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. +The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests. ### `mockFn.mockReset()` @@ -103,7 +105,7 @@ This is useful when you want to mock functions in certain test cases and restore Beware that `mockFn.mockRestore` only works when the mock was created with `jest.spyOn`. Thus you have to take care of restoration yourself when manually assigning `jest.fn()`. -The [`restoreMocks`](configuration.html#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. +The [`restoreMocks`](configuration#restoremocks-boolean) configuration option is available to restore mocks automatically between tests. ### `mockFn.mockImplementation(fn)` @@ -372,7 +374,7 @@ test('calculate calls add', () => { // Now we can easily set up mock implementations. // All the `.mock*` API can now give you proper types for `add`. - // https://jestjs.io/docs/en/mock-function-api + // https://jestjs.io/docs/mock-function-api // `.mockImplementation` can now infer that `a` and `b` are `number` // and that the returned value is a `number`. diff --git a/docs/SnapshotTesting.md b/docs/SnapshotTesting.md index c55fc86c1a08..511fc0b51b21 100644 --- a/docs/SnapshotTesting.md +++ b/docs/SnapshotTesting.md @@ -43,7 +43,7 @@ The snapshot artifact should be committed alongside code changes, and reviewed a > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. -More information on how snapshot testing works and why we built it can be found on the [release blog post](https://jestjs.io/blog/2016/07/27/jest-14.html). We recommend reading [this blog post](http://benmccormick.org/2016/09/19/testing-with-jest-snapshots-first-impressions/) to get a good sense of when you should use snapshot testing. We also recommend watching this [egghead video](https://egghead.io/lessons/javascript-use-jest-s-snapshot-testing-feature?pl=testing-javascript-with-jest-a36c4074) on Snapshot Testing with Jest. +More information on how snapshot testing works and why we built it can be found on the [release blog post](/blog/2016/07/27/jest-14). We recommend reading [this blog post](http://benmccormick.org/2016/09/19/testing-with-jest-snapshots-first-impressions/) to get a good sense of when you should use snapshot testing. We also recommend watching this [egghead video](https://egghead.io/lessons/javascript-use-jest-s-snapshot-testing-feature?pl=testing-javascript-with-jest-a36c4074) on Snapshot Testing with Jest. ### Updating Snapshots @@ -295,7 +295,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### What's the difference between snapshot testing and visual regression testing? -Snapshot testing and visual regression testing are two distinct ways of testing UIs, and they serve different purposes. Visual regression testing tools take screenshots of web pages and compare the resulting images pixel by pixel. With Snapshot testing values are serialized, stored within text files, and compared using a diff algorithm. There are different trade-offs to consider and we listed the reasons why snapshot testing was built in the [Jest blog](https://jestjs.io/blog/2016/07/27/jest-14.html#why-snapshot-testing). +Snapshot testing and visual regression testing are two distinct ways of testing UIs, and they serve different purposes. Visual regression testing tools take screenshots of web pages and compare the resulting images pixel by pixel. With Snapshot testing values are serialized, stored within text files, and compared using a diff algorithm. There are different trade-offs to consider and we listed the reasons why snapshot testing was built in the [Jest blog](/blog/2016/07/27/jest-14#why-snapshot-testing). ### Does snapshot testing replace unit testing? diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md index 9ac94779758a..52ca0f3358e4 100644 --- a/docs/Troubleshooting.md +++ b/docs/Troubleshooting.md @@ -207,4 +207,4 @@ _Note:_ This means when you are using `test.each` you cannot set the table async ## Still unresolved? -See [Help](/help.html). +See [Help](/help). diff --git a/docs/TutorialAsync.md b/docs/TutorialAsync.md index e953ad4ed443..aea53809b0cf 100644 --- a/docs/TutorialAsync.md +++ b/docs/TutorialAsync.md @@ -140,7 +140,7 @@ it('tests error with async/await', async () => { ## `.rejects` -The`.rejects` helper works like the `.resolves` helper. If the promise is fulfilled, the test will automatically fail. `expect.assertions(number)` is not required but recommended to verify that a certain number of [assertions](https://jestjs.io/docs/en/expect#expectassertionsnumber) are called during a test. It is otherwise easy to forget to `return`/`await` the `.resolves` assertions. +The`.rejects` helper works like the `.resolves` helper. If the promise is fulfilled, the test will automatically fail. `expect.assertions(number)` is not required but recommended to verify that a certain number of [assertions](expect#expectassertionsnumber) are called during a test. It is otherwise easy to forget to `return`/`await` the `.resolves` assertions. ```js // Testing for async errors using `.rejects`. diff --git a/docs/TutorialReactNative.md b/docs/TutorialReactNative.md index fd2a3e160dbd..bba83bf1c291 100644 --- a/docs/TutorialReactNative.md +++ b/docs/TutorialReactNative.md @@ -136,7 +136,7 @@ The preset sets up the environment and is very opinionated and based on what we ### transformIgnorePatterns customization -The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-arraystring) option can be used to specify which files shall be transformed by Babel. Many react-native npm modules unfortunately don't pre-compile their source code before publishing. +The [`transformIgnorePatterns`](configuration#transformignorepatterns-arraystring) option can be used to specify which files shall be transformed by Babel. Many react-native npm modules unfortunately don't pre-compile their source code before publishing. By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than react-native: @@ -150,11 +150,11 @@ By default the jest-react-native preset only processes the project's own source ### setupFiles -If you'd like to provide additional configuration for every test file, the [`setupFiles` configuration option](configuration.html#setupfiles-array) can be used to specify setup scripts. +If you'd like to provide additional configuration for every test file, the [`setupFiles` configuration option](configuration#setupfiles-array) can be used to specify setup scripts. ### moduleNameMapper -The [`moduleNameMapper`](configuration.html#modulenamemapper-objectstring-string--arraystring) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help: +The [`moduleNameMapper`](configuration#modulenamemapper-objectstring-string--arraystring) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help: ```json { @@ -176,7 +176,7 @@ For example, if your code depends on a third party native video component called jest.mock('react-native-video', () => 'Video'); ``` -This will render the component as `