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

test: migrate tests with type: module #8252

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ module.exports = defineConfig({
'node/no-unpublished-import': 'off',
'node/no-unpublished-require': 'off',
'node/no-unsupported-features/es-syntax': 'off',
'node/no-unsupported-features/node-builtins': [
'error',
{
version: '>=14.6.0'
}
],

'@typescript-eslint/ban-ts-comment': 'off', // TODO: we should turn this on in a new PR
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
Expand Down
14 changes: 8 additions & 6 deletions playground/css-sourcemap/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const MagicString = require('magic-string')
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import MagicString from 'magic-string'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
resolve: {
alias: {
'@': __dirname
Expand Down Expand Up @@ -58,4 +60,4 @@ module.exports = {
}
}
]
}
})
1 change: 1 addition & 0 deletions playground/data-uri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-data-uri",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
1 change: 1 addition & 0 deletions playground/define/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-define",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
6 changes: 4 additions & 2 deletions playground/define/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import { defineConfig } from 'vite'

export default defineConfig({
define: {
__EXP__: 'false',
__STRING__: '"hello"',
Expand All @@ -20,4 +22,4 @@ module.exports = {
ÖUNICODE_LETTERɵ: 789,
__VAR_NAME__: false
}
}
})
1 change: 0 additions & 1 deletion playground/dynamic-import/nested/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ document.querySelector('.mxdjson').addEventListener('click', async () => {
// data URLs (`blob:`)
const code1 = 'export const msg = "blob"'
const blob = new Blob([code1], { type: 'text/javascript;charset=UTF-8' })
// eslint-disable-next-line node/no-unsupported-features/node-builtins
const blobURL = URL.createObjectURL(blob)
document.querySelector('.issue-2658-1').addEventListener('click', async () => {
const { msg } = await import(/*@vite-ignore*/ blobURL)
Expand Down
1 change: 1 addition & 0 deletions playground/dynamic-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-dynamic-import",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
31 changes: 17 additions & 14 deletions playground/dynamic-import/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
const fs = require('fs')
const path = require('path')
const vite = require('vite')
import { copyFileSync } from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vite'

module.exports = vite.defineConfig({
const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
plugins: [
{
name: 'copy',
writeBundle() {
fs.copyFileSync(
path.resolve(__dirname, 'qux.js'),
path.resolve(__dirname, 'dist/qux.js')
copyFileSync(
resolve(__dirname, 'qux.js'),
resolve(__dirname, 'dist/qux.js')
)
fs.copyFileSync(
path.resolve(__dirname, 'mxd.js'),
path.resolve(__dirname, 'dist/mxd.js')
copyFileSync(
resolve(__dirname, 'mxd.js'),
resolve(__dirname, 'dist/mxd.js')
)
fs.copyFileSync(
path.resolve(__dirname, 'mxd.json'),
path.resolve(__dirname, 'dist/mxd.json')
copyFileSync(
resolve(__dirname, 'mxd.json'),
resolve(__dirname, 'dist/mxd.json')
)
}
}
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'alias')
'@': resolve(__dirname, 'alias')
}
}
})
1 change: 1 addition & 0 deletions playground/env-nested/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-env-nested",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
4 changes: 2 additions & 2 deletions playground/env-nested/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

module.exports = defineConfig({
export default defineConfig({
envDir: './envs'
})
1 change: 1 addition & 0 deletions playground/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-env",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "cross-env VITE_INLINE=inline-serve vite",
"build": "cross-env VITE_INLINE=inline-build vite build",
Expand Down
4 changes: 2 additions & 2 deletions playground/env/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require('vite')
import { defineConfig } from 'vite'

module.exports = defineConfig({
export default defineConfig({
base: '/env/',
envPrefix: ['VITE_', 'CUSTOM_PREFIX_'],
build: {
Expand Down
1 change: 1 addition & 0 deletions playground/extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-extensions",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
6 changes: 4 additions & 2 deletions playground/extensions/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
import { defineConfig } from 'vite'

export default defineConfig({
resolve: {
alias: [{ find: 'vue', replacement: 'vue/dist/vue.esm-bundler.js' }],
extensions: ['.js']
}
}
})
1 change: 1 addition & 0 deletions playground/file-delete-restore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-file-delete-restore",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
10 changes: 4 additions & 6 deletions playground/file-delete-restore/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const react = require('@vitejs/plugin-react')
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
plugins: [react()],
build: {
// to make tests faster
minify: false
}
}
})
1 change: 1 addition & 0 deletions playground/fs-serve/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test-fs-serve",
"private": true,
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "vite root",
Expand Down
10 changes: 4 additions & 6 deletions playground/fs-serve/root/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const path = require('path')
import path from 'path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
build: {
rollupOptions: {
input: {
Expand All @@ -23,4 +21,4 @@ module.exports = {
define: {
ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/'))
}
}
})
1 change: 1 addition & 0 deletions playground/glob-import/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test-import-context",
"private": true,
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand Down
1 change: 1 addition & 0 deletions playground/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@example/my-lib",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
12 changes: 5 additions & 7 deletions playground/lib/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const fs = require('fs')
const path = require('path')
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/main.js'),
Expand All @@ -28,4 +26,4 @@ module.exports = {
}
}
]
}
})
12 changes: 5 additions & 7 deletions playground/lib/vite.dyimport.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const fs = require('fs')
const path = require('path')
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/main2.js'),
Expand All @@ -14,4 +12,4 @@ module.exports = {
},
outDir: 'dist/lib'
}
}
})
2 changes: 1 addition & 1 deletion playground/ssr-html/__tests__/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const port = ports['ssr-html']
export async function serve() {
await kill(port)

const { createServer } = require(path.resolve(rootDir, 'server.js'))
const { createServer } = await import(path.resolve(rootDir, 'server.js'))
const { app, vite } = await createServer(rootDir, hmrPorts['ssr-html'])

return new Promise((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions playground/ssr-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test-ssr-html",
"private": true,
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "node server",
Expand Down
18 changes: 8 additions & 10 deletions playground/ssr-html/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
const fs = require('fs')
const path = require('path')
const express = require('express')
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import express from 'express'

const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD

Expand All @@ -22,16 +22,17 @@ const DYNAMIC_STYLES = `
</style>
`

async function createServer(root = process.cwd(), hmrPort) {
const resolve = (p) => path.resolve(__dirname, p)
export async function createServer(root = process.cwd(), hmrPort) {
const { createServer } = await import('vite')
const resolve = (p) => path.resolve(fileURLToPath(import.meta.url), '..', p)

const app = express()

/**
* @type {import('vite').ViteDevServer}
*/
let vite
vite = await require('vite').createServer({
vite = await createServer({
root,
logLevel: isTest ? 'error' : 'info',
server: {
Expand Down Expand Up @@ -93,6 +94,3 @@ if (!isTest) {
})
)
}

// for test use
exports.createServer = createServer
1 change: 1 addition & 0 deletions playground/vue-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-vue-jsx",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
13 changes: 6 additions & 7 deletions playground/vue-jsx/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const vueJsxPlugin = require('@vitejs/plugin-vue-jsx')
const vuePlugin = require('@vitejs/plugin-vue')
import { defineConfig } from 'vite'

/**
* @type {import('vite').UserConfig}
*/
module.exports = {
import vueJsxPlugin from '@vitejs/plugin-vue-jsx'
import vuePlugin from '@vitejs/plugin-vue'

export default defineConfig({
plugins: [
vueJsxPlugin({
include: [/\.tesx$/, /\.[jt]sx$/]
Expand Down Expand Up @@ -39,4 +38,4 @@ export default defineComponent(() => {
optimizeDeps: {
disabled: true
}
}
})
1 change: 1 addition & 0 deletions playground/vue-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test-vue-lib",
"private": true,
"type": "module",
"version": "0.0.0",
"scripts": {
"dev-consumer": "vite --config ./vite.config.consumer.ts",
Expand Down
1 change: 1 addition & 0 deletions playground/vue-server-origin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test-vue-server-origin",
"private": true,
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "vite",
Expand Down
Loading