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: update test for inline sourcemap #14597

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -36,6 +37,7 @@ if (!isBuild) {
)
Dunqing marked this conversation as resolved.
Show resolved Hide resolved
const js = await res.text()

expect(js).toContain(commentSourceMap)
const sourcemapComments = js.match(mapFileCommentRegex).length
expect(sourcemapComments).toBe(1)

Expand All @@ -46,9 +48,6 @@ if (!isBuild) {
"sources": [
"",
],
"sourcesContent": [
null,
],
"version": 3,
}
`)
Expand Down
15 changes: 15 additions & 0 deletions playground/js-sourcemap/foo-with-sourcemap-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Plugin } from 'vite'

export const commentSourceMap =
'//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHIn0='

export default function transformFooWithInlineSourceMap(): Plugin {
return {
name: 'transform-foo-with-inline-sourcemap',
transform(code, id) {
if (id.includes('foo-with-sourcemap.js')) {
return `${code}\n${commentSourceMap}`
}
},
}
}
2 changes: 0 additions & 2 deletions playground/js-sourcemap/foo-with-sourcemap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const foo = 'foo'

// default boundary sourcemap with magic-string
Dunqing marked this conversation as resolved.
Show resolved Hide resolved

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHIn0=
2 changes: 2 additions & 0 deletions playground/js-sourcemap/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'vite'
import transformFooWithInlineSourceMap from './foo-with-sourcemap-plugin'

export default defineConfig({
plugins: [transformFooWithInlineSourceMap()],
build: {
sourcemap: true,
rollupOptions: {
Expand Down