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

feat: support vite 3 #1543

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@testing-library/react": "^13.2.0",
"@types/node": "17.0.23",
"@types/react": "17.0.44",
"@vitejs/plugin-react": "1.3.1",
"@vitejs/plugin-react": "2.0.0-beta.0",
"jsdom": "^19.0.0",
"typescript": "4.6.3",
"vitest": "latest"
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
2 changes: 1 addition & 1 deletion examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"devDependencies": {
"jsdom": "*",
"solid-start": "next",
"solid-testing-library": "0.3.0",
"vite-plugin-solid": "^2.2.6",
"vitest": "latest"
}
}
2 changes: 1 addition & 1 deletion examples/solid/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference types="vite/client" />

import { defineConfig } from 'vite'
import solid from 'solid-start' // or use 'vite-plugin-solid' instead
import solid from 'vite-plugin-solid' // or use 'vite-plugin-solid' instead
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove comment now


export default defineConfig({
test: {
Expand Down
4 changes: 2 additions & 2 deletions examples/vue-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": "vitest"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue-jsx": "^1.3.10",
"@vitejs/plugin-vue": "3.0.0-beta.0",
"@vitejs/plugin-vue-jsx": "2.0.0-beta.0",
"@vue/test-utils": "^2.0.0",
"jsdom": "latest",
"vite": "^2.9.9",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"vue": "^3.2.36"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue": "3.0.0-beta.0",
"@vue/test-utils": "^2.0.0",
"jsdom": "latest",
"vitest": "latest"
Expand Down
6 changes: 2 additions & 4 deletions examples/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"vue": "2.6.14"
"vue": "2.7.0-beta.5"
},
"devDependencies": {
"@vue/composition-api": "^1.6.2",
"@vitejs/plugin-vue2": "^1.1.0",
"@vue/test-utils": "^1.3.0",
"jsdom": "latest",
"unplugin-vue2-script-setup": "^0.10.2",
"vite": "latest",
"vite-plugin-vue2": "^1.9.3",
"vitest": "latest",
"vue-template-compiler": "2.6.14"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/vue2/src/components/Options.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import { defineComponent } from 'vue'

export default defineComponent({
props: {
Expand Down
2 changes: 1 addition & 1 deletion examples/vue2/src/components/ScriptSetup.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref } from '@vue/composition-api'
import { computed, ref } from 'vue'

const props = defineProps<{ count: number }>()

Expand Down
7 changes: 7 additions & 0 deletions examples/vue2/test/__snapshots__/script-setup.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Vitest Snapshot v1

exports[`mount component 1`] = `
"<div>
<div>4 x 2 = 8</div><button> x1 </button>
</div>"
`;
4 changes: 2 additions & 2 deletions examples/vue2/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils'
import { nextTick } from '@vue/composition-api'
import Vue from 'vue'
import Hello from '../src/components/Options.vue'

test('mount component', async () => {
Expand All @@ -11,7 +11,7 @@ test('mount component', async () => {
},
})

await nextTick()
await Vue.nextTick()

expect(wrapper.text()).toContain('4 x 2 = 8')
expect(wrapper.html()).toMatchSnapshot()
Expand Down
4 changes: 2 additions & 2 deletions examples/vue2/test/script-setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from '@vue/test-utils'
import { nextTick } from '@vue/composition-api'
import Vue from 'vue'
import Hello from '../src/components/ScriptSetup.vue'

// TODO: find out why
Expand All @@ -12,7 +12,7 @@ test.skip('mount component', async () => {
},
})

await nextTick()
await Vue.nextTick()

expect(wrapper.text()).toContain('4 x 2 = 8')
expect(wrapper.html()).toMatchSnapshot()
Expand Down
12 changes: 12 additions & 0 deletions examples/vue2/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue2'

export default defineConfig({
plugins: [
Vue(),
],
test: {
globals: true,
environment: 'jsdom',
},
})
17 changes: 0 additions & 17 deletions examples/vue2/vitest.config.ts

This file was deleted.

4 changes: 0 additions & 4 deletions examples/vue2/vitest.setup.ts

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
"rollup-plugin-license": "^2.8.1",
"simple-git-hooks": "^2.8.0",
"typescript": "^4.7.4",
"vite": "^2.9.12",
"vite": "3.0.0-beta.2",
"vitest": "workspace:*",
"vue": "^3.2.37"
},
"pnpm": {
"overrides": {
"vite": "^2.9.10",
"vite": "3.0.0-beta.2",
"esbuild": "^0.14.42",
"vitest": "workspace:*"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const extraInlineDeps = [
/@vitest\/dist/,
// Nuxt
'@nuxt/test-utils',
/vite\w*\/dist\/client\/env.mjs/,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is backported to #1546

]

export function resolveApiConfig<Options extends ApiConfig & UserConfig>(
Expand Down Expand Up @@ -113,9 +114,9 @@ export function resolveConfig(
if (resolved.deps.inline !== true) {
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore ssr is not typed in Vite 2, but defined in Vite 3, so we can't use expect-error
const ssrOptions = viteConfig.ssr || {}
const ssrOptions = viteConfig.ssr

if (ssrOptions.noExternal === true && resolved.deps.inline == null) {
if (ssrOptions?.noExternal === true && resolved.deps.inline == null) {
resolved.deps.inline = true
}
else {
Expand Down
1 change: 0 additions & 1 deletion packages/web-worker/src/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export function defineWebWorker() {
let id = url instanceof URL ? url.toString() : url

id = id
.replace('?worker_file', '')
.replace(/^file:\/+/, '/')

const fsPath = toFilePath(id, config.root)
Expand Down