Skip to content

Commit

Permalink
Merge branch 'main' into fix/workspace-deps-optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
thebanjomatic committed Aug 29, 2023
2 parents fe30982 + 0d0f35f commit 71ae736
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/coverage-istanbul/package.json
Expand Up @@ -50,6 +50,7 @@
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^4.0.1",
"istanbul-reports": "^3.1.5",
"picocolors": "^1.0.0",
"test-exclude": "^6.0.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions packages/coverage-istanbul/src/provider.ts
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'pathe'
import type { AfterSuiteRunMeta, CoverageIstanbulOptions, CoverageProvider, ReportContext, ResolvedCoverageOptions, Vitest } from 'vitest'
import { coverageConfigDefaults, defaultExclude, defaultInclude } from 'vitest/config'
import { BaseCoverageProvider } from 'vitest/coverage'
import c from 'picocolors'
import libReport from 'istanbul-lib-report'
import reports from 'istanbul-reports'
import type { CoverageMap } from 'istanbul-lib-coverage'
Expand Down Expand Up @@ -134,6 +135,9 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
watermarks: this.options.watermarks,
})

if (hasTerminalReporter(this.options.reporter))
this.ctx.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.name))

for (const reporter of this.options.reporter) {
reports.create(reporter[0], {
skipFull: this.options.skipFull,
Expand Down Expand Up @@ -253,3 +257,11 @@ function isEmptyCoverageRange(range: libCoverage.Range) {
|| range.end.column === undefined
)
}

function hasTerminalReporter(reporters: Options['reporter']) {
return reporters.some(([reporter]) =>
reporter === 'text'
|| reporter === 'text-summary'
|| reporter === 'text-lcov'
|| reporter === 'teamcity')
}
11 changes: 11 additions & 0 deletions packages/coverage-v8/src/provider.ts
Expand Up @@ -143,6 +143,9 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
watermarks: this.options.watermarks,
})

if (hasTerminalReporter(this.options.reporter))
this.ctx.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.name))

for (const reporter of this.options.reporter) {
reports.create(reporter[0], {
skipFull: this.options.skipFull,
Expand Down Expand Up @@ -295,3 +298,11 @@ function normalizeTransformResults(fetchCaches: Map<string, { result: FetchResul

return normalized
}

function hasTerminalReporter(reporters: Options['reporter']) {
return reporters.some(([reporter]) =>
reporter === 'text'
|| reporter === 'text-summary'
|| reporter === 'text-lcov'
|| reporter === 'teamcity')
}
47 changes: 24 additions & 23 deletions packages/vitest/src/integrations/vi.ts
Expand Up @@ -200,7 +200,7 @@ function createVitest(): VitestUtils {
return stack?.file || ''
}

return {
const utils: VitestUtils = {
useFakeTimers(config?: FakeTimerInstallOpts) {
if (config) {
_timers.configure(config)
Expand All @@ -210,58 +210,58 @@ function createVitest(): VitestUtils {
_timers.configure(workerState.config.fakeTimers)
}
_timers.useFakeTimers()
return this
return utils
},

useRealTimers() {
_timers.useRealTimers()
_mockedDate = null
return this
return utils
},

runOnlyPendingTimers() {
_timers.runOnlyPendingTimers()
return this
return utils
},

async runOnlyPendingTimersAsync() {
await _timers.runOnlyPendingTimersAsync()
return this
return utils
},

runAllTimers() {
_timers.runAllTimers()
return this
return utils
},

async runAllTimersAsync() {
await _timers.runAllTimersAsync()
return this
return utils
},

runAllTicks() {
_timers.runAllTicks()
return this
return utils
},

advanceTimersByTime(ms: number) {
_timers.advanceTimersByTime(ms)
return this
return utils
},

async advanceTimersByTimeAsync(ms: number) {
await _timers.advanceTimersByTimeAsync(ms)
return this
return utils
},

advanceTimersToNextTimer() {
_timers.advanceTimersToNextTimer()
return this
return utils
},

async advanceTimersToNextTimerAsync() {
await _timers.advanceTimersToNextTimerAsync()
return this
return utils
},

getTimerCount() {
Expand All @@ -272,7 +272,7 @@ function createVitest(): VitestUtils {
const date = time instanceof Date ? time : new Date(time)
_mockedDate = date
_timers.setSystemTime(date)
return this
return utils
},

getMockedSystemTime() {
Expand All @@ -285,7 +285,7 @@ function createVitest(): VitestUtils {

clearAllTimers() {
_timers.clearAllTimers()
return this
return utils
},

// mocks
Expand Down Expand Up @@ -337,17 +337,17 @@ function createVitest(): VitestUtils {

clearAllMocks() {
spies.forEach(spy => spy.mockClear())
return this
return utils
},

resetAllMocks() {
spies.forEach(spy => spy.mockReset())
return this
return utils
},

restoreAllMocks() {
spies.forEach(spy => spy.mockRestore())
return this
return utils
},

stubGlobal(name: string | symbol | number, value: any) {
Expand All @@ -359,14 +359,14 @@ function createVitest(): VitestUtils {
configurable: true,
enumerable: true,
})
return this
return utils
},

stubEnv(name: string, value: string) {
if (!_stubsEnv.has(name))
_stubsEnv.set(name, process.env[name])
process.env[name] = value
return this
return utils
},

unstubAllGlobals() {
Expand All @@ -377,7 +377,7 @@ function createVitest(): VitestUtils {
Object.defineProperty(globalThis, name, original)
})
_stubsGlobal.clear()
return this
return utils
},

unstubAllEnvs() {
Expand All @@ -388,13 +388,13 @@ function createVitest(): VitestUtils {
process.env[name] = original
})
_stubsEnv.clear()
return this
return utils
},

resetModules() {
const state = getWorkerState()
resetModules(state.moduleCache)
return this
return utils
},

async dynamicImportSettled() {
Expand All @@ -414,8 +414,9 @@ function createVitest(): VitestUtils {
Object.assign(state.config, _config)
}
},

}

return utils
}

export const vitest = createVitest()
Expand Down
4 changes: 1 addition & 3 deletions packages/vitest/src/node/core.ts
Expand Up @@ -730,10 +730,8 @@ export class Vitest {
if (!this.config.coverage.reportOnFailure && this.state.getCountOfFailedTests() > 0)
return

if (this.coverageProvider) {
this.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.coverageProvider.name))
if (this.coverageProvider)
await this.coverageProvider.reportCoverage({ allTestsRun })
}
}

async close() {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71ae736

Please sign in to comment.