Skip to content

Commit 4cee671

Browse files
authoredOct 16, 2023
fix(runner): removes deprecated error option from TaskResult (#4313)
BREAKING CHANGE: `error` property is no longer available
1 parent f8e4724 commit 4cee671

File tree

10 files changed

+3
-41
lines changed

10 files changed

+3
-41
lines changed
 

Diff for: ‎packages/runner/src/collect.ts

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export async function collectTests(paths: string[], runner: VitestRunner): Promi
6565
const error = processError(e)
6666
file.result = {
6767
state: 'fail',
68-
error,
6968
errors: [error],
7069
}
7170
}

Diff for: ‎packages/runner/src/run.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ export async function runTest(test: Test | Custom, runner: VitestRunner) {
217217
if (test.result.state === 'pass') {
218218
const error = processError(new Error('Expect test to fail'))
219219
test.result.state = 'fail'
220-
test.result.error = error
221220
test.result.errors = [error]
222221
}
223222
else {
224223
test.result.state = 'pass'
225-
test.result.error = undefined
226224
test.result.errors = undefined
227225
}
228226
}
@@ -248,7 +246,6 @@ function failTask(result: TaskResult, err: unknown, diffOptions?: DiffOptions) {
248246
: [err]
249247
for (const e of errors) {
250248
const error = processError(e, diffOptions)
251-
result.error ??= error
252249
result.errors ??= []
253250
result.errors.push(error)
254251
}
@@ -333,9 +330,8 @@ export async function runSuite(suite: Suite, runner: VitestRunner) {
333330
if (suite.mode === 'run') {
334331
if (!hasTests(suite)) {
335332
suite.result.state = 'fail'
336-
if (!suite.result.error) {
333+
if (!suite.result.errors?.length) {
337334
const error = processError(new Error(`No test found in suite ${suite.name}`))
338-
suite.result.error = error
339335
suite.result.errors = [error]
340336
}
341337
}
@@ -370,7 +366,6 @@ export async function runFiles(files: File[], runner: VitestRunner) {
370366
const error = processError(new Error(`No test suite found in file ${file.filepath}`))
371367
file.result = {
372368
state: 'fail',
373-
error,
374369
errors: [error],
375370
}
376371
}

Diff for: ‎packages/runner/src/types/tasks.ts

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ export interface TaskResult {
3939
duration?: number
4040
startTime?: number
4141
heap?: number
42-
/**
43-
* @deprecated Use "errors" instead
44-
*/
45-
error?: ErrorWithDiff
4642
errors?: ErrorWithDiff[]
4743
htmlError?: string
4844
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>

Diff for: ‎packages/runner/src/utils/collect.ts

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ function checkAllowOnly(task: TaskBase, allowOnly?: boolean) {
6969
const error = processError(new Error('[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error'))
7070
task.result = {
7171
state: 'fail',
72-
error,
7372
errors: [error],
7473
}
7574
}

Diff for: ‎packages/vitest/src/api/setup.ts

-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ class WebSocketReporter implements Reporter {
179179
getSourceMap: file => project.getBrowserSourceMapModuleById(file),
180180
}
181181

182-
// TODO remove after "error" deprecation is removed
183-
if (result?.error && !isPrimitive(result.error))
184-
result.error.stacks = parseErrorStacktrace(result.error, parserOptions)
185182
result?.errors?.forEach((error) => {
186183
if (!isPrimitive(error))
187184
error.stacks = parseErrorStacktrace(error, parserOptions)

Diff for: ‎packages/vitest/src/node/reporters/junit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class JUnitReporter implements Reporter {
179179
await this.logger.log('<skipped/>')
180180

181181
if (task.result?.state === 'fail') {
182-
const errors = task.result.errors?.length ? task.result.errors : [task.result.error]
182+
const errors = task.result.errors || []
183183
for (const error of errors) {
184184
await this.writeElement('failure', {
185185
message: error?.message,

Diff for: ‎test/reporters/src/data-for-junit.ts

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function createSuiteHavingFailedTestWithXmlInError(): File[] {
4545
file,
4646
result: {
4747
state: 'fail',
48-
error: errorWithXml,
4948
errors: [errorWithXml],
5049
duration: 2.123123123,
5150
},

Diff for: ‎test/reporters/src/data.ts

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const innerTasks: Task[] = [
6666
file,
6767
result: {
6868
state: 'fail',
69-
error,
7069
errors: [error],
7170
duration: 1.4422860145568848,
7271
},

Diff for: ‎test/reporters/tests/__snapshots__/html.test.ts.snap

-19
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,6 @@ exports[`html reporter > resolves to "failing" status for test file "json-fail"
4242
"name": "should fail",
4343
"result": {
4444
"duration": 0,
45-
"error": {
46-
"actual": "2",
47-
"constructor": "Function<AssertionError>",
48-
"diff": "- Expected
49-
+ Received
50-
51-
- 1
52-
+ 2",
53-
"expected": "1",
54-
"message": "expected 2 to deeply equal 1",
55-
"name": "AssertionError",
56-
"nameStr": "AssertionError",
57-
"operator": "strictEqual",
58-
"showDiff": true,
59-
"stack": "AssertionError: expected 2 to deeply equal 1",
60-
"stackStr": "AssertionError: expected 2 to deeply equal 1",
61-
"toJSON": "Function<anonymous>",
62-
"toString": "Function<toString>",
63-
},
6445
"errors": [
6546
{
6647
"actual": "2",

Diff for: ‎test/reporters/tests/html.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('html reporter', async () => {
3333
task.id = 0
3434
task.result.duration = 0
3535
task.result.startTime = 0
36-
expect(task.result.error).not.toBeDefined()
36+
expect(task.result.errors).not.toBeDefined()
3737
expect(task.result.logs).not.toBeDefined()
3838
expect(resultJson).toMatchSnapshot(`tests are ${expected}`)
3939
expect(indexHtml).toMatch('window.METADATA_PATH="html.meta.json.gz"')
@@ -61,11 +61,8 @@ describe('html reporter', async () => {
6161
task.id = 0
6262
task.result.duration = 0
6363
task.result.startTime = 0
64-
expect(task.result.error).toBeDefined()
6564
expect(task.result.errors).toBeDefined()
66-
task.result.error.stack = task.result.error.stack.split('\n')[0]
6765
task.result.errors[0].stack = task.result.errors[0].stack.split('\n')[0]
68-
task.result.error.stackStr = task.result.error.stackStr.split('\n')[0]
6966
task.result.errors[0].stackStr = task.result.errors[0].stackStr.split('\n')[0]
7067
expect(task.logs).toBeDefined()
7168
expect(task.logs).toHaveLength(1)

0 commit comments

Comments
 (0)
Please sign in to comment.