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 Babel configuration file
To write tests using the latest ECMAScript syntax and proposals, Babel (1) must be in place and set up to transpile the sources before passing them to Jest to run them. This step is documented in the sections "Creating a configuration file for Jest" (2) of the Gatsby guide about the preprocess file and the Jest docs about "Using Babel" (3). The file is placed in the base `test` folder within the project root. It initially uses the `babel-preset-gatsby` (4) preset package which includes all necessary Babel plugins to write tests for Gatsby based projects. This includes all plugins mentioned in the Jest Babel setup guide and additionally adds useful syntax proposal plugins that are also used in the project sources like e.g. `babel-plugin-proposal-class-properties` (5) and `babel-plugin-proposal-optional-chaining` (6). The the custom transformer is exported using babel-jest's `createTransformer` function (7) which takes the created Babel config object as parameter. References: (1) https://babeljs.io (2) https://www.gatsbyjs.org/docs/unit-testing/#2-creating-a-configuration-file-for-jest (3) https://jestjs.io/docs/en/getting-started#using-babel (4) https://www.npmjs.com/package/babel-preset-gatsby (5) https://babeljs.io/docs/en/babel-plugin-proposal-class-properties (6) https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining (7) https://jestjs.io/docs/en/tutorial-react#custom-transformers GH-39
- Loading branch information