Skip to content

Commit

Permalink
fix: cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed Feb 14, 2019
1 parent d0f2231 commit 1d67101
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 34 deletions.
27 changes: 12 additions & 15 deletions src/cli/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,6 @@ Jest configuration written to "${normalize('/foo/bar/package.json')}".
"transform": {
"^.+\\\\.[tj]sx?$": "ts-jest"
},
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)+(spec|test).js?(x)",
"**/__tests__/**/*.ts?(x)",
"**/?(*.)+(spec|test).ts?(x)"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node",
"ts",
"tsx"
],
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.test.json",
Expand Down Expand Up @@ -387,7 +373,7 @@ Migrated Jest configuration:
() => ({
jest: {
globals: { __TS_CONFIG__: { target: 'es6' } },
moduleFileExtensions: ['js', 'json', 'tsx', 'jsx', 'node', 'ts'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
testMatch: [
'**/__tests__/**/*.js?(x)',
'**/?(*.)+(spec|test).js?(x)',
Expand All @@ -408,6 +394,17 @@ Migrated Jest configuration:
}
}
},
\\"moduleFileExtensions\\": [
\\"js\\",
\\"ts\\",
\\"tsx\\"
],
\\"testMatch\\": [
\\"**/?(*.)+(spec|test).js?(x)\\",
\\"**/?(*.)+(spec|test).ts?(x)\\",
\\"**/__tests__/**/*.js?(x)\\",
\\"**/__tests__/**/*.ts?(x)\\"
],
\\"preset\\": \\"ts-jest\\"
}
"
Expand Down
1 change: 0 additions & 1 deletion src/cli/config/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger */) =>
content.push(` },`)
content.push(` },`)
}

content.push('};')

// join all together
Expand Down
4 changes: 0 additions & 4 deletions src/config/create-jest-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { createJestPreset } from './create-jest-preset'

it('should return correct defaults when allowJs is false or not set', () => {
const withoutJs = {
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
Expand All @@ -14,8 +12,6 @@ it('should return correct defaults when allowJs is false or not set', () => {

it('should return correct defaults when allowJs is true', () => {
expect(createJestPreset({ allowJs: true })).toEqual({
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
Expand Down
19 changes: 5 additions & 14 deletions src/config/create-jest-preset.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import * as TJestConfigPkg from 'jest-config'

import { rootLogger } from '../util/logger'

import { getJestConfigPkg } from './jest-config-resolver'

const logger = rootLogger.child({ namespace: 'jest-preset' })

const jestConfigPkg: typeof TJestConfigPkg = getJestConfigPkg(logger)

const defaults = jestConfigPkg.defaults

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

export interface CreateJestPresetOptions {
Expand All @@ -22,16 +14,15 @@ export interface CreateJestPresetOptions {

export function createJestPreset(
{ allowJs = false }: CreateJestPresetOptions = {},
from?: jest.InitialOptions,
from: jest.InitialOptions = {},
): TsJestPresets {
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files')
from = { ...defaults, ...from }
return {
transform: {
...from.transform,
[allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest',
},
testMatch: from.testMatch || undefined,
moduleFileExtensions: from.moduleFileExtensions || undefined,
...(from.testMatch ? { testMatch: from.testMatch } : undefined),
...(from.moduleFileExtensions ? { moduleFileExtensions: from.moduleFileExtensions } : undefined),
}
}

0 comments on commit 1d67101

Please sign in to comment.