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

Dynamically created test description not displayed in browser mode #515

Open
4 tasks done
kayahr opened this issue Oct 29, 2024 · 3 comments
Open
4 tasks done

Dynamically created test description not displayed in browser mode #515

kayahr opened this issue Oct 29, 2024 · 3 comments

Comments

@kayahr
Copy link

kayahr commented Oct 29, 2024

Describe the bug

If a test uses a dynamically created description (like describe("sum" + " some context", ...) then the testing panel in VSCode shows the text <unknown> instead of the real text:

image

But this only happens with enabled browser mode. When browser mode is disabled (running in node) then the description is shown directly.

image

When executing the tests then the <unknown> description is replaced with the correct one. But every time the tests are refreshed, the description vanishes again.

Reproduction

  • Clone https://github.com/kayahr/vitest-bugs-1
  • Run npm i
  • Open project in vscode with enabled vitest extension
  • Open Testing panel.
  • Click Refresh tests button and expand the tree. It shows text <unknown>
  • Click Run tests button. Now the description is correct.
  • Click Refresh tests again and the description is broken again.

Output

[INFO 5:02:38 PM] [v1.6.2] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 5:02:38 PM] [API] Running Vitest v2.1.4 (vitest-bug-1/vitest.config.js) with [email protected]: /usr/bin/node 
[INFO 5:02:38 PM] [Worker] Port 63315 is in use, trying another one...
[INFO 5:02:38 PM] [Worker] Port 63316 is in use, trying another one...
[INFO 5:02:38 PM] [API] Vitest v2.1.4 (vitest-bug-1/vitest.config.js) child process 452285 created
[INFO 5:02:38 PM] [VSCODE] Watching vitest-bug-1 with pattern **/*
[INFO 5:02:38 PM] [API] Collecting tests: sum.test.js
[INFO 5:02:39 PM] [Worker] Collecting /home/k/Projects/vitest-bugs/vitest-bug-1/sum.test.js const __vite_ssr_import_0__ = await __vite_ssr_import__("/node_modules/vitest/dist/index.js", {"importedNames":["describe","it","expect"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("/sum.js", {"importedNames":["sum"]});



const someContext = "xyz";

__vite_ssr_import_0__.describe("sum " + "someContext", () => {
    __vite_ssr_import_0__.it("sums numbers", () => {
        __vite_ssr_import_0__.expect(__vite_ssr_import_1__.sum(1, 2)).toBe(3);
    });
});

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN1bS50ZXN0LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGRlc2NyaWJlLCBpdCwgZXhwZWN0IH0gZnJvbSBcIi9ub2RlX21vZHVsZXMvdml0ZXN0L2Rpc3QvaW5kZXguanNcIjtcbmltcG9ydCB7IHN1bSB9IGZyb20gXCIvc3VtLmpzXCI7XG5cbmNvbnN0IHNvbWVDb250ZXh0ID0gXCJ4eXpcIjtcblxuZGVzY3JpYmUoXCJzdW0gXCIgKyBcInNvbWVDb250ZXh0XCIsICgpID0+IHtcbiAgICBpdChcInN1bXMgbnVtYmVyc1wiLCAoKSA9PiB7XG4gICAgICAgIGV4cGVjdChzdW0oMSwgMikpLnRvQmUoMyk7XG4gICAgfSk7XG59KTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxDQUFBOztBQUEwRTtBQUM1QztBQUM5QjtBQUNBLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUM7QUFDMUI7QUFDQSw4QkFBUSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDeEMsQ0FBQyxDQUFDLENBQUMsQ0FBQyx3QkFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUM5QixDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsNEJBQU0sQ0FBQyx5QkFBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ2xDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQzsifQ==

Skipping __vite_ssr_import__ (unknown call)
Skipping __vite_ssr_import__ (unknown call)
Skipping sum (unknown call)
Skipping expect (unknown call)
Found it sums numbers (run)
Found describe <unknown> (run)
Found location for suite <unknown> 8:0 -> 6:0
Found location for test sums numbers 9:4 -> 7:4
[5:02:39 PM] [VSCODE] Ignoring file: sum.test.js.git
[5:02:39 PM] [VSCODE] Ignoring file: .git/FETCH_HEAD
[5:02:40 PM] [VSCODE] Ignoring file: sum.test.js.git

Version

1.6.2

Validations

@sheremet-va
Copy link
Member

When using the browser mode, the extension parses the file instead of running it directly during the collection phase. This is needed because spinning up a browser just to collect tests is very expensive, and it's possible to make fast edits and halt your IDE even. You can achieve the same for your Node.js tests by enabling vitest.experimentalStaticAstCollect.

Ideally, it should at least show "sum" + " some context" as the name here instead of <unknown>.

@kayahr
Copy link
Author

kayahr commented Oct 29, 2024

Ideally, it should at least show "sum" + " some context" as the name here instead of <unknown>.

Wouldn't be that much more useful. It is such a simple expression because this is just a minimal example for this bug report. What I actually want to do there is calling a function which checks if test is executed in browser or node. And I only do this as a workaround for the other bug I just reported (#516) so Browser and Node tests have different paths so they are handled separately in vscode-vitest.

But maybe there are other use-cases for having a dynamic test description.

@kayahr
Copy link
Author

kayahr commented Oct 31, 2024

Now that #516 is fixed (Thanks! Works perfectly now!) I no longer need my workaround with dynamic test names. So feel free to close this issue. If I understood it correctly it cannot be improved further anyway.

EDIT: Sorry for the comment mess. I lost myself between pull requests and issues :D

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