Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,3 +1531,43 @@ test('combine mappings', async () => {
`)
}
})

test('deps', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const result = await ssrTransformSimple(`\
import a from "a";
export { b } from "b";
export * from "c";
export * as d from "d";
import("e")
export * as A from "a";
`)
expect(result?.code).toMatchInlineSnapshot(`
"Object.defineProperty(__vite_ssr_exports__, "b", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_1__.b }});
Object.defineProperty(__vite_ssr_exports__, "d", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_3__ }});
Object.defineProperty(__vite_ssr_exports__, "A", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_4__ }});
const __vite_ssr_import_0__ = await __vite_ssr_import__("a", {"importedNames":["default"]});
const __vite_ssr_import_1__ = await __vite_ssr_import__("b", {"importedNames":["b"]});
const __vite_ssr_import_2__ = await __vite_ssr_import__("c");__vite_ssr_exportAll__(__vite_ssr_import_2__);

const __vite_ssr_import_3__ = await __vite_ssr_import__("d");const __vite_ssr_import_4__ = await __vite_ssr_import__("a");
__vite_ssr_dynamic_import__("e");

"
`)
expect({
deps: result?.deps,
dynamicDeps: result?.dynamicDeps,
}).toMatchInlineSnapshot(`
{
"deps": [
"a",
"b",
"c",
"d",
],
"dynamicDeps": [
"e",
],
}
`)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// comment
throw new Error('__TEST__')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('__TEST__')
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ describe('module runner initialization', async () => {
)
})

it('stacktrace column on first line', async ({ runner, server }) => {
// column is off by "use strict"
const topLevelError = await getError(() =>
runner.import('/fixtures/has-error-first.js'),
)
expect(serializeStack(server, topLevelError)).toBe(
' at <root>/fixtures/has-error-first.js:1:18',
)

const topLevelErrorTs = await getError(() =>
runner.import('/fixtures/has-error-first-comment.ts'),
)
expect(serializeStack(server, topLevelErrorTs)).toBe(
' at <root>/fixtures/has-error-first-comment.ts:2:17',
)
})

it('deep stacktrace', async ({ runner, server }) => {
const methodError = await getError(async () => {
const mod = await runner.import('/fixtures/has-error-deep.ts')
Expand Down