Skip to content

Commit 52bc5bf

Browse files
committed
test: add module assertions in spec tests
1 parent 21ab2a4 commit 52bc5bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+50598
-68
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test-all": "node --unhandled-rejections=strict ./scriptsRunner.js generate validate test:*",
1313
"test-all-extended": "node --unhandled-rejections=strict ./scriptsRunner.js generate-extended validate generate validate test:*",
1414
"test-specific": "node ./scriptsRunner.js generate validate test:*",
15+
"test-specific-only": "node ./scriptsRunner.js test:*",
1516
"prepare": "npm run test-all-extended",
1617
"generate": "node tests/generate.js",
1718
"generate-extended": "node tests/generate-extended.js",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require("fs");
2+
const gitDiff = require("git-diff");
3+
4+
const assertGeneratedModule = (pathToModule1, pathToModule2) => {
5+
const output = fs.readFileSync(pathToModule1).toString("utf8");
6+
const expected = fs.readFileSync(pathToModule2).toString("utf8");
7+
8+
const diff = gitDiff(output, expected, {
9+
color: true,
10+
flags: "--diff-algorithm=default",
11+
});
12+
13+
if (diff && diff.length) {
14+
console.error("\n" + diff);
15+
throw new Error("expected another output");
16+
}
17+
18+
return void 0;
19+
};
20+
21+
module.exports = assertGeneratedModule;

tests/helpers/validateGeneratedModule.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@ module.exports = (pathToFile) => {
6363
// );
6464
// });
6565

66+
if (diagnostics.length) {
67+
console.error(diagnostics);
68+
throw new Error("Failed");
69+
}
70+
6671
return diagnostics;
6772
};

0 commit comments

Comments
 (0)