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 blocks in a called function hang the VS Code runner UI (but work on command line) #212

Closed
openHawkes opened this issue Jan 15, 2024 · 1 comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@openHawkes
Copy link

openHawkes commented Jan 15, 2024

Describe the bug

When I have a test file that includes tests defined in a function outside of a fully denormalized, nested testing flow, the test runner in VS Code hangs. On the command line, the tests execute as expected.

To Reproduce

Here's the code (for a simplest case reproduction):

const sharedTestSuite = (key: string) => {
    it('test', () => { // normally would be it(`test of ${key}` or whatever, but keeping it simple
        expect(key).toEqual('yes');
    });
};

describe('simple repro', () => {
    sharedTestSuite('no');
});

Results on command line (some text cleanup performed):

PS C:/path/to/test> npx vitest run ./shared/services/simplest.test.ts
Debugger attached.
Debugger attached.

 RUN  v0.34.6 C:/path/to/test

 ❯ src/tests/shared/services/simplest.test.ts (1)
   ❯ simple repro (1)
     × test

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/tests/shared/services/simplest.test.ts > simple repro > test
AssertionError: expected 'no' to deeply equal 'yes'

- Expected
+ Received

- yes
+ no

 ❯ src/tests/shared/services/simplest.test.ts:3:21
      1| const sharedTestSuite = (key: string) => {
      2|     it('test', () => {
      3|         expect(key).toEqual('yes');
       |                     ^
      4|     });
      5| };

⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  1 failed (1)
   Start at  11:06:19
   Duration  1.85s (transform 116ms, setup 0ms, collect 15ms, tests 8ms, environment 516ms, prepare 288ms)

That's good. That's what we want.


In the runner

In the runner, things hang.

I'm using the "Run test" button pictured here. Note that this is a TypeScript environment, for what that's worth.

Button in UI used to execute tests -- running all tests in the file that contains the sample code provided earlier

Screenshot of VS Code with tests running, showing the "test" entry for the function is still churning in two locations, with the following text superimposed on the screenshot: "Test Results pane shows we're done, but the UI hangs forever, seemingly waiting on the "test" test to execute (it has, so to speak)."

The tests are run. You can follow through by debugging and everything's happy. It hangs on completion.

Expected behavior

  • "test" should show up in the test context, as a branch under "simple repro", not on the same level as "simple repro"
  • The test run should complete.

Environment

Tried this:

(Paste info.txt content generated by the example project)

but stopped when I got 'yarn' is not recognized as an internal or external command,.

By hand, we've got...

  • OS:
    • OS Name: Microsoft Windows 11 Pro
    • OS Version: 10.0.22000 N/A Build 22000
  • VSCode version:
    • Version: 1.85.1 (user setup)
    • Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
    • Date: 2023-12-13T09:49:37.021Z
    • Electron: 25.9.7
    • ElectronBuildId: 25551756
    • Chromium: 114.0.5735.289
    • Node.js: 18.15.0
    • V8: 11.4.183.29-electron.0
    • OS: Windows_NT x64 10.0.22000
  • Vitest version (from package-lock.json):
    • "node_modules/@vitest/browser": { "version": "0.34.4",
    • "node_modules/@vitest/coverage-v8": { "version": "0.34.4",
    • "node_modules/@vitest/expect": { "version": "0.34.6",
    • "node_modules/@vitest/runner": { "version": "0.34.6",
  • Vitest plugin version:
    • v0.2.43 (preview)

Spitball: I wonder if this is related to describe.each and test.each are shown as 'test result not found' #7, as that's the entry point for this issue. I originally had tests running in a loop, and the above construction seems to reduce the actual error to its simplest case.

The VS Code plugin seems to be doing a naïve pass through the file, grabbing all the test-related markers (describe, it, etc), and building an expected test tree that includes those as conventional tests, even though they're in a different, reused scope.

Either way, this isn't working in the runner, but works fine on the command line.

@openHawkes openHawkes added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jan 15, 2024
@sheremet-va
Copy link
Member

This should be fixed in pre-release 0.5.0 and higher. Note that the extension now requires Vitest 1.4.0 or higher.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants