|
| 1 | +import { runJest } from '../run-jest' |
| 2 | +import { getFixturePath, runCommand, runNpmCi } from '../utils' |
| 3 | + |
| 4 | +const fixtureName = 'babel-8-compat' |
| 5 | +const fixturePath = getFixturePath(fixtureName) |
| 6 | +const nodeMajor = Number(process.versions.node.split('.')[0]) |
| 7 | +const supportsBabel8 = nodeMajor >= 22 |
| 8 | + |
| 9 | +const itWithBabel8Node = (...args: Parameters<typeof it>) => { |
| 10 | + if (supportsBabel8) { |
| 11 | + // eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests |
| 12 | + return it(...args) |
| 13 | + } |
| 14 | + |
| 15 | + // eslint-disable-next-line jest/valid-title,jest/expect-expect,jest/no-disabled-tests |
| 16 | + return it.skip(...args) |
| 17 | +} |
| 18 | + |
| 19 | +beforeAll(async () => { |
| 20 | + if (supportsBabel8) { |
| 21 | + await runNpmCi(fixtureName) |
| 22 | + } |
| 23 | +}) |
| 24 | + |
| 25 | +describe('Babel 8 compatibility', () => { |
| 26 | + itWithBabel8Node('uses Babel 8 from the fixture', async () => { |
| 27 | + const result = await runCommand( |
| 28 | + process.execPath, |
| 29 | + ['-p', "require('@babel/core/package.json').version"], |
| 30 | + fixturePath, |
| 31 | + ) |
| 32 | + |
| 33 | + // eslint-disable-next-line jest/no-standalone-expect |
| 34 | + expect(result).toMatchObject({ exitCode: 0 }) |
| 35 | + // eslint-disable-next-line jest/no-standalone-expect |
| 36 | + expect(result.stdout.trim()).toMatch(/^8\./) |
| 37 | + }) |
| 38 | + |
| 39 | + for (const configFile of ['jest-compiler-cjs.config.ts', 'jest-compiler-esm.config.ts']) { |
| 40 | + itWithBabel8Node(`runs ${configFile} with Babel 8`, async () => { |
| 41 | + const result = await runJest(fixtureName, configFile) |
| 42 | + |
| 43 | + // eslint-disable-next-line jest/no-standalone-expect |
| 44 | + expect(result).toMatchObject({ exitCode: 0 }) |
| 45 | + }) |
| 46 | + } |
| 47 | +}) |
0 commit comments