Skip to content

Commit

Permalink
fix: don't use global timers (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 25, 2022
1 parent f1b247f commit 16d65a7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .eslintrc
Expand Up @@ -19,6 +19,19 @@
}
]
}
},
{
"files": "packages/vitest/**/*.*",
"rules": {
"no-restricted-globals": [
"error",
"setTimeout",
"clearTimeout",
"setInterval",
"clearInterval",
"performance"
]
}
}
]
}
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -7,7 +7,7 @@ import c from 'picocolors'
import { ViteNodeServer } from 'vite-node/server'
import type { ArgumentsType, Reporter, ResolvedConfig, UserConfig } from '../types'
import { SnapshotManager } from '../integrations/snapshot/manager'
import { deepMerge, hasFailed, noop, slash, toArray } from '../utils'
import { clearTimeout, deepMerge, hasFailed, noop, setTimeout, slash, toArray } from '../utils'
import { cleanCoverage, reportCoverage } from '../integrations/coverage'
import { ReportersMap } from './reporters'
import { createPool } from './pool'
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/reporters/dot.ts
@@ -1,4 +1,5 @@
import type { UserConsoleLog } from '../../types'
import { setTimeout } from '../../utils'
import { BaseReporter } from './base'
import { createDotRenderer } from './renderers/dotRenderer'
import type { createListRenderer } from './renderers/listRenderer'
Expand Down
@@ -1,7 +1,7 @@
import { createLogUpdate } from 'log-update'
import c from 'picocolors'
import type { Task } from '../../../types'
import { getTests } from '../../../utils'
import { clearInterval, getTests, setInterval } from '../../../utils'

export interface DotRendererOptions {
outputStream: NodeJS.WritableStream
Expand Down
Expand Up @@ -3,7 +3,7 @@ import c from 'picocolors'
import cliTruncate from 'cli-truncate'
import stripAnsi from 'strip-ansi'
import type { SuiteHooks, Task } from '../../../types'
import { getTests } from '../../../utils'
import { clearInterval, getTests, setInterval } from '../../../utils'
import { F_RIGHT } from '../../../utils/figures'
import { getCols, getHookStateSymbol, getStateSymbol } from './utils'

Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/collect.ts
@@ -1,3 +1,4 @@
import { performance } from 'perf_hooks'
import { createHash } from 'crypto'
import { relative } from 'pathe'
import type { File, ResolvedConfig, Suite, TaskBase } from '../types'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/context.ts
@@ -1,5 +1,5 @@
import type { Awaitable, DoneCallback, RuntimeContext, SuiteCollector, TestFunction } from '../types'
import { getWorkerState } from '../utils'
import { clearTimeout, getWorkerState, setTimeout } from '../utils'

export const context: RuntimeContext = {
tasks: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/run.ts
Expand Up @@ -2,7 +2,7 @@ import { performance } from 'perf_hooks'
import type { File, HookListener, ResolvedConfig, Suite, SuiteHooks, Task, TaskResult, TaskState, Test } from '../types'
import { vi } from '../integrations/vi'
import { getSnapshotClient } from '../integrations/snapshot/chai'
import { getFullName, getWorkerState, hasFailed, hasTests, partitionSuiteChildren } from '../utils'
import { clearTimeout, getFullName, getWorkerState, hasFailed, hasTests, partitionSuiteChildren, setTimeout } from '../utils'
import { getState, setState } from '../integrations/chai/jest-expect'
import { takeCoverage } from '../integrations/coverage'
import { getFn, getHooks } from './map'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/setup.ts
Expand Up @@ -2,7 +2,7 @@ import { Console } from 'console'
import { Writable } from 'stream'
import { environments } from '../integrations/env'
import type { ResolvedConfig } from '../types'
import { getWorkerState, toArray } from '../utils'
import { clearTimeout, getWorkerState, setTimeout, toArray } from '../utils'
import * as VitestIndex from '../index'
import { resetRunOnceCounter } from '../integrations/run-once'
import { RealDate } from '../integrations/mockdate'
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/utils/index.ts
Expand Up @@ -8,6 +8,7 @@ export * from './tasks'
export * from './path'
export * from './base'
export * from './global'
export * from './timers'

export const isWindows = process.platform === 'win32'

Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/utils/timers.ts
@@ -0,0 +1,4 @@
export const setTimeout = globalThis.setTimeout
export const setInterval = globalThis.setInterval
export const clearInterval = globalThis.clearInterval
export const clearTimeout = globalThis.clearTimeout

0 comments on commit 16d65a7

Please sign in to comment.