Skip to content

TypeError: arg.split is not a function when passed a numerical argument #5028

Closed
@nferch

Description

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) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

With similar symptoms to #3861, Mocha fails when given a numerical argument:

>npx mocha 1234                                                                 
/Users/nf/.npm/_npx/508606763866ae01/node_modules/mocha/lib/cli/options.js:113
      const pair = arg.split('=');
                       ^

TypeError: arg.split is not a function
    at /Users/nf/.npm/_npx/508606763866ae01/node_modules/mocha/lib/cli/options.js:113:24
    at Array.reduce (<anonymous>)
    at parse (/Users/nf/.npm/_npx/508606763866ae01/node_modules/mocha/lib/cli/options.js:111:67)
    at loadOptions (/Users/nf/.npm/_npx/508606763866ae01/node_modules/mocha/lib/cli/options.js:246:10)
    at Object.<anonymous> (/Users/nf/.npm/_npx/508606763866ae01/node_modules/mocha/bin/mocha.js:27:14)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

Node.js v18.12.1
[1]    79408 exit 1     npx mocha 1234

Expected behavior:
Mocha to proceed as expected, or to throw a more descriptive error message.

Actual behavior:
A crash and a stacktrace.

Reproduces how often:
100%

Versions

Mocha 10.2.0
Node v18.12.1
macOS Sonoma 14.0
zsh 5.9 (x86_64-apple-darwin23.0)

Additional Information

It can be expected that argv is a string array, but it appears that yargsParser.Arguments._ which is fed back into parse at

args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {});
will contain numbers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificstatus: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions