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

fix(browser): working again #2143

Merged
merged 2 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/browser/node/index.ts
Expand Up @@ -13,6 +13,7 @@ const stubs = [
'module',
'noop',
'perf_hooks',
'console',
]

const polyfills = [
Expand Down
1 change: 1 addition & 0 deletions packages/browser/stubs/console.js
@@ -0,0 +1 @@
export const Console = {}
5 changes: 3 additions & 2 deletions packages/vitest/src/constants.ts
@@ -1,8 +1,9 @@
import url from 'url'
import { resolve } from 'pathe'
import { isNode } from './utils/env'

export const rootDir = resolve(url.fileURLToPath(import.meta.url), '../../')
export const distDir = resolve(url.fileURLToPath(import.meta.url), '../../dist')
export const rootDir = isNode ? resolve(url.fileURLToPath(import.meta.url), '../../') : import.meta.url
export const distDir = isNode ? resolve(url.fileURLToPath(import.meta.url), '../../dist') : import.meta.url

// if changed, update also jsdocs and docs
export const defaultPort = 51204
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/utils/env.ts
@@ -0,0 +1,2 @@
export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
export const isBrowser = typeof window !== 'undefined'
7 changes: 5 additions & 2 deletions packages/vitest/src/utils/index.ts
Expand Up @@ -8,15 +8,18 @@ import type { Suite, Task } from '../types'
import { EXIT_CODE_RESTART } from '../constants'
import { getWorkerState } from '../utils'
import { getNames } from './tasks'
import { isBrowser, isNode } from './env'

export * from './tasks'
export * from './base'
export * from './global'
export * from './timers'

export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
export { isNode, isBrowser } from './env'
// export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
userquin marked this conversation as resolved.
Show resolved Hide resolved
// export const isNode = typeof process !== 'undefined' && typeof process.platform !== 'undefined'
export const isBrowser = typeof window !== 'undefined'
// export const isBrowser = typeof window !== 'undefined'

export const isWindows = isNode && process.platform === 'win32'
export const getRunMode = () => getWorkerState().config.mode
export const isRunningInTest = () => getRunMode() === 'test'
Expand Down