diff --git a/src/preset.ts b/src/preset.ts index 66364f7..2c5f677 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -10,23 +10,12 @@ const moduleExtensionRegexp = `(${moduleExtensions.join('|')})`; /** * Create a Jest preset configuration for Stencil components. */ -export function createJestStencilPreset( - options: { - rootDir?: string; - moduleNameMapper?: Record; - } = {}, -): Config.InitialOptions { +export function createJestStencilPreset(options: Config.InitialOptions = {}): Config.InitialOptions { const preset: Config.InitialOptions = { testEnvironment: 'node', moduleFileExtensions: [...moduleExtensions, 'json', 'd.ts'], - moduleNameMapper: { - '^@stencil/core/testing$': 'jest-stencil-runner', - '^@stencil/core$': '@stencil/core', - ...options.moduleNameMapper, - }, setupFilesAfterEnv: ['jest-stencil-runner/setup'], testPathIgnorePatterns: ['/.cache', '/.stencil', '/.vscode', '/dist', '/node_modules', '/www'], - testRegex: `${String.raw`(/__tests__/.*|\.?(test|spec))\.` + moduleExtensionRegexp}$`, transform: { '^.+\\.(ts|tsx|jsx|js|mjs|css)(\\?.*)?$': path.resolve(__dirname, 'preprocessor.js'), }, @@ -34,7 +23,17 @@ export function createJestStencilPreset( collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts', '!src/**/*.spec.{ts,tsx}', '!src/**/*.e2e.{ts,tsx}'], testTimeout: 30000, snapshotSerializers: [path.resolve(__dirname, 'snapshot.js')], + ...options, + moduleNameMapper: { + '^@stencil/core/testing$': 'jest-stencil-runner', + '^@stencil/core$': '@stencil/core', + ...options.moduleNameMapper, + }, }; + if (!options.testMatch && !options.testRegex) { + preset.testRegex = `${String.raw`(/__tests__/.*|\.?(test|spec))\.` + moduleExtensionRegexp}$`; + } + return preset; }