Skip to content

Commit 1e0b2ce

Browse files
authored
refactor(config): remove support for astTransformers string array (#2129)
BREAKING CHANGE: One is defining ast transformers in `jest.config.js`/`package.json` should change to ``` // jest.config.js module.exports = { //... globals: { 'ts-jest': { astTransformers: { before: ['your_before_transformer_path'], after: ['your_after_transformer_path'], afterDeclarations: ['your_afterDeclarations_transformer_path'], } } } } ``` or ``` // package.json { "jest": { "globals": { "ts-jest": { "astTransformers": { "before": ["your_before_transformer_path"], "after": ["your_after_transformer_path"], "afterDeclarations": ["your_afterDeclarations_transformer_path"] } } } } } ```
1 parent 5bbfd06 commit 1e0b2ce

6 files changed

Lines changed: 24 additions & 138 deletions

File tree

e2e/__tests__/__snapshots__/logger.test.ts.snap

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -127,63 +127,6 @@ Array [
127127
]
128128
`;
129129
130-
exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "default" 1`] = `
131-
√ jest
132-
↳ exit code: 0
133-
===[ STDOUT ]===================================================================
134-
135-
===[ STDERR ]===================================================================
136-
ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers
137-
PASS ./Hello.spec.ts
138-
Hello Class
139-
√ should create a new Hello
140-
141-
Test Suites: 1 passed, 1 total
142-
Tests: 1 passed, 1 total
143-
Snapshots: 0 total
144-
Time: XXs
145-
Ran all test suites.
146-
================================================================================
147-
`;
148-
149-
exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7" 1`] = `
150-
√ jest
151-
↳ exit code: 0
152-
===[ STDOUT ]===================================================================
153-
154-
===[ STDERR ]===================================================================
155-
ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers
156-
PASS ./Hello.spec.ts
157-
Hello Class
158-
√ should create a new Hello
159-
160-
Test Suites: 1 passed, 1 total
161-
Tests: 1 passed, 1 total
162-
Snapshots: 0 total
163-
Time: XXs
164-
Ran all test suites.
165-
================================================================================
166-
`;
167-
168-
exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7-string-config" 1`] = `
169-
√ jest
170-
↳ exit code: 0
171-
===[ STDOUT ]===================================================================
172-
173-
===[ STDERR ]===================================================================
174-
ts-jest[config] (WARN) The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers
175-
PASS ./Hello.spec.ts
176-
Hello Class
177-
√ should create a new Hello
178-
179-
Test Suites: 1 passed, 1 total
180-
Tests: 1 passed, 1 total
181-
Snapshots: 0 total
182-
Time: XXs
183-
Ran all test suites.
184-
================================================================================
185-
`;
186-
187130
exports[`ts-jest logging deprecation warning with packageJson config should pass using template "default" 1`] = `
188131
√ jest
189132
↳ exit code: 0

e2e/__tests__/logger.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ describe('ts-jest logging', () => {
9292
}
9393

9494
describe('deprecation warning', () => {
95-
describe('with astTransformers config as string array', () => {
96-
const testCase = configureTestCase('simple', {
97-
tsJestConfig: {
98-
astTransformers: []
99-
}
100-
})
101-
102-
testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
103-
it(testLabel, () => {
104-
const result = runTest()
105-
expect(result.status).toBe(0)
106-
expect(result).toMatchSnapshot()
107-
})
108-
})
109-
})
110-
11195
describe('with packageJson config', () => {
11296
const testCase = configureTestCase('simple', {
11397
tsJestConfig: {

src/config/config-set.spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ describe('compilerModule', () => {
154154
}) // compilerModule
155155

156156
describe('customTransformers', () => {
157-
const logger = testing.createLoggerMock()
158-
159157
it.each([
160158
{},
161159
{
@@ -189,29 +187,6 @@ describe('customTransformers', () => {
189187

190188
expect(cs.customTransformers).toMatchSnapshot()
191189
})
192-
193-
it('should return an object containing all resolved transformers when astTransformers config is an array', () => {
194-
expect(
195-
createConfigSet({
196-
jestConfig: {
197-
rootDir: 'src',
198-
cwd: 'src',
199-
} as any,
200-
logger,
201-
tsJestConfig: {
202-
astTransformers: ['<rootDir>/__mocks__/dummy-transformer'],
203-
},
204-
resolve: null,
205-
}).customTransformers,
206-
).toMatchInlineSnapshot(`
207-
Object {
208-
"before": Array [
209-
[Function],
210-
[Function],
211-
],
212-
}
213-
`)
214-
})
215190
})
216191

217192
describe('tsCompiler', () => {

src/config/config-set.ts

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -291,49 +291,34 @@ export class ConfigSet {
291291
before: [hoisting(this)],
292292
}
293293
if (astTransformers) {
294-
if (Array.isArray(astTransformers)) {
295-
this.logger.warn(Deprecations.AstTransformerArrayConfig)
294+
const resolveTransformers = (transformers: (string | AstTransformer)[]) =>
295+
transformers.map((transformer) => {
296+
let transformerPath: string
297+
if (typeof transformer === 'string') {
298+
transformerPath = this.resolvePath(transformer, { nodeResolve: true })
296299

297-
this.customTransformers = {
298-
before: [
299-
...this.customTransformers.before,
300-
...astTransformers.map((transformer) => {
301-
const transformerPath = this.resolvePath(transformer, { nodeResolve: true })
302-
303-
return require(transformerPath).factory(this)
304-
}),
305-
],
306-
}
307-
} else {
308-
const resolveTransformers = (transformers: (string | AstTransformer)[]) =>
309-
transformers.map((transformer) => {
310-
let transformerPath: string
311-
if (typeof transformer === 'string') {
312-
transformerPath = this.resolvePath(transformer, { nodeResolve: true })
313-
314-
return require(transformerPath).factory(this)
315-
} else {
316-
transformerPath = this.resolvePath(transformer.path, { nodeResolve: true })
300+
return require(transformerPath).factory(this)
301+
} else {
302+
transformerPath = this.resolvePath(transformer.path, { nodeResolve: true })
317303

318-
return require(transformerPath).factory(this, transformer.options)
319-
}
320-
})
321-
if (astTransformers.before) {
322-
this.customTransformers = {
323-
before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)],
304+
return require(transformerPath).factory(this, transformer.options)
324305
}
306+
})
307+
if (astTransformers.before) {
308+
this.customTransformers = {
309+
before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)],
325310
}
326-
if (astTransformers.after) {
327-
this.customTransformers = {
328-
...this.customTransformers,
329-
after: resolveTransformers(astTransformers.after),
330-
}
311+
}
312+
if (astTransformers.after) {
313+
this.customTransformers = {
314+
...this.customTransformers,
315+
after: resolveTransformers(astTransformers.after),
331316
}
332-
if (astTransformers.afterDeclarations) {
333-
this.customTransformers = {
334-
...this.customTransformers,
335-
afterDeclarations: resolveTransformers(astTransformers.afterDeclarations),
336-
}
317+
}
318+
if (astTransformers.afterDeclarations) {
319+
this.customTransformers = {
320+
...this.customTransformers,
321+
afterDeclarations: resolveTransformers(astTransformers.afterDeclarations),
337322
}
338323
}
339324
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface TsJestGlobalOptions {
8383
/**
8484
* Custom transformers (mostly used by jest presets)
8585
*/
86-
astTransformers?: string[] | ConfigCustomTransformer
86+
astTransformers?: ConfigCustomTransformer
8787

8888
/**
8989
* TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:

src/utils/messages.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const enum Deprecations {
3535
ConfigOption = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.',
3636
ConfigOptionWithNote = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.\n ↳ {{note}}',
3737
ConfigOptionUseBabelRcNote = 'See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845',
38-
AstTransformerArrayConfig = 'The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers',
3938
PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`',
4039
}
4140

0 commit comments

Comments
 (0)