Skip to content

Commit 9921c82

Browse files
committedApr 10, 2023
use: js script instead of shell script to run precheck and mocha
1 parent e0cb86d commit 9921c82

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed
 

‎packages/tests/.eslintrc.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ module.exports = {
66
rules: {
77
"@typescript-eslint/no-non-null-assertion": "off",
88
},
9+
globals: {
10+
process: true,
11+
},
912
};

‎packages/tests/package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141
"check:lint": "eslint src tests",
4242
"check:spelling": "cspell \"{README.md,{tests,src}/**/*.ts}\"",
4343
"check:tsc": "tsc -p tsconfig.dev.json",
44-
"pretest": "if docker inspect ${WAKUNODE_IMAGE} > /dev/null 2>&1; then echo 'Using local image'; else docker pull ${WAKUNODE_IMAGE:-statusteam/nim-waku:v0.16.0} && echo 'Image pulled'; fi",
4544
"test": "run-s test:*",
46-
"test:node": "npm run pretest && TS_NODE_PROJECT=./tsconfig.dev.json mocha",
45+
"test:node": "node ./src/run-tests.js",
4746
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
4847
},
4948
"engines": {
@@ -57,18 +56,18 @@
5756
"@waku/utils": "*",
5857
"app-root-path": "^3.1.0",
5958
"debug": "^4.3.4",
59+
"dockerode": "^3.3.5",
6060
"p-timeout": "^6.1.0",
6161
"portfinder": "^1.0.32",
62-
"tail": "^2.2.6",
63-
"dockerode": "^3.3.5"
62+
"tail": "^2.2.6"
6463
},
6564
"devDependencies": {
66-
"@types/dockerode": "^3.3.15",
6765
"@libp2p/bootstrap": "^6.0.3",
6866
"@libp2p/components": "^3.1.1",
6967
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.5",
7068
"@libp2p/interface-peer-id": "^2.0.1",
7169
"@types/chai": "^4.3.4",
70+
"@types/dockerode": "^3.3.15",
7271
"@types/mocha": "^10.0.1",
7372
"@types/tail": "^2.2.1",
7473
"@typescript-eslint/eslint-plugin": "^5.57.0",

‎packages/tests/src/run-tests.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { exec, spawn } from "child_process";
2+
import { promisify } from "util";
3+
4+
import debug from "debug";
5+
6+
const log = debug("waku:test:run");
7+
8+
const execAsync = promisify(exec);
9+
10+
const WAKUNODE_IMAGE =
11+
process.env.WAKUNODE_IMAGE || "statusteam/nim-waku:v0.16.0";
12+
13+
async function main() {
14+
try {
15+
await execAsync(`docker inspect ${WAKUNODE_IMAGE}`);
16+
17+
log("Using local image");
18+
} catch (error) {
19+
log("Pulling image...");
20+
21+
await execAsync(`docker pull ${WAKUNODE_IMAGE}`);
22+
log("Image pulled");
23+
}
24+
25+
// Run mocha tests
26+
const mocha = spawn(
27+
"npx",
28+
[
29+
"mocha",
30+
"--require",
31+
"ts-node/register",
32+
"--project",
33+
"./tsconfig.dev.json",
34+
],
35+
{
36+
stdio: "inherit",
37+
}
38+
);
39+
40+
mocha.on("error", (error) => {
41+
log(`Error running mocha tests: ${error.message}`);
42+
process.exit(1);
43+
});
44+
45+
mocha.on("exit", (code) => {
46+
log(`Mocha tests exited with code ${code}`);
47+
process.exit(code || 0);
48+
});
49+
}
50+
51+
main().catch((error) => {
52+
log(error);
53+
process.exit(1);
54+
});

‎packages/tests/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"rootDir": "src",
66
"tsBuildInfoFile": "dist/.tsbuildinfo"
77
},
8-
"include": ["src"],
8+
"include": ["src", "src/run-tests.js"],
99
"exclude": ["src/**/*.spec.ts", "src/test_utils"]
1010
}

0 commit comments

Comments
 (0)