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

[FEATURE]: Support Node's built-in test runner #5378

Open
OliverJAsh opened this issue Mar 7, 2025 · 1 comment
Open

[FEATURE]: Support Node's built-in test runner #5378

OliverJAsh opened this issue Mar 7, 2025 · 1 comment

Comments

@OliverJAsh
Copy link

OliverJAsh commented Mar 7, 2025

Package Name

No response

Package Version(s)

No response

Describe the feature you'd like

I am using Node's built-in test runner and I would like to use it with Datadog's Test Visibility feature.

The documentation doesn't seem to mention that this is supported. When I tried it I got an error. Reduced test case here. Contents inlined below:

package.json:

{
  "name": "lib",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "NODE_OPTIONS=\"--require dd-trace/ci/init --import dd-trace/register.js\" node --experimental-strip-types --test"
  },
  "dependencies": {
    "dd-trace": "^5.40.0"
  }
}

foo.test.ts:

import assert from "node:assert/strict";
import { describe, it } from "node:test";

declare global {
  const foo: string;
}

describe("foo", () => {
  it("bar", () => {
    assert.strictEqual(1, 1);
  });
});
$ pnpm run test

> lib@ test /Users/oliver/Code/reduced-test-cases/datadog-test-node
> NODE_OPTIONS="--require dd-trace/ci/init --import dd-trace/register.js" node --experimental-strip-types --test

(node:81233) Error: 'import-in-the-middle' failed to wrap 'file:///Users/oliver/Code/reduced-test-cases/datadog-test-node/foo.test.ts'
(Use `node --trace-warnings ...` to show where the warning was created)
file:///Users/oliver/Code/reduced-test-cases/datadog-test-node/foo.test.ts?iitm=true:4
declare global {
        ^^^^^^

SyntaxError: Unexpected identifier 'global'
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
    at #translate (node:internal/modules/esm/loader:468:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:515:27)
    at async ModuleJob._link (node:internal/modules/esm/module_job:115:19)

Node.js v22.14.0
✖ foo.test.ts (209.429292ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 216.805792

✖ failing tests:

test at foo.test.ts:1:1
✖ foo.test.ts (209.429292ms)
  'test failed'
 ELIFECYCLE  Test failed. See above for more details.

Is your feature request related to a problem?

No response

Describe alternatives you've considered

No response

Additional context

No response

@juan-fernandez
Copy link
Collaborator

hey @OliverJAsh ! Thanks for the request. We've been meaning to add support for node:test for a bit (it's indeed not supported), but haven't had the bandwidth to do it 😄. Your request is useful, as we can use it to add weight to the decision

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

No branches or pull requests

2 participants