Skip to content

Commit 608dcf5

Browse files
authored
Ignore config and fixtures in test coverage (#949)
1 parent 24e2c5c commit 608dcf5

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

jest/browser/jest.config.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const config: Config = {
3535
clearMocks: true,
3636

3737
// Indicates whether the coverage information should be collected while executing the test
38-
//collectCoverage: true,
38+
// collectCoverage: true,
3939

4040
// An array of glob patterns indicating a set of files for which coverage information should be collected
4141
// collectCoverageFrom: undefined,
@@ -44,10 +44,12 @@ const config: Config = {
4444
//coverageDirectory: "coverage",
4545

4646
// An array of regexp pattern strings used to skip coverage collection
47-
/* coveragePathIgnorePatterns: [
48-
"/node_modules/",
49-
"src/test-utils",
50-
], */
47+
coveragePathIgnorePatterns: [
48+
'/node_modules/',
49+
'src/test-utils',
50+
'/__fixtures__/',
51+
'\\.config\\.ts(x)?$',
52+
],
5153

5254
// Indicates which provider should be used to instrument code for coverage
5355
// coverageProvider: "v8",

jest/node/jest.config.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type { Config } from 'jest';
22
import nextJest from 'next/jest.js';
33

4-
const esModules = ['query-string', 'decode-uri-component','split-on-first','filter-obj']
4+
const esModules = [
5+
'query-string',
6+
'decode-uri-component',
7+
'split-on-first',
8+
'filter-obj',
9+
];
510

611
const createJestConfig = nextJest({
712
dir: './',
8-
})
13+
});
914
const config: Config = {
1015
displayName: {
1116
color: 'cyan',
@@ -17,16 +22,19 @@ const config: Config = {
1722
},
1823
rootDir: '../../',
1924
preset: 'ts-jest',
20-
setupFilesAfterEnv: ["<rootDir>/jest/node/jest.setup.ts"],
21-
testEnvironment: "node",
22-
testMatch: [
23-
"**/__tests__/**/*.node.ts"
25+
setupFilesAfterEnv: ['<rootDir>/jest/node/jest.setup.ts'],
26+
testEnvironment: 'node',
27+
testMatch: ['**/__tests__/**/*.node.ts'],
28+
coveragePathIgnorePatterns: [
29+
'/node_modules/',
30+
'src/test-utils',
31+
'/__fixtures__/',
32+
'\\.config\\.ts$',
2433
],
2534
transformIgnorePatterns: [`/node_modules/(?!(${esModules.join('|')})/)`],
2635
};
27-
2836

29-
const getCustomizedConfig= async () => {
37+
const getCustomizedConfig = async () => {
3038
const jestConfig = await createJestConfig(config)();
3139
return {
3240
...jestConfig,
@@ -35,7 +43,7 @@ const getCustomizedConfig= async () => {
3543
transformIgnorePatterns: jestConfig.transformIgnorePatterns?.filter(
3644
(ptn) => ptn !== '/node_modules/'
3745
),
38-
}
39-
}
46+
};
47+
};
4048
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
41-
export default getCustomizedConfig
49+
export default getCustomizedConfig;

0 commit comments

Comments
 (0)