tutanota/test/test.js

40 lines
1.4 KiB
JavaScript
Raw Normal View History

import child_process from "child_process"
2022-05-09 18:41:10 +02:00
import {runTestBuild} from "./TestBuilder.js"
2022-05-10 16:16:38 +02:00
import {Argument, Option, program} from "commander"
2017-08-15 13:54:22 +02:00
2022-05-10 16:16:38 +02:00
await program
.addArgument(new Argument("project")
.choices(["api", "client"])
.argOptional()
)
.addOption(new Option("-i, --integration", "Include integration tests (requires local server)"))
.addOption(new Option("-c, --clean"))
.action(async (project, {clean, integration}) => {
2022-05-09 18:41:10 +02:00
await runTestBuild({clean})
2019-09-13 13:49:11 +02:00
console.log("build finished!")
2022-05-10 16:16:38 +02:00
const testProjects = project ? [project] : ["api", "client"]
await runTestsAndExit(testProjects, integration)
})
.parseAsync(process.argv)
/** Function which runs tests for {@param projects} and exits with the most suitable code afterwards. */
async function runTestsAndExit(projects, integration) {
const codes = []
for (const project of projects) {
codes.push(await runTest(project, integration))
2017-08-15 13:54:22 +02:00
}
2022-05-10 16:16:38 +02:00
const code = codes.find((code) => code !== 0) ?? 0
process.exit(code)
}
2017-08-15 13:54:22 +02:00
2022-05-10 16:16:38 +02:00
function runTest(project, integration) {
2019-09-13 13:49:11 +02:00
return new Promise((resolve) => {
2022-05-10 16:16:38 +02:00
console.log("running", project, "tests")
const args = integration ? ["-i"] : []
// We fork because ospec is very weird and doesn't just let you wait for the results unless you do something with report
const testProcess = child_process.fork(`./build/${project}/bootstrapTests-${project}.js`, args)
testProcess.on('exit', resolve)
2019-09-13 13:49:11 +02:00
})
}