Skip to content

Commit

Permalink
fix(test): transitive module dependencies with js extensions will be …
Browse files Browse the repository at this point in the history
…processed (ionic-team#2178)
  • Loading branch information
chrisdarroch committed Jul 7, 2020
1 parent 959faaf commit 167cf00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions scripts/bundles/helpers/jest/jest-preset.js
Expand Up @@ -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'),
Expand All @@ -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'),
},
};
2 changes: 1 addition & 1 deletion src/compiler/transpile.ts
Expand Up @@ -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<any> => {
Expand Down

0 comments on commit 167cf00

Please sign in to comment.