Skip to content

Commit

Permalink
chore(dev-infra): create TsJestPresets type based on Jest `InitialO…
Browse files Browse the repository at this point in the history
…ptions` type (#1675)
  • Loading branch information
ahnpnl committed May 24, 2020
1 parent a1d425c commit 8f2b2dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
41 changes: 22 additions & 19 deletions src/config/create-jest-preset.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { createJestPreset } from './create-jest-preset'

it('should return correct defaults when allowJs is false or not set', () => {
const withoutJs = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
}
expect(createJestPreset()).toEqual(withoutJs)
expect(createJestPreset({ allowJs: false })).toEqual(withoutJs)
})
describe('create-jest-preset', () => {
it('should return correct defaults when allowJs is false or not set', () => {
const withoutJs = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
}
expect(createJestPreset()).toEqual(withoutJs)
expect(createJestPreset({ allowJs: false })).toEqual(withoutJs)
})

it('should return correct defaults when allowJs is true', () => {
expect(createJestPreset({ allowJs: true })).toEqual({
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
it('should return correct defaults when allowJs is true', () => {
expect(createJestPreset({ allowJs: true })).toEqual({
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
})
})
})

it('should be able to use a base config', () => {
expect(createJestPreset(undefined, {})).toMatchInlineSnapshot(`
it('should be able to use a base config', () => {
expect(createJestPreset(undefined, {})).toMatchInlineSnapshot(`
Object {
"transform": Object {
"^.+\\\\.tsx?$": "ts-jest",
},
}
`)
expect(createJestPreset(undefined, { testMatch: ['foo'], moduleFileExtensions: ['bar'], transform: { foo: 'bar' } }))
.toMatchInlineSnapshot(`
expect(
createJestPreset(undefined, { testMatch: ['foo'], moduleFileExtensions: ['bar'], transform: { foo: 'bar' } }),
).toMatchInlineSnapshot(`
Object {
"moduleFileExtensions": Array [
"bar",
Expand All @@ -41,4 +43,5 @@ Object {
},
}
`)
})
})
7 changes: 2 additions & 5 deletions src/config/create-jest-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { rootLogger } from '../util/logger'

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

export interface TsJestPresets {
transform: Config.InitialOptions['transform']
testMatch?: string[]
moduleFileExtensions?: string[]
}
export type TsJestPresets = Pick<Config.InitialOptions, 'moduleFileExtensions' | 'transform' | 'testMatch'>

export interface CreateJestPresetOptions {
allowJs?: boolean
Expand All @@ -19,6 +15,7 @@ export function createJestPreset(
from: Config.InitialOptions = {},
): TsJestPresets {
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files')

return {
transform: {
...from.transform,
Expand Down

0 comments on commit 8f2b2dc

Please sign in to comment.