Skip to content

Commit 699132e

Browse files
use snapshot api
1 parent 9f4ce5c commit 699132e

File tree

11 files changed

+58
-52
lines changed

11 files changed

+58
-52
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# Tests files
12
src/generators/api-links/test/fixtures/
3+
*.snapshot

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"format": "prettier .",
1111
"format:write": "prettier --write .",
1212
"test": "node --test",
13-
"test:watch": "node --test --watch",
1413
"test:coverage": "node --experimental-test-coverage --test",
14+
"test:update-snapshots": "node --test --test-update-snapshots",
15+
"test:watch": "node --test --watch",
1516
"prepare": "husky",
1617
"run": "node bin/cli.mjs",
1718
"watch": "node --watch bin/cli.mjs"

src/generators/api-links/test/fixtures.test.mjs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { equal, notStrictEqual, ok } from 'node:assert';
21
import { describe, it } from 'node:test';
3-
import { readFile, readdir } from 'node:fs/promises';
2+
import { readdir } from 'node:fs/promises';
43
import { basename, extname, join } from 'node:path';
54
import astJs from '../../ast-js/index.mjs';
65
import apiLinks from '../index.mjs';
@@ -15,32 +14,17 @@ const sourceFiles = fixtures
1514
describe('api links', () => {
1615
describe('should work correctly for all fixtures', () => {
1716
sourceFiles.forEach(sourceFile => {
18-
it(`${basename(sourceFile)}`, async () => {
17+
it(`${basename(sourceFile)}`, async t => {
1918
const astJsResult = await astJs.generate(undefined, {
2019
input: [sourceFile],
2120
});
2221

2322
const actualOutput = await apiLinks.generate(astJsResult, {});
24-
25-
const expectedOutput = JSON.parse(
26-
await readFile(sourceFile.replace('.js', '.json'), 'utf8')
27-
);
28-
29-
for (const [k, v] of Object.entries(expectedOutput)) {
30-
notStrictEqual(actualOutput[k], undefined, `missing ${k}`);
31-
ok(
32-
actualOutput[k].endsWith(`/${v}`),
33-
`expected ${v}, got ${actualOutput[k]}`
34-
);
35-
36-
delete actualOutput[k];
23+
for (const [k, v] of Object.entries(actualOutput)) {
24+
actualOutput[k] = v.replace(/.*(?=lib\/)/, '');
3725
}
3826

39-
equal(
40-
Object.keys(actualOutput).length,
41-
0,
42-
'actual output has extra keys'
43-
);
27+
t.assert.snapshot(actualOutput);
4428
});
4529
});
4630
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exports[`api links > should work correctly for all fixtures > buffer.js 1`] = `
2+
{
3+
"buffer.Buffer": "lib/buffer.js#L5",
4+
"buf.instanceMethod": "lib/buffer.js#L8"
5+
}
6+
`;
7+
8+
exports[`api links > should work correctly for all fixtures > class.js 1`] = `
9+
{
10+
"Class": "lib/class.js#L5",
11+
"new Class": "lib/class.js#L6",
12+
"class.method": "lib/class.js#L7"
13+
}
14+
`;
15+
16+
exports[`api links > should work correctly for all fixtures > exports.js 1`] = `
17+
{
18+
"exports.fn1": "lib/exports.js#L8",
19+
"exports.fn2": "lib/exports.js#L10",
20+
"exports.Buffer": "lib/exports.js#L5",
21+
"exports.fn3": "lib/exports.js#L12"
22+
}
23+
`;
24+
25+
exports[`api links > should work correctly for all fixtures > mod.js 1`] = `
26+
{
27+
"mod.foo": "lib/mod.js#L5"
28+
}
29+
`;
30+
31+
exports[`api links > should work correctly for all fixtures > prototype.js 1`] = `
32+
{
33+
"prototype.Class": "lib/prototype.js#L5",
34+
"Class.classMethod": "lib/prototype.js#L8",
35+
"class.instanceMethod": "lib/prototype.js#L9"
36+
}
37+
`;
38+
39+
exports[`api links > should work correctly for all fixtures > reverse.js 1`] = `
40+
{
41+
"asserts": "lib/reverse.js#L8",
42+
"asserts.ok": "lib/reverse.js#L5",
43+
"asserts.strictEqual": "lib/reverse.js#L12"
44+
}
45+
`;
46+
47+
exports[`api links > should work correctly for all fixtures > root.js 1`] = `
48+
{}
49+
`;

src/generators/api-links/test/fixtures/buffer.json

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

src/generators/api-links/test/fixtures/class.json

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

src/generators/api-links/test/fixtures/exports.json

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

src/generators/api-links/test/fixtures/mod.json

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

src/generators/api-links/test/fixtures/prototype.json

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

src/generators/api-links/test/fixtures/reverse.json

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

0 commit comments

Comments
 (0)