Skip to content

Commit 2364906

Browse files
authored
Merge pull request #7 from OzanAlpay/allow-override-jest-config
Fix: Allow overriding Jest configuration in createJestStencilPreset function
2 parents da31405 + b21e181 commit 2364906

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/preset.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,30 @@ const moduleExtensionRegexp = `(${moduleExtensions.join('|')})`;
1010
/**
1111
* Create a Jest preset configuration for Stencil components.
1212
*/
13-
export function createJestStencilPreset(
14-
options: {
15-
rootDir?: string;
16-
moduleNameMapper?: Record<string, string>;
17-
} = {},
18-
): Config.InitialOptions {
13+
export function createJestStencilPreset(options: Config.InitialOptions = {}): Config.InitialOptions {
1914
const preset: Config.InitialOptions = {
2015
testEnvironment: 'node',
2116
moduleFileExtensions: [...moduleExtensions, 'json', 'd.ts'],
22-
moduleNameMapper: {
23-
'^@stencil/core/testing$': 'jest-stencil-runner',
24-
'^@stencil/core$': '@stencil/core',
25-
...options.moduleNameMapper,
26-
},
2717
setupFilesAfterEnv: ['jest-stencil-runner/setup'],
2818
testPathIgnorePatterns: ['/.cache', '/.stencil', '/.vscode', '/dist', '/node_modules', '/www'],
29-
testRegex: `${String.raw`(/__tests__/.*|\.?(test|spec))\.` + moduleExtensionRegexp}$`,
3019
transform: {
3120
'^.+\\.(ts|tsx|jsx|js|mjs|css)(\\?.*)?$': path.resolve(__dirname, 'preprocessor.js'),
3221
},
3322
watchPathIgnorePatterns: [String.raw`^.+\.d\.ts$`],
3423
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts', '!src/**/*.spec.{ts,tsx}', '!src/**/*.e2e.{ts,tsx}'],
3524
testTimeout: 30000,
3625
snapshotSerializers: [path.resolve(__dirname, 'snapshot.js')],
26+
...options,
27+
moduleNameMapper: {
28+
'^@stencil/core/testing$': 'jest-stencil-runner',
29+
'^@stencil/core$': '@stencil/core',
30+
...options.moduleNameMapper,
31+
},
3732
};
3833

34+
if (!options.testMatch && !options.testRegex) {
35+
preset.testRegex = `${String.raw`(/__tests__/.*|\.?(test|spec))\.` + moduleExtensionRegexp}$`;
36+
}
37+
3938
return preset;
4039
}

0 commit comments

Comments
 (0)