Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ssr): test ssrTransform re-export deps and test stacktrace with first line #19629

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,44 @@ test('combine mappings', async () => {
`)
}
})

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

const __vite_ssr_import_4__ = await __vite_ssr_import__("d");
Object.defineProperty(__vite_ssr_exports__, "d", { enumerable: true, configurable: true, get(){ return __vite_ssr_import_4__ }});
__vite_ssr_dynamic_import__("e");
__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
Loading