Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@putout/plugin-vitest NPM version

A Vite-native testing framework. It's fast!

(c) vitest.dev

🐊Putout plugin helps to migrate to latest version of vitest.

Install

npm i @putout/plugin-vitest -D

Rules

Config

{
    "rules": {
        "vitest/apply-hoisted": "on",
        "vitest/convert-jest-to-vitest": "on",
        "vitest/v3-apply-options-as-second-argument": "on",
        "vitest/v3-apply-browser-instances": "on"
    },
    "plugins": ["vitest"]
}

apply-hoisted

All static import statements in ES modules are hoisted to the top of the file, so any code that is defined before the imports will actually be executed after imports are evaluated.

(c) vitest.dev

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

let hello;
let world;

it('hello', () => {
    hello.calledWith();
});

✅ Example of correct code

const hoisted = vi.hoisted({
    hello: vi.fn(),
    world: vi.fn(),
});

beforeEach(() => {
    hello.mockClear();
    world.mockClear();
});

it('hello', () => {
    hoisted.hello.calledWith();
});

convert-jest-to-vitest

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

jest.mock('hello', {
    ...jest.requireActual('hello'),
    abc: jest.fn(),
});

✅ Example of correct code

vi.mock('hello', async () => ({
    ...await vi.importActual('hello'),
    abc: vi.fn(),
}));

v3-apply-options-as-second-argument

Vitest 3.0 prints a warning if you pass down an object as a third argument to test or describe functions. Vitest 4.0 will throw an error if the third argument is an object.

(c) vitest.dev

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

test('validation works', () => {
    // ...
}, {
    retry: 3,
});

✅ Example of correct code

test('validation works', {retry: 3}, () => {
    // ...
});

v3-apply-browser-instances

Both browser.name and browser.providerOptions will be removed in Vitest 4. Instead of them, use the new browser.instances option.

(c) vitest.dev

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

export default defineConfig({
    test: {
        browser: {
            name: 'chromium',
            providerOptions: {
                launch: {
                    devtools: true,
                },
            },
        },
    },
});

✅ Example of correct code

export default defineConfig({
    test: {
        browser: {
            instances: [{
                name: 'chromium',
                providerOptions: {
                    launch: {
                        devtools: true,
                    },
                },
            }],
        },
    },
});

License

MIT