Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
nferch opened this issue Nov 14, 2023 · 9 comments · Fixed by #5263
Closed
4 tasks done

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

nferch opened this issue Nov 14, 2023 · 9 comments · Fixed by #5263
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@nferch
Copy link

nferch commented Nov 14, 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) 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.

@Uzlopak
Copy link
Member

Uzlopak commented Nov 30, 2023

Can you please provide a minimal viable code example, for example a repo to clone?

@nferch
Copy link
Author

nferch commented Dec 15, 2023

I'm able to repro this with https://github.com/mochajs/mocha-examples/tree/master/packages/typescript

>node_modules/.bin/mocha 12345
/Users/nf/src/mocha-examples/packages/typescript/node_modules/mocha/lib/cli/options.js:113
      const pair = arg.split('=');
                       ^

TypeError: arg.split is not a function
    at /Users/nf/src/mocha-examples/packages/typescript/node_modules/mocha/lib/cli/options.js:113:24
    at Array.reduce (<anonymous>)
    at parse (/Users/nf/src/mocha-examples/packages/typescript/node_modules/mocha/lib/cli/options.js:111:67)
    at loadOptions (/Users/nf/src/mocha-examples/packages/typescript/node_modules/mocha/lib/cli/options.js:246:10)
    at Object.<anonymous> (/Users/nf/src/mocha-examples/packages/typescript/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]    68011 exit 1     node_modules/.bin/mocha 12345

@JoshuaKGoldberg
Copy link
Member

Ha, I happened upon this accidentally while triaging an issue around --delay. npx mocha --delay 123 causes this. Accepting PRs!

@JoshuaKGoldberg JoshuaKGoldberg added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! area: node.js command-line-or-Node.js-specific and removed unconfirmed-bug labels Jan 21, 2024
@deauthe
Copy link

deauthe commented Nov 16, 2024

no solution yet?

@JoshuaKGoldberg
Copy link
Member

@deauthe This repo is fully open source. It's staffed by volunteers such myself, not a private entity. If there is an update or solution it will be posted here.

If you're interested in this getting fixed, then the best next step would be to send a PR yourself. Since you seem interested in it I look forward to seeing your PR. 🙂

@deauthe
Copy link

deauthe commented Nov 17, 2024

@JoshuaKGoldberg Thank you for your response! I appreciate the work and effort that goes into maintaining mocha. My earlier message wasn’t intended to come across as rude, and I apologize if it seemed that way.

I value the work of volunteers like you, and I’ll take a closer look to see if I can contribute a PR to help address this issue.

@Dinika
Copy link
Contributor

Dinika commented Nov 22, 2024

@deauthe @JoshuaKGoldberg I stumbled onto this issue too and would like to look into fixing it. If a PR is not already in the works, is it okay if I start working on this issue?

@JoshuaKGoldberg
Copy link
Member

Truck speeding off a dessert hill and getting real airtime. Caption: "Send it"

We don't have any kind of issue claiming system, as folks often end up not having time for things they'd wanted to do.

@Dinika
Copy link
Contributor

Dinika commented Nov 27, 2024

Thanks for the go-ahead @JoshuaKGoldberg. I've opened a PR for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants