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

Fixture "task" is not available anymore #4418

Closed
6 tasks done
luixo opened this issue Oct 31, 2023 · 4 comments · Fixed by #4419
Closed
6 tasks done

Fixture "task" is not available anymore #4418

luixo opened this issue Oct 31, 2023 · 4 comments · Fixed by #4419

Comments

@luixo
Copy link

luixo commented Oct 31, 2023

Describe the bug

According to test extension guide, we can create a test fixture like this:

import { test } from 'vitest'

export const myTest = test.extend({
  logTaskId: async ({ task }, use) => {
    console.log('Task id', task.id);
  },
})

Unfortunately, this doesn't work since v0.34.5, probably because something happened here.
In a version before this change context passed to the function included task (and other default fixtures), currently it included only user-added fixtures.

Also, at v1.0.0-beta.0 the types changed to mirror the change which is incorrect as well.

Reproduction

import { test } from 'vitest'

export const myTest = test.extend({
  logTaskId: async ({ task }, use) => {
    console.log('Task id', task.id);
  },
})

Expected: running logTaskId in a test will log task id
Actual: failed with error in the console

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 388.06 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.2.0 - ~/.nvm/versions/node/v20.2.0/bin/node
    Yarn: 3.6.2 - ~/.nvm/versions/node/v20.2.0/bin/yarn
    npm: 9.6.6 - ~/.nvm/versions/node/v20.2.0/bin/npm
  Browsers:
    Chrome: 118.0.5993.117
    Safari: 17.0

Used Package Manager

yarn

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Oct 31, 2023

Did you try the latest beta? Works fine for me including types

It's possible it's not released yet 🤔

@luixo
Copy link
Author

luixo commented Oct 31, 2023

Do you mean v1.0.0-beta.3? It is the latest beta.

@luixo
Copy link
Author

luixo commented Oct 31, 2023

Seems like types are actually fixed!

Eventually, I found a bug in a latest commit so far as well.

Add this to a fixture-concurrent.test.ts and run pnpm test:

beforeEach(async ({ task }) => {
  console.log('task id', task.id);
});

Expected to have logged task id, got type error:

TypeError: Cannot destructure property 'isFn' of 'fixture' as it is undefined.

@dsyddall
Copy link
Contributor

dsyddall commented Nov 1, 2023

TypeError: Cannot destructure property 'isFn' of 'fixture' as it is undefined.

The error seems to occur when the test is extended with fixtures but the fixtures are unused in the test.
Reproduction here: https://stackblitz.com/edit/vitest-dev-vitest-bdohnv?file=test%2Funused-fixtures.test.ts

This PR should fix it: #4419

@luixo luixo mentioned this issue Nov 12, 2023
6 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants