-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathtest.ts
executable file
·64 lines (56 loc) · 1.72 KB
/
test.ts
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
#!/usr/bin/env ts-node
/* This starts the test suite. The II canister id is read from dfx.
* This expects the replica to be running, and expects the II canister to have
* been deployed.
*/
import { execSync, spawn } from "child_process";
/**
* Read a canister ID from dfx's local state
*/
export const readCanisterId = ({
canisterName,
}: {
canisterName: string;
}): string => {
const command = `dfx canister id ${canisterName}`;
try {
const stdout = execSync(command);
return stdout.toString().trim();
} catch (e) {
throw Error(
`Could not get canister ID for '${canisterName}' with command '${command}', was the canister deployed? ${e}`
);
}
};
function getCanisterHost({ canisterName }: { canisterName: string }): string {
const port = execSync("dfx info webserver-port");
const canisterId = readCanisterId({ canisterName });
return `http://${canisterId}.localhost:${port}`;
}
function main() {
console.log("Starting tests");
const wdio = spawn("npm", ["run", "wdio"], {
env: {
...process.env,
II_DAPP_URL: getCanisterHost({ canisterName: "internet_identity" }),
},
});
wdio.stdout.on("data", (data) => {
console.log(`wdio: ${data}`);
});
wdio.stderr.on("data", (data) => {
console.log(`wdio: ${data}`);
});
wdio.on("exit", (code, signal) => {
if (code !== null && code > 0) {
// if code is set and non-zero, bubble up error from wdio tests
throw new Error(`End-to-end tests returned with ${code}`);
} else if (signal) {
// otherwise, if the child was killed externally
throw new Error(`End-to-end tests killed with signal ${signal}`);
} else {
console.log("End-to-end tests finished successfully");
}
});
}
main();