From c39b91436613f1bf3c45b39a612a22ef6ab9446f Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 15 May 2024 16:05:22 +0200 Subject: [PATCH] test: allow compact diff for test failures (#6783) * Allow the compact diff for tests * Update the doc * Update docs/pages/contribution/testing/index.md Co-authored-by: Julien * Fix linting on docs * Fix linting --------- Co-authored-by: Julien --- docs/pages/contribution/testing/index.md | 6 ++++++ scripts/vitest/vitest.diff.ts | 9 +++++++++ vitest.base.unit.config.ts | 1 + 3 files changed, 16 insertions(+) create mode 100644 scripts/vitest/vitest.diff.ts diff --git a/docs/pages/contribution/testing/index.md b/docs/pages/contribution/testing/index.md index 9de62895323c..fd1f8e47a6e4 100644 --- a/docs/pages/contribution/testing/index.md +++ b/docs/pages/contribution/testing/index.md @@ -2,6 +2,12 @@ Testing is critical to the Lodestar project and there are many types of tests that are run to build a product that is both effective AND efficient. This page will help to break down the different types of tests you will find in the Lodestar repo. +There are few flags you can set through env variables to override behavior of testing and it's output. + +| ENV variable | Effect | Impact | +| ----------------- | ------ | ----------------------------------------------------------------------------------------------------------- | +| TEST_COMPACT_DIFF | All | Will strip down the object difference rendered during test failures. Very useful for large object matching. | + ### Unit Tests This is the most fundamental type of test in most code bases. In all instances mocks, stubs and other forms of isolation are used to test code on a functional, unit level. See the [Unit Tests](./unit-tests.md) page for more information. diff --git a/scripts/vitest/vitest.diff.ts b/scripts/vitest/vitest.diff.ts new file mode 100644 index 000000000000..9ad445b97efe --- /dev/null +++ b/scripts/vitest/vitest.diff.ts @@ -0,0 +1,9 @@ +import type {DiffOptions} from "vitest"; + +export default { + aIndicator: "--", + bIndicator: "++", + includeChangeCounts: true, + contextLines: 2, + expand: false, +} satisfies DiffOptions; diff --git a/vitest.base.unit.config.ts b/vitest.base.unit.config.ts index 4e9d4c39f84e..776d05d26142 100644 --- a/vitest.base.unit.config.ts +++ b/vitest.base.unit.config.ts @@ -41,5 +41,6 @@ export default defineConfig({ "**/node_modules/**", ], }, + diff: process.env.TEST_COMPACT_DIFF ? path.join(import.meta.dirname, "./scripts/vitest/vitest.diff.ts") : undefined, }, });