Skip to content

fix!(runner): correctly process custom tasks, update runner hooks naming#4076

Merged
sheremet-va merged 4 commits intovitest-dev:mainfrom
sheremet-va:fix/break-custom-tasks
Sep 29, 2023
Merged

fix!(runner): correctly process custom tasks, update runner hooks naming#4076
sheremet-va merged 4 commits intovitest-dev:mainfrom
sheremet-va:fix/break-custom-tasks

Conversation

@sheremet-va
Copy link
Member

@sheremet-va sheremet-va commented Sep 5, 2023

Description

This is a breaking change. Previous support for custom tasks has been rewritten a little bit.

Fixes #3404

  1. Methods on custom runner that referenced "test" now mention "task" (onAfterRunTest is now onAfterRunTask and so on, onBeforeRun and onAfterRun are now named onBeforeRunFiles and onAfterRunFiles). They now also accept tasks with type "custom" (the shape of the object is identical)
  2. To collect custom tasks you now need to call getCurrentSuite().task() instead of getCurrentSuite().custom(). It now accepts a second arguments which are options. You can pass down handler as handler instead of saving it using setFn. If you used createChainable before, you can spread this in options instead of calling custom.call(this) - this now has no effect, it no longer relies on this at all:
  getCurrentSuite().task(name, {
    ...this, // so "todo"/"skip" is tracked correctly
    meta: {
      customPropertyToDifferentiateTask: true
    },
    handler: fn,
    timeout,
  })
  1. Vitest also now provides a createTaskCollector utility - this will define a function that supports todo/skip/each/skipIf/runIf and other .test chainables. The difference with createChainable is that you don't need to specify what you need to support, and it also supports more methods (each/runIf/skipIf):
const myCustomTask = createTaskCollector(function (name, fn, timeout) {
   getCurrentSuite().task(name, {
     ...this, // so "todo"/"skip" is tracked correctly
     meta: {
       customPropertyToDifferentiateTask: true
     },
     handler: fn,
     timeout,
   })
 })

myCustomTask.each([1, 2])('name', (data: number) => {
  // ... do whatever you want
})

myCustomTask.skipIf(isWindows)('name', () => {
   // ...
})
  1. SnapshotClient now accepts options - instead of overriding equalityCheck you need to pass down isEqual function. If you don't rely on .toMatchSnapshot({ ... }) tests (checking an object shape AND a snapshot string), you don't need to pass anything.
  2. Some of the methods on SnapshotClient were renamed to better represent what they do: setTest -> startCurrentRun, resetCurrent -> finishCurrentRun (you need to call .assert between those two calls)
  3. This PR also removes context.meta. It was deprecated for some time, please use context.task instead.

And now it actually works :)

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to Apply decorator to all tests within block

1 participant