Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

test: fix line numbers in stack traces (#5664)

Andy Edwardsf49aca510c65
diff --git a/.nycrc b/.nycrc
index f5da62b6..4ada3bab 100644
--- a/.nycrc
+++ b/.nycrc
@@ -17,6 +17,7 @@
"package-lock.json",
"**/package-lock.json",
"node_modules/**",
- "scripts/**"
+ "scripts/**",
+ "!test/integration/fixtures/stack-trace.fixture.js"
]
}
diff --git a/package.json b/package.json
index 51f795e6..c09c9eaa 100644
--- a/package.json
+++ b/package.json
@@ -65,8 +65,8 @@
"test-browser": "run-s clean build test-browser:*",
"test-coverage-clean": "rimraf .nyc_output coverage",
"test-coverage-generate": "nyc report --reporter=lcov --reporter=text",
- "test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js --no-forbid-only",
- "test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only",
+ "test-node-run-only": "cross-env NODE_OPTIONS=--enable-source-maps nyc --no-clean --reporter=json node bin/mocha.js --no-forbid-only",
+ "test-node-run": "cross-env NODE_OPTIONS=--enable-source-maps nyc --no-clean --reporter=json node bin/mocha.js --forbid-only",
"test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"",
"test-node:integration:watch": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/options/watch.spec.js\"",
"test-node:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec",
diff --git a/test/integration/fixtures/stack-trace.fixture.js b/test/integration/fixtures/stack-trace.fixture.js
new file mode 100644
index 00000000..f81f9653
--- /dev/null
+++ b/test/integration/fixtures/stack-trace.fixture.js
@@ -0,0 +1,9 @@
+'use strict';
+
+var assert = require('assert');
+
+describe('a suite', function() {
+ it('should succeed', function() {
+ assert(false);
+ });
+});
diff --git a/test/integration/repo-tooling.spec.js b/test/integration/repo-tooling.spec.js
new file mode 100644
index 00000000..f85adf24
--- /dev/null
+++ b/test/integration/repo-tooling.spec.js
@@ -0,0 +1,16 @@
+"use strict";
+
+const { runMochaJSONAsync } = require("./helpers");
+
+describe("repo tooling", function () {
+ it("issue-5663: line numbers are wrong in stack traces when running mocha self tests", async function () {
+ const output = await runMochaJSONAsync("stack-trace.fixture.js");
+ expect(
+ output.failures[0].err.stack,
+ "to contain",
+ // this file needs to be un-excluded from nyc instrumentation, or else this test would fail to catch any
+ // issues with nyc instrumentation affecting stack traces.
+ "stack-trace.fixture.js:7",
+ );
+ });
+});