-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathfixtures.test.mjs
More file actions
47 lines (39 loc) · 1.45 KB
/
fixtures.test.mjs
File metadata and controls
47 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { equal, notStrictEqual, ok } from 'node:assert';
import { describe, it } from 'node:test';
import { readFile, readdir } from 'node:fs/promises';
import { basename, extname, join } from 'node:path';
import astJs from '../../ast-js/index.mjs';
import apiLinks from '../index.mjs';
const FIXTURES_DIRECTORY = join(import.meta.dirname, 'fixtures');
const fixtures = await readdir(FIXTURES_DIRECTORY);
const sourceFiles = fixtures
.filter(fixture => extname(fixture) === '.js')
.map(fixture => join(FIXTURES_DIRECTORY, fixture));
describe('api links', () => {
describe('should work correctly for all fixtures', () => {
sourceFiles.forEach(sourceFile => {
it(`${basename(sourceFile)}`, async () => {
const astJsResult = await astJs.generate(undefined, {
input: [sourceFile],
});
const actualOutput = await apiLinks.generate(astJsResult, {});
const expectedOutput = JSON.parse(
await readFile(sourceFile.replace('.js', '.json'), 'utf8')
);
for (const [k, v] of Object.entries(expectedOutput)) {
notStrictEqual(actualOutput[k], undefined, `missing ${k}`);
ok(
actualOutput[k].endsWith(`/${v}`),
`expected ${v}, got ${actualOutput[k]}`
);
delete actualOutput[k];
}
equal(
Object.keys(actualOutput).length,
0,
'actual output has extra keys'
);
});
});
});
});