Skip to content

Commit

Permalink
chore: make tests pass with rollup4 (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 18, 2023
1 parent c60119f commit 298d419
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
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

0 comments on commit 298d419

Please sign in to comment.