Skip to content

Commit

Permalink
chore: revert some
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 10, 2024
1 parent 0f39deb commit 06d820e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect } from 'vitest'
import type { ModuleRunner } from 'vite/module-runner'
import { createModuleRunnerTester, editFile, resolvePath } from './utils'

describe('module runner initialization', async () => {
Expand All @@ -17,11 +18,13 @@ describe('module runner initialization', async () => {
return err
}
}
const serializeStack = (root: string, err: Error) => {
return err.stack!.split('\n')[1].replace(root, '<root>')
const serializeStack = (runner: ModuleRunner, err: Error) => {
return err.stack!.split('\n')[1].replace(runner.options.root, '<root>')
}
const serializeStackDeep = (root: string, err: Error) => {
return err.stack!.split('\n').map((s) => s.replace(root, '<root>'))
const serializeStackDeep = (runtime: ModuleRunner, err: Error) => {
return err
.stack!.split('\n')
.map((s) => s.replace(runtime.options.root, '<root>'))
}

it('source maps are correctly applied to stack traces', async ({
Expand All @@ -32,15 +35,15 @@ describe('module runner initialization', async () => {
const topLevelError = await getError(() =>
runner.import('/fixtures/has-error.js'),
)
expect(serializeStack(server.config.root, topLevelError)).toBe(
expect(serializeStack(runner, topLevelError)).toBe(
' at <root>/fixtures/has-error.js:2:7',
)

const methodError = await getError(async () => {
const mod = await runner.import('/fixtures/throws-error-method.ts')
mod.throwError()
})
expect(serializeStack(server.config.root, methodError)).toBe(
expect(serializeStack(runner, methodError)).toBe(
' at Module.throwError (<root>/fixtures/throws-error-method.ts:6:9)',
)

Expand All @@ -57,19 +60,17 @@ describe('module runner initialization', async () => {
mod.throwError()
})

expect(serializeStack(server.config.root, methodErrorNew)).toBe(
expect(serializeStack(runner, methodErrorNew)).toBe(
' at Module.throwError (<root>/fixtures/throws-error-method.ts:11:9)',
)
})

it('deep stacktrace', async ({ runner, server }) => {
it('deep stacktrace', async ({ runner }) => {
const methodError = await getError(async () => {
const mod = await runner.import('/fixtures/has-error-deep.ts')
mod.main()
})
expect(
serializeStackDeep(server.config.root, methodError).slice(0, 3),
).toEqual([
expect(serializeStackDeep(runner, methodError).slice(0, 3)).toEqual([
'Error: crash',
' at crash (<root>/fixtures/has-error-deep.ts:2:9)',
' at Module.main (<root>/fixtures/has-error-deep.ts:6:3)',
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/ssr/runtime/serverModuleRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import type { ModuleRunnerTransport } from '../../../shared/moduleRunnerTranspor
* @experimental
*/
export interface ServerModuleRunnerOptions
extends Omit<ModuleRunnerOptions, 'fetchModule' | 'hmr' | 'transport'> {
extends Omit<
ModuleRunnerOptions,
'root' | 'fetchModule' | 'hmr' | 'transport'
> {
/**
* Disable HMR or configure HMR logger.
*/
Expand Down

0 comments on commit 06d820e

Please sign in to comment.