Skip to content

Commit

Permalink
feat: add an option to hide skipped test lines (#2745)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
  • Loading branch information
g4rry420 and sheremet-va committed May 3, 2023
1 parent f3c3607 commit 9bdb160
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Expand Up @@ -76,6 +76,7 @@ const config = {
update: false,
reporters: [],
silent: false,
hideSkippedTests: false,
api: false,
ui: false,
uiBase: '/__vitest__/',
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli.ts
Expand Up @@ -23,6 +23,7 @@ cli
.option('--threads', 'Enabled threads (default: true)')
.option('--single-thread', 'Run tests inside a single thread, requires --threads (default: false)')
.option('--silent', 'Silent console output from tests')
.option('--hideSkippedTests', 'Hide logs for skipped tests')
.option('--isolate', 'Isolate environment for each test file (default: true)')
.option('--reporter <name>', 'Specify reporters')
.option('--outputFile <filename/-s>', 'Write test results to a file when supporter reporter is also specified, use cac\'s dot notation for individual outputs of multiple reporters')
Expand Down
52 changes: 39 additions & 13 deletions packages/vitest/src/node/reporters/renderers/listRenderer.ts
Expand Up @@ -150,8 +150,15 @@ export function renderTree(tasks: Task[], options: ListRendererOptions, level =
taskOutput.push(renderHookState(task, 'beforeAll', level + 1))
taskOutput.push(renderHookState(task, 'beforeEach', level + 1))
if (task.type === 'suite' && task.tasks.length > 0) {
if ((task.result?.state === 'fail' || task.result?.state === 'run' || options.renderSucceed))
taskOutput.push(renderTree(task.tasks, options, level + 1, maxRows))
if ((task.result?.state === 'fail' || task.result?.state === 'run' || options.renderSucceed)) {
if (options.logger.ctx.config.hideSkippedTests) {
const filteredTasks = task.tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
taskOutput.push(renderTree(filteredTasks, options, level + 1, maxRows))
}
else {
taskOutput.push(renderTree(task.tasks, options, level + 1, maxRows))
}
}
}
taskOutput.push(renderHookState(task, 'afterAll', level + 1))
taskOutput.push(renderHookState(task, 'afterEach', level + 1))
Expand All @@ -175,14 +182,27 @@ export function createListRenderer(_tasks: Task[], options: ListRendererOptions)
const log = options.logger.logUpdate

function update() {
log(renderTree(
tasks,
options,
0,
// log-update already limits the amount of printed rows to fit the current terminal
// but we can optimize performance by doing it ourselves
process.stdout.rows,
))
if (options.logger.ctx.config.hideSkippedTests) {
const filteredTasks = tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
log(renderTree(
filteredTasks,
options,
0,
// log-update already limits the amount of printed rows to fit the current terminal
// but we can optimize performance by doing it ourselves
process.stdout.rows,
))
}
else {
log(renderTree(
tasks,
options,
0,
// log-update already limits the amount of printed rows to fit the current terminal
// but we can optimize performance by doing it ourselves
process.stdout.rows,
))
}
}

return {
Expand All @@ -202,9 +222,15 @@ export function createListRenderer(_tasks: Task[], options: ListRendererOptions)
timer = undefined
}
log.clear()

// Note that at this point the renderTree should output all tasks
options.logger.log(renderTree(tasks, options))
if (options.logger.ctx.config.hideSkippedTests) {
const filteredTasks = tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
// Note that at this point the renderTree should output all tasks
options.logger.log(renderTree(filteredTasks, options))
}
else {
// Note that at this point the renderTree should output all tasks
options.logger.log(renderTree(tasks, options))
}
return this
},
clear() {
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/types/config.ts
Expand Up @@ -309,6 +309,13 @@ export interface InlineConfig {
*/
silent?: boolean

/**
* Hide logs for skipped tests
*
* @default false
*/
hideSkippedTests?: boolean

/**
* Path to setup files
*/
Expand Down

0 comments on commit 9bdb160

Please sign in to comment.