Skip to content
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
43 changes: 25 additions & 18 deletions playground/vue-lib/__tests__/vue-lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import path from 'node:path'
import type { Rollup } from 'vite'
import { build } from 'vite'
import * as vite from 'vite'
import { describe, expect, test } from 'vitest'

const isRolldownVite = 'rolldownVersion' in vite

describe('vue component library', () => {
test('should output tree shakeable css module code', async () => {
// Build lib
await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.lib.ts'),
})
// Build app
const { output } = (await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.consumer.ts'),
})) as Rollup.RollupOutput
const { code } = output.find(
(e) => e.type === 'chunk' && e.isEntry,
) as Rollup.OutputChunk
// Unused css module should be treeshaked
expect(code).toContain('styleA') // styleA is used by CompA
expect(code).not.toContain('styleB') // styleB is not used
})
// skip this test for now with rolldown-vite due to https://github.com/oxc-project/oxc/issues/10033
test.skipIf(isRolldownVite)(
'should output tree shakeable css module code',
async () => {
// Build lib
await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.lib.ts'),
})
// Build app
const { output } = (await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.consumer.ts'),
})) as Rollup.RollupOutput
const { code } = output.find(
(e) => e.type === 'chunk' && e.isEntry,
) as Rollup.OutputChunk
// Unused css module should be treeshaked
expect(code).toContain('styleA') // styleA is used by CompA
expect(code).not.toContain('styleB') // styleB is not used
},
)

test('should inject css when cssCodeSplit = true', async () => {
// Build lib
Expand Down
6 changes: 5 additions & 1 deletion playground/vue-sourcemap/__tests__/vue-sourcemap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { URL } from 'node:url'
import { describe, expect, test } from 'vitest'
import * as vite from 'vite'
import {
extractSourcemap,
formatSourcemapForSnapshot,
Expand All @@ -9,6 +10,8 @@ import {
serverLogs,
} from '~utils'

const isRolldownVite = 'rolldownVersion' in vite

describe.runIf(isServe)('serve:vue-sourcemap', () => {
const getStyleTagContentIncluding = async (content: string) => {
const styles = await page.$$('style')
Expand All @@ -28,7 +31,8 @@ describe.runIf(isServe)('serve:vue-sourcemap', () => {
expect(formatSourcemapForSnapshot(map)).toMatchSnapshot('serve-js')
})

test('ts', async () => {
// skip this test for now with rolldown-vite as the snapshot is slightly different
test.skipIf(isRolldownVite)('ts', async () => {
const res = await page.request.get(new URL('./Ts.vue', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
Expand Down
15 changes: 11 additions & 4 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'vitest'
import { version } from 'vue'
import * as vite from 'vite'
import {
browserLogs,
editFile,
Expand All @@ -12,6 +13,8 @@ import {
untilUpdated,
} from '~utils'

const isRolldownVite = 'rolldownVersion' in vite

test('should render', async () => {
expect(await page.textContent('h1')).toMatch(`Vue version ${version}`)
})
Expand Down Expand Up @@ -461,7 +464,11 @@ describe('template parse options', () => {
})
})

test.runIf(isBuild)('scoped style should be tree-shakeable', async () => {
const indexCss = findAssetFile(/index-[\w-]+\.css/)
expect(indexCss).not.toContain('.tree-shake-scoped-style')
})
// skip this test for now with rolldown-vite as this requires https://github.com/rolldown/rolldown/issues/4812 to be implemented
test.runIf(isBuild && !isRolldownVite)(
'scoped style should be tree-shakeable',
async () => {
const indexCss = findAssetFile(/index-[\w-]+\.css/)
expect(indexCss).not.toContain('.tree-shake-scoped-style')
},
)
8 changes: 7 additions & 1 deletion vitest.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from 'node:path'
import { defineConfig } from 'vitest/config'
import { defaultExclude, defineConfig } from 'vitest/config'
import * as vite from 'vite'

const timeout = process.env.CI ? 50000 : 30000

Expand All @@ -15,6 +16,11 @@ export default defineConfig({
},
test: {
include: ['./playground/**/*.spec.[tj]s'],
exclude: [
...defaultExclude,
// plugin-legacy is not supported with rolldown-vite
...('rolldownVersion' in vite ? ['./playground/vue-legacy/**/*'] : []),
],
setupFiles: ['./playground/vitestSetup.ts'],
globalSetup: ['./playground/vitestGlobalSetup.ts'],
testTimeout: timeout,
Expand Down