diff --git a/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts b/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts index ed9d88eba7b1f1..074ed12c63cb37 100644 --- a/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts +++ b/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts @@ -234,27 +234,32 @@ describe('module runner initialization', async () => { }) it.for([ - ['/fixtures/cyclic2/test1/index.js', true], - ['/fixtures/cyclic2/test2/index.js', true], - ['/fixtures/cyclic2/test3/index.js', true], - ['/fixtures/cyclic2/test4/index.js', true], - ['/fixtures/cyclic2/test5/index.js', false], - ] as const)(`cyclic %s`, async ([entry, ok], { runner }) => { - if (ok) { - const mod = await runner.import(entry) - expect({ ...mod }).toEqual({ - dep1: { - ok: true, - }, - dep2: { - ok: true, - }, - }) - } else { - await expect(() => runner.import(entry)).rejects.toMatchObject({ - name: 'ReferenceError', - }) - } + '/fixtures/cyclic2/test1/index.js', + '/fixtures/cyclic2/test2/index.js', + '/fixtures/cyclic2/test3/index.js', + '/fixtures/cyclic2/test4/index.js', + ] as const)(`cyclic %s`, async (entry, { runner }) => { + const mod = await runner.import(entry) + expect({ ...mod }).toEqual({ + dep1: { + ok: true, + }, + dep2: { + ok: true, + }, + }) + }) + + it(`cyclic invalid`, async ({ runner }) => { + // Node also fails but with a different message + // $ node packages/vite/src/node/ssr/runtime/__tests__/fixtures/cyclic2/test5/index.js + // ReferenceError: Cannot access 'dep1' before initialization + await expect(() => + runner.import('/fixtures/cyclic2/test5/index.js'), + ).rejects.toMatchObject({ + name: 'ReferenceError', + message: `Cannot access '__vite_ssr_import_1__' before initialization`, + }) }) })