mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
test: update test for inline sourcemap (#14597)
This commit is contained in:
parent
7861a337f6
commit
1243c2f1cc
@ -1,6 +1,7 @@
|
||||
import { URL } from 'node:url'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { mapFileCommentRegex } from 'convert-source-map'
|
||||
import { commentSourceMap } from '../foo-with-sourcemap-plugin'
|
||||
import {
|
||||
extractSourcemap,
|
||||
findAssetFile,
|
||||
@ -30,12 +31,13 @@ if (!isBuild) {
|
||||
`)
|
||||
})
|
||||
|
||||
test('js with existing inline sourcemap', async () => {
|
||||
test('js with inline sourcemap injected by a plugin', async () => {
|
||||
const res = await page.request.get(
|
||||
new URL('./foo-with-sourcemap.js', page.url()).href,
|
||||
)
|
||||
const js = await res.text()
|
||||
|
||||
expect(js).toContain(commentSourceMap)
|
||||
const sourcemapComments = js.match(mapFileCommentRegex).length
|
||||
expect(sourcemapComments).toBe(1)
|
||||
|
||||
@ -46,9 +48,6 @@ if (!isBuild) {
|
||||
"sources": [
|
||||
"",
|
||||
],
|
||||
"sourcesContent": [
|
||||
null,
|
||||
],
|
||||
"version": 3,
|
||||
}
|
||||
`)
|
||||
|
17
playground/js-sourcemap/foo-with-sourcemap-plugin.ts
Normal file
17
playground/js-sourcemap/foo-with-sourcemap-plugin.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
export const commentSourceMap = [
|
||||
'// default boundary sourcemap with magic-string',
|
||||
'//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHIn0=',
|
||||
].join('\n')
|
||||
|
||||
export default function transformFooWithInlineSourceMap(): Plugin {
|
||||
return {
|
||||
name: 'transform-foo-with-inline-sourcemap',
|
||||
transform(code, id) {
|
||||
if (id.includes('foo-with-sourcemap.js')) {
|
||||
return `${code}${commentSourceMap}`
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
@ -1,5 +1 @@
|
||||
export const foo = 'foo'
|
||||
|
||||
// default boundary sourcemap with magic-string
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHIn0=
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import transformFooWithInlineSourceMap from './foo-with-sourcemap-plugin'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [transformFooWithInlineSourceMap()],
|
||||
build: {
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
|
Loading…
Reference in New Issue
Block a user