From b4e14ffac474a4eca04d6e8a90af7bc95116365d Mon Sep 17 00:00:00 2001 From: yoho Date: Thu, 1 Dec 2022 10:00:01 +0800 Subject: [PATCH 1/2] fix: tab effect vi.mock --- packages/vitest/src/node/plugins/mock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/plugins/mock.ts b/packages/vitest/src/node/plugins/mock.ts index c41c7c65c420..f05598b4f0ae 100644 --- a/packages/vitest/src/node/plugins/mock.ts +++ b/packages/vitest/src/node/plugins/mock.ts @@ -2,7 +2,7 @@ import type { Plugin } from 'vite' import MagicString from 'magic-string' import { getCallLastIndex } from '../../utils' -const hoistRegexp = /^ *\b((?:vitest|vi)\s*.\s*(mock|unmock)\(["`'\s]+(.*[@\w_-]+)["`'\s]+)[),]{1};?/gm +const hoistRegexp = /^[ \t]*\b((?:vitest|vi)\s*.\s*(mock|unmock)\(["`'\s]+(.*[@\w_-]+)["`'\s]+)[),]{1};?/gm const vitestRegexp = /import {[^}]*}.*(?=["'`]vitest["`']).*/gm export function hoistMocks(code: string) { From 574838b84cd57277c387b9df8d90d194fe0a792d Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 3 Dec 2022 18:15:06 +0800 Subject: [PATCH 2/2] test: tab effect --- test/core/test/tab-effect.spec.mjs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/core/test/tab-effect.spec.mjs diff --git a/test/core/test/tab-effect.spec.mjs b/test/core/test/tab-effect.spec.mjs new file mode 100644 index 000000000000..840a43864fdc --- /dev/null +++ b/test/core/test/tab-effect.spec.mjs @@ -0,0 +1,20 @@ +/* eslint-disable eslint-comments/no-unlimited-disable */ +/* eslint-disable */ +import { expect, test, vi } from 'vitest' +import { join as joinPath } from 'node:path' + +const helloWorld = () => { +return joinPath('hello', 'world') +} + +test('Are you mocking me?', () => { +// note there are NO indents in this file +// except the next line +// test pass with spaces, test fails with tab + vi.mock('node:path', () => { +return { +join: vi.fn().mockReturnValue('goodbye world') +} +}) +expect(helloWorld()).toBe('goodbye world') +})