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

mocha failed and shows ERROR: null #5048

Closed
ramanarupa opened this issue Dec 18, 2023 · 9 comments
Closed

mocha failed and shows ERROR: null #5048

ramanarupa opened this issue Dec 18, 2023 · 9 comments
Labels
type: question support question

Comments

@ramanarupa
Copy link

I'm using ts-mocha and put mistaken code like this:
this.logger?.error(e)

ts-mocha is failed, and after debugging code of mocha I've detected stupid reaction like this
(node:13116) ExperimentalWarning:--experimental-loadermay be removed in the future; instead useregister(): --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));' (Use node --trace-warnings ...` to show where the warning was created)
mocha inspect [spec..]

Run tests with Mocha

Rules & Behavior
--allow-uncaught Allow uncaught errors to propagate [boolean]
-A, --async-only Require all tests to use a callback (async) or
return a Promise [boolean]
-b, --bail Abort ("bail") after first test failure [boolean]
--check-leaks Check for global variable leaks [boolean]
--delay Delay initial execution of root suite [boolean]
--dry-run Report tests without executing them [boolean]
--exit Force Mocha to quit after tests complete [boolean]
--fail-zero Fail test run if no test(s) encountered [boolean]
--forbid-only Fail if exclusive test(s) encountered [boolean]
--forbid-pending Fail if pending test(s) encountered [boolean]
--global, --globals List of allowed global variables [array]
-j, --jobs Number of concurrent jobs for --parallel; use 1 to
run in serial
[number] [default: (number of CPU cores - 1)]
-p, --parallel Run tests in parallel [boolean]
--retries Retry failed tests this many times [number]
-s, --slow Specify "slow" test threshold (in milliseconds)
[string] [default: 75]
-t, --timeout, --timeouts Specify test timeout threshold (in milliseconds)
[string] [default: 2000]
-u, --ui Specify user interface [string] [default: "bdd"]

Reporting & Output
-c, --color, --colors Force-enable color output [boolean]
--diff Show diff on failure
[boolean] [default: true]
--full-trace Display full stack traces [boolean]
--inline-diffs Display actual/expected differences
inline within each string [boolean]
-R, --reporter Specify reporter to use
[string] [default: "spec"]
-O, --reporter-option, Reporter-specific options
--reporter-options (<k=v,[k1=v1,..]>) [array]

Configuration
--config Path to config file [string] [default: (nearest rc file)]
-n, --node-option Node or V8 option (no leading "--") [array]
--package Path to package.json for config [string]

File Handling
--extension File extension(s) to load
[array] [default: ["js","cjs","mjs"]]
--file Specify file(s) to be loaded prior to root suite
execution [array] [default: (none)]
--ignore, --exclude Ignore file(s) or glob pattern(s)
[array] [default: (none)]
--recursive Look for tests in subdirectories [boolean]
-r, --require Require module [array] [default: (none)]
-S, --sort Sort test files [boolean]
-w, --watch Watch files in the current working directory for
changes [boolean]
--watch-files List of paths or globs to watch [array]
--watch-ignore List of paths or globs to exclude from watching
[array] [default: ["node_modules",".git"]]

Test Filters
-f, --fgrep Only run tests containing this string [string]
-g, --grep Only run tests matching this string or regexp [string]
-i, --invert Inverts --grep and --fgrep matches [boolean]

Positional Arguments
spec One or more files, directories, or globs to test
[array] [default: ["test"]]

Other Options
-h, --help Show usage information & exit [boolean]
-V, --version Show version number & exit [boolean]
--list-interfaces List built-in user interfaces & exit [boolean]
--list-reporters List built-in reporters & exit [boolean]

× ERROR: null
`

@mklenbw
Copy link

mklenbw commented Dec 20, 2023

I'm having the same issue with following configuration:

extensions:
  - "ts"
project: "./tsconfig.json"
spec:
  - "./**/*.test.ts"
require:
  - "ts-node/register"
  - "tsconfig-paths/register"
reporter: "dot"
node-option:
  - "experimental-specifier-resolution=node"
  - "loader=ts-node/esm"

@kuba-orlik
Copy link

I'm also experiencing this issue. I'm using node v21.4.0 and ts-node.

This command fails with "Error: null":

TS_NODE_PROJECT='./src/back/tsconfig.json' npx mocha --recursive --timeout 20000  --require ts-node/register src/back/some.test.ts

@tpluscode
Copy link

I found that this happens with recent versions of node. For example, worked find in 18.17 but is broken in 18.19

@tpluscode
Copy link

My problem is actually ts-node/esm loader. I switched to tsm and the tests work again.

@tpluscode
Copy link

Alternatively, see TypeStrong/ts-node#1007 (comment)

@ramanarupa
Copy link
Author

ramanarupa commented Jan 3, 2024

I resolved this problem by changing "ts-node/esm" to "tsx/esm":

"node-option": [
"experimental-specifier-resolution=node",
"import=tsx/esm",
"trace-uncaught"
],

@tpluscode
Copy link

tpluscode commented Jan 3, 2024 via email

@JoshuaKGoldberg
Copy link
Member

The Mocha config file, such as .mocharc.json, I'm guessing.

See also:

This issue seems to have turned into a general Q&A, so I'm going to close it out as resolved. Glad things seem to have been figured out!

If there's still a bug you'd like to report (echoing ERROR: null?) please do file a new issue with our new bug report template. We'd be happy to take a look.

...and also, please, use ``` code blocks to capture monospace output. This issue was very difficult to read. https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

@ClementValot
Copy link

For whom it may help, I've had this issue because my tsconfig.json had "moduleResolution": "bundler"

Still, the ERROR: null is worth investigating 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question support question
Projects
None yet
Development

No branches or pull requests

6 participants