Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions test/runTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ if (process.platform === "win32") {
// });

// Run tests in Docker container
describe("Run tests sucessfully", async function () {
describe("Run tests successfully", async function () {
// Set indefinite timeout
this.timeout(0);
it("All specs pass", async () => { return new Promise((resolve, reject) => {
let hasExited = false;
it("All specs pass", async () => {
return new Promise((resolve, reject) => {
let hasCompleted = false;

const handleCompletion = (callback) => {
if (hasCompleted) return;
hasCompleted = true;
callback();
};

const runTests = exec(
`docker run --rm -v "${artifactPath}:${internalPath}" docdetective/docdetective:${version}-${os} -c ./config.json -i . -o ./results.json`
);
Expand All @@ -71,34 +79,30 @@ describe("Run tests sucessfully", async function () {

runTests.on("error", (error) => {
console.error(`Error: ${error.message}`);
if (!hasExited) {
hasExited = true;
reject(error);
}
handleCompletion(() => reject(error));
});

runTests.on("exit", (code) => {
if (hasExited) return;
hasExited = true;

console.log(`Child process exited with code ${code}`);

if (code !== null && code !== 0) {
reject(new Error(`Docker process exited with code ${code}`));
return;
}

try {
const result = JSON.parse(
fs.readFileSync(outputFile, { encoding: "utf8" })
);
console.log(JSON.stringify(result, null, 2));
assert.equal(result.summary.specs.fail, 0);
fs.unlinkSync(outputFile);
resolve();
} catch (error) {
reject(error);
}
runTests.on("close", (code) => {
handleCompletion(() => {
console.log(`Child process closed with code ${code}`);

if (code !== null && code !== 0) {
reject(new Error(`Docker process exited with code ${code}`));
return;
}

try {
const result = JSON.parse(
fs.readFileSync(outputFile, { encoding: "utf8" })
);
console.log(JSON.stringify(result, null, 2));
assert.equal(result.summary.specs.fail, 0);
fs.unlinkSync(outputFile);
resolve();
} catch (error) {
reject(error);
}
});
});
});
});
Expand Down