Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lintMD": "markdownlint **/*.md --fix",
"docs": "node_modules/.bin/jsdoc lib/countly.js lib/countly-bulk.js lib/countly-bulk-user.js README.md -c jsdoc_conf.json -d docs",
"pretest": "eslint --ignore-path .eslintignore .",
"test": "mocha --timeout 180000 test/tests_*.js --exit --allow-uncaught",
"test": "mocha --timeout 180000 test/tests_*.js --exit",
"coverage": "nyc --reporter=text --reporter=lcov npm test",
"requests:update": "node test/helpers/request_scenarios.js"
},
Expand Down
17 changes: 17 additions & 0 deletions test/helpers/scripts/mocha_failing_suite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const assert = require("assert");

describe("A suite with an asynchronous hook", () => {
beforeEach(async() => {
await new Promise((resolve) => {
setTimeout(resolve, 1);
});
});

it("fails", () => {
assert.equal(1, 2);
});

it("passes after the failure", () => {
assert.ok(true);
});
});
15 changes: 14 additions & 1 deletion test/tests_package.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require("assert");
const { execSync } = require("child_process");
const { execSync, spawnSync } = require("child_process");
const fs = require("fs");
const path = require("path");

Expand All @@ -13,4 +13,17 @@ describe("Package tests", () => {
const expected = ["CHANGELOG.md", "LICENSE", "README.md", "index.js", "package.json"].concat(libFiles).sort();
assert.deepStrictEqual(packed, expected);
});

it("2- the test script reports a failing test and fails the run", () => {
const suite = "test/helpers/scripts/mocha_failing_suite.js";
const args = JSON.parse(fs.readFileSync(path.join(sdkRoot, "package.json"), "utf8")).scripts.test.split(" ");
assert.equal(args[0], "mocha");
const glob = args.indexOf("test/tests_*.js");
assert.notEqual(glob, -1, "the test script no longer runs test/tests_*.js");
args[glob] = suite;
const run = spawnSync(process.execPath, [path.join(sdkRoot, "node_modules", "mocha", "bin", "mocha.js")].concat(args.slice(1)), { cwd: sdkRoot, encoding: "utf8" });
assert.equal(run.status, 1, `exit code ${run.status}, output:\n${run.stdout}${run.stderr}`);
assert.ok(run.stdout.indexOf("1 passing") !== -1, run.stdout);
assert.ok(run.stdout.indexOf("1 failing") !== -1, run.stdout);
});
});
Loading