Skip to content

Commit 53dcf2f

Browse files
committed
chore(all): replace Jest with Mocha and Node's assert module
1 parent 5081ddf commit 53dcf2f

File tree

509 files changed

+20466
-29499
lines changed

Some content is hidden

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

509 files changed

+20466
-29499
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- main
1212
- release
1313
- beta
14+
- remove-jest
1415
pull_request:
1516
paths:
1617
- 'packages/typedoc-plugin-markdown/**'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import assert from 'assert';
2+
import { diff } from 'jest-diff';
3+
import { getSnapshot } from './helpers.js';
4+
5+
export function assertToMatchSnapshot(name: string, actual: string | string[]) {
6+
const snapshot = getSnapshot(name, actual);
7+
try {
8+
assert.strictEqual(actual, snapshot);
9+
} catch (error) {
10+
console.error(diff(actual, snapshot));
11+
throw error;
12+
}
13+
}

devtools/packages/testing/helpers.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import fs from 'fs-extra';
2+
import path from 'path';
3+
4+
export function getSnapshot(name: string, actual: string | string[]) {
5+
const snapshotDir = `${process.cwd()}/test/__snapshots__`;
6+
const snapshotPath = path.join(snapshotDir, `${name}.snap`);
7+
8+
if (!fs.existsSync(snapshotPath)) {
9+
fs.outputFileSync(snapshotPath, serialize(actual));
10+
return actual;
11+
}
12+
13+
return fs.readFileSync(snapshotPath, 'utf-8');
14+
}
15+
16+
export function getFileContents(filePath: string) {
17+
const fullFilePath = `${process.cwd()}/test/${filePath}`;
18+
return fs.readFileSync(fullFilePath).toString();
19+
}
20+
21+
export function getDirContents(dirPath: string) {
22+
const fullDirPath = `${process.cwd()}/test/${dirPath}`;
23+
return JSON.stringify(fs.readdirSync(fullDirPath), null, 2);
24+
}
25+
26+
export function serialize(content: string | string[]) {
27+
if (Array.isArray(content)) {
28+
return JSON.stringify(content, null, 2);
29+
}
30+
return content;
31+
}

devtools/packages/testing/index.ts

Lines changed: 2 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,2 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
3-
4-
export function expectFileToEqual(
5-
key: string,
6-
outputFileStrategy: 'modules' | 'members' | ('modules' | 'members')[],
7-
file: string | string[],
8-
limit?: number,
9-
range?: Array<number>,
10-
) {
11-
const outputFileStrategies = Array.isArray(outputFileStrategy)
12-
? outputFileStrategy
13-
: [outputFileStrategy];
14-
outputFileStrategies.forEach((outputFileStrategy) => {
15-
const basePath = getOutputFileStrategyPath(key, outputFileStrategy);
16-
17-
const optionDirs = fs.readdirSync(basePath);
18-
optionDirs.forEach((optionDir, index) => {
19-
const isArray = Array.isArray(file);
20-
if (index < file.length) {
21-
if (!limit || limit > index) {
22-
const fullPath = path.join(
23-
basePath,
24-
optionDir,
25-
isArray ? file[index] : file,
26-
);
27-
let actual = fs.readFileSync(fullPath).toString();
28-
if (range) {
29-
actual = actual.split('\n').slice(range[0], range[1]).join('\n');
30-
}
31-
expect(actual).toMatchSnapshot(
32-
`(Output File Strategy "${outputFileStrategy}") (Option Group "${
33-
index + 1
34-
}")`,
35-
);
36-
}
37-
}
38-
});
39-
});
40-
}
41-
42-
export function expectUrlsToEqual(
43-
outDir: string,
44-
outputFileStrategies: ('members' | 'modules')[],
45-
) {
46-
outputFileStrategies.forEach((outputFileStrategy) => {
47-
const basePath = getOutputFileStrategyPath(outDir, outputFileStrategy);
48-
const optionDirs = fs.readdirSync(basePath);
49-
optionDirs.forEach((optionDir) => {
50-
const optionsBasePath = path.join(basePath, optionDir);
51-
const rootDirectory = fs.readdirSync(path.join(basePath, optionDir));
52-
const reduceDirectory = (
53-
basePath: string,
54-
baseDirectory: string,
55-
directory: string[],
56-
) => {
57-
return directory.reduce((prev: any, item) => {
58-
if (fs.lstatSync(`${basePath}/${item}`).isDirectory()) {
59-
const nestedDir = fs.readdirSync(`${basePath}/${item}`);
60-
return [
61-
...prev,
62-
...reduceDirectory(
63-
`${basePath}/${item}`,
64-
`${baseDirectory}/${item}`,
65-
nestedDir,
66-
),
67-
];
68-
}
69-
if (path.extname(item) === '.json') {
70-
return prev;
71-
}
72-
return [...prev, `${baseDirectory}/${item}`.replace(/^\/+/, '')];
73-
}, []);
74-
};
75-
const urls = reduceDirectory(optionsBasePath, '', rootDirectory);
76-
expect(urls).toMatchSnapshot(`outputFileStrategy: ${outputFileStrategy}`);
77-
});
78-
});
79-
}
80-
81-
export function getOutDir() {
82-
return path.join(process.cwd(), 'test', 'fixtures', 'out');
83-
}
84-
85-
export function expectDirToEqual(outDir: string) {
86-
const basePath = getPath(outDir);
87-
const rootDirectory = fs.readdirSync(path.join(basePath));
88-
const reduceDirectory = (
89-
basePath: string,
90-
baseDirectory: string,
91-
directory: string[],
92-
) => {
93-
return directory.reduce((prev: any, item) => {
94-
if (fs.lstatSync(`${basePath}/${item}`).isDirectory()) {
95-
const nestedDir = fs.readdirSync(`${basePath}/${item}`);
96-
return [
97-
...prev,
98-
...reduceDirectory(
99-
`${basePath}/${item}`,
100-
`${baseDirectory}/${item}`,
101-
nestedDir,
102-
),
103-
];
104-
}
105-
return [...prev, `${baseDirectory}/${item}`.replace(/^\/+/, '')];
106-
}, []);
107-
};
108-
const urls = reduceDirectory(basePath, '', rootDirectory);
109-
expect(urls).toMatchSnapshot(`dir: ${outDir}`);
110-
}
111-
112-
function getPath(dir: string) {
113-
return path.join(process.cwd(), 'test', 'fixtures', 'out', dir);
114-
}
115-
116-
function getOutputFileStrategyPath(
117-
key: string,
118-
outputFileStrategy: 'modules' | 'members',
119-
) {
120-
const basePath = path.join(
121-
process.cwd(),
122-
'test',
123-
'fixtures',
124-
'out',
125-
'md',
126-
key,
127-
outputFileStrategy,
128-
);
129-
return basePath;
130-
}
1+
export * from './assertions.js';
2+
export * from './helpers.js';

devtools/packages/testing/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@devtools/testing",
33
"version": "0.0.0",
44
"private": true,
5+
"type": "module",
56
"main": "index.ts",
67
"files": [
78
"/"

jest.config.base.js

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

jest.config.js

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

jest.helpers.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)