Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/runner/src/types/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface VitestRunnerConfig {
hookTimeout: number
retry: number
includeTaskLocation?: boolean
includeImportDurations?: boolean
diffOptions?: DiffOptions
}

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ export const cliOptionsConfig: VitestCLIOptions = {
includeTaskLocation: {
description: 'Collect test and suite locations in the `location` property',
},
includeImportDurations: {
description: 'Collect `importDurtaions`',
},
attachmentsDir: {
description: 'The directory where attachments from `context.annotate` are stored in (default: `.vitest-attachments`)',
argument: '<dir>',
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ export function resolveConfig(
resolved.includeTaskLocation ??= true
}

resolved.includeImportDurations ??= true

resolved.server ??= {}
resolved.server.deps ??= {}

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/config/serializeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function serializeConfig(project: TestProject): SerializedConfig {
includeTaskLocation:
config.includeTaskLocation
?? globalConfig.includeTaskLocation,
includeImportDurations:
config.includeImportDurations
?? globalConfig.includeImportDurations,
env: {
...viteConfig?.env,
...config.env,
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/node/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,13 @@ export interface InlineConfig {
*/
includeTaskLocation?: boolean

/**
* Include "importDurations" property inside the test definition
*
* @default true
*/
includeImportDurations?: boolean

/**
* Directory path for storing attachments created by `context.annotate`
*
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface SerializedConfig {
diff: string | SerializedDiffOptions | undefined
retry: number
includeTaskLocation: boolean | undefined
includeImportDurations: boolean | undefined
inspect: boolean | string | undefined
inspectBrk: boolean | string | undefined
inspector: {
Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/runtime/moduleRunner/moduleDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ExecutionInfoOptions {
startOffset: number
external?: boolean
importer?: string
includeImportDurations?: boolean
}

const performanceNow = performance.now.bind(performance)
Expand All @@ -37,6 +38,13 @@ export class ModuleDebug {
private executionStack: ExecutionStack = []

startCalculateModuleExecutionInfo(filename: string, options: ExecutionInfoOptions): () => ModuleExecutionInfoEntry {
if (!options.includeImportDurations) {
return () => ({
startOffset: options.startOffset,
duration: 0,
selfTime: 0,
})
}
const startTime = performanceNow()

this.executionStack.push({
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/runtime/moduleRunner/moduleEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface VitestModuleEvaluatorOptions {
getCurrentTestFilepath?: () => string | undefined
compiledFunctionArgumentsNames?: string[]
compiledFunctionArgumentsValues?: unknown[]
includeImportDurations?: boolean
/**
* @internal
*/
Expand Down Expand Up @@ -113,6 +114,7 @@ export class VitestModuleEvaluator implements ModuleEvaluator {
const finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(
filename,
{
includeImportDurations: this.options.includeImportDurations,
startOffset: 0,
external: true,
importer,
Expand Down Expand Up @@ -313,6 +315,7 @@ export class VitestModuleEvaluator implements ModuleEvaluator {
// this will always be 1 element because it's cached after load
const importer = module.importers.values().next().value
const finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(options.filename, {
includeImportDurations: this.options.includeImportDurations,
startOffset: codeDefinition.length,
importer,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function startVitestModuleRunner(options: ContextModuleRunnerOptions): Vi
return state().config.deps.interopDefault
},
getCurrentTestFilepath: () => state().filepath,
includeImportDurations: state().config.includeImportDurations,
},
)

Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/runtime/runners/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ export class VitestTestRunner implements VitestRunner {
}

getImportDurations(): Record<string, ImportDuration> {
if (!this.config.includeImportDurations) {
return {}
}

const importDurations: Record<string, ImportDuration> = {}
const entries = this.workerState.moduleExecutionInfo?.entries() || []

Expand Down
Loading