Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

ci: improve test runner script

thecodrr8679dbed62a5
diff --git a/apps/web/package.json b/apps/web/package.json
index df69b8f40..eaffdcff1 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -51,7 +51,6 @@
"@types/hookrouter": "^2.2.5",
"@types/node-fetch": "^2.5.10",
"@types/quill": "^2.0.5",
- "find-process": "^1.4.4",
"babel-eslint": "^10.1.0",
"chalk": "^4.1.0",
"env-cmd": "^10.1.0",
@@ -62,6 +61,7 @@
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
+ "find-process": "^1.4.4",
"progress-bar-webpack-plugin": "^2.1.0",
"source-map-explorer": "^2.5.2",
"typescript": "^4.1.5",
diff --git a/apps/web/scripts/run-tests.mjs b/apps/web/scripts/run-tests.mjs
index c8d7271f2..3b4dae09b 100644
--- a/apps/web/scripts/run-tests.mjs
+++ b/apps/web/scripts/run-tests.mjs
@@ -1,23 +1,24 @@
const find = require("find-process");
-const { p, u, f } = argv;
+const { p, updateSnapshots, file, noServer } = argv;
-const args = [];
-if (u) args.push("-u");
-if (f) args.push(f);
-
-const res = nothrow($`yarn debug -p ${p || 3000}`);
-res.stdout.on("data", async (data) => {
- const message = data.toString();
- if (
- message.includes("create a production build, use yarn build.") ||
- message.includes("Compiled with warnings")
- ) {
- const testRes = await $`yarn playwright test ${args.join(" ")}`;
- await killServer();
- process.exit(testRes.exitCode);
- }
-});
+if (!noServer) {
+ const res = nothrow($`yarn debug -p ${p || 3000}`);
+ res.stdout.on("data", async (data) => {
+ const message = data.toString();
+ if (
+ message.includes("create a production build, use yarn build.") ||
+ message.includes("Compiled with warnings")
+ ) {
+ const testRes = await startTestRunner();
+ await killServer();
+ process.exit(testRes.exitCode);
+ }
+ });
+} else {
+ const testRes = await startTestRunner();
+ process.exit(testRes.exitCode);
+}
async function killServer() {
const nodeProcesses = await find("name", "node");
@@ -28,3 +29,10 @@ async function killServer() {
process.kill(rprocess.pid, "SIGINT");
}
}
+
+async function startTestRunner() {
+ if (!updateSnapshots && !file) return $`yarn playwright test`;
+ else if (updateSnapshots && file) return $`yarn playwright test -u ${file}`;
+ else if (file) return $`yarn playwright test ${file}`;
+ else if (updateSnapshots) return $`yarn playwright test -u`;
+}