angular/vscode-ng-language-service/syntaxes/test/driver.ts
Alan Agius fe0e5ab294 build: bump vscode-tmgrammar-test to 0.1.3 (#64078)
Update `vscode-tmgrammar-test`.

PR Close #64078
2025-09-25 10:58:41 -04:00

62 lines
1.5 KiB
JavaScript

#!/usr/bin/env node
// Usage:
// pnpm test:syntaxes [options]
//
// Options:
// -u update snapshot files (always passes)
import 'jasmine';
import * as cp from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import {cases} from './cases';
interface TestCase {
name: string;
scopeName: string;
grammarFiles: string[];
testFile: string;
}
const dummyGrammarDir = 'syntaxes/test/dummy';
const DUMMY_GRAMMARS = fs
.readdirSync(dummyGrammarDir)
.map((file: string) => path.join(dummyGrammarDir, file));
/** Wraps node's spawn in a Promise. */
function spawn(...args: Parameters<typeof cp.spawn>): Promise<number> {
const child = cp.spawn(...args);
return new Promise((resolve, reject) => {
child.on('exit', (code: number) => {
if (code === 0) resolve(0);
else reject(code);
});
});
}
async function snapshotTest({scopeName, grammarFiles, testFile}: TestCase): Promise<number> {
grammarFiles.push(...DUMMY_GRAMMARS);
const grammarOptions = grammarFiles.reduce((acc, file) => [...acc, '-g', file], [] as string[]);
const options = [
'node_modules/vscode-tmgrammar-test/dist/snapshot.js',
'-s',
scopeName,
...grammarOptions,
testFile,
];
return spawn('node', options, {stdio: 'inherit' /* use parent process IO */}).catch(
(code) => code,
);
}
describe('snapshot tests', () => {
for (let tc of cases) {
it(`should work for ${tc.name}`, async () => {
const ec = await snapshotTest(tc);
expect(ec).toBe(0);
});
}
});