Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an option to hide skipped test lines #2745

Merged
merged 9 commits into from
May 3, 2023
1 change: 1 addition & 0 deletions packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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