Skip to content

Commit ba11eec

Browse files
committed
ci: run all tests with Babel 7 and Babel 8
1 parent 30ddd25 commit ba11eec

5 files changed

Lines changed: 54 additions & 172 deletions

File tree

.github/workflows/build.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,33 @@ env:
1515
jobs:
1616
tests:
1717
strategy:
18+
fail-fast: false
1819
matrix:
20+
babel: ["7", "8"]
1921
node: ["22.13.0", "24", "25", "26"]
2022
os: ["ubuntu"]
23+
exclude:
24+
# Babel 8 requires Node.js 22.18.0 or newer on the 22.x line.
25+
- babel: "8"
26+
node: "22.13.0"
2127
include:
28+
- os: ubuntu
29+
node: "22.18.0"
30+
babel: "8"
2231
- os: macos
2332
node: "24"
33+
babel: "7"
34+
- os: macos
35+
node: "24"
36+
babel: "8"
37+
- os: windows
38+
node: "24"
39+
babel: "7"
2440
- os: windows
2541
node: "24"
42+
babel: "8"
2643

27-
name: Tests (Node.js v${{ matrix.node }}, ${{ matrix.os }})
44+
name: Tests (Babel ${{ matrix.babel }}, Node.js v${{ matrix.node }}, ${{ matrix.os }})
2845
runs-on: ${{ matrix.os }}-latest
2946

3047
steps:
@@ -43,21 +60,29 @@ jobs:
4360
- name: Install dependencies
4461
run: pnpm install --frozen-lockfile
4562

63+
# Compile against the declared Babel 7 types before testing each runtime.
64+
- name: Build packages
65+
run: pnpm build
66+
67+
- name: Install Babel 8 runtime
68+
if: "${{ matrix.babel == '8' }}"
69+
run: pnpm --filter react-docgen add --save-exact @babel/core@8.0.1 @babel/traverse@8.0.4 @babel/types@8.0.4
70+
4671
- name: Unit tests with coverage
4772
if: "${{ matrix.node == env.NODE_VERSION }}"
48-
run: pnpm test -- --coverage
73+
run: pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test --coverage
4974

5075
- name: Unit tests
5176
if: "${{ matrix.node != env.NODE_VERSION }}"
52-
run: pnpm test
77+
run: pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test
5378

5479
- name: Upload coverage
5580
if: "${{ matrix.node == env.NODE_VERSION }}"
5681
continue-on-error: true
5782
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2
5883
with:
5984
parallel: true
60-
flag-name: test-${{ matrix.os }}
85+
flag-name: test-babel-${{ matrix.babel }}-${{ matrix.os }}
6186

6287
finish:
6388
needs: tests

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ We actively welcome your pull requests.
1414
4. Ensure the test suite passes.
1515
5. Make sure your code lints and typechecks.
1616

17+
## Babel compatibility tests
18+
19+
CI runs all library and CLI tests separately with Babel 7 and Babel 8.
20+
Both runs build with the declared Babel 7 dependencies first. The Babel 8
21+
run then replaces the runtime dependencies, including those used by CLI
22+
subprocesses. This checks runtime compatibility, not compilation with Babel 8 types.
23+
24+
To reproduce the Babel 8 run in a clean checkout:
25+
26+
```sh
27+
pnpm install --frozen-lockfile
28+
pnpm build
29+
pnpm --filter react-docgen add --save-exact @babel/core@8.0.1 @babel/traverse@8.0.4 @babel/types@8.0.4
30+
pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test --coverage
31+
```
32+
33+
The install command changes `packages/react-docgen/package.json` and
34+
`pnpm-lock.yaml`. After testing, restore those two files and run
35+
`pnpm install --frozen-lockfile` to return to Babel 7.
36+
1737
## Issues
1838
We use GitHub issues to track public bugs. Please ensure your description is
1939
clear and has sufficient instructions to be able to reproduce the issue.

packages/react-docgen/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,5 @@
5353
"doctrine": "^3.0.0",
5454
"resolve": "^1.22.1",
5555
"strip-indent": "^4.0.0"
56-
},
57-
"devDependencies": {
58-
"babel-core-8": "npm:@babel/core@8.0.1"
5956
}
6057
}

packages/react-docgen/src/__tests__/babel8-test.ts renamed to packages/react-docgen/src/__tests__/parserCompatibility-test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { parse } from '../main.js';
2-
import { expect, test, vi } from 'vitest';
2+
import { expect, test } from 'vitest';
33

4-
vi.mock('@babel/core', () => import('babel-core-8'));
5-
6-
test('parses components with Babel 8', () => {
4+
test('parses components', () => {
75
const result = parse('export function Button() { return <button />; }');
86

97
expect(result).toHaveLength(1);
108
});
119

12-
test('parses TypeScript function props with Babel 8', () => {
10+
test('parses TypeScript function props', () => {
1311
const result = parse(
1412
`export type MenuProps = {
1513
onOpenChange?: (open: boolean) => void;
@@ -37,7 +35,7 @@ test('parses TypeScript function props with Babel 8', () => {
3735
});
3836
});
3937

40-
test('parses generic arrow functions in TypeScript files with Babel 8', () => {
38+
test('parses generic arrow functions in TypeScript files', () => {
4139
const result = parse(
4240
`import React from 'react';
4341
@@ -54,7 +52,7 @@ test('parses generic arrow functions in TypeScript files with Babel 8', () => {
5452
expect(result).toHaveLength(1);
5553
});
5654

57-
test('parses mapped TypeScript props with Babel 8', () => {
55+
test('parses mapped TypeScript props', () => {
5856
const result = parse(
5957
`export type StatusFiltersProps<K extends string = string> = {
6058
statuses?: { readonly [Key in K]: number };

0 commit comments

Comments
 (0)