diff --git a/scripts/bundles/helpers/jest/jest-preset.js b/scripts/bundles/helpers/jest/jest-preset.js index a7d5b024e7f..683c647ae3b 100644 --- a/scripts/bundles/helpers/jest/jest-preset.js +++ b/scripts/bundles/helpers/jest/jest-preset.js @@ -3,8 +3,12 @@ const testingDir = __dirname; const rootDir = path.join(testingDir, '..'); const internalDir = path.join(rootDir, 'internal'); +// NOTE: if you change this, also change compiler/transpile.ts +const moduleExtensions = ['ts', 'tsx', 'mjs', 'js', 'jsx']; +const moduleExtensionRegexp = '(' + moduleExtensions.join('|') + ')'; + module.exports = { - moduleFileExtensions: ['ts', 'tsx', 'js', 'mjs', 'jsx', 'json', 'd.ts'], + moduleFileExtensions: [...moduleExtensions, 'json', 'd.ts'], moduleNameMapper: { '^@stencil/core/cli$': path.join(rootDir, 'cli', 'index.js'), '^@stencil/core/compiler$': path.join(rootDir, 'compiler', 'stencil.js'), @@ -21,8 +25,8 @@ module.exports = { testEnvironment: path.join(testingDir, 'jest-environment.js'), testPathIgnorePatterns: ['/.cache', '/.stencil', '/.vscode', '/dist', '/node_modules', '/www'], maxConcurrency: 1, - testRegex: '(/__tests__/.*|\\.?(test|spec))\\.(tsx?|ts?|jsx?|js?)$', + testRegex: '(/__tests__/.*|\\.?(test|spec))\\.' + moduleExtensionRegexp + '$', transform: { - '^.+\\.(ts|tsx|jsx|css)$': path.join(testingDir, 'jest-preprocessor.js'), + ['^.+\\.' + moduleExtensionRegexp + '$']: path.join(testingDir, 'jest-preprocessor.js'), }, }; diff --git a/src/compiler/transpile.ts b/src/compiler/transpile.ts index 57c92265ce5..f2c8a23698a 100644 --- a/src/compiler/transpile.ts +++ b/src/compiler/transpile.ts @@ -124,7 +124,7 @@ const transpileJson = (results: TranspileResults) => { results.map = { mappings: '' }; }; -// @todo: could/should this be borrowed from either tsconfig's allowJs or jest config's ? +// NOTE: if you change this, also change scripts/bundles/helpers/jest/jest-preset.js const shouldTranspileModule = (ext: string) => ['tsx', 'ts', 'mjs', 'jsx', 'js'].includes(ext); export const compile = (code: string, opts: any = {}): Promise => {