Skip to content

Commit

Permalink
feat: add test fetchModule got sourcemap absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKS12138 committed Apr 5, 2023
1 parent 5b85635 commit d37fa3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/vite-node/src/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const add = (a, b) => a + b
18 changes: 18 additions & 0 deletions test/vite-node/test/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { resolve } from 'pathe'
import { ViteNodeServer } from 'vite-node/server'
import { describe, expect, test, vi } from 'vitest'
import { createServer } from 'vite'
import { extractSourceMap } from '../../../packages/vite-node/src/source-map'

describe('server works correctly', async () => {
test('resolve id considers transform mode', async () => {
Expand All @@ -26,4 +29,19 @@ describe('server works correctly', async () => {
await vnServer.resolveId('/ssr', '/ssr path')
expect(resolveId).toHaveBeenCalledWith('/ssr', '/ssr path', { ssr: true })
})
test('fetchModule with id, and got sourcemap source in absolute path', async () => {
const server = await createServer({
logLevel: 'error',
root: resolve(__dirname, '../'),
})
const vnServer = new ViteNodeServer(server)

// fetchModule in not a valid filesystem path
const fetchResult = await vnServer.fetchModule('/src/foo.js')

const sourceMap = extractSourceMap(fetchResult.code!)

// expect got sourcemap source in a valid filesystem path
expect(sourceMap?.sources[0]).toBe(resolve(__dirname, '../src/foo.js'))
})
})

0 comments on commit d37fa3c

Please sign in to comment.