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

Test cases not found if using CommonJS instead of ES6 #42

Open
Tkong1 opened this issue Jun 17, 2024 · 3 comments
Open

Test cases not found if using CommonJS instead of ES6 #42

Tkong1 opened this issue Jun 17, 2024 · 3 comments

Comments

@Tkong1
Copy link

Tkong1 commented Jun 17, 2024

I am new to node:test and wanted to use the extension to execute my first node unit tests.
I am usually using CommonJS module style for my node.js projects.
But i was only able to see the tests on the Testing window in VSCode if i use the ES6 module style.

Setup:
OS: Ubuntu 22.04
VS-Code: v1.90.1
Node.js: v22.3.0
node:test runner: v1.5.1

Test file (ES6): /test/test.js

import { test } from "node:test";

test("will pass", () => {
  console.log("hello world");
});

test("will fail", () => {
  throw new Error("fail");
});

2024-06-17 21-00-55

Test file (CommonJS): test/test.js

const test = require('node:test');

test("will pass", () => {
  console.log("hello world");
});

test("will fail", () => {
  throw new Error("fail");
});

2024-06-17 20-59-01

When i run the node:test's with the CLI it works with CommonJS module style.

2024-06-17 21-05-48

@connor4312
Copy link
Owner

You want to change

const test = require('node:test');

to

const { test } = require('node:test');

@Tkong1
Copy link
Author

Tkong1 commented Jun 18, 2024

Thanks a lot for this tip, this works.
Even if i don't really know what the issue with
const test = require('node:test');
is.

@Tkong1 Tkong1 closed this as completed Jun 18, 2024
@connor4312
Copy link
Owner

We don't handle that case, I didn't know they default-export the test function. I'll add support for that.

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

No branches or pull requests

2 participants