Skip to content

Commit d50a9d1

Browse files
committed
feat: change to vitest
1 parent 8e71fa2 commit d50a9d1

36 files changed

+1393
-2237
lines changed

jest.config.js

-16
This file was deleted.

jest.e2e.config.js

-25
This file was deleted.

package.json

+14-17
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,28 @@
2020
"lint:fix": "eslint --fix",
2121
"build": "cd packages/lib && pnpm build",
2222
"test": "npm-run-all test:unit test:e2e",
23-
"test:unit": "jest --coverage",
24-
"test:e2e": "jest --runInBand --config ./jest.e2e.config.js"
23+
"test:unit": "vitest run --coverage",
24+
"test:e2e": "vitest run -c vitest.config.e2e.ts"
2525
},
2626
"devDependencies": {
27-
"@types/jest": "^27.0.1",
28-
"@types/node": "^15.12.2",
29-
"@typescript-eslint/eslint-plugin": "^4.29.0",
30-
"@typescript-eslint/parser": "^4.29.0",
31-
"chalk": "^4.1.2",
32-
"eslint": "^7.32.0",
27+
"@types/node": "^18.6.4",
28+
"@typescript-eslint/eslint-plugin": "^5.32.0",
29+
"@typescript-eslint/parser": "^5.32.0",
30+
"chalk": "^5.0.1",
31+
"eslint": "^8.21.0",
3332
"eslint-plugin-node": "^11.1.0",
34-
"execa": "^5.1.1",
33+
"execa": "^6.1.0",
3534
"fs-extra": "^10.0.0",
36-
"husky": "^7.0.4",
37-
"jest": "^27.3.1",
38-
"jest-environment-node": "^27.3.1",
39-
"kill-port": "^1.6.1",
40-
"lint-staged": "^12.4.0",
35+
"husky": "^8.0.1",
36+
"kill-port": "^2.0.1",
37+
"lint-staged": "^13.0.3",
4138
"npm-run-all": "^4.1.5",
4239
"playwright-chromium": "^1.24.2",
4340
"prettier": "^2.3.2",
4441
"rimraf": "^3.0.2",
45-
"ts-jest": "^27.0.7",
46-
"tslib": "^2.3.0",
47-
"typescript": "^4.3.5"
42+
"tslib": "^2.4.0",
43+
"typescript": "^4.7.4",
44+
"vitest": "^0.21.0"
4845
},
4946
"lint-staged": {
5047
"*.{ts,js,json,tsx,jsx,vue}": [

packages/examples/basic-host-remote/__tests__/basic-host-remote.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
1+
import {
2+
browserLogs,
3+
page
4+
} from '~utils'
25

36
test('should have no 404s', () => {
47
browserLogs.forEach((msg) => {

packages/examples/basic-host-remote/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"devDependencies": {
1212
"@originjs/vite-plugin-federation": "workspace:*",
1313
"http-server": "^13.0.1",
14-
"kill-port": "^1.6.1"
14+
"kill-port": "^2.0.1"
1515
}
1616
}

packages/examples/react-in-vue/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"@originjs/vite-plugin-federation": "workspace:*",
16-
"kill-port": "^1.6.1"
16+
"kill-port": "^2.0.1"
1717
}
1818
}

packages/examples/simple-react-esm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"@originjs/vite-plugin-federation": "workspace:*",
1717
"http-server": "^13.0.1",
18-
"kill-port": "^1.6.1"
18+
"kill-port": "^2.0.1"
1919
}
2020
}
2121

packages/examples/simple-react-systemjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"@originjs/vite-plugin-federation": "workspace:*",
1717
"http-server": "^13.0.1",
18-
"kill-port": "^1.6.1"
18+
"kill-port": "^2.0.1"
1919
}
2020
}
2121

packages/examples/simple-react-webpack/__tests__/simple-react-systemjs.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22

3-
test.skip('should have no 404s', () => {
3+
test('should have no 404s', () => {
44
browserLogs.forEach((msg) => {
55
expect(msg).not.toMatch('404')
66
})
77
})
88

9-
test.skip('remote button', async () => {
9+
test('remote button', async () => {
1010
expect(
1111
await page.textContent('button')
1212
).toBe('Webpack Remote Button')

packages/examples/simple-react-webpack/host/rollup.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default {
2020
}),
2121
federation({
2222
remotes: {
23-
remote_app: 'http://localhost:5001/remoteEntry.js'
23+
remote_app: {
24+
external: 'http://localhost:5001/remoteEntry.js',
25+
from: 'webpack'
26+
}
2427
},
2528
shared: {
2629
react: {
@@ -31,7 +34,7 @@ export default {
3134
'react-dom': {
3235
singleton: true,
3336
requiredVersion: pkg.dependencies['react-dom'],
34-
version:'16.14.0'
37+
version: '16.14.0'
3538
}
3639
}
3740
})

packages/examples/simple-react-webpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"@originjs/vite-plugin-federation": "workspace:*",
1717
"http-server": "^13.0.1",
18-
"kill-port": "^1.6.1"
18+
"kill-port": "^2.0.1"
1919
}
2020
}
2121

packages/examples/simple-react-webpack/remote/webpack.config.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const path = require('path')
2-
3-
const { ModuleFederationPlugin } = require('webpack').container
1+
const path = require('path');
2+
const { ModuleFederationPlugin } = require('webpack').container;
3+
const HtmlWebpackPlugin = require("html-webpack-plugin");
44

55

66
/** @type {import('webpack').Configuration} */
@@ -50,7 +50,10 @@ module.exports = {
5050
requiredVersion: '^16.12.0'
5151
}
5252
}
53-
})
53+
}),
54+
new HtmlWebpackPlugin({
55+
template: path.resolve(__dirname, "./index.html"),
56+
}),
5457
],
5558
devServer: {
5659
static: {

packages/examples/testEnv.d.ts

-12
This file was deleted.

packages/examples/testUtils.ts

+2-132
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,4 @@
11
// test utils used in e2e tests for playgrounds.
2-
// this can be directly imported in any playground tests as 'testUtils', e.g.
3-
// `import { getColor } from 'testUtils'`
2+
// `import { getColor } from '~utils'`
43

5-
import fs from 'fs'
6-
import path from 'path'
7-
import colors from 'css-color-names'
8-
import { ElementHandle } from 'playwright-chromium'
9-
import type { Manifest } from 'vite'
10-
11-
export function slash(p: string): string {
12-
return p.replace(/\\/g, '/')
13-
}
14-
15-
export const isBuild = !!process.env.VITE_TEST_BUILD
16-
17-
const testPath = expect.getState().testPath
18-
const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1]
19-
export const testDir = path.resolve(__dirname, '../../temp', testName)
20-
21-
const hexToNameMap: Record<string, string> = {}
22-
Object.keys(colors).forEach((color) => {
23-
hexToNameMap[colors[color]] = color
24-
})
25-
26-
function componentToHex(c: number): string {
27-
const hex = c.toString(16)
28-
return hex.length === 1 ? '0' + hex : hex
29-
}
30-
31-
function rgbToHex(rgb: string): string {
32-
const match = rgb.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/)
33-
if (match) {
34-
const [_, rs, gs, bs] = match
35-
return (
36-
'#' +
37-
componentToHex(parseInt(rs, 10)) +
38-
componentToHex(parseInt(gs, 10)) +
39-
componentToHex(parseInt(bs, 10))
40-
)
41-
} else {
42-
return '#000000'
43-
}
44-
}
45-
46-
const timeout = (n: number) => new Promise((r) => setTimeout(r, n))
47-
48-
async function toEl(el: string | ElementHandle): Promise<ElementHandle> {
49-
if (typeof el === 'string') {
50-
return await page.$(el)
51-
}
52-
return el
53-
}
54-
55-
export async function getColor(el: string | ElementHandle): Promise<string> {
56-
el = await toEl(el)
57-
const rgb = await el.evaluate((el) => getComputedStyle(el as Element).color)
58-
return hexToNameMap[rgbToHex(rgb)] || rgb
59-
}
60-
61-
export async function getBg(el: string | ElementHandle): Promise<string> {
62-
el = await toEl(el)
63-
return el.evaluate((el) => getComputedStyle(el as Element).backgroundImage)
64-
}
65-
66-
export function readFile(filename: string): string {
67-
return fs.readFileSync(path.resolve(testDir, filename), 'utf-8')
68-
}
69-
70-
export function editFile(
71-
filename: string,
72-
replacer: (str: string) => string,
73-
runInBuild: boolean = false
74-
): void {
75-
if (isBuild && !runInBuild) return
76-
filename = path.resolve(testDir, filename)
77-
const content = fs.readFileSync(filename, 'utf-8')
78-
const modified = replacer(content)
79-
fs.writeFileSync(filename, modified)
80-
}
81-
82-
export function addFile(filename: string, content: string): void {
83-
fs.writeFileSync(path.resolve(testDir, filename), content)
84-
}
85-
86-
export function removeFile(filename: string): void {
87-
fs.unlinkSync(path.resolve(testDir, filename))
88-
}
89-
90-
export function listAssets(base = ''): string[] {
91-
const assetsDir = path.join(testDir, 'dist', base, 'assets')
92-
return fs.readdirSync(assetsDir)
93-
}
94-
95-
export function findAssetFile(match: string | RegExp, base = ''): string {
96-
const assetsDir = path.join(testDir, 'dist', base, 'assets')
97-
const files = fs.readdirSync(assetsDir)
98-
const file = files.find((file) => {
99-
return file.match(match)
100-
})
101-
return file ? fs.readFileSync(path.resolve(assetsDir, file), 'utf-8') : ''
102-
}
103-
104-
export function readManifest(base = ''): Manifest {
105-
return JSON.parse(
106-
fs.readFileSync(path.join(testDir, 'dist', base, 'manifest.json'), 'utf-8')
107-
)
108-
}
109-
110-
/**
111-
* Poll a getter until the value it returns includes the expected value.
112-
*/
113-
export async function untilUpdated(
114-
poll: () => string | Promise<string>,
115-
expected: string,
116-
runInBuild = false
117-
): Promise<void> {
118-
if (isBuild && !runInBuild) return
119-
const maxTries = process.env.CI ? 100 : 50
120-
for (let tries = 0; tries < maxTries; tries++) {
121-
const actual = (await poll()) || ''
122-
if (actual.indexOf(expected) > -1 || tries === maxTries - 1) {
123-
expect(actual).toMatch(expected)
124-
break
125-
} else {
126-
await timeout(50)
127-
}
128-
}
129-
}
130-
131-
/**
132-
* Send the rebuild complete message in build watch
133-
*/
134-
export { notifyRebuildComplete } from '../../scripts/jestPerTestSetup'
4+
export * from './vitestSetup'

packages/examples/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"moduleResolution": "node",
1010
"baseUrl": ".",
1111
"jsx": "preserve",
12-
"types": ["vite/client", "jest", "node"]
12+
"types": ["vite/client", "vitest/globals", "node"]
1313
}
1414
}

0 commit comments

Comments
 (0)