Skip to content

Commit 9012470

Browse files
committed
Initial test setup
1 parent 43487bd commit 9012470

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '22'
22+
node-version: "22"
2323

2424
- name: Install dependencies
2525
run: npm ci
@@ -32,6 +32,9 @@ jobs:
3232
working-directory: ./tools/TypeScript-DOM-lib-generator
3333
run: npm run build
3434

35+
- name: Run tests
36+
run: npm test
37+
3538
- name: get-npm-version
3639
id: package-version
3740
uses: martinbeentjes/[email protected]
@@ -50,7 +53,7 @@ jobs:
5053
uses: actions/upload-artifact@v4
5154
with:
5255
name: npm-package
53-
path: '*.tgz'
56+
path: "*.tgz"
5457

5558
- name: Publish to npm
5659
if: false

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
"rescript.json",
2626
"src/**/*.res"
2727
],
28+
"type": "module",
2829
"scripts": {
29-
"test": "echo \"Error: no test specified\" && exit 1"
30+
"test": "node tests/index.js",
31+
"build": "rewatch"
3032
},
3133
"license": "MIT",
3234
"dependencies": {

rescript.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
{
66
"dir": "src",
77
"subdirs": true
8+
},
9+
{
10+
"dir": "tests",
11+
"subdirs": true
812
}
913
],
1014
"package-specs": {

tests/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { execSync } from "child_process";
2+
import { fileURLToPath } from "url";
3+
import * as path from "path";
4+
import { exit } from "process";
5+
6+
const currentFileName = fileURLToPath(import.meta.url);
7+
const currentDir = path.dirname(currentFileName);
8+
const repoRoot = path.resolve(currentDir, "..");
9+
const testsDir = path.join(repoRoot, "tests");
10+
11+
// Compile all tests
12+
execSync("npx rewatch", { cwd: repoRoot, stdio: "inherit" });
13+
14+
const successGreen = "\x1b[32m";
15+
const warningYellow = "\x1b[33m";
16+
const resetColor = "\x1b[0m";
17+
18+
// Assert nothing changed
19+
const gitDff = execSync("git ls-files --modified .", {
20+
cwd: testsDir,
21+
}).toString();
22+
if (!gitDff) {
23+
console.log(`${successGreen}✅ No unstaged tests difference!${resetColor}`);
24+
exit(0);
25+
} else {
26+
console.log(
27+
`${warningYellow}⚠️ There are unstaged differences in tests! Did you break a test?\n${gitDff}${resetColor}`,
28+
);
29+
execSync("git --no-pager diff .", { stdio: "inherit" });
30+
exit(1);
31+
}

0 commit comments

Comments
 (0)