-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathfixtures.test.mjs
More file actions
57 lines (42 loc) · 1.64 KB
/
fixtures.test.mjs
File metadata and controls
57 lines (42 loc) · 1.64 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
48
49
50
51
52
53
54
55
56
57
import { basename, join, relative, sep } from 'node:path';
import { after, before, describe, it } from 'node:test';
import { globSync } from 'tinyglobby';
import createWorkerPool from '../../../threading/index.mjs';
import createParallelWorker from '../../../threading/parallel.mjs';
import { setConfig } from '../../../utils/configuration/index.mjs';
import { generate as astJsGenerate } from '../../ast-js/generate.mjs';
import { generate as apiLinksGenerate } from '../generate.mjs';
const relativePath = relative(process.cwd(), import.meta.dirname);
const sourceFiles = globSync('*.js', {
cwd: new URL(import.meta.resolve('./fixtures')),
});
const config = await setConfig({});
describe('api links', () => {
let pool;
before(() => {
pool = createWorkerPool(config.threads);
});
after(async () => {
await pool.destroy();
});
describe('should work correctly for all fixtures', () => {
sourceFiles.forEach(sourceFile => {
it(`${basename(sourceFile)}`, async t => {
config['ast-js'].input = [
join(relativePath, 'fixtures', sourceFile).replaceAll(sep, '/'),
];
const worker = await createParallelWorker('ast-js', pool, config);
// Collect results from the async generator
const astJsResults = [];
for await (const chunk of astJsGenerate(undefined, worker)) {
astJsResults.push(...chunk);
}
const actualOutput = await apiLinksGenerate(astJsResults);
for (const [k, v] of Object.entries(actualOutput)) {
actualOutput[k] = v.replace(/.*(?=lib\/)/, '');
}
t.assert.snapshot(actualOutput);
});
});
});
});