Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add js sourcemap tests (#7494)
- Loading branch information
1 parent
42c15f6
commit 9707f0e
Showing
17 changed files
with
199 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isBuild } from 'testUtils' | ||
|
||
if (isBuild) { | ||
test('should not output sourcemap warning (#4939)', () => { | ||
serverLogs.forEach((log) => { | ||
expect(log).not.toMatch('Sourcemap is likely to be incorrect') | ||
}) | ||
}) | ||
} else { | ||
test('this file only includes test for build', () => { | ||
expect(true).toBe(true) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { URL } from 'url' | ||
import { | ||
extractSourcemap, | ||
formatSourcemapForSnapshot, | ||
isBuild | ||
} from 'testUtils' | ||
|
||
if (!isBuild) { | ||
test('js', async () => { | ||
const res = await page.request.get(new URL('./foo.js', page.url()).href) | ||
const js = await res.text() | ||
const lines = js.split('\n') | ||
expect(lines[lines.length - 1].includes('//')).toBe(false) // expect no sourcemap | ||
}) | ||
|
||
test('ts', async () => { | ||
const res = await page.request.get(new URL('./bar.ts', page.url()).href) | ||
const js = await res.text() | ||
const map = extractSourcemap(js) | ||
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` | ||
Object { | ||
"mappings": "AAAO,aAAM,MAAM;", | ||
"sources": Array [ | ||
"/root/bar.ts", | ||
], | ||
"sourcesContent": Array [ | ||
"export const bar = 'bar' | ||
", | ||
], | ||
"version": 3, | ||
} | ||
`) | ||
}) | ||
|
||
test('should not output missing source file warning', () => { | ||
serverLogs.forEach((log) => { | ||
expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/) | ||
}) | ||
}) | ||
} else { | ||
test('this file only includes test for serve', () => { | ||
expect(true).toBe(true) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const bar = 'bar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const foo = 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="wrapper"> | ||
<h1>JS Sourcemap</h1> | ||
</div> | ||
|
||
<script type="module" src="./foo.js"></script> | ||
<script type="module" src="./bar.ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "test-js-sourcemap", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
module.exports = { | ||
build: { | ||
sourcemap: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<p><js></p> | ||
</template> | ||
|
||
<script> | ||
console.log('script') | ||
</script> | ||
|
||
<script setup> | ||
console.log('setup') | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<p><ts></p> | ||
</template> | ||
|
||
<script lang="ts"> | ||
console.log('ts script') | ||
</script> | ||
|
||
<script lang="ts" setup> | ||
console.log('ts setup') | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.