From 5c0d56f3e2174280fd0c4061d3f526165ddfa798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grzegorzewski?= <4864089+spamshaker@users.noreply.github.com> Date: Sat, 14 Sep 2024 09:46:39 +0200 Subject: [PATCH 1/9] Update index.ts Adding possibility to get rid of printing prototype in diff output --- packages/utils/src/diff/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/diff/index.ts b/packages/utils/src/diff/index.ts index d6dc8a084a83..dab8d222d5da 100644 --- a/packages/utils/src/diff/index.ts +++ b/packages/utils/src/diff/index.ts @@ -53,6 +53,7 @@ const PLUGINS = [ ] const FORMAT_OPTIONS = { plugins: PLUGINS, + printBasicPrototype: true } const FALLBACK_FORMAT_OPTIONS = { callToJSON: false, @@ -180,11 +181,12 @@ function getFormatOptions( formatOptions: PrettyFormatOptions, options?: DiffOptions, ): PrettyFormatOptions { - const { compareKeys } = normalizeDiffOptions(options) + const { compareKeys, printBasicPrototype } = normalizeDiffOptions(options) return { ...formatOptions, compareKeys, + printBasicPrototype } } From d0170178cfb1983f505789f39fb828009094411a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grzegorzewski?= <4864089+spamshaker@users.noreply.github.com> Date: Sat, 14 Sep 2024 09:50:24 +0200 Subject: [PATCH 2/9] Update types.ts --- packages/utils/src/diff/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/utils/src/diff/types.ts b/packages/utils/src/diff/types.ts index 951fcdbb27c1..1bb55fb9e92b 100644 --- a/packages/utils/src/diff/types.ts +++ b/packages/utils/src/diff/types.ts @@ -26,6 +26,7 @@ export interface DiffOptions { includeChangeCounts?: boolean omitAnnotationLines?: boolean patchColor?: DiffOptionsColor + printBasicPrototype?: boolean compareKeys?: CompareKeys truncateThreshold?: number truncateAnnotation?: string @@ -51,6 +52,7 @@ export interface DiffOptionsNormalized { includeChangeCounts: boolean omitAnnotationLines: boolean patchColor: DiffOptionsColor + printBasicPrototype: boolean truncateThreshold: number truncateAnnotation: string truncateAnnotationColor: DiffOptionsColor From b26cbcbe3fab8a465876fb01a4871ba883190c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grzegorzewski?= Date: Sat, 14 Sep 2024 10:07:07 +0200 Subject: [PATCH 3/9] Update config documentation to include diff.printBasicPrototype Added a new configuration option `printBasicPrototype` to the diff section. This allows users to set the pretty-format option for the diff output, with a default value of `true`. --- docs/config/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/config/index.md b/docs/config/index.md index a62e485720ca..b4be2c0b4559 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -2294,6 +2294,7 @@ export default { aIndicator: c.bold('--'), bIndicator: c.bold('++'), omitAnnotationLines: true, + printBasicPrototype: false, } satisfies DiffOptions ``` @@ -2330,6 +2331,13 @@ Annotation that is output at the end of diff result if it's truncated. Color of truncate annotation, default is output with no color. +#### diff.printBasicPrototype + +- **Type**: `boolean` +- **Default**: `true` + +Allows to set pretty-format option printBasicPrototype for diff output + ### fakeTimers - **Type:** `FakeTimerInstallOpts` From aaf6ce77710fe7f402dbae3b32588c1cef873652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Grzegorzewski?= <4864089+spamshaker@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:52:26 +0200 Subject: [PATCH 4/9] Update index.ts CR Fixes --- packages/utils/src/diff/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/diff/index.ts b/packages/utils/src/diff/index.ts index dab8d222d5da..85521f3997ab 100644 --- a/packages/utils/src/diff/index.ts +++ b/packages/utils/src/diff/index.ts @@ -53,7 +53,7 @@ const PLUGINS = [ ] const FORMAT_OPTIONS = { plugins: PLUGINS, - printBasicPrototype: true + printBasicPrototype: true, } const FALLBACK_FORMAT_OPTIONS = { callToJSON: false, @@ -186,7 +186,7 @@ function getFormatOptions( return { ...formatOptions, compareKeys, - printBasicPrototype + printBasicPrototype, } } From ac8acc70a58b171c9a9ce0fe141af7f7a6bc9869 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 20 Oct 2024 14:15:15 +0900 Subject: [PATCH 5/9] test: add test --- test/config/fixtures/diff/basic.test.ts | 11 ++++++++++ test/config/fixtures/diff/diff.ts | 5 +++++ test/config/fixtures/diff/vite.config.ts | 7 +++++++ .../test/__snapshots__/diff.test.ts.snap | 20 +++++++++++++++++++ test/config/test/diff.test.ts | 17 ++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 test/config/fixtures/diff/basic.test.ts create mode 100644 test/config/fixtures/diff/diff.ts create mode 100644 test/config/fixtures/diff/vite.config.ts create mode 100644 test/config/test/__snapshots__/diff.test.ts.snap create mode 100644 test/config/test/diff.test.ts diff --git a/test/config/fixtures/diff/basic.test.ts b/test/config/fixtures/diff/basic.test.ts new file mode 100644 index 000000000000..ebc0f87bba6e --- /dev/null +++ b/test/config/fixtures/diff/basic.test.ts @@ -0,0 +1,11 @@ +import { expect, test } from 'vitest' + +test("printBasicPrototype false", () => { + expect({ + obj: { k: "foo" }, + arr: [1, 2] + }).toEqual({ + obj: { k: "bar" }, + arr: [1, 3] + }); +}) diff --git a/test/config/fixtures/diff/diff.ts b/test/config/fixtures/diff/diff.ts new file mode 100644 index 000000000000..d7fb2db32a8b --- /dev/null +++ b/test/config/fixtures/diff/diff.ts @@ -0,0 +1,5 @@ +import { DiffOptions } from "vitest"; + +export default { + printBasicPrototype: false +} satisfies DiffOptions diff --git a/test/config/fixtures/diff/vite.config.ts b/test/config/fixtures/diff/vite.config.ts new file mode 100644 index 000000000000..1776a93a0803 --- /dev/null +++ b/test/config/fixtures/diff/vite.config.ts @@ -0,0 +1,7 @@ +import {defineConfig} from 'vitest/config' + +export default defineConfig({ + test: { + diff: './diff.ts' + } +}) diff --git a/test/config/test/__snapshots__/diff.test.ts.snap b/test/config/test/__snapshots__/diff.test.ts.snap new file mode 100644 index 000000000000..5778c5d89b7e --- /dev/null +++ b/test/config/test/__snapshots__/diff.test.ts.snap @@ -0,0 +1,20 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`diff 1`] = ` +[ + "- Expected ++ Received + + { + "arr": [ + 1, +- 3, ++ 2, + ], + "obj": { +- "k": "bar", ++ "k": "foo", + }, + }", +] +`; diff --git a/test/config/test/diff.test.ts b/test/config/test/diff.test.ts new file mode 100644 index 000000000000..2e747ec73eb2 --- /dev/null +++ b/test/config/test/diff.test.ts @@ -0,0 +1,17 @@ +import { stripVTControlCharacters } from 'node:util' +import { expect, test } from 'vitest' +import { runVitest } from '../../test-utils' + +test('diff', async () => { + const { ctx } = await runVitest({ + root: './fixtures/diff', + }) + const errors = ctx!.state + .getFiles() + .flatMap(f => + f.tasks.flatMap(t => t.result?.errors ?? []), + ) + expect( + errors.map(e => e.diff && stripVTControlCharacters(e.diff)) + ).matchSnapshot() +}) From d36f55d733355f23af346b047b5606e9727cdd92 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 20 Oct 2024 14:16:53 +0900 Subject: [PATCH 6/9] chore: type error --- packages/utils/src/diff/index.ts | 1 - packages/utils/src/diff/normalizeDiffOptions.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/diff/index.ts b/packages/utils/src/diff/index.ts index 85521f3997ab..96ffbb3f4f2f 100644 --- a/packages/utils/src/diff/index.ts +++ b/packages/utils/src/diff/index.ts @@ -53,7 +53,6 @@ const PLUGINS = [ ] const FORMAT_OPTIONS = { plugins: PLUGINS, - printBasicPrototype: true, } const FALLBACK_FORMAT_OPTIONS = { callToJSON: false, diff --git a/packages/utils/src/diff/normalizeDiffOptions.ts b/packages/utils/src/diff/normalizeDiffOptions.ts index 660bab3e32ab..f3b0388ebf77 100644 --- a/packages/utils/src/diff/normalizeDiffOptions.ts +++ b/packages/utils/src/diff/normalizeDiffOptions.ts @@ -34,6 +34,7 @@ function getDefaultOptions(): DiffOptionsNormalized { includeChangeCounts: false, omitAnnotationLines: false, patchColor: c.yellow, + printBasicPrototype: true, truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT, truncateAnnotation: '... Diff result is truncated', truncateAnnotationColor: noColor, From 9203e3a0d694da2699215176700348f3433ecfa8 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 20 Oct 2024 14:17:16 +0900 Subject: [PATCH 7/9] chore: lint --- test/config/test/diff.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config/test/diff.test.ts b/test/config/test/diff.test.ts index 2e747ec73eb2..30cc63c02eca 100644 --- a/test/config/test/diff.test.ts +++ b/test/config/test/diff.test.ts @@ -12,6 +12,6 @@ test('diff', async () => { f.tasks.flatMap(t => t.result?.errors ?? []), ) expect( - errors.map(e => e.diff && stripVTControlCharacters(e.diff)) + errors.map(e => e.diff && stripVTControlCharacters(e.diff)), ).matchSnapshot() }) From 06fa1d26b0ea7ce55bee3348700fcd1b8afc9d3c Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 20 Oct 2024 14:27:48 +0900 Subject: [PATCH 8/9] test: fix threshold test --- test/config/test/failures.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/config/test/failures.test.ts b/test/config/test/failures.test.ts index a753863dbf33..108578b4ffae 100644 --- a/test/config/test/failures.test.ts +++ b/test/config/test/failures.test.ts @@ -247,7 +247,9 @@ test('coverage.autoUpdate cannot update thresholds when configuration file doesn }) test('boolean flag 100 should not crash CLI', async () => { - const { stderr } = await runVitestCli('--coverage.enabled', '--coverage.thresholds.100') + let { stderr } = await runVitestCli('--coverage.enabled', '--coverage.thresholds.100') + // non-zero coverage shows up, which is non-deterministic, so strip it. + stderr = stderr.replace(/\([0-9.]+%\) does/g, '(0%) does') expect(stderr).toMatch('ERROR: Coverage for lines (0%) does not meet global threshold (100%)') expect(stderr).toMatch('ERROR: Coverage for functions (0%) does not meet global threshold (100%)') From 04ec5fa451792a83bdca3e4ca63a6d822204c463 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 13 Nov 2024 09:52:25 +0900 Subject: [PATCH 9/9] chore: lint --- test/config/test/diff.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/config/test/diff.test.ts b/test/config/test/diff.test.ts index 30cc63c02eca..aa658ade6e6e 100644 --- a/test/config/test/diff.test.ts +++ b/test/config/test/diff.test.ts @@ -6,11 +6,9 @@ test('diff', async () => { const { ctx } = await runVitest({ root: './fixtures/diff', }) - const errors = ctx!.state - .getFiles() - .flatMap(f => - f.tasks.flatMap(t => t.result?.errors ?? []), - ) + const errors = ctx!.state.getFiles().flatMap(f => + f.tasks.flatMap(t => t.result?.errors ?? []), + ) expect( errors.map(e => e.diff && stripVTControlCharacters(e.diff)), ).matchSnapshot()