Skip to content

Commit 340a305

Browse files
authored
feat(config): support custom AST transformers written in TypeScript (#3063)
Closes #2831
1 parent 3649e73 commit 340a305

40 files changed

Lines changed: 611 additions & 132 deletions

e2e/__tests__/ast-transformers.test.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import path from 'path'
22

3+
import execa from 'execa'
4+
35
import { json as runWithJson } from '../run-jest'
46
import { runNpmInstall } from '../utils'
57

8+
const { createBundle } = require('../../scripts/lib/bundle')
9+
10+
const AST_TRANSFORMERS_DIR_NAME = 'ast-transformers'
11+
612
const executeTest = (testDir: string): void => {
713
test(`successfully runs the tests inside ${testDir} with isolatedModules: false`, () => {
814
const { json } = runWithJson(testDir)
@@ -18,15 +24,56 @@ const executeTest = (testDir: string): void => {
1824
}
1925

2026
describe('path-mapping', () => {
21-
executeTest('ast-transformers/path-mapping')
27+
executeTest(`${AST_TRANSFORMERS_DIR_NAME}/path-mapping`)
2228
})
2329

24-
const TRANSFORM_OPT_DIR_NAME = 'transformer-options'
25-
2630
describe('transformer-options', () => {
31+
const TRANSFORM_OPT_DIR_NAME = 'transformer-options'
32+
2733
beforeAll(() => {
28-
runNpmInstall(path.join(__dirname, '..', 'ast-transformers', TRANSFORM_OPT_DIR_NAME))
34+
runNpmInstall(path.join(__dirname, '..', AST_TRANSFORMERS_DIR_NAME, TRANSFORM_OPT_DIR_NAME))
35+
})
36+
37+
test(`successfully runs the tests inside ${AST_TRANSFORMERS_DIR_NAME}/${TRANSFORM_OPT_DIR_NAME}`, () => {
38+
const { json } = runWithJson(`${AST_TRANSFORMERS_DIR_NAME}/${TRANSFORM_OPT_DIR_NAME}`)
39+
40+
expect(json.success).toBe(true)
2941
})
42+
})
43+
44+
describe('hoist-jest', () => {
45+
const NON_TS_FACTORY_DIR_NAME = 'non-ts-factory'
46+
const TS_FACTORY_DIR_NAME = 'ts-factory'
47+
48+
describe('non-ts-factory', () => {
49+
const DIR = path.resolve(__dirname, '..', AST_TRANSFORMERS_DIR_NAME, 'hoist-jest', NON_TS_FACTORY_DIR_NAME)
3050

31-
executeTest(`ast-transformers/${TRANSFORM_OPT_DIR_NAME}`)
51+
beforeAll(() => {
52+
runNpmInstall(DIR)
53+
const bundle = createBundle()
54+
execa.sync('npm', ['install', '--no-package-lock', '--no-shrinkwrap', '--no-save', bundle], {
55+
cwd: DIR,
56+
})
57+
})
58+
59+
executeTest(`${AST_TRANSFORMERS_DIR_NAME}/hoist-jest/${NON_TS_FACTORY_DIR_NAME}`)
60+
})
61+
62+
describe('ts-factory', () => {
63+
beforeAll(() => {
64+
runNpmInstall(path.resolve(__dirname, '..', AST_TRANSFORMERS_DIR_NAME, 'hoist-jest', TS_FACTORY_DIR_NAME))
65+
})
66+
67+
executeTest(`${AST_TRANSFORMERS_DIR_NAME}/hoist-jest/${TS_FACTORY_DIR_NAME}`)
68+
})
69+
})
70+
71+
describe('transformer-in-ts', () => {
72+
const TRANSFORMER_IN_TS_DIR_NAME = `${AST_TRANSFORMERS_DIR_NAME}/transformer-in-ts`
73+
74+
test(`successfully runs the tests inside ${TRANSFORMER_IN_TS_DIR_NAME}`, () => {
75+
const { json } = runWithJson(TRANSFORMER_IN_TS_DIR_NAME)
76+
77+
expect(json.success).toBe(true)
78+
})
3279
})

e2e/__tests__/hoist-jest.test.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

e2e/hoist-jest/__test_modules__/__mocks__/jest-backticks.js renamed to e2e/ast-transformers/hoist-jest/__test_modules__/__mocks__/jest-backticks.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)