Skip to content

Commit

Permalink
Merge branch 'main' into fix-browser-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 27, 2024
2 parents 6dbf85b + 48fba19 commit 2028762
Show file tree
Hide file tree
Showing 427 changed files with 1,362 additions and 2,757 deletions.
31 changes: 6 additions & 25 deletions .github/workflows/ci.yml
Expand Up @@ -32,22 +32,6 @@ jobs:
- name: Lint
run: pnpm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-and-cache

- name: Install
run: pnpm i

- name: Build
run: pnpm run build

- name: Typecheck
run: pnpm run typecheck

test:
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -85,11 +69,8 @@ jobs:
- name: Test
run: pnpm run test:ci

- name: Test No Threads
run: pnpm run test:ci:no-threads

- name: Test Vm Threads
run: pnpm run test:ci:vm-threads
- name: Test Examples
run: pnpm run test:examples

test-ui:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -147,8 +128,6 @@ jobs:

timeout-minutes: 30

env:
BROWSER: ${{ matrix.browser[0] }}
steps:
- uses: actions/checkout@v4

Expand All @@ -170,6 +149,8 @@ jobs:

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (playwright)
run: pnpm run test:browser:playwright
Expand All @@ -185,8 +166,6 @@ jobs:

timeout-minutes: 30

env:
BROWSER: ${{ matrix.browser[0] }}
steps:
- uses: actions/checkout@v4

Expand All @@ -208,6 +187,8 @@ jobs:

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (playwright)
run: pnpm run test:browser:playwright
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -27,4 +27,4 @@ docs/public/user-avatars
docs/public/sponsors
.eslintcache
docs/.vitepress/cache/
!test/cwd/**/.cache
!test/cli/fixtures/dotted-files/**/.cache
4 changes: 2 additions & 2 deletions eslint.config.js
Expand Up @@ -14,7 +14,7 @@ export default antfu(
'**/*.timestamp-*',
'test/core/src/self',
'test/cache/cache/.vitest-base/results.json',
'test/wasm-modules/src/wasm-bindgen-no-cyclic',
'test/core/src/wasm/wasm-bindgen-no-cyclic',
'test/workspaces/results.json',
'test/workspaces-browser/results.json',
'test/reporters/fixtures/with-syntax-error.test.js',
Expand Down Expand Up @@ -100,7 +100,7 @@ export default antfu(
files: [
`docs/${GLOB_SRC}`,
`packages/web-worker/${GLOB_SRC}`,
`test/web-worker/${GLOB_SRC}`,
`test/core/${GLOB_SRC}`,
],
rules: {
'no-restricted-globals': 'off',
Expand Down
9 changes: 3 additions & 6 deletions package.json
Expand Up @@ -24,12 +24,9 @@
"lint:fix": "nr lint --fix",
"publish-ci": "tsx scripts/publish-ci.ts",
"release": "bumpp package.json packages/*/package.json --commit --push --tag && git update-ref refs/heads/release refs/heads/main && git push origin release",
"test": "vitest --api -r test/core",
"test:run": "vitest run -r test/core",
"test:all": "CI=true pnpm -r --stream run test --allowOnly",
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly",
"test:ci:vm-threads": "CI=true pnpm -r --reporter-hide-prefix --stream --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-network-imports --filter !test-browser --filter !example-react-testing-lib-msw run test --allowOnly --pool vmThreads",
"test:ci:no-threads": "CI=true pnpm -r --reporter-hide-prefix --stream --filter !test-vm-threads --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --pool forks",
"test": "pnpm --filter test-core test:threads",
"test:ci": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/test-*' --filter !test-browser run test",
"test:examples": "CI=true pnpm -r --reporter-hide-prefix --stream --filter '@vitest/example-*' run test",
"typecheck": "tsc -p tsconfig.check.json --noEmit",
"typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt",
"ui:build": "vite build packages/ui",
Expand Down
19 changes: 15 additions & 4 deletions packages/vitest/src/node/plugins/workspace.ts
@@ -1,4 +1,5 @@
import { basename, dirname, relative } from 'pathe'
import { existsSync, readFileSync } from 'node:fs'
import { basename, dirname, relative, resolve } from 'pathe'
import type { UserConfig as ViteConfig, Plugin as VitePlugin } from 'vite'
import { configDefaults } from '../../defaults'
import { generateScopedClassName } from '../../integrations/css/css-modules'
Expand Down Expand Up @@ -35,10 +36,20 @@ export function WorkspaceVitestPlugin(project: WorkspaceProject, options: Worksp
const root = testConfig.root || viteConfig.root || options.root
let name = testConfig.name
if (!name) {
if (typeof options.workspacePath === 'string')
name = basename(options.workspacePath.endsWith('/') ? options.workspacePath.slice(0, -1) : dirname(options.workspacePath))
else
if (typeof options.workspacePath === 'string') {
// if there is a package.json, read the name from it
const dir = options.workspacePath.endsWith('/')
? options.workspacePath.slice(0, -1)
: dirname(options.workspacePath)
const pkgJsonPath = resolve(dir, 'package.json')
if (existsSync(pkgJsonPath))
name = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')).name
if (typeof name !== 'string' || !name)
name = basename(dir)
}
else {
name = options.workspacePath.toString()
}
}

const config: ViteConfig = {
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/node/pool.ts
@@ -1,6 +1,7 @@
import mm from 'micromatch'
import type { Awaitable } from '@vitest/utils'
import type { BuiltinPool, Pool } from '../types/pool-options'
import { isWindows } from '../utils/env'
import type { Vitest } from './core'
import { createForksPool } from './pools/forks'
import { createThreadsPool } from './pools/threads'
Expand Down Expand Up @@ -91,6 +92,12 @@ export function createPool(ctx: Vitest): ProcessPool {
},
}

// env are case-insensitive on Windows, but spawned processes don't support it
if (isWindows) {
for (const name in options.env)
options.env[name.toUpperCase()] = options.env[name]
}

const customPools = new Map<string, ProcessPool>()
async function resolveCustomPool(filepath: string) {
if (customPools.has(filepath))
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/suite.ts
@@ -1,3 +1,3 @@
export { getCurrentSuite, createTaskCollector, getFn, setFn, getHooks, setHooks } from '@vitest/runner'
export { getCurrentSuite, getCurrentTest, createTaskCollector, getFn, setFn, getHooks, setHooks } from '@vitest/runner'
export { createChainable } from '@vitest/runner/utils'
export { getBenchFn, getBenchOptions } from './runtime/benchmark'
1 change: 1 addition & 0 deletions packages/vitest/src/utils/env.ts
@@ -1,3 +1,4 @@
export const isNode: boolean = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
export const isWindows = isNode && process.platform === 'win32'
export const isBrowser: boolean = typeof window !== 'undefined'
export { isCI, provider as stdProvider } from 'std-env'
3 changes: 1 addition & 2 deletions packages/vitest/src/utils/index.ts
@@ -1,6 +1,5 @@
import { relative } from 'pathe'
import { getWorkerState } from '../utils'
import { isNode } from './env'

export * from './graph'
export * from './tasks'
Expand All @@ -10,8 +9,8 @@ export * from './timers'
export * from './env'
export * from './modules'
export * from './serialization'
export { isWindows } from './env'

export const isWindows = isNode && process.platform === 'win32'
export function getRunMode() {
return getWorkerState().config.mode
}
Expand Down

0 comments on commit 2028762

Please sign in to comment.