Skip to content

Commit ca34c64

Browse files
authored
test(ssr): add import and export ordering snapshot (#14468)
1 parent fbfad21 commit ca34c64

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -948,3 +948,31 @@ test('import assertion attribute', async () => {
948948
__vite_ssr_dynamic_import__('./bar.json', { assert: { type: 'json' } });
949949
"`)
950950
})
951+
952+
test('import and export ordering', async () => {
953+
// Given all imported modules logs `mod ${mod}` on execution,
954+
// and `foo` is `bar`, the logging order should be:
955+
// "mod a", "mod foo", "mod b", "bar1", "bar2"
956+
expect(
957+
await ssrTransformSimpleCode(`
958+
console.log(foo + 1)
959+
export * from './a'
960+
import { foo } from './foo'
961+
export * from './b'
962+
console.log(foo + 2)
963+
`),
964+
).toMatchInlineSnapshot(`
965+
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\");
966+
const __vite_ssr_import_1__ = await __vite_ssr_import__(\\"./a\\");
967+
__vite_ssr_exportAll__(__vite_ssr_import_1__);
968+
const __vite_ssr_import_2__ = await __vite_ssr_import__(\\"./b\\");
969+
__vite_ssr_exportAll__(__vite_ssr_import_2__);
970+
971+
console.log(__vite_ssr_import_0__.foo + 1)
972+
973+
974+
975+
console.log(__vite_ssr_import_0__.foo + 2)
976+
"
977+
`)
978+
})

0 commit comments

Comments
 (0)