forked from bytecodealliance/jco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodegen.js
51 lines (44 loc) · 1.64 KB
/
codegen.js
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
import { readFile } from 'node:fs/promises';
import { exec, jsctPath } from './helpers.js';
import { strictEqual } from 'node:assert';
const eslintPath = 'node_modules/.bin/eslint';
const tscPath = 'node_modules/.bin/tsc';
export async function readFlags (fixture) {
try {
var source = await readFile(fixture, 'utf8');
}
catch (e) {
if (e && e.code === 'ENOENT')
return [];
throw e;
}
const firstLine = source.split('\n')[0];
if (firstLine.startsWith('// Flags:'))
return firstLine.slice(9).trim().split(' ');
return [];
}
export async function codegenTest (fixtures) {
suite(`Transpiler codegen`, () => {
for (const fixture of fixtures) {
const name = fixture.replace('.component.wasm', '');
test(`${fixture} transpile`, async () => {
const flags = await readFlags(`test/runtime/${name}.ts`);
var { stderr } = await exec(jsctPath, 'transpile', `test/fixtures/${fixture}`, '--name', name, ...flags, '-o', `test/output/${name}`);
strictEqual(stderr, '');
});
test(`${fixture} lint`, async () => {
const flags = await readFlags(`test/runtime/${name}.ts`);
if (flags.includes('--js'))
return;
var { stderr } = await exec(eslintPath, `test/output/${name}/${name}.js`, '-c', 'test/eslintrc.cjs');
strictEqual(stderr, '');
});
}
// TypeScript tests _must_ run after codegen to complete successfully
// This is due to type checking against generated bindings
test('TypeScript Compilation', async () => {
var { stderr } = await exec(tscPath, '-p', 'test/tsconfig.json');
strictEqual(stderr, '');
});
});
}