From dd042c16badf79e71f9fb2ec4c41865b7d9794c5 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Thu, 15 Aug 2024 18:59:35 +0200 Subject: [PATCH] test: fix snapshots --- .../__snapshots__/injector-mock.test.ts.snap | 102 ++++++++---------- test/core/test/browserAutomocker.test.ts | 56 +++++----- test/core/test/injector-esm.test.ts | 2 +- 3 files changed, 73 insertions(+), 87 deletions(-) diff --git a/test/core/test/__snapshots__/injector-mock.test.ts.snap b/test/core/test/__snapshots__/injector-mock.test.ts.snap index fb1477b26ad58..d88551d9d5e69 100644 --- a/test/core/test/__snapshots__/injector-mock.test.ts.snap +++ b/test/core/test/__snapshots__/injector-mock.test.ts.snap @@ -3,160 +3,146 @@ exports[`throws an error when nodes are incompatible > correctly throws an error if awaited assigned vi.hoisted is called inside vi.mock 1`] = `"Cannot call vi.hoisted() inside vi.mock(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited assigned vi.hoisted is called inside vi.mock 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| vi.mock('./mocked', async () => { + | ^ 4| const variable = await vi.hoisted(() => 1) - | ^ - 5| }) - 6| " + 5| })" `; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is called inside vi.mock 1`] = `"Cannot call vi.hoisted() inside vi.mock(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is called inside vi.mock 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| vi.mock('./mocked', async () => { + | ^ 4| await vi.hoisted(() => 1) - | ^ - 5| }) - 6| " + 5| })" `; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is exported as default export 1`] = `"Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first."`; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is exported as default export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export default await vi.hoisted(async () => { - | ^ - 4| return {} - 5| })" + 3| export default await vi.hoisted(async () => {" `; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is exported as named export 1`] = `"Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first."`; exports[`throws an error when nodes are incompatible > correctly throws an error if awaited vi.hoisted is exported as named export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export const values = await vi.hoisted(async () => { - | ^ - 4| return {} - 5| })" + 3| export const values = await vi.hoisted(async () => {" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is called inside vi.mock 1`] = `"Cannot call vi.hoisted() inside vi.mock(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is called inside vi.mock 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| vi.mock('./mocked', () => { + | ^ 4| const variable = vi.hoisted(() => 1) - | ^ - 5| console.log(variable) - 6| })" + 5| console.log(variable)" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is exported as a named export 1`] = `"Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is exported as a named export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export const values = vi.hoisted(async () => { - | ^ - 4| return {} - 5| })" + 3| export const values = vi.hoisted(async () => {" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is exported as default 1`] = `"Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.hoisted is exported as default 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export default vi.hoisted(() => { - | ^ - 4| return {} - 5| })" + 3| export default vi.hoisted(() => {" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock inside vi.hoisted 1`] = `"Cannot call vi.mock() inside vi.hoisted(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock inside vi.hoisted 2`] = ` -" 2| - 3| vi.hoisted(() => { - 4| vi.mock('./mocked') - | ^ - 5| }) - 6| " +" 1| import { vi } from 'vitest' + | ^ + 2| + 3| vi.hoisted(() => {" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside assigned awaited vi.hoisted 1`] = `"Cannot call vi.mock() inside vi.hoisted(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside assigned awaited vi.hoisted 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| const values = await vi.hoisted(async () => { + | ^ 4| vi.mock('./mocked') - | ^ - 5| }) - 6| " + 5| })" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside assigned vi.hoisted 1`] = `"Cannot call vi.mock() inside vi.hoisted(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside assigned vi.hoisted 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| const values = vi.hoisted(() => { + | ^ 4| vi.mock('./mocked') - | ^ - 5| }) - 6| " + 5| })" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside awaited vi.hoisted 1`] = `"Cannot call vi.mock() inside vi.hoisted(): both methods are hoisted to the top of the file and not actually called inside each other."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is called inside awaited vi.hoisted 2`] = ` -" 2| +" 1| import { vi } from 'vitest' + 2| 3| await vi.hoisted(async () => { + | ^ 4| vi.mock('./mocked') - | ^ - 5| }) - 6| " + 5| })" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is exported as a named export 1`] = `"Cannot export the result of "vi.mock". Remove export declaration because "vi.mock" doesn't return anything."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is exported as a named export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export const mocked = vi.mock('./mocked') - | ^ - 4| " + 3| export const mocked = vi.mock('./mocked')" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is exported as default export 1`] = `"Cannot export the result of "vi.mock". Remove export declaration because "vi.mock" doesn't return anything."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.mock is exported as default export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export default vi.mock('./mocked') - | ^ - 4| " + 3| export default vi.mock('./mocked')" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.unmock is exported as a named export 1`] = `"Cannot export the result of "vi.unmock". Remove export declaration because "vi.unmock" doesn't return anything."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.unmock is exported as a named export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export const mocked = vi.unmock('./mocked') - | ^ - 4| " + 3| export const mocked = vi.unmock('./mocked')" `; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.unmock is exported as default export 1`] = `"Cannot export the result of "vi.unmock". Remove export declaration because "vi.unmock" doesn't return anything."`; exports[`throws an error when nodes are incompatible > correctly throws an error if vi.unmock is exported as default export 2`] = ` " 1| import { vi } from 'vitest' + | ^ 2| - 3| export default vi.unmock('./mocked') - | ^ - 4| " + 3| export default vi.unmock('./mocked')" `; diff --git a/test/core/test/browserAutomocker.test.ts b/test/core/test/browserAutomocker.test.ts index 4b2d53181cc97..7d295c7d930ce 100644 --- a/test/core/test/browserAutomocker.test.ts +++ b/test/core/test/browserAutomocker.test.ts @@ -13,11 +13,11 @@ export function test() {} " function test() {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] export { __vitest_mocked_0__ as test, @@ -33,11 +33,11 @@ export class Test {} " class Test {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["Test"]: Test, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["Test"] export { __vitest_mocked_0__ as Test, @@ -53,11 +53,11 @@ export default class Test {} " const __vitest_default = class Test {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -71,11 +71,11 @@ export default function test() {} " const __vitest_default = function test() {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -89,11 +89,11 @@ export default someVariable " const __vitest_default = someVariable - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -107,11 +107,11 @@ export default 'test' " const __vitest_default = 'test' - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -125,11 +125,11 @@ export default null " const __vitest_default = null - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -145,11 +145,11 @@ export default test const test = '123' const __vitest_default = test - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_default"]: __vitest_default, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_default"] export { __vitest_mocked_0__ as default, @@ -169,13 +169,13 @@ export const test3 = function test4() {} const test2 = () => {} const test3 = function test4() {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, ["test2"]: test2, ["test3"]: test3, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] const __vitest_mocked_1__ = __vitest_mocked_module__["test2"] const __vitest_mocked_2__ = __vitest_mocked_module__["test3"] @@ -197,13 +197,13 @@ export const [...rest2] = [] const [test, ...rest] = [] const [...rest2] = [] - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, ["rest"]: rest, ["rest2"]: rest2, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] const __vitest_mocked_1__ = __vitest_mocked_module__["rest"] const __vitest_mocked_2__ = __vitest_mocked_module__["rest2"] @@ -223,14 +223,14 @@ export const test = 2, test2 = 3, test4 = () => {}, test5 = function() {}; " const test = 2, test2 = 3, test4 = () => {}, test5 = function() {}; - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, ["test2"]: test2, ["test4"]: test4, ["test5"]: test5, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] const __vitest_mocked_1__ = __vitest_mocked_module__["test2"] const __vitest_mocked_2__ = __vitest_mocked_module__["test4"] @@ -256,14 +256,14 @@ export const { ...rest2 } = {} const { test: alias } = {} const { ...rest2 } = {} - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, ["rest"]: rest, ["alias"]: alias, ["rest2"]: rest2, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] const __vitest_mocked_1__ = __vitest_mocked_module__["rest"] const __vitest_mocked_2__ = __vitest_mocked_module__["alias"] @@ -287,13 +287,13 @@ it('correctly parses export specifiers', () => { const test = '1' - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["test"]: test, ["test"]: test, ["test"]: test, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["test"] const __vitest_mocked_1__ = __vitest_mocked_module__["test"] const __vitest_mocked_2__ = __vitest_mocked_module__["test"] @@ -317,14 +317,14 @@ export { testing as name4 } from './another-module' import { testing as name4 } from './another-module' import { testing as __vitest_imported_3__ } from './another-module' - const __vitest_es_current_module__ = { + const __vitest_current_es_module__ = { __esModule: true, ["__vitest_imported_0__"]: __vitest_imported_0__, ["__vitest_imported_1__"]: __vitest_imported_1__, ["__vitest_imported_2__"]: __vitest_imported_2__, ["__vitest_imported_3__"]: __vitest_imported_3__, } - const __vitest_mocked_module__ = __vitest_mocker__.mockObject(__vitest_es_current_module__, "automock") + const __vitest_mocked_module__ = globalThis["__vitest_mocker__"].mockObject(__vitest_current_es_module__, "automock") const __vitest_mocked_0__ = __vitest_mocked_module__["__vitest_imported_0__"] const __vitest_mocked_1__ = __vitest_mocked_module__["__vitest_imported_1__"] const __vitest_mocked_2__ = __vitest_mocked_module__["__vitest_imported_2__"] diff --git a/test/core/test/injector-esm.test.ts b/test/core/test/injector-esm.test.ts index 75f0ff6ff678c..7fb2e8e49e407 100644 --- a/test/core/test/injector-esm.test.ts +++ b/test/core/test/injector-esm.test.ts @@ -14,5 +14,5 @@ test('dynamic import', async () => { const result = injectSimpleCode( 'export const i = () => import(\'./foo\')', ) - expect(result).toMatchInlineSnapshot(`"export const i = () => __vitest_browser_runner__.wrapModule(() => import('./foo'))"`) + expect(result).toMatchInlineSnapshot(`"export const i = () => globalThis["__vitest_mocker__"].wrapDynamicImport(() => import('./foo'))"`) })