Description
openedon Aug 4, 2023
Prerequisites
- Checked that your issue hasn't already been filed by cross-referencing issues with the
faq
label - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.
Description
When trying to use the delay
option, the root suite is not delayed and instead runs immediately. I was trying run async code before the root suite describe
and use it in describe block. I found this issue which said to use the delay
flag and gave an example. The docs say that it delays running the root suite until run
is called, but when I try to use it in that way doesn't delay the suite and instead runs the suite immediately.
Steps to Reproduce
// index.js
const assert = require('assert');
assert(run); // ensure `delay` was processed
let z;
setTimeout(() => {
z = 6
run();
}, 1000);
describe('my suite', function () {
it(z, function () {
assert.strictEqual(z, 6);
});
});
npx mocha --delay index.js
Expected behavior: Delays processing the root suite until run
is called
Actual behavior: Errors while processing the inner it
as the async variable has not been set
TypeError: Test argument "title" should be a string. Received type "undefined"
at createInvalidArgumentTypeError (/Users/stevenlambert/sandbox/mocha-delay/node_modules/mocha/lib/errors.js:268:13)
at new Test (/Users/stevenlambert/sandbox/mocha-delay/node_modules/mocha/lib/test.js:23:11)
at context.it.context.specify (/Users/stevenlambert/sandbox/mocha-delay/node_modules/mocha/lib/interfaces/bdd.js:87:18)
at Suite.<anonymous> (/Users/stevenlambert/sandbox/mocha-delay/index.js:10:3)
at Object.create (/Users/stevenlambert/sandbox/mocha-delay/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/Users/stevenlambert/sandbox/mocha-delay/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object.<anonymous> (/Users/stevenlambert/sandbox/mocha-delay/index.js:9:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Reproduces how often: 100%
Versions
- The output of
mocha --version
andnode_modules/.bin/mocha --version
:10.2.0
- The output of
node --version
:18.16.0
- Your operating system
- name and version:
MacOS Ventura 13.4.1
- name and version:
- Your shell (e.g., bash, zsh, PowerShell, cmd):
zsh
Additional Information
I realize that the issue linked above is from 2015 so maybe the delay
flag no longer does what the fix in the issue describes. If that's the case then I'd like to resurface that issue since I want do to exactly what that issue was asking.