forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
66 lines (62 loc) · 2.55 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const path = require(`path`)
const glob = require(`glob`)
const fs = require(`fs`)
const pkgs = glob.sync(`./packages/*`).map(p => p.replace(/^\./, `<rootDir>`))
const reGatsby = /gatsby$/
const gatsbyDir = pkgs.find(p => reGatsby.exec(p))
const gatsbyBuildDirs = [`dist`].map(dir => path.join(gatsbyDir, dir))
const builtTestsDirs = pkgs
.filter(p => fs.existsSync(path.join(p, `src`)))
.map(p => path.join(p, `__tests__`))
const distDirs = pkgs.map(p => path.join(p, `dist`))
const ignoreDirs = [`<rootDir>/packages/gatsby-dev-cli/verdaccio`].concat(
gatsbyBuildDirs,
builtTestsDirs,
distDirs
)
const coverageDirs = pkgs.map(p => path.join(p, `src/**/*.js`))
const useCoverage = !!process.env.GENERATE_JEST_REPORT
module.exports = {
notify: true,
verbose: true,
roots: pkgs,
modulePathIgnorePatterns: ignoreDirs,
coveragePathIgnorePatterns: ignoreDirs,
testPathIgnorePatterns: [
`<rootDir>/examples/`,
`<rootDir>/dist/`,
`<rootDir>/node_modules/`,
`<rootDir>/packages/gatsby-admin/.cache/`,
`<rootDir>/packages/gatsby-plugin-gatsby-cloud/src/__tests__/mocks/`,
`<rootDir>/packages/gatsby/src/utils/worker/__tests__/test-helpers/`,
`<rootDir>/deprecated-packages/`,
`__tests__/fixtures`,
`__testfixtures__/`,
],
transform: {
"^.+\\.[jt]sx?$": `<rootDir>/jest-transformer.js`,
},
moduleNameMapper: {
"^highlight.js$": `<rootDir>/node_modules/highlight.js/lib/index.js`,
"^@reach/router(.*)": `<rootDir>/node_modules/@gatsbyjs/reach-router$1`,
"^weak-lru-cache$": `<rootDir>/node_modules/weak-lru-cache/dist/index.cjs`,
"^ordered-binary$": `<rootDir>/node_modules/ordered-binary/dist/index.cjs`,
"^msgpackr$": `<rootDir>/node_modules/msgpackr/dist/node.cjs`,
"^gatsby-page-utils/(.*)$": `gatsby-page-utils/dist/$1`, // Workaround for https://github.com/facebook/jest/issues/9771
"^gatsby-core-utils/(.*)$": `gatsby-core-utils/dist/$1`, // Workaround for https://github.com/facebook/jest/issues/9771
"^gatsby-plugin-utils/(.*)$": [
`gatsby-plugin-utils/dist/$1`,
`gatsby-plugin-utils/$1`,
], // Workaround for https://github.com/facebook/jest/issues/9771
},
snapshotSerializers: [`jest-serializer-path`],
collectCoverageFrom: coverageDirs,
reporters: process.env.CI
? [[`jest-silent-reporter`, { useDots: true }]].concat(
useCoverage ? `jest-junit` : []
)
: [`default`].concat(useCoverage ? `jest-junit` : []),
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
setupFiles: [`<rootDir>/.jestSetup.js`],
setupFilesAfterEnv: [`jest-extended`],
}