Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(config): remove support for astTransformers string array #2129

Merged
merged 2 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 0 additions & 57 deletions e2e/__tests__/__snapshots__/logger.test.ts.snap
Expand Up @@ -127,63 +127,6 @@ Array [
]
`;

exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "default" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
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
PASS ./Hello.spec.ts
Hello Class
√ should create a new Hello

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
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
PASS ./Hello.spec.ts
Hello Class
√ should create a new Hello

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`ts-jest logging deprecation warning with astTransformers config as string array should pass using template "with-babel-7-string-config" 1`] = `
√ jest
↳ exit code: 0
===[ STDOUT ]===================================================================

===[ STDERR ]===================================================================
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
PASS ./Hello.spec.ts
Hello Class
√ should create a new Hello

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: XXs
Ran all test suites.
================================================================================
`;

exports[`ts-jest logging deprecation warning with packageJson config should pass using template "default" 1`] = `
√ jest
↳ exit code: 0
Expand Down
16 changes: 0 additions & 16 deletions e2e/__tests__/logger.test.ts
Expand Up @@ -92,22 +92,6 @@ describe('ts-jest logging', () => {
}

describe('deprecation warning', () => {
describe('with astTransformers config as string array', () => {
const testCase = configureTestCase('simple', {
tsJestConfig: {
astTransformers: []
}
})

testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot()
})
})
})

describe('with packageJson config', () => {
const testCase = configureTestCase('simple', {
tsJestConfig: {
Expand Down
25 changes: 0 additions & 25 deletions src/config/config-set.spec.ts
Expand Up @@ -154,8 +154,6 @@ describe('compilerModule', () => {
}) // compilerModule

describe('customTransformers', () => {
const logger = testing.createLoggerMock()

it.each([
{},
{
Expand Down Expand Up @@ -189,29 +187,6 @@ describe('customTransformers', () => {

expect(cs.customTransformers).toMatchSnapshot()
})

it('should return an object containing all resolved transformers when astTransformers config is an array', () => {
expect(
createConfigSet({
jestConfig: {
rootDir: 'src',
cwd: 'src',
} as any,
logger,
tsJestConfig: {
astTransformers: ['<rootDir>/__mocks__/dummy-transformer'],
},
resolve: null,
}).customTransformers,
).toMatchInlineSnapshot(`
Object {
"before": Array [
[Function],
[Function],
],
}
`)
})
})

describe('tsCompiler', () => {
Expand Down
61 changes: 23 additions & 38 deletions src/config/config-set.ts
Expand Up @@ -291,49 +291,34 @@ export class ConfigSet {
before: [hoisting(this)],
}
if (astTransformers) {
if (Array.isArray(astTransformers)) {
this.logger.warn(Deprecations.AstTransformerArrayConfig)
const resolveTransformers = (transformers: (string | AstTransformer)[]) =>
transformers.map((transformer) => {
let transformerPath: string
if (typeof transformer === 'string') {
transformerPath = this.resolvePath(transformer, { nodeResolve: true })

this.customTransformers = {
before: [
...this.customTransformers.before,
...astTransformers.map((transformer) => {
const transformerPath = this.resolvePath(transformer, { nodeResolve: true })

return require(transformerPath).factory(this)
}),
],
}
} else {
const resolveTransformers = (transformers: (string | AstTransformer)[]) =>
transformers.map((transformer) => {
let transformerPath: string
if (typeof transformer === 'string') {
transformerPath = this.resolvePath(transformer, { nodeResolve: true })

return require(transformerPath).factory(this)
} else {
transformerPath = this.resolvePath(transformer.path, { nodeResolve: true })
return require(transformerPath).factory(this)
} else {
transformerPath = this.resolvePath(transformer.path, { nodeResolve: true })

return require(transformerPath).factory(this, transformer.options)
}
})
if (astTransformers.before) {
this.customTransformers = {
before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)],
return require(transformerPath).factory(this, transformer.options)
}
})
if (astTransformers.before) {
this.customTransformers = {
before: [...this.customTransformers.before, ...resolveTransformers(astTransformers.before)],
}
if (astTransformers.after) {
this.customTransformers = {
...this.customTransformers,
after: resolveTransformers(astTransformers.after),
}
}
if (astTransformers.after) {
this.customTransformers = {
...this.customTransformers,
after: resolveTransformers(astTransformers.after),
}
if (astTransformers.afterDeclarations) {
this.customTransformers = {
...this.customTransformers,
afterDeclarations: resolveTransformers(astTransformers.afterDeclarations),
}
}
if (astTransformers.afterDeclarations) {
this.customTransformers = {
...this.customTransformers,
afterDeclarations: resolveTransformers(astTransformers.afterDeclarations),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -83,7 +83,7 @@ export interface TsJestGlobalOptions {
/**
* Custom transformers (mostly used by jest presets)
*/
astTransformers?: string[] | ConfigCustomTransformer
astTransformers?: ConfigCustomTransformer

/**
* TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
Expand Down
1 change: 0 additions & 1 deletion src/utils/messages.ts
Expand Up @@ -35,7 +35,6 @@ export const enum Deprecations {
ConfigOption = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.',
ConfigOptionWithNote = '"[jest-config].{{oldPath}}" is deprecated, use "[jest-config].{{newPath}}" instead.\n ↳ {{note}}',
ConfigOptionUseBabelRcNote = 'See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845',
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',
PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`',
}

Expand Down