diff --git a/package.json b/package.json index f6b9ba3..47c9865 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/helpers/scripts/mocha_failing_suite.js b/test/helpers/scripts/mocha_failing_suite.js new file mode 100644 index 0000000..7e471af --- /dev/null +++ b/test/helpers/scripts/mocha_failing_suite.js @@ -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); + }); +}); diff --git a/test/tests_package.js b/test/tests_package.js index 323f682..499e460 100644 --- a/test/tests_package.js +++ b/test/tests_package.js @@ -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"); @@ -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); + }); });