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

vitest freezes when extending a test and testTimeout occurs #4669

Closed
6 tasks done
emcell opened this issue Dec 5, 2023 · 6 comments · Fixed by #4679
Closed
6 tasks done

vitest freezes when extending a test and testTimeout occurs #4669

emcell opened this issue Dec 5, 2023 · 6 comments · Fixed by #4679
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@emcell
Copy link

emcell commented Dec 5, 2023

Describe the bug

vitest freezes when I extend a test like this:

import { describe, test } from 'vitest';

interface TestContext {
  context: {
    hello: string;
  };
}

const myTest = test.extend<TestContext>({
  context: async ({}, use) => {
    const context: TestContext['context'] = {
      hello: 'world',
    };
    await use(context);
  },
});

and a test timeout occurs:

describe('extended test', () => {
  myTest('test-1', async ({ context }) => {
    console.log(context.hello);
    await new Promise<void>((resolve) => setTimeout(resolve, 7000));
  });
});

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-zgzzy9?file=test%2Fsuite.test.ts

npm run test:run

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.10.5 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 1.0.1 
    vite: latest => 5.0.5 
    vitest: latest => 1.0.1

Used Package Manager

npm

Validations

@emcell
Copy link
Author

emcell commented Dec 5, 2023

Removing the await from the use(context) statement solves this issue.

https://stackblitz.com/edit/vitest-dev-vitest-tzqky9?file=test%2Fsuite.test.ts

But the examples in the docs also await the call of use(). https://vitest.dev/guide/test-context.html#test-extend

@sheremet-va
Copy link
Member

  1. use should be awaited
  2. Why is there a Promise that causes a timeout? If I remove it, everything works fine for me

Copy link

github-actions bot commented Dec 5, 2023

Hello @emcell. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@emcell
Copy link
Author

emcell commented Dec 5, 2023

  1. use should be awaited

Ok

  1. Why is there a Promise that causes a timeout? If I remove it, everything works fine for me

This is my minimal example. I faced the issue caused by a test that didn't finish in 5 seconds.

My assumption is, that if a test does not finish in time vitest run will finish with an error. Instead of this, it freezes forever.

@JesusTheHun
Copy link

I'm facing the same issue.
In my case I'm using some third-party NAPI so I have little control over the pending operations and their timeout.

@sheremet-va
Copy link
Member

sheremet-va commented Dec 5, 2023

My assumption is, that if a test does not finish in time vitest run will finish with an error. Instead of this, it freezes forever.

I see now, you reproduction also freezes it for me. Looks like something is up with fixtures resolution when the test is failing due to a timeout

@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome and removed needs reproduction labels Dec 5, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
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) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants