Skip to content

Commit

Permalink
fix: some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed Feb 14, 2019
1 parent b327450 commit d0f2231
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/cli/config/migrate.ts
Expand Up @@ -88,7 +88,7 @@ Visit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more inf

// check the extensions
if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && preset) {
const presetValue = dedupSort(preset.value.moduleFileExtensions).join('::')
const presetValue = dedupSort(preset.value.moduleFileExtensions || []).join('::')
const migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::')
if (presetValue === migratedValue) {
delete migratedConfig.moduleFileExtensions
Expand All @@ -100,7 +100,7 @@ Visit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more inf
}
// check the testMatch
else if (migratedConfig.testMatch && migratedConfig.testMatch.length && preset) {
const presetValue = dedupSort(preset.value.testMatch).join('::')
const presetValue = dedupSort(preset.value.testMatch || []).join('::')
const migratedValue = dedupSort(migratedConfig.testMatch).join('::')
if (presetValue === migratedValue) {
delete migratedConfig.testMatch
Expand Down
2 changes: 1 addition & 1 deletion src/config/config-set.spec.ts
Expand Up @@ -415,7 +415,7 @@ describe('versions', () => {
describe('with babel', () => {
it('should return correct version map', () => {
expect(createConfigSet({ tsJestConfig: { babelConfig: {} } }).versions).toEqual({
'@babel/core': '-',
'@babel/core': pkgVersion('@babel/core'),
'babel-jest': pkgVersion('babel-jest'),
jest: pkgVersion('jest'),
'ts-jest': myModule.version,
Expand Down
12 changes: 0 additions & 12 deletions src/config/create-jest-preset.spec.ts
Expand Up @@ -25,18 +25,6 @@ it('should return correct defaults when allowJs is true', () => {
it('should be able to use a base config', () => {
expect(createJestPreset(undefined, {})).toMatchInlineSnapshot(`
Object {
"moduleFileExtensions": Array [
"js",
"json",
"jsx",
"ts",
"tsx",
"node",
],
"testMatch": Array [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)",
],
"transform": Object {
"^.+\\\\.tsx?$": "ts-jest",
},
Expand Down
8 changes: 4 additions & 4 deletions src/config/create-jest-preset.ts
Expand Up @@ -12,8 +12,8 @@ const defaults = jestConfigPkg.defaults

export interface TsJestPresets {
transform: Record<string, string>
testMatch: string[]
moduleFileExtensions: string[]
testMatch: string[] | undefined
moduleFileExtensions: string[] | undefined
}

export interface CreateJestPresetOptions {
Expand All @@ -31,7 +31,7 @@ export function createJestPreset(
...from.transform,
[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest',
},
testMatch: from.testMatch || [],
moduleFileExtensions: from.moduleFileExtensions || [],
testMatch: from.testMatch || undefined,
moduleFileExtensions: from.moduleFileExtensions || undefined,
}
}
4 changes: 2 additions & 2 deletions src/util/importer.spec.ts
Expand Up @@ -116,8 +116,8 @@ describe('babelCore', () => {
})
it('should fail with correct error message', () => {
expect(() => new Importer().babelCore(fakers.importReason())).toThrowErrorMatchingInlineSnapshot(`
"Unable to load any of these modules: \\"@babel/core\\". [[BECAUSE]]. To fix it:
• for Babel 7: \`npm i -D babel-jest @babel/core\` (or \`yarn add --dev babel-jest @babel/core\`)"
"Unable to load the module \\"@babel/core\\". [[BECAUSE]] To fix it:
↳ install \\"@babel/core\\": \`npm i -D @babel/core\` (or \`yarn add --dev @babel/core\`)"
`)
})
})
12 changes: 1 addition & 11 deletions src/util/importer.ts
Expand Up @@ -47,17 +47,7 @@ export class Importer {
}

babelCore(why: ImportReasons): TBabelCore {
// the bridge will choose correct babel version
return this._import(why, 'babel-core', {
alternatives: ['@babel/core'],
installTip: [
// as in https://github.com/facebook/jest/tree/master/packages/babel-jest
{
label: 'for Babel 7',
module: `babel-jest @babel/core`,
},
],
})
return this._import(why, '@babel/core')
}

typescript(why: ImportReasons, which: string): TTypeScript {
Expand Down

0 comments on commit d0f2231

Please sign in to comment.