Skip to content

Commit

Permalink
fix(browser): working again (#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Oct 14, 2022
1 parent a6618c1 commit 01ca7ad
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
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'
5 changes: 2 additions & 3 deletions packages/vitest/src/utils/index.ts
Expand Up @@ -8,15 +8,14 @@ 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 * from './env'

export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
// export const isNode = typeof process !== 'undefined' && typeof process.platform !== '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

0 comments on commit 01ca7ad

Please sign in to comment.