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
2 changes: 1 addition & 1 deletion examples/basic/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('Math.sqrt()', () => {
expect(Math.sqrt(2)).toBe(Math.SQRT2)
})

test('JSON', () => {
test.skip('JSON', () => {
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
const input = {
foo: 'hello',
bar: 'world',
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/test/suite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('suite name', () => {
assert.equal(Math.sqrt(4), 2)
})

it('bar', () => {
it.only('bar', () => {
expect(1 + 1).eq(2)
})

Expand Down
2 changes: 2 additions & 0 deletions examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export default defineConfig({
test: {
/* for example, use global to avoid globals imports (describe, test, expect): */
// globals: true,
reporter: ['verbose'],
silentSkip: true,
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
},
})
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,
silentSkip: false,
api: false,
ui: false,
uiBase: '/__vitest__/',
Expand Down
27 changes: 23 additions & 4 deletions packages/vitest/src/node/reporters/renderers/listRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ export function renderTree(tasks: Task[], options: ListRendererOptions, level =
output = output.concat(renderHookState(task, 'beforeAll', level + 1))
output = output.concat(renderHookState(task, 'beforeEach', level + 1))
if (task.type === 'suite' && task.tasks.length > 0) {
if ((task.result?.state === 'fail' || task.result?.state === 'run' || options.renderSucceed))
output = output.concat(renderTree(task.tasks, options, level + 1))
if ((task.result?.state === 'fail' || task.result?.state === 'run' || options.renderSucceed)) {
if (options.logger.ctx.config.silentSkip) {
const filteredTasks = task.tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
output = output.concat(renderTree(filteredTasks, options, level + 1))
}
else {
output = output.concat(renderTree(task.tasks, options, level + 1))
}
}
}
output = output.concat(renderHookState(task, 'afterAll', level + 1))
output = output.concat(renderHookState(task, 'afterEach', level + 1))
Expand All @@ -161,7 +168,13 @@ export const createListRenderer = (_tasks: Task[], options: ListRendererOptions)
const log = options.logger.logUpdate

function update() {
log(renderTree(tasks, options))
if (options.logger.ctx.config.silentSkip) {
const filteredTasks = tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
log(renderTree(filteredTasks, options))
}
else {
log(renderTree(tasks, options))
}
}

return {
Expand All @@ -182,7 +195,13 @@ export const createListRenderer = (_tasks: Task[], options: ListRendererOptions)
timer = undefined
}
log.clear()
options.logger.log(renderTree(tasks, options))
if (options.logger.ctx.config.silentSkip) {
const filteredTasks = tasks.filter(t => t.mode !== 'skip' && t.mode !== 'todo')
options.logger.log(renderTree(filteredTasks, options))
}
else {
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 @@ -263,6 +263,13 @@ export interface InlineConfig {
*/
silent?: boolean

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

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