Skip to content

Commit 2c8cdb6

Browse files
authored
feat!: migrate react-docgen to ESM and vitest (#688)
BREAKING CHANGE: react-docgen is now an ES module. Please read [this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) BREAKING CHANGE: The lowest supported version of Node.js is now 14.17.0
1 parent 2f3f195 commit 2c8cdb6

File tree

180 files changed

+3462
-3838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+3462
-3838
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,5 @@ module.exports = {
5757
'@typescript-eslint/sort-type-union-intersection-members': 'error',
5858
},
5959
},
60-
{
61-
files: '**/__tests__/*-test.js',
62-
env: { jest: true },
63-
},
6460
],
6561
};

.github/workflows/build.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
tests:
1717
strategy:
1818
matrix:
19-
node: ['14.15.0', '16', '18']
19+
node: ['14.17.0', '16', '18']
2020
os: ['ubuntu']
2121
include:
2222
- os: macos
@@ -37,19 +37,19 @@ jobs:
3737
node-version: ${{ matrix.node }}
3838
cache: 'yarn'
3939

40-
- uses: actions/cache@v3
41-
name: Cache jest cache
42-
with:
43-
path: .jest-cache
44-
key: ${{ runner.os }}-${{ matrix.node }}-jest
45-
4640
- name: Install dependencies
4741
run: yarn install --immutable
4842

43+
- name: Unit tests with coverage
44+
if: '${{ matrix.node == env.NODE_VERSION }}'
45+
run: yarn test --coverage
46+
4947
- name: Unit tests
50-
run: yarn test:ci
48+
if: '${{ matrix.node != env.NODE_VERSION }}'
49+
run: yarn test
5150

5251
- name: Upload coverage to Codecov
52+
if: '${{ matrix.node == env.NODE_VERSION }}'
5353
uses: codecov/codecov-action@v3
5454

5555
lint:
@@ -90,6 +90,9 @@ jobs:
9090
- name: Install dependencies
9191
run: yarn install --immutable
9292

93+
- name: Build
94+
run: yarn build
95+
9396
- name: Build website
9497
run: yarn website:build
9598

@@ -114,6 +117,9 @@ jobs:
114117
run: yarn install --immutable
115118

116119
- name: Build
120+
run: yarn build
121+
122+
- name: Build website
117123
run: yarn website:build
118124

119125
- name: Deploy

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
dist
22
node_modules/
33
.idea/
4-
.jest-cache/
54
coverage/
65
yarn-error.log
76
.pnp.*

benchmark/__fixtures__/CircularProgress.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import clsx from 'clsx';
44
import { chainPropTypes } from '@material-ui/utils';
5-
import withStyles from '../styles/withStyles';
6-
import { capitalize } from '../utils/helpers';
5+
import withStyles from '../styles/withStyles.js';
6+
import { capitalize } from '../utils/helpers.js';
77

88
const SIZE = 44;
99

package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"private": true,
33
"engines": {
4-
"node": ">=14.15.0",
4+
"node": ">=14.17.0",
55
"yarn": ">=3.2.2"
66
},
77
"scripts": {
8-
"build": "yarn --verbose workspaces foreach --exclude 'benchmark' --exclude 'website' -p run build",
8+
"build": "yarn --verbose workspaces foreach --exclude 'benchmark' --exclude 'website' run build",
9+
"watch": "yarn --verbose workspaces foreach --exclude 'benchmark' --exclude 'website' -p run watch",
910
"lint": "eslint . --ext .js,.ts --report-unused-disable-directives",
1011
"fix": "eslint . --ext .js,.ts --fix --report-unused-disable-directives",
11-
"test": "yarn build && jest",
12-
"test:ci": "yarn build && jest --ci --cacheDirectory $(pwd)/.jest-cache/ --coverage",
12+
"test": "yarn build && vitest run",
13+
"test:dev": "vitest",
1314
"website:build": "yarn workspace website run build",
1415
"website:start": "yarn workspace website run start"
1516
},
@@ -21,22 +22,18 @@
2122
],
2223
"devDependencies": {
2324
"@types/cross-spawn": "6.0.2",
24-
"@types/jest": "29.2.3",
2525
"@types/rimraf": "3.0.2",
2626
"@typescript-eslint/eslint-plugin": "5.44.0",
2727
"@typescript-eslint/parser": "5.44.0",
28-
"cross-spawn": "7.0.3",
28+
"@vitest/coverage-c8": "0.25.3",
2929
"eslint": "8.28.0",
3030
"eslint-config-prettier": "8.5.0",
3131
"eslint-plugin-prettier": "4.2.1",
32-
"jest": "29.3.1",
33-
"jest-diff": "29.3.1",
34-
"jest-matcher-utils": "29.3.1",
3532
"prettier": "2.8.0",
3633
"rimraf": "3.0.2",
3734
"tempy": "1.0.1",
38-
"ts-jest": "29.0.3",
39-
"typescript": "4.9.3"
35+
"typescript": "4.9.3",
36+
"vitest": "0.25.3"
4037
},
4138
"packageManager": "[email protected]"
4239
}

packages/react-docgen-cli/jest.config.mjs

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

packages/react-docgen-cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
"version": "6.0.0-alpha.3",
44
"description": "A CLI and toolkit to extract information from React components for documentation generation.",
55
"repository": "reactjs/react-docgen",
6+
"type": "module",
67
"bin": {
78
"react-docgen": "bin/react-docgen.js"
89
},
910
"files": [
1011
"bin"
1112
],
1213
"engines": {
13-
"node": ">=14.15.0"
14+
"node": ">=14.17.0"
1415
},
1516
"scripts": {
1617
"build": "echo 'done'",
17-
"test": "yarn build && jest"
18+
"watch": "echo 'done'"
1819
},
1920
"keywords": [
2021
"react",

packages/react-docgen-cli/src/__tests__/react-docgen-test.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import path from 'path';
88
import rimraf from 'rimraf';
99
import { directory as tempDirectory, file as tempFile } from 'tempy';
1010
import spawn from 'cross-spawn';
11+
import { afterEach, describe, expect, test } from 'vitest';
1112

1213
const { writeFile, mkdir } = promises;
1314

@@ -85,7 +86,7 @@ describe.skip('react-docgen CLI', () => {
8586
tempNoComponents = [];
8687
}, TEST_TIMEOUT);
8788

88-
it(
89+
test(
8990
'reads from stdin',
9091
async () => {
9192
return run([], component).then(([stdout, stderr]) => {
@@ -96,7 +97,7 @@ describe.skip('react-docgen CLI', () => {
9697
TEST_TIMEOUT,
9798
);
9899

99-
it(
100+
test(
100101
'reads files provided as command line arguments',
101102
async () => {
102103
await createTempfiles();
@@ -110,7 +111,7 @@ describe.skip('react-docgen CLI', () => {
110111
TEST_TIMEOUT,
111112
);
112113

113-
it(
114+
test(
114115
'reads directories provided as command line arguments',
115116
async () => {
116117
await createTempfiles();
@@ -122,7 +123,7 @@ describe.skip('react-docgen CLI', () => {
122123
TEST_TIMEOUT,
123124
);
124125

125-
it(
126+
test(
126127
'considers js and jsx by default',
127128
async () => {
128129
await createTempfiles();
@@ -141,7 +142,7 @@ describe.skip('react-docgen CLI', () => {
141142
TEST_TIMEOUT,
142143
);
143144

144-
it(
145+
test(
145146
'considers files with the specified extension',
146147
async () => {
147148
await createTempfiles('foo');
@@ -162,7 +163,7 @@ describe.skip('react-docgen CLI', () => {
162163
TEST_TIMEOUT,
163164
);
164165

165-
it(
166+
test(
166167
'considers files with the specified extension shortcut',
167168
async () => {
168169
await createTempfiles('foo');
@@ -179,7 +180,7 @@ describe.skip('react-docgen CLI', () => {
179180
TEST_TIMEOUT,
180181
);
181182

182-
it(
183+
test(
183184
'ignores files in node_modules, __tests__ and __mocks__ by default',
184185
async () => {
185186
await createTempfiles(undefined, 'node_modules');
@@ -194,7 +195,7 @@ describe.skip('react-docgen CLI', () => {
194195
TEST_TIMEOUT,
195196
);
196197

197-
it(
198+
test(
198199
'ignores specified folders',
199200
async () => {
200201
await createTempfiles(undefined, 'foo');
@@ -207,7 +208,7 @@ describe.skip('react-docgen CLI', () => {
207208
TEST_TIMEOUT,
208209
);
209210

210-
it(
211+
test(
211212
'ignores specified folders shortcut',
212213
async () => {
213214
await createTempfiles(undefined, 'foo');
@@ -220,7 +221,7 @@ describe.skip('react-docgen CLI', () => {
220221
TEST_TIMEOUT,
221222
);
222223

223-
it(
224+
test(
224225
'writes to stdout',
225226
async () => {
226227
const [stdout, stderr] = await run([], component);
@@ -231,7 +232,7 @@ describe.skip('react-docgen CLI', () => {
231232
TEST_TIMEOUT,
232233
);
233234

234-
it(
235+
test(
235236
'writes to stderr',
236237
async () => {
237238
const [stdout, stderr] = await run([], '{}');
@@ -242,7 +243,7 @@ describe.skip('react-docgen CLI', () => {
242243
TEST_TIMEOUT,
243244
);
244245

245-
it(
246+
test(
246247
'writes to a file if provided',
247248
async () => {
248249
const outFile = tempFile();
@@ -257,7 +258,7 @@ describe.skip('react-docgen CLI', () => {
257258
TEST_TIMEOUT,
258259
);
259260

260-
it(
261+
test(
261262
'writes to a file if provided shortcut',
262263
async () => {
263264
const outFile = tempFile();
@@ -274,7 +275,7 @@ describe.skip('react-docgen CLI', () => {
274275

275276
describe('--resolver', () => {
276277
describe('accepts the names of built in resolvers', () => {
277-
it(
278+
test(
278279
'findExportedComponentDefinition (default)',
279280
async () => {
280281
// No option passed: same as --resolver=findExportedComponentDefinition
@@ -287,7 +288,7 @@ describe.skip('react-docgen CLI', () => {
287288
TEST_TIMEOUT,
288289
);
289290

290-
it(
291+
test(
291292
'findExportedComponentDefinition',
292293
async () => {
293294
const [stdout] = await run([
@@ -300,7 +301,7 @@ describe.skip('react-docgen CLI', () => {
300301
TEST_TIMEOUT,
301302
);
302303

303-
it(
304+
test(
304305
'findAllComponentDefinitions',
305306
async () => {
306307
const [stdout] = await run([
@@ -314,7 +315,7 @@ describe.skip('react-docgen CLI', () => {
314315
TEST_TIMEOUT,
315316
);
316317

317-
it(
318+
test(
318319
'findAllExportedComponentDefinitions',
319320
async () => {
320321
const [stdout] = await run([
@@ -329,7 +330,7 @@ describe.skip('react-docgen CLI', () => {
329330
);
330331
});
331332

332-
it(
333+
test(
333334
'accepts a path to a resolver function',
334335
async () => {
335336
const [stdout] = await run([
@@ -347,7 +348,7 @@ describe.skip('react-docgen CLI', () => {
347348
});
348349

349350
describe('--exclude/-e', () => {
350-
it(
351+
test(
351352
'ignores files by name',
352353
async () => {
353354
await createTempfiles(undefined, 'foo');
@@ -365,7 +366,7 @@ describe.skip('react-docgen CLI', () => {
365366
TEST_TIMEOUT,
366367
);
367368

368-
it(
369+
test(
369370
'ignores files by name shortcut',
370371
async () => {
371372
await createTempfiles(undefined, 'foo');
@@ -385,7 +386,7 @@ describe.skip('react-docgen CLI', () => {
385386
TEST_TIMEOUT,
386387
);
387388

388-
it(
389+
test(
389390
'ignores files by regex',
390391
async () => {
391392
await createTempfiles(undefined, 'foo');
@@ -402,7 +403,7 @@ describe.skip('react-docgen CLI', () => {
402403
TEST_TIMEOUT,
403404
);
404405

405-
it(
406+
test(
406407
'ignores files by regex shortcut',
407408
async () => {
408409
await createTempfiles(undefined, 'foo');

packages/react-docgen/jest.config.mjs

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

0 commit comments

Comments
 (0)