Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Jest's main configuration file
This commit implements the main configuration file of Jest. It follows the "Setting up your environment" (1) guide of Gatsby and the Jest docs about how to get started (2). The file is placed in the project root and initially contains the following options: - `coverageDirectory` - The directory where Jest should output its coverage files. - `collectCoverageFrom` - To ensure only relevant files are included in the coverage stats this array of glob patterns matches files for which coverage information should be collected. - `globals` - A set of global variables that need to be available in all test environments. The `__PATH_PREFIX__` variable is specific to Gatsby based projects which is necessary for some components. - `moduleNameMapper` - A map from regular expressions to module names that allow to stub out resources, like images or styles with a single module. It is also used to set up "resolve aliases" that reflect the same setup like the ones configured for Gatsby's Webpack configuration. - `modulePaths` - An array with paths to additional locations to search when resolving modules. This is useful to define test specific utils which can then be imported like an aliased module. - `setupFiles` - The paths to modules that run some code to configure or set up the testing environment before each test. The `___loader` shim is a global function used by internal Gatsby APIs. Note that this is executed BEFORE the `setupTestFrameworkScriptFile` option! - `setupTestFrameworkScriptFile` - The path to the module that runs to configure or set up the testing framework before each test. Note that this is executed AFTER the `setupFiles` option! - `testPathIgnorePatterns` - An array of regexp pattern strings that are matched against all test paths before executing the test. If the test path matches any of the patterns, it will be skipped. - `transform` - To write tests using the latest ECMAScript syntax and proposals, Babel must be in place and set up to transpile the sources before they are processed by Jest to run them. This mapping from regular expressions to paths of transformers will transpile matching files with the specified Babel config. See the Jest documentation (3) about how to use Jest with Babel for more details. - `transformIgnorePatterns` - This is an important and required option for Gatsby based projects since Gastby includes un-transpiled ES6 code and by default Jest doesn't try to transform code inside `node_modules`, therefore the` gatsby-browser-entry.js` file isn't transpiled before running Jest so the `gatsby` module must be excluded. The array of regexp pattern strings that are matched against all source file paths before transformation. If the test path matches any of the patterns, it will not be transformed. References: (1) https://www.gatsbyjs.org/docs/unit-testing/#setting-up-your-environment (2) https://jestjs.io/docs/en/getting-started (3) https://jestjs.io/docs/en/getting-started#using-babel GH-39
- Loading branch information