Skip to content

Commit a5f3894

Browse files
committed
Lazily run generateScopes in tests
**Bug** In the tests, if the grammar causes a hang we do not handle this currently. This is because `generateScopes` is being run in the `describe` block instead of inside one of the tests **Fix** Move `generateScopes` into the `it` block of the test
1 parent f0fc7a0 commit a5f3894

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ ensureCleanGeneratedFolder();
2222
// Generate the new baselines
2323
for (const fileName of fs.readdirSync('cases')) {
2424
describe("Generating baseline for " + fileName, () => {
25-
const text = fs.readFileSync(path.join('./cases', fileName), 'utf8');
26-
const parsedFileName = path.parse(fileName);
27-
const { markerScopes, wholeBaseline } = build.generateScopes(text, parsedFileName);
28-
if (markerScopes) {
29-
addTestCase(parsedFileName.name + '.txt', markerScopes);
30-
}
31-
addTestCase(parsedFileName.name + '.baseline.txt', wholeBaseline);
25+
it('Comparing generated', () => {
26+
const text = fs.readFileSync(path.join('./cases', fileName), 'utf8');
27+
const parsedFileName = path.parse(fileName);
28+
const { markerScopes, wholeBaseline } = build.generateScopes(text, parsedFileName);
29+
if (markerScopes) {
30+
assertBaselinesMatch(parsedFileName.name + '.txt', markerScopes);
31+
}
32+
assertBaselinesMatch(parsedFileName.name + '.baseline.txt', wholeBaseline);
33+
});
3234
});
3335
}
3436

35-
function addTestCase(file: string, generatedText: string) {
37+
function assertBaselinesMatch(file: string, generatedText: string) {
3638
const generatedFileName = path.join(generatedFolder, file);
3739
fs.writeFileSync(generatedFileName, generatedText);
3840

39-
it('Comparing generated' + file, () => {
40-
const baselineFile = path.join(baselineFolder, file);
41-
if (fs.existsSync(baselineFile)) {
42-
chai.assert.equal(generatedText, fs.readFileSync(baselineFile, 'utf8'), "Expected baselines to match");
43-
}
44-
else {
45-
chai.assert(false, "New generated baseline");
46-
}
47-
});
41+
const baselineFile = path.join(baselineFolder, file);
42+
if (fs.existsSync(baselineFile)) {
43+
chai.assert.equal(generatedText, fs.readFileSync(baselineFile, 'utf8'), "Expected baselines to match: " + file);
44+
}
45+
else {
46+
chai.assert(false, "New generated baseline");
47+
}
4848
}

0 commit comments

Comments
 (0)