From d582d36d2183635f723ebb380d1a4cc18f75ba62 Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Wed, 24 Aug 2022 15:34:07 +0800 Subject: [PATCH 01/11] fix: correct error source position in json report --- packages/vitest/src/node/reporters/json.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/vitest/src/node/reporters/json.ts b/packages/vitest/src/node/reporters/json.ts index c9041c811acf..13497c42bd9b 100644 --- a/packages/vitest/src/node/reporters/json.ts +++ b/packages/vitest/src/node/reporters/json.ts @@ -4,7 +4,7 @@ import type { Vitest } from '../../node' import type { File, Reporter, Suite, TaskState, Test } from '../../types' import { getSuites, getTests } from '../../utils' import { getOutputFile } from '../../utils/config-helpers' -import { parseStacktrace } from '../../utils/source-map' +import { interpretSourcePos, parseStacktrace } from '../../utils/source-map' // for compatibility reasons, the reporter produces a JSON similar to the one produced by the Jest JSON reporter // the following types are extracted from the Jest repository (and simplified) @@ -94,7 +94,7 @@ export class JsonReporter implements Reporter { startTime = this.start const endTime = tests.reduce((prev, next) => Math.max(prev, (next.result?.startTime ?? 0) + (next.result?.duration ?? 0)), startTime) - const assertionResults = tests.map((t) => { + const assertionResults = await Promise.all(tests.map(async (t) => { const ancestorTitles = [] as string[] let iter: Suite | undefined = t.suite while (iter) { @@ -110,9 +110,9 @@ export class JsonReporter implements Reporter { title: t.name, duration: t.result?.duration, failureMessages: t.result?.error?.message == null ? [] : [t.result.error.message], - location: this.getFailureLocation(t), + location: await this.getFailureLocation(t), } as FormattedAssertionResult - }) + })) if (tests.some(t => t.result?.state === 'run')) { this.ctx.logger.warn('WARNING: Some tests are still running when generating the JSON report.' @@ -180,12 +180,13 @@ export class JsonReporter implements Reporter { } } - protected getFailureLocation(test: Test): Callsite | undefined { + protected async getFailureLocation(test: Test): Promise { const error = test.result?.error if (!error) return const stack = parseStacktrace(error) + await interpretSourcePos(stack, this.ctx) const frame = stack[stack.length - 1] if (!frame) return From a20e71f81a8f0870941c1d0858ae8f1dc6cd188a Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Wed, 24 Aug 2022 16:46:17 +0800 Subject: [PATCH 02/11] chore: fix json reporter test --- test/reporters/src/context.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/reporters/src/context.ts b/test/reporters/src/context.ts index 363f98b8e69f..38c67c54067d 100644 --- a/test/reporters/src/context.ts +++ b/test/reporters/src/context.ts @@ -1,3 +1,4 @@ +import type { ModuleGraph, ViteDevServer } from 'vite' import type { Logger } from '../../../packages/vitest/src/node/logger' import type { Vitest } from '../../../packages/vitest/src/node' import type { StateManager } from '../../../packages/vitest/src/node/state' @@ -15,6 +16,14 @@ export function getContext(): Context { root: '/', } + const moduleGraph: Partial = { + getModuleById: () => undefined, + } + + const server: Partial = { + moduleGraph: moduleGraph as ModuleGraph, + } + const state: Partial = { filesMap: new Map(), } @@ -22,6 +31,7 @@ export function getContext(): Context { const context: Partial = { state: state as StateManager, config: config as ResolvedConfig, + server: server as ViteDevServer, } context.logger = { From 02a3ef10aae14f6b8fa20f6e596d9c9e40b77328 Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Thu, 25 Aug 2022 18:49:15 +0800 Subject: [PATCH 03/11] test: add json report snapshot --- test/reporters/src/data.ts | 5 + .../tests/__snapshots__/json.test.ts.snap | 245 ++++++++++++++++++ test/reporters/tests/json.test.ts | 135 ++++++++++ 3 files changed, 385 insertions(+) create mode 100644 test/reporters/tests/__snapshots__/json.test.ts.snap create mode 100644 test/reporters/tests/json.test.ts diff --git a/test/reporters/src/data.ts b/test/reporters/src/data.ts index b22b6a92be2f..f8271a00db25 100644 --- a/test/reporters/src/data.ts +++ b/test/reporters/src/data.ts @@ -176,5 +176,10 @@ suite.tasks = tasks const files = [file] +export function clearSourcePos() { + if (error.stacks) + error.stacks = undefined +} + export { files } diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap new file mode 100644 index 000000000000..f2c3a5bc8f96 --- /dev/null +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -0,0 +1,245 @@ +// Vitest Snapshot v1 + +exports[`with comment 1`] = ` +{ + "numFailedTestSuites": 0, + "numFailedTests": 1, + "numPassedTestSuites": 3, + "numPassedTests": 8, + "numPendingTestSuites": 0, + "numPendingTests": 0, + "numTodoTests": 1, + "numTotalTestSuites": 3, + "numTotalTests": 9, + "startTime": 1742587001759, + "success": false, + "testResults": [ + { + "assertionResults": [ + { + "ancestorTitles": [ + "suite", + "inner suite", + ], + "duration": 1.4422860145568848, + "failureMessages": [ + "expected 2.23606797749979 to equal 2", + ], + "fullName": "suite inner suite Math.sqrt()", + "location": { + "column": 9, + "line": 10, + }, + "status": "failed", + "title": "Math.sqrt()", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 1.0237109661102295, + "failureMessages": [], + "fullName": "suite JSON", + "status": "passed", + "title": "JSON", + }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite async with timeout", + "status": "skipped", + "title": "async with timeout", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 100.50598406791687, + "failureMessages": [], + "fullName": "suite timeout", + "status": "passed", + "title": "timeout", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 20.184875011444092, + "failureMessages": [], + "fullName": "suite callback setup success ", + "status": "passed", + "title": "callback setup success ", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 0.33245420455932617, + "failureMessages": [], + "fullName": "suite callback test success ", + "status": "passed", + "title": "callback test success ", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 19.738605976104736, + "failureMessages": [], + "fullName": "suite callback setup success done(false)", + "status": "passed", + "title": "callback setup success done(false)", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 0.1923508644104004, + "failureMessages": [], + "fullName": "suite callback test success done(false)", + "status": "passed", + "title": "callback test success done(false)", + }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite todo test", + "status": "todo", + "title": "todo test", + }, + ], + "endTime": 1742587001759, + "message": "", + "name": "/vitest/test/core/test/basic.test.ts", + "startTime": 1742587001759, + "status": "failed", + }, + ], +} +`; + +exports[`without comment 1`] = ` +{ + "numFailedTestSuites": 0, + "numFailedTests": 1, + "numPassedTestSuites": 3, + "numPassedTests": 8, + "numPendingTestSuites": 0, + "numPendingTests": 0, + "numTodoTests": 1, + "numTotalTestSuites": 3, + "numTotalTests": 9, + "startTime": 1642587001759, + "success": false, + "testResults": [ + { + "assertionResults": [ + { + "ancestorTitles": [ + "suite", + "inner suite", + ], + "duration": 1.4422860145568848, + "failureMessages": [ + "expected 2.23606797749979 to equal 2", + ], + "fullName": "suite inner suite Math.sqrt()", + "location": { + "column": 9, + "line": 8, + }, + "status": "failed", + "title": "Math.sqrt()", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 1.0237109661102295, + "failureMessages": [], + "fullName": "suite JSON", + "status": "passed", + "title": "JSON", + }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite async with timeout", + "status": "skipped", + "title": "async with timeout", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 100.50598406791687, + "failureMessages": [], + "fullName": "suite timeout", + "status": "passed", + "title": "timeout", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 20.184875011444092, + "failureMessages": [], + "fullName": "suite callback setup success ", + "status": "passed", + "title": "callback setup success ", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 0.33245420455932617, + "failureMessages": [], + "fullName": "suite callback test success ", + "status": "passed", + "title": "callback test success ", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 19.738605976104736, + "failureMessages": [], + "fullName": "suite callback setup success done(false)", + "status": "passed", + "title": "callback setup success done(false)", + }, + { + "ancestorTitles": [ + "suite", + ], + "duration": 0.1923508644104004, + "failureMessages": [], + "fullName": "suite callback test success done(false)", + "status": "passed", + "title": "callback test success done(false)", + }, + { + "ancestorTitles": [ + "suite", + ], + "failureMessages": [], + "fullName": "suite todo test", + "status": "todo", + "title": "todo test", + }, + ], + "endTime": 1642587001759, + "message": "", + "name": "/vitest/test/core/test/basic.test.ts", + "startTime": 1642587001759, + "status": "failed", + }, + ], +} +`; diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts new file mode 100644 index 000000000000..b4d020dc16a5 --- /dev/null +++ b/test/reporters/tests/json.test.ts @@ -0,0 +1,135 @@ +import { afterEach, expect, test, vi } from 'vitest' +import { JsonReporter } from 'vitest/src/node/reporters/json' +import type { ModuleGraph, ModuleNode, TransformResult } from 'vite' +import { getContext } from '../src/context' +import { clearSourcePos, files } from '../src/data' + +const no_comment: TransformResult = { + code: 'const __vite_ssr_import_0__ = await __vite_ssr_import__("vitest");\n' + + '\n' + + '__vite_ssr_import_0__.test("Math.sqrt()", () => {\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 300);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + '});\n' + + '\n' + + '\n' + + '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IjtBQUE2QjtBQUU3QiwyQkFBSyxlQUFlLE1BQU07QUFDeEIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLEdBQUc7QUFDOUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDOUIsQ0FBQyIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYXNzZXJ0LCB0ZXN0IH0gZnJvbSAndml0ZXN0J1xuXG50ZXN0KCdNYXRoLnNxcnQoKScsICgpID0+IHtcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMzAwKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxufSlcbiJdLCJmaWxlIjoiQzovcHJvamVjdHMvR2l0aHViL25ldy1wcmovdGVzdC9pbmRleC50ZXN0LnRzIn0=\n', + map: { + version: 3, + mappings: ';AAA6B;AAE7B,2BAAK,eAAe,MAAM;AACxB,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,GAAG;AAC9B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC9B,CAAC', + names: [], + sources: ['C:/projects/Github/new-prj/test/index.test.ts'], + sourcesContent: [ + 'import { assert, test } from \'vitest\'\n' + + '\n' + + 'test(\'Math.sqrt()\', () => {\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 300)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + '})\n', + ], + file: 'C:/projects/Github/new-prj/test/index.test.ts', + toUrl: () => '', + toString: () => '', + }, + deps: ['vitest'], + dynamicDeps: [], +} + +const comment: TransformResult = { + code: 'const __vite_ssr_import_0__ = await __vite_ssr_import__("vitest");\n' + + '\n' + + '__vite_ssr_import_0__.test("Math.sqrt()", () => {\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 300);\n' + + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' + + '});\n' + + '\n' + + '\n' + + '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IjtBQUE2QjtBQUk3QiwyQkFBSyxlQUFlLE1BQU07QUFDeEIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLEdBQUc7QUFDOUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDOUIsQ0FBQyIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYXNzZXJ0LCB0ZXN0IH0gZnJvbSAndml0ZXN0J1xuXG4vLyBjb21tZW50MVxuLy8gY29tbWVudDJcbnRlc3QoJ01hdGguc3FydCgpJywgKCkgPT4ge1xuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAzMDApXG4gIGFzc2VydC5lcXVhbChNYXRoLnNxcnQoNCksIDIpXG59KVxuIl0sImZpbGUiOiJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMifQ==\n', + map: { + version: 3, + mappings: ';AAA6B;AAI7B,2BAAK,eAAe,MAAM;AACxB,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,GAAG;AAC9B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC9B,CAAC', + names: [], + sources: ['C:/projects/Github/new-prj/test/index.test.ts'], + sourcesContent: [ + 'import { assert, test } from \'vitest\'\n' + + '\n' + + '// comment1\n' + + '// comment2\n' + + 'test(\'Math.sqrt()\', () => {\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + ' assert.equal(Math.sqrt(4), 300)\n' + + ' assert.equal(Math.sqrt(4), 2)\n' + + '})\n', + ], + file: 'C:/projects/Github/new-prj/test/index.test.ts', + toUrl: () => '', + toString: () => '', + }, + deps: ['vitest'], + dynamicDeps: [], +} + +const no_comment_mod: Partial = { + ssrTransformResult: no_comment, +} + +const comment_mod: Partial = { + ssrTransformResult: comment, +} + +const moduleGraphNoComment: Partial = { + getModuleById: () => no_comment_mod as ModuleNode, +} + +const moduleGraphentComment: Partial = { + getModuleById: () => comment_mod as ModuleNode, +} + +afterEach(() => { + vi.useRealTimers() +}) + +test('without comment', async () => { + // Arrange + const reporter = new JsonReporter() + const context = getContext() + context.vitest.server.moduleGraph = moduleGraphNoComment as ModuleGraph + + vi.setSystemTime(1642587001759) + // Act + reporter.onInit(context.vitest) + await reporter.onFinished(files) + // Assert + expect(JSON.parse(context.output)).toMatchSnapshot() +}) + +test('with comment', async () => { + // Arrange + const reporter = new JsonReporter() + const context = getContext() + context.vitest.server.moduleGraph = moduleGraphentComment as ModuleGraph + + vi.setSystemTime(1742587001759) + // Act + clearSourcePos() + reporter.onInit(context.vitest) + await reporter.onFinished(files) + // Assert + expect(JSON.parse(context.output)).toMatchSnapshot() +}) + From 6d8ed43724d805132306077f23aa0534a9f4ef53 Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Mon, 29 Aug 2022 15:41:25 +0800 Subject: [PATCH 04/11] chore: json report test --- test/reporters/fixtures/expect.test.ts | 6 + .../tests/__snapshots__/json.test.ts.snap | 286 +++--------------- test/reporters/tests/json.test.ts | 163 ++-------- 3 files changed, 79 insertions(+), 376 deletions(-) create mode 100644 test/reporters/fixtures/expect.test.ts diff --git a/test/reporters/fixtures/expect.test.ts b/test/reporters/fixtures/expect.test.ts new file mode 100644 index 000000000000..90c6b977c53b --- /dev/null +++ b/test/reporters/fixtures/expect.test.ts @@ -0,0 +1,6 @@ +import { expect, test } from 'vitest' +// I am comment1 +// I am comment2 +test('should fail', () => { + expect(2).toEqual(1) +}) diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap index f2c3a5bc8f96..36211ec80928 100644 --- a/test/reporters/tests/__snapshots__/json.test.ts.snap +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -1,245 +1,47 @@ // Vitest Snapshot v1 -exports[`with comment 1`] = ` -{ - "numFailedTestSuites": 0, - "numFailedTests": 1, - "numPassedTestSuites": 3, - "numPassedTests": 8, - "numPendingTestSuites": 0, - "numPendingTests": 0, - "numTodoTests": 1, - "numTotalTestSuites": 3, - "numTotalTests": 9, - "startTime": 1742587001759, - "success": false, - "testResults": [ - { - "assertionResults": [ - { - "ancestorTitles": [ - "suite", - "inner suite", - ], - "duration": 1.4422860145568848, - "failureMessages": [ - "expected 2.23606797749979 to equal 2", - ], - "fullName": "suite inner suite Math.sqrt()", - "location": { - "column": 9, - "line": 10, - }, - "status": "failed", - "title": "Math.sqrt()", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 1.0237109661102295, - "failureMessages": [], - "fullName": "suite JSON", - "status": "passed", - "title": "JSON", - }, - { - "ancestorTitles": [ - "suite", - ], - "failureMessages": [], - "fullName": "suite async with timeout", - "status": "skipped", - "title": "async with timeout", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 100.50598406791687, - "failureMessages": [], - "fullName": "suite timeout", - "status": "passed", - "title": "timeout", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 20.184875011444092, - "failureMessages": [], - "fullName": "suite callback setup success ", - "status": "passed", - "title": "callback setup success ", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 0.33245420455932617, - "failureMessages": [], - "fullName": "suite callback test success ", - "status": "passed", - "title": "callback test success ", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 19.738605976104736, - "failureMessages": [], - "fullName": "suite callback setup success done(false)", - "status": "passed", - "title": "callback setup success done(false)", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 0.1923508644104004, - "failureMessages": [], - "fullName": "suite callback test success done(false)", - "status": "passed", - "title": "callback test success done(false)", - }, - { - "ancestorTitles": [ - "suite", - ], - "failureMessages": [], - "fullName": "suite todo test", - "status": "todo", - "title": "todo test", - }, - ], - "endTime": 1742587001759, - "message": "", - "name": "/vitest/test/core/test/basic.test.ts", - "startTime": 1742587001759, - "status": "failed", - }, - ], -} -`; - -exports[`without comment 1`] = ` -{ - "numFailedTestSuites": 0, - "numFailedTests": 1, - "numPassedTestSuites": 3, - "numPassedTests": 8, - "numPendingTestSuites": 0, - "numPendingTests": 0, - "numTodoTests": 1, - "numTotalTestSuites": 3, - "numTotalTests": 9, - "startTime": 1642587001759, - "success": false, - "testResults": [ - { - "assertionResults": [ - { - "ancestorTitles": [ - "suite", - "inner suite", - ], - "duration": 1.4422860145568848, - "failureMessages": [ - "expected 2.23606797749979 to equal 2", - ], - "fullName": "suite inner suite Math.sqrt()", - "location": { - "column": 9, - "line": 8, - }, - "status": "failed", - "title": "Math.sqrt()", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 1.0237109661102295, - "failureMessages": [], - "fullName": "suite JSON", - "status": "passed", - "title": "JSON", - }, - { - "ancestorTitles": [ - "suite", - ], - "failureMessages": [], - "fullName": "suite async with timeout", - "status": "skipped", - "title": "async with timeout", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 100.50598406791687, - "failureMessages": [], - "fullName": "suite timeout", - "status": "passed", - "title": "timeout", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 20.184875011444092, - "failureMessages": [], - "fullName": "suite callback setup success ", - "status": "passed", - "title": "callback setup success ", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 0.33245420455932617, - "failureMessages": [], - "fullName": "suite callback test success ", - "status": "passed", - "title": "callback test success ", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 19.738605976104736, - "failureMessages": [], - "fullName": "suite callback setup success done(false)", - "status": "passed", - "title": "callback setup success done(false)", - }, - { - "ancestorTitles": [ - "suite", - ], - "duration": 0.1923508644104004, - "failureMessages": [], - "fullName": "suite callback test success done(false)", - "status": "passed", - "title": "callback test success done(false)", - }, - { - "ancestorTitles": [ - "suite", - ], - "failureMessages": [], - "fullName": "suite todo test", - "status": "todo", - "title": "todo test", - }, - ], - "endTime": 1642587001759, - "message": "", - "name": "/vitest/test/core/test/basic.test.ts", - "startTime": 1642587001759, - "status": "failed", - }, - ], -} +exports[`should fails > should fails 1`] = ` +[ + "logTask....", + "{", + " \\"numTotalTestSuites\\": 1,", + " \\"numPassedTestSuites\\": 1,", + " \\"numFailedTestSuites\\": 0,", + " \\"numPendingTestSuites\\": 0,", + " \\"numTotalTests\\": 1,", + " \\"numPassedTests\\": 0,", + " \\"numFailedTests\\": 1,", + " \\"numPendingTests\\": 0,", + " \\"numTodoTests\\": 0,", + "", + " \\"success\\": false,", + " \\"testResults\\": [", + " {", + " \\"assertionResults\\": [", + " {", + " \\"ancestorTitles\\": [", + " \\"\\"", + " ],", + " \\"fullName\\": \\" should fail\\",", + " \\"status\\": \\"failed\\",", + " \\"title\\": \\"should fail\\",", + "", + " \\"failureMessages\\": [", + " \\"expected 2 to deeply equal 1\\"", + " ],", + " \\"location\\": {", + " \\"line\\": 5,", + " \\"column\\": 12", + " }", + " }", + " ],", + "", + "", + " \\"status\\": \\"failed\\",", + " \\"message\\": \\"\\",", + " \\"name\\": \\"C:/projects/Github/vitest/test/reporters/fixtures/expect.test.ts\\"", + " }", + " ]", + "}", +] `; diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts index b4d020dc16a5..fa31453c5d20 100644 --- a/test/reporters/tests/json.test.ts +++ b/test/reporters/tests/json.test.ts @@ -1,135 +1,30 @@ -import { afterEach, expect, test, vi } from 'vitest' -import { JsonReporter } from 'vitest/src/node/reporters/json' -import type { ModuleGraph, ModuleNode, TransformResult } from 'vite' -import { getContext } from '../src/context' -import { clearSourcePos, files } from '../src/data' - -const no_comment: TransformResult = { - code: 'const __vite_ssr_import_0__ = await __vite_ssr_import__("vitest");\n' - + '\n' - + '__vite_ssr_import_0__.test("Math.sqrt()", () => {\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 300);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + '});\n' - + '\n' - + '\n' - + '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IjtBQUE2QjtBQUU3QiwyQkFBSyxlQUFlLE1BQU07QUFDeEIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLEdBQUc7QUFDOUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDOUIsQ0FBQyIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYXNzZXJ0LCB0ZXN0IH0gZnJvbSAndml0ZXN0J1xuXG50ZXN0KCdNYXRoLnNxcnQoKScsICgpID0+IHtcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMilcbiAgYXNzZXJ0LmVxdWFsKE1hdGguc3FydCg0KSwgMzAwKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxufSlcbiJdLCJmaWxlIjoiQzovcHJvamVjdHMvR2l0aHViL25ldy1wcmovdGVzdC9pbmRleC50ZXN0LnRzIn0=\n', - map: { - version: 3, - mappings: ';AAA6B;AAE7B,2BAAK,eAAe,MAAM;AACxB,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,GAAG;AAC9B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC9B,CAAC', - names: [], - sources: ['C:/projects/Github/new-prj/test/index.test.ts'], - sourcesContent: [ - 'import { assert, test } from \'vitest\'\n' - + '\n' - + 'test(\'Math.sqrt()\', () => {\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 300)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + '})\n', - ], - file: 'C:/projects/Github/new-prj/test/index.test.ts', - toUrl: () => '', - toString: () => '', - }, - deps: ['vitest'], - dynamicDeps: [], -} - -const comment: TransformResult = { - code: 'const __vite_ssr_import_0__ = await __vite_ssr_import__("vitest");\n' - + '\n' - + '__vite_ssr_import_0__.test("Math.sqrt()", () => {\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 300);\n' - + ' __vite_ssr_import_0__.assert.equal(Math.sqrt(4), 2);\n' - + '});\n' - + '\n' - + '\n' - + '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IjtBQUE2QjtBQUk3QiwyQkFBSyxlQUFlLE1BQU07QUFDeEIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDNUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLEdBQUc7QUFDOUIsK0JBQU8sTUFBTSxLQUFLLEtBQUssQ0FBQyxHQUFHLENBQUM7QUFDOUIsQ0FBQyIsIm5hbWVzIjpbXSwic291cmNlcyI6WyJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgYXNzZXJ0LCB0ZXN0IH0gZnJvbSAndml0ZXN0J1xuXG4vLyBjb21tZW50MVxuLy8gY29tbWVudDJcbnRlc3QoJ01hdGguc3FydCgpJywgKCkgPT4ge1xuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAyKVxuICBhc3NlcnQuZXF1YWwoTWF0aC5zcXJ0KDQpLCAzMDApXG4gIGFzc2VydC5lcXVhbChNYXRoLnNxcnQoNCksIDIpXG59KVxuIl0sImZpbGUiOiJDOi9wcm9qZWN0cy9HaXRodWIvbmV3LXByai90ZXN0L2luZGV4LnRlc3QudHMifQ==\n', - map: { - version: 3, - mappings: ';AAA6B;AAI7B,2BAAK,eAAe,MAAM;AACxB,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC5B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,GAAG;AAC9B,+BAAO,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;AAC9B,CAAC', - names: [], - sources: ['C:/projects/Github/new-prj/test/index.test.ts'], - sourcesContent: [ - 'import { assert, test } from \'vitest\'\n' - + '\n' - + '// comment1\n' - + '// comment2\n' - + 'test(\'Math.sqrt()\', () => {\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + ' assert.equal(Math.sqrt(4), 300)\n' - + ' assert.equal(Math.sqrt(4), 2)\n' - + '})\n', - ], - file: 'C:/projects/Github/new-prj/test/index.test.ts', - toUrl: () => '', - toString: () => '', - }, - deps: ['vitest'], - dynamicDeps: [], -} - -const no_comment_mod: Partial = { - ssrTransformResult: no_comment, -} - -const comment_mod: Partial = { - ssrTransformResult: comment, -} - -const moduleGraphNoComment: Partial = { - getModuleById: () => no_comment_mod as ModuleNode, -} - -const moduleGraphentComment: Partial = { - getModuleById: () => comment_mod as ModuleNode, -} - -afterEach(() => { - vi.useRealTimers() +import { resolve } from 'pathe' +import { execa } from 'execa' +import { describe, expect, it } from 'vitest' + +describe('should fails', async () => { + const root = resolve(__dirname, '../fixtures') + // in Windows child_process is very unstable, we skip testing it + if (process.platform === 'win32' && process.env.CI) + return + + it('should fails', async () => { + const { stdout } = await execa('npx ', ['vitest', 'run', 'expect.test.ts', '--reporter=json'], { + cwd: root, + env: { + ...process.env, + CI: 'true', + NO_COLOR: 'true', + }, + }).catch(e => e) + + // remove the Timestamp/Duration part from json report + const msg = stdout + .split(/\n/g) + .map(line => + line.includes('startTime') || line.includes('endTime') || line.includes('duration') ? '' : line, + ) + + expect(msg).toMatchSnapshot() + }, 10000) }) - -test('without comment', async () => { - // Arrange - const reporter = new JsonReporter() - const context = getContext() - context.vitest.server.moduleGraph = moduleGraphNoComment as ModuleGraph - - vi.setSystemTime(1642587001759) - // Act - reporter.onInit(context.vitest) - await reporter.onFinished(files) - // Assert - expect(JSON.parse(context.output)).toMatchSnapshot() -}) - -test('with comment', async () => { - // Arrange - const reporter = new JsonReporter() - const context = getContext() - context.vitest.server.moduleGraph = moduleGraphentComment as ModuleGraph - - vi.setSystemTime(1742587001759) - // Act - clearSourcePos() - reporter.onInit(context.vitest) - await reporter.onFinished(files) - // Assert - expect(JSON.parse(context.output)).toMatchSnapshot() -}) - From 30a97ede93ce2233610977f84b328532c7132d7c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 16:09:46 +0800 Subject: [PATCH 05/11] chore: update --- .../{expect.test.ts => json-fail.test.ts} | 1 + test/reporters/fixtures/vitest.config.ts | 4 ++ .../tests/__snapshots__/json.test.ts.snap | 59 ++++++------------- test/reporters/tests/json.test.ts | 20 +++---- test/reporters/vitest.config.ts | 9 +++ 5 files changed, 41 insertions(+), 52 deletions(-) rename test/reporters/fixtures/{expect.test.ts => json-fail.test.ts} (99%) create mode 100644 test/reporters/fixtures/vitest.config.ts create mode 100644 test/reporters/vitest.config.ts diff --git a/test/reporters/fixtures/expect.test.ts b/test/reporters/fixtures/json-fail.test.ts similarity index 99% rename from test/reporters/fixtures/expect.test.ts rename to test/reporters/fixtures/json-fail.test.ts index 90c6b977c53b..093f0e1bcfc6 100644 --- a/test/reporters/fixtures/expect.test.ts +++ b/test/reporters/fixtures/json-fail.test.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest' + // I am comment1 // I am comment2 test('should fail', () => { diff --git a/test/reporters/fixtures/vitest.config.ts b/test/reporters/fixtures/vitest.config.ts new file mode 100644 index 000000000000..1b3a79748ed4 --- /dev/null +++ b/test/reporters/fixtures/vitest.config.ts @@ -0,0 +1,4 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ +}) diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap index 36211ec80928..185ff4c1ebbb 100644 --- a/test/reporters/tests/__snapshots__/json.test.ts.snap +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -1,47 +1,22 @@ // Vitest Snapshot v1 -exports[`should fails > should fails 1`] = ` +exports[`json reporter > generates correct report 1`] = ` [ - "logTask....", - "{", - " \\"numTotalTestSuites\\": 1,", - " \\"numPassedTestSuites\\": 1,", - " \\"numFailedTestSuites\\": 0,", - " \\"numPendingTestSuites\\": 0,", - " \\"numTotalTests\\": 1,", - " \\"numPassedTests\\": 0,", - " \\"numFailedTests\\": 1,", - " \\"numPendingTests\\": 0,", - " \\"numTodoTests\\": 0,", - "", - " \\"success\\": false,", - " \\"testResults\\": [", - " {", - " \\"assertionResults\\": [", - " {", - " \\"ancestorTitles\\": [", - " \\"\\"", - " ],", - " \\"fullName\\": \\" should fail\\",", - " \\"status\\": \\"failed\\",", - " \\"title\\": \\"should fail\\",", - "", - " \\"failureMessages\\": [", - " \\"expected 2 to deeply equal 1\\"", - " ],", - " \\"location\\": {", - " \\"line\\": 5,", - " \\"column\\": 12", - " }", - " }", - " ],", - "", - "", - " \\"status\\": \\"failed\\",", - " \\"message\\": \\"\\",", - " \\"name\\": \\"C:/projects/Github/vitest/test/reporters/fixtures/expect.test.ts\\"", - " }", - " ]", - "}", + { + "ancestorTitles": [ + "", + ], + "duration": 2, + "failureMessages": [ + "expected 2 to deeply equal 1", + ], + "fullName": " should fail", + "location": { + "column": 12, + "line": 6, + }, + "status": "failed", + "title": "should fail", + }, ] `; diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts index fa31453c5d20..575cd76cec08 100644 --- a/test/reporters/tests/json.test.ts +++ b/test/reporters/tests/json.test.ts @@ -2,29 +2,29 @@ import { resolve } from 'pathe' import { execa } from 'execa' import { describe, expect, it } from 'vitest' -describe('should fails', async () => { +describe('json reporter', async () => { const root = resolve(__dirname, '../fixtures') + // in Windows child_process is very unstable, we skip testing it if (process.platform === 'win32' && process.env.CI) return - it('should fails', async () => { - const { stdout } = await execa('npx ', ['vitest', 'run', 'expect.test.ts', '--reporter=json'], { + it('generates correct report', async () => { + const { stdout } = await execa('npx', ['vitest', 'run', 'json-fail', '--reporter=json'], { cwd: root, env: { ...process.env, CI: 'true', NO_COLOR: 'true', }, + stdio: 'pipe', }).catch(e => e) - // remove the Timestamp/Duration part from json report - const msg = stdout - .split(/\n/g) - .map(line => - line.includes('startTime') || line.includes('endTime') || line.includes('duration') ? '' : line, - ) + const data = JSON.parse(stdout) + + expect(data.testResults).toBeInstanceOf(Array) + expect(data.testResults).toHaveLength(1) - expect(msg).toMatchSnapshot() + expect(data.testResults[0].assertionResults).toMatchSnapshot() }, 10000) }) diff --git a/test/reporters/vitest.config.ts b/test/reporters/vitest.config.ts new file mode 100644 index 000000000000..cdff0694c9a2 --- /dev/null +++ b/test/reporters/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + exclude: [ + 'fixtures/**', + ], + }, +}) From c2454652f8bc9518ee5066346c480cd90c0eed92 Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Mon, 29 Aug 2022 16:14:16 +0800 Subject: [PATCH 06/11] chore: remove expect test from test target --- test/reporters/tests/__snapshots__/json.test.ts.snap | 2 +- test/reporters/tests/json.test.ts | 6 +++--- test/reporters/vite.config.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/reporters/vite.config.ts diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap index 36211ec80928..3035f429981c 100644 --- a/test/reporters/tests/__snapshots__/json.test.ts.snap +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -39,7 +39,7 @@ exports[`should fails > should fails 1`] = ` "", " \\"status\\": \\"failed\\",", " \\"message\\": \\"\\",", - " \\"name\\": \\"C:/projects/Github/vitest/test/reporters/fixtures/expect.test.ts\\"", + "", " }", " ]", "}", diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts index fa31453c5d20..e3df44cdb433 100644 --- a/test/reporters/tests/json.test.ts +++ b/test/reporters/tests/json.test.ts @@ -18,13 +18,13 @@ describe('should fails', async () => { }, }).catch(e => e) - // remove the Timestamp/Duration part from json report + // remove the Timestamp/Duration/test file name part from json report const msg = stdout .split(/\n/g) .map(line => - line.includes('startTime') || line.includes('endTime') || line.includes('duration') ? '' : line, + line.includes('startTime') || line.includes('endTime') || line.includes('duration') || line.includes('name') ? '' : line, ) expect(msg).toMatchSnapshot() - }, 10000) + }) }) diff --git a/test/reporters/vite.config.ts b/test/reporters/vite.config.ts new file mode 100644 index 000000000000..a3039353269f --- /dev/null +++ b/test/reporters/vite.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + test: { + exclude: ['fixtures/*.test.ts'], + testTimeout: 100000, + }, + +}) From 46d8bfa84b639d51e7ce4c879eaa6c03acd0cf42 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 16:25:24 +0800 Subject: [PATCH 07/11] chore: update --- .../tests/__snapshots__/json.test.ts.snap | 31 +++++++++---------- test/reporters/tests/json.test.ts | 6 ++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap index 185ff4c1ebbb..9cdc37ea070f 100644 --- a/test/reporters/tests/__snapshots__/json.test.ts.snap +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -1,22 +1,19 @@ // Vitest Snapshot v1 exports[`json reporter > generates correct report 1`] = ` -[ - { - "ancestorTitles": [ - "", - ], - "duration": 2, - "failureMessages": [ - "expected 2 to deeply equal 1", - ], - "fullName": " should fail", - "location": { - "column": 12, - "line": 6, - }, - "status": "failed", - "title": "should fail", +{ + "ancestorTitles": [ + "", + ], + "failureMessages": [ + "expected 2 to deeply equal 1", + ], + "fullName": " should fail", + "location": { + "column": 12, + "line": 6, }, -] + "status": "failed", + "title": "should fail", +} `; diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts index 575cd76cec08..b7e2a1eef539 100644 --- a/test/reporters/tests/json.test.ts +++ b/test/reporters/tests/json.test.ts @@ -22,9 +22,11 @@ describe('json reporter', async () => { const data = JSON.parse(stdout) - expect(data.testResults).toBeInstanceOf(Array) expect(data.testResults).toHaveLength(1) + expect(data.testResults[0].assertionResults).toHaveLength(1) - expect(data.testResults[0].assertionResults).toMatchSnapshot() + const result = data.testResults[0].assertionResults[0] + delete result.duration + expect(result).toMatchSnapshot() }, 10000) }) From 0448f52b038e6f10b01aa979913a09256ea29465 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 16:59:58 +0800 Subject: [PATCH 08/11] chore: cleanup --- test/reporters/src/data.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/reporters/src/data.ts b/test/reporters/src/data.ts index f8271a00db25..b22b6a92be2f 100644 --- a/test/reporters/src/data.ts +++ b/test/reporters/src/data.ts @@ -176,10 +176,5 @@ suite.tasks = tasks const files = [file] -export function clearSourcePos() { - if (error.stacks) - error.stacks = undefined -} - export { files } From 41593e62468fe462874acd77ce659a2674ca88fa Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 17:02:57 +0800 Subject: [PATCH 09/11] chore: filter tests --- test/reporters/vite.config.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/reporters/vite.config.ts b/test/reporters/vite.config.ts index a3039353269f..30ab6abe9a5e 100644 --- a/test/reporters/vite.config.ts +++ b/test/reporters/vite.config.ts @@ -2,8 +2,7 @@ import { defineConfig } from 'vite' export default defineConfig({ test: { - exclude: ['fixtures/*.test.ts'], + exclude: ['fixtures/*.test.ts', '**/node_modules/**'], testTimeout: 100000, }, - }) From ab7f008367ef5ba326d07ea0e15e2e0071f20d7e Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 17:18:38 +0800 Subject: [PATCH 10/11] chore: fix test config --- pnpm-lock.yaml | 5 ++--- test/reporters/vite.config.ts | 8 -------- test/reporters/vitest.config.ts | 5 ++--- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 test/reporters/vite.config.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ac0708e2651..6b735dea72ba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -123,7 +123,7 @@ importers: unocss: 0.45.13_vite@3.0.7 unplugin-vue-components: 0.22.4_vite@3.0.7+vue@3.2.37 vite: 3.0.7 - vite-plugin-pwa: 0.12.3_vtbnhijtt34ozcbtxu53ekyo5y + vite-plugin-pwa: 0.12.3_vite@3.0.7 vitepress: 1.0.0-alpha.12 workbox-window: 6.5.4 @@ -19992,11 +19992,10 @@ packages: - supports-color dev: true - /vite-plugin-pwa/0.12.3_vtbnhijtt34ozcbtxu53ekyo5y: + /vite-plugin-pwa/0.12.3_vite@3.0.7: resolution: {integrity: sha512-gmYdIVXpmBuNjzbJFPZFzxWYrX4lHqwMAlOtjmXBbxApiHjx9QPXKQPJjSpeTeosLKvVbNcKSAAhfxMda0QVNQ==} peerDependencies: vite: ^2.0.0 || ^3.0.0-0 - workbox-window: ^6.4.0 dependencies: debug: 4.3.4 fast-glob: 3.2.11 diff --git a/test/reporters/vite.config.ts b/test/reporters/vite.config.ts deleted file mode 100644 index 30ab6abe9a5e..000000000000 --- a/test/reporters/vite.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'vite' - -export default defineConfig({ - test: { - exclude: ['fixtures/*.test.ts', '**/node_modules/**'], - testTimeout: 100000, - }, -}) diff --git a/test/reporters/vitest.config.ts b/test/reporters/vitest.config.ts index cdff0694c9a2..5abcd0981b0c 100644 --- a/test/reporters/vitest.config.ts +++ b/test/reporters/vitest.config.ts @@ -2,8 +2,7 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { - exclude: [ - 'fixtures/**', - ], + exclude: ['node_modules', 'fixtures', 'dist'], + testTimeout: 100000, }, }) From 9f726a84000d80c27d24cd0fcb9aa7169bbebf25 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 29 Aug 2022 17:32:23 +0800 Subject: [PATCH 11/11] chore: update --- test/reporters/tests/json.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/reporters/tests/json.test.ts b/test/reporters/tests/json.test.ts index b7e2a1eef539..3963d9dfc405 100644 --- a/test/reporters/tests/json.test.ts +++ b/test/reporters/tests/json.test.ts @@ -5,11 +5,9 @@ import { describe, expect, it } from 'vitest' describe('json reporter', async () => { const root = resolve(__dirname, '../fixtures') - // in Windows child_process is very unstable, we skip testing it - if (process.platform === 'win32' && process.env.CI) - return + const skip = (process.platform === 'win32' || process.platform === 'darwin') && process.env.CI - it('generates correct report', async () => { + it.skipIf(skip)('generates correct report', async () => { const { stdout } = await execa('npx', ['vitest', 'run', 'json-fail', '--reporter=json'], { cwd: root, env: { @@ -28,5 +26,5 @@ describe('json reporter', async () => { const result = data.testResults[0].assertionResults[0] delete result.duration expect(result).toMatchSnapshot() - }, 10000) + }, 40000) })