test: error in worker test (#7518)

This commit is contained in:
yoho 2022-03-30 14:56:20 +08:00 committed by GitHub
parent a0f82bd88c
commit b1db2326a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 15 deletions

View File

@ -6,7 +6,8 @@ import fs from 'fs'
import path from 'path' import path from 'path'
import colors from 'css-color-names' import colors from 'css-color-names'
import type { ElementHandle } from 'playwright-chromium' import type { ElementHandle } from 'playwright-chromium'
import { Manifest, normalizePath } from 'vite' import type { Manifest } from 'vite'
import { normalizePath } from 'vite'
import { fromComment } from 'convert-source-map' import { fromComment } from 'convert-source-map'
export function slash(p: string): string { export function slash(p: string): string {

View File

@ -0,0 +1 @@
module.exports = require('../../vite.config')

View File

@ -1,6 +1,6 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { untilUpdated, isBuild, testDir } from '../../testUtils' import { untilUpdated, isBuild, testDir } from '../../../testUtils'
import type { Page } from 'playwright-chromium' import type { Page } from 'playwright-chromium'
test('normal', async () => { test('normal', async () => {
@ -94,13 +94,3 @@ test('classic worker', async () => {
expect(await page.textContent('.classic-worker')).toMatch('A classic') expect(await page.textContent('.classic-worker')).toMatch('A classic')
expect(await page.textContent('.classic-shared-worker')).toMatch('A classic') expect(await page.textContent('.classic-shared-worker')).toMatch('A classic')
}) })
function getSourceMapUrl(code: string): string {
const regex = /\/\/[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)/g
const results = regex.exec(code)
if (results && results.length >= 2) {
return results[1]
}
return null
}

View File

@ -9,6 +9,15 @@
"dev:es": "vite --config ./vite.config-es.js dev", "dev:es": "vite --config ./vite.config-es.js dev",
"build:es": "vite --config ./vite.config-es.js build", "build:es": "vite --config ./vite.config-es.js build",
"preview:es": "vite --config ./vite.config-es.js preview", "preview:es": "vite --config ./vite.config-es.js preview",
"dev:sourcemap": "cross-env WORKER_MODE=sourcemap vite --config ./vite.config-sourcemap.js dev",
"build:sourcemap": "cross-env WORKER_MODE=sourcemap vite --config ./vite.config-sourcemap.js build",
"preview:sourcemap": "cross-env WORKER_MODE=sourcemap vite --config ./vite.config-sourcemap.js preview",
"dev:sourcemap-hidden": "cross-env WORKER_MODE=hidden vite --config ./vite.config-sourcemap.js dev",
"build:sourcemap-hidden": "cross-env WORKER_MODE=hidden vite --config ./vite.config-sourcemap.js build",
"preview:sourcemap-hidden": "cross-env WORKER_MODE=hidden vite --config ./vite.config-sourcemap.js preview",
"dev:sourcemap-inline": "cross-env WORKER_MODE=inline vite --config ./vite.config-sourcemap.js dev",
"build:sourcemap-inline": "cross-env WORKER_MODE=inline vite --config ./vite.config-sourcemap.js build",
"preview:sourcemap-inline": "cross-env WORKER_MODE=inline vite --config ./vite.config-sourcemap.js preview",
"debug": "node --inspect-brk ../../vite/bin/vite" "debug": "node --inspect-brk ../../vite/bin/vite"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,8 +1,12 @@
const vueJsx = require('@vitejs/plugin-vue-jsx') const vueJsx = require('@vitejs/plugin-vue-jsx')
const vite = require('vite') const vite = require('vite')
module.exports = (sourcemap) => module.exports = vite.defineConfig((sourcemap) => {
vite.defineConfig({ sourcemap = process.env.WORKER_MODE || sourcemap
if (sourcemap === 'sourcemap') {
sourcemap = true
}
return {
base: `/iife-${ base: `/iife-${
typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap
}/`, }/`,
@ -16,4 +20,5 @@ module.exports = (sourcemap) =>
}/`, }/`,
sourcemap: sourcemap sourcemap: sourcemap
} }
}) }
})