/
backports.spec.ts
56 lines (39 loc) · 1.64 KB
/
backports.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { inspect } from 'util'
import { testing } from 'bs-logger'
import set from 'lodash/set'
import { backportJestConfig } from './backports'
const logger = testing.createLoggerMock()
const logTarget = logger.target
beforeEach(() => {
logTarget.clear()
})
describe('backportJestConfig', () => {
const makeTestsFor = (oldPath: string, values: unknown[]) => {
values.forEach((val) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let original: any
beforeEach(() => {
original = {}
set(original, oldPath, val)
})
describe(`with "${oldPath}" set to ${inspect(val)}`, () => {
it('should warn the user', () => {
backportJestConfig(logger, original)
expect(logTarget.lines.warn).toMatchSnapshot()
}) // should warn the user
it('should have changed the config correctly', () => {
expect(original).toMatchSnapshot('before')
expect(backportJestConfig(logger, original)).toMatchSnapshot('migrated')
}) // should have changed the config
}) // with xxx set to yyy
}) // for
} // makeTestsFor
makeTestsFor('globals.__TS_CONFIG__', [{ foo: 'bar' }])
makeTestsFor('globals.__TRANSFORM_HTML__', [true, false])
makeTestsFor('globals.ts-jest.tsConfigFile', ['tsconfig.build.json'])
makeTestsFor('globals.ts-jest.tsConfig', ['tsconfig.build.json'])
makeTestsFor('globals.ts-jest.enableTsDiagnostics', [true, false, '\\.spec\\.ts$'])
makeTestsFor('globals.ts-jest.useBabelrc', [true, false])
makeTestsFor('globals.ts-jest.typeCheck', [true, false])
makeTestsFor('globals.ts-jest.skipBabel', [true, false])
})