-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
test-runner.js
75 lines (61 loc) · 2.23 KB
/
test-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// This module was originally build by the OrchardCore team
const child_process = require("child_process");
const fs = require("fs-extra");
const path = require("path");
global.log = function (msg) {
let now = new Date().toLocaleTimeString();
console.log(`[${now}] ${msg}\n`);
};
// Build the dotnet application in release mode
export function build(dir, dotnetVersion) {
global.log("Building ...");
child_process.spawnSync("dotnet", ["build", "-c", "Release", "-f", dotnetVersion], { cwd: dir });
}
// destructive action that deletes the App_Data folder
export function deleteDirectory(dir) {
fs.removeSync(dir);
global.log(`${dir} deleted`);
}
// Host the dotnet application, does not rebuild
export function host(dir, assembly, { appDataLocation = './App_Data', dotnetVersion = 'net8.0' } = {}) {
if (fs.existsSync(path.join(dir, `bin/Release/${dotnetVersion}/`, assembly))) {
global.log("Application already built, skipping build");
} else {
build(dir, dotnetVersion);
}
global.log("Starting application ...");
const ocEnv = {};
ocEnv["ORCHARD_APP_DATA"] = appDataLocation;
let server = child_process.spawn(
"dotnet",
[`bin/Release/${dotnetVersion}/` + assembly],
{ cwd: dir, env: { ...process.env, ...ocEnv } }
);
server.stdout.on("data", data => {
global.log(data);
});
server.stderr.on("data", data => {
global.log(`stderr: ${data}`);
});
server.on("close", code => {
global.log(`Server process exited with code ${code}`);
});
return server;
}
// combines the functions above, useful when triggering tests from CI
export function e2e(dir, assembly, { dotnetVersion = 'net8.0' } = {}) {
deleteDirectory(path.join(dir, "App_Data_Tests"));
var server = host(dir, assembly, { appDataLocation: "./App_Data_Tests", dotnetVersion });
let test = child_process.exec("npx cypress run");
test.stdout.on("data", data => {
console.log(data);
});
test.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
test.on("close", code => {
console.log(`Cypress process exited with code ${code}`);
server.kill("SIGINT");
process.exit(code);
});
}