-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-ci.js
46 lines (40 loc) · 1.84 KB
/
run-ci.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
let ContractPolice = require("./index.js");
// Define used variables used by ContractPolice, injected by Docker
const targetUrl = process.env.CP_TARGET;
const contractsDirectory = "/contractpolice/ci-contracts";
const generatorSourceDir = "/contractpolice/generator";
const outputsDirectory = "/contractpolice/outputs";
const configFailOnError = (process.env.CP_FAIL_ON_ERROR !== "false");
const configReporter = (process.env.CP_REPORTER === "junit") ? "junit" : "default";
const configAppLogsFile = (process.env.CP_LOGS_FILE_ENABLED === "true");
const configAppLogsConsole = (process.env.CP_LOGS_CONSOLE_ENABLED === "true");
const configAppLogsLevel = (process.env.CP_LOGS_LEVEL === undefined) ? "warn" : process.env.CP_LOGS_LEVEL;
// Gather injected config into single object
let config = {
contractDefinitionsDir: contractsDirectory,
generatorSourceDir: generatorSourceDir,
reportOutputDir: outputsDirectory,
failOnError: configFailOnError,
reporter: configReporter,
enableAppLogsFile: configAppLogsFile,
enableAppLogsConsole: configAppLogsConsole,
loglevel: configAppLogsLevel
};
(async () => {
try {
// Execution
console.log("Contract Police - Contract testing utility");
const contractPolice = new ContractPolice(targetUrl, config);
console.log("Generating contract test definitions (if applicable)...");
await contractPolice.generateContractTests();
console.log("Starting contract test execution with ContractPolice");
await contractPolice.testContracts();
// Successful test, no errors found
console.log("ContractPolice successfully finished executing contract tests");
process.exitCode = 0; // success
} catch (err) {
// Show output of contract test
console.error(err.message);
process.exitCode = 1; // failure
}
})();