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

chore: make tests pass with rollup4 #271

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
SFCTemplateCompileOptions,
} from 'vue/compiler-sfc'
import type * as _compiler from 'vue/compiler-sfc'
import type { ExistingRawSourceMap } from 'rollup'
/* eslint-enable import/no-duplicates */
import { computed, shallowRef } from 'vue'
import { version } from '../package.json'
Expand Down Expand Up @@ -259,10 +260,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
refTransformFilter.value(filename) &&
options.value.compiler.shouldTransformRef(code)
) {
return options.value.compiler.transformRef(code, {
const result = options.value.compiler.transformRef(code, {
filename,
sourceMap: true,
})
return result as Omit<typeof result, 'map'> & {
map: ExistingRawSourceMap | null
}
}
return
}
Expand Down
30 changes: 15 additions & 15 deletions playground/ssr-vue/__tests__/ssr-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ test('/about', async () => {
if (isBuild) {
// assert correct preload directive generation for async chunks and CSS
expect(aboutHtml).not.toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/Home-[-\w]{8}\.js"/,
)
expect(aboutHtml).not.toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/Home-[-\w]{8}\.css"/,
)
expect(aboutHtml).toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/About-[-\w]{8}\.js"/,
)
expect(aboutHtml).toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/About-[-\w]{8}\.css"/,
)
}
})
Expand All @@ -72,13 +72,13 @@ test('/external', async () => {
if (isBuild) {
// assert correct preload directive generation for async chunks and CSS
expect(externalHtml).not.toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/Home-[-\w]{8}\.js"/,
)
expect(externalHtml).not.toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/Home-[-\w]{8}\.css"/,
)
expect(externalHtml).toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/External-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/External-[-\w]{8}\.js"/,
)
}
})
Expand All @@ -97,23 +97,23 @@ test('/', async () => {
if (isBuild) {
// assert correct preload directive generation for async chunks and CSS
expect(html).toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/Home-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/Home-[-\w]{8}\.js"/,
)
expect(html).toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/Home-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/Home-[-\w]{8}\.css"/,
)
// JSX component preload registration
expect(html).toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/Foo-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/Foo-[-\w]{8}\.js"/,
)
expect(html).toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/Foo-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/Foo-[-\w]{8}\.css"/,
)
expect(html).not.toMatch(
/link rel="modulepreload".*?href="\/test\/assets\/About-\w{8}\.js"/,
/link rel="modulepreload".*?href="\/test\/assets\/About-[-\w]{8}\.js"/,
)
expect(html).not.toMatch(
/link rel="stylesheet".*?href="\/test\/assets\/About-\w{8}\.css"/,
/link rel="stylesheet".*?href="\/test\/assets\/About-[-\w]{8}\.css"/,
)
}
})
Expand All @@ -139,7 +139,7 @@ test('asset', async () => {
})
const img = await page.$('img')
expect(await img.getAttribute('src')).toMatch(
isBuild ? /\/test\/assets\/logo-\w{8}\.png/ : '/src/assets/logo.png',
isBuild ? /\/test\/assets\/logo-[-\w]{8}\.png/ : '/src/assets/logo.png',
)
})

Expand Down Expand Up @@ -200,7 +200,7 @@ test.runIf(isBuild)('dynamic css file should be preloaded', async () => {
await page.goto(url)
const homeHtml = await (await fetch(url)).text()
const re =
/link rel="modulepreload".*?href="\/test\/assets\/(Home-\w{8}\.js)"/
/link rel="modulepreload".*?href="\/test\/assets\/(Home-[-\w]{8}\.js)"/
const filename = re.exec(homeHtml)[1]
const manifest = (
await import(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isBuild, page } from '~utils'

test('should render', async () => {
const expected = isBuild
? /assets\/asset-[\da-f]+\.png/
? /assets\/asset-[-\w]+\.png/
: 'http://localhost/server-origin/test/assets/asset.png'

expect(await page.getAttribute('img', 'src')).toMatch(expected)
Expand Down
4 changes: 2 additions & 2 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('css modules', () => {

describe('asset reference', () => {
const assetMatch = isBuild
? /\/assets\/asset-\w{8}\.png/
? /\/assets\/asset-[-\w]{8}\.png/
: '/assets/asset.png'

test('should not 404', () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('asset reference', () => {

test('relative url from <style>', async () => {
const assetMatch = isBuild
? /\/assets\/asset-\w{8}\.png/
? /\/assets\/asset-[-\w]{8}\.png/
: '/assets/asset.png'
expect(await getBg('.relative-style-url')).toMatch(assetMatch)
})
Expand Down