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

fix!(vitest, runner): removes deprecated error option from TaskResult #4313

Merged
merged 3 commits into from
Oct 16, 2023
Merged
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: 0 additions & 1 deletion packages/runner/src/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export async function collectTests(paths: string[], runner: VitestRunner): Promi
const error = processError(e)
file.result = {
state: 'fail',
error,
errors: [error],
}
}
Expand Down
7 changes: 1 addition & 6 deletions packages/runner/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ export async function runTest(test: Test | Custom, runner: VitestRunner) {
if (test.result.state === 'pass') {
const error = processError(new Error('Expect test to fail'))
test.result.state = 'fail'
test.result.error = error
test.result.errors = [error]
}
else {
test.result.state = 'pass'
test.result.error = undefined
test.result.errors = undefined
}
}
Expand All @@ -248,7 +246,6 @@ function failTask(result: TaskResult, err: unknown, diffOptions?: DiffOptions) {
: [err]
for (const e of errors) {
const error = processError(e, diffOptions)
result.error ??= error
result.errors ??= []
result.errors.push(error)
}
Expand Down Expand Up @@ -333,9 +330,8 @@ export async function runSuite(suite: Suite, runner: VitestRunner) {
if (suite.mode === 'run') {
if (!hasTests(suite)) {
suite.result.state = 'fail'
if (!suite.result.error) {
if (!suite.result.errors?.length) {
const error = processError(new Error(`No test found in suite ${suite.name}`))
suite.result.error = error
suite.result.errors = [error]
}
}
Expand Down Expand Up @@ -370,7 +366,6 @@ export async function runFiles(files: File[], runner: VitestRunner) {
const error = processError(new Error(`No test suite found in file ${file.filepath}`))
file.result = {
state: 'fail',
error,
errors: [error],
}
}
Expand Down
4 changes: 0 additions & 4 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export interface TaskResult {
duration?: number
startTime?: number
heap?: number
/**
* @deprecated Use "errors" instead
*/
error?: ErrorWithDiff
errors?: ErrorWithDiff[]
htmlError?: string
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>
Expand Down
1 change: 0 additions & 1 deletion packages/runner/src/utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function checkAllowOnly(task: TaskBase, allowOnly?: boolean) {
const error = processError(new Error('[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error'))
task.result = {
state: 'fail',
error,
errors: [error],
}
}
Expand Down
3 changes: 0 additions & 3 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ class WebSocketReporter implements Reporter {
getSourceMap: file => project.getBrowserSourceMapModuleById(file),
}

// TODO remove after "error" deprecation is removed
if (result?.error && !isPrimitive(result.error))
result.error.stacks = parseErrorStacktrace(result.error, parserOptions)
result?.errors?.forEach((error) => {
if (!isPrimitive(error))
error.stacks = parseErrorStacktrace(error, parserOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class JUnitReporter implements Reporter {
await this.logger.log('<skipped/>')

if (task.result?.state === 'fail') {
const errors = task.result.errors?.length ? task.result.errors : [task.result.error]
const errors = task.result.errors || []
for (const error of errors) {
await this.writeElement('failure', {
message: error?.message,
Expand Down
1 change: 0 additions & 1 deletion test/reporters/src/data-for-junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function createSuiteHavingFailedTestWithXmlInError(): File[] {
file,
result: {
state: 'fail',
error: errorWithXml,
errors: [errorWithXml],
duration: 2.123123123,
},
Expand Down
1 change: 0 additions & 1 deletion test/reporters/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const innerTasks: Task[] = [
file,
result: {
state: 'fail',
error,
errors: [error],
duration: 1.4422860145568848,
},
Expand Down
19 changes: 0 additions & 19 deletions test/reporters/tests/__snapshots__/html.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,6 @@ exports[`html reporter > resolves to "failing" status for test file "json-fail"
"name": "should fail",
"result": {
"duration": 0,
"error": {
"actual": "2",
"constructor": "Function<AssertionError>",
"diff": "- Expected
+ Received

- 1
+ 2",
"expected": "1",
"message": "expected 2 to deeply equal 1",
"name": "AssertionError",
"nameStr": "AssertionError",
"operator": "strictEqual",
"showDiff": true,
"stack": "AssertionError: expected 2 to deeply equal 1",
"stackStr": "AssertionError: expected 2 to deeply equal 1",
"toJSON": "Function<anonymous>",
"toString": "Function<toString>",
},
"errors": [
{
"actual": "2",
Expand Down
5 changes: 1 addition & 4 deletions test/reporters/tests/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('html reporter', async () => {
task.id = 0
task.result.duration = 0
task.result.startTime = 0
expect(task.result.error).not.toBeDefined()
expect(task.result.errors).not.toBeDefined()
expect(task.result.logs).not.toBeDefined()
expect(resultJson).toMatchSnapshot(`tests are ${expected}`)
expect(indexHtml).toMatch('window.METADATA_PATH="html.meta.json.gz"')
Expand Down Expand Up @@ -61,11 +61,8 @@ describe('html reporter', async () => {
task.id = 0
task.result.duration = 0
task.result.startTime = 0
expect(task.result.error).toBeDefined()
expect(task.result.errors).toBeDefined()
task.result.error.stack = task.result.error.stack.split('\n')[0]
task.result.errors[0].stack = task.result.errors[0].stack.split('\n')[0]
task.result.error.stackStr = task.result.error.stackStr.split('\n')[0]
task.result.errors[0].stackStr = task.result.errors[0].stackStr.split('\n')[0]
expect(task.logs).toBeDefined()
expect(task.logs).toHaveLength(1)
Expand Down
Loading