Skip to content

Commit

Permalink
test: allow compact diff for test failures (#6783)
Browse files Browse the repository at this point in the history
* Allow the compact diff for tests

* Update the doc

* Update docs/pages/contribution/testing/index.md

Co-authored-by: Julien <jeluard@users.noreply.github.com>

* Fix linting on docs

* Fix linting

---------

Co-authored-by: Julien <jeluard@users.noreply.github.com>
  • Loading branch information
nazarhussain and jeluard committed May 15, 2024
1 parent d0893ab commit c39b914
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/pages/contribution/testing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions scripts/vitest/vitest.diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {DiffOptions} from "vitest";

export default {
aIndicator: "--",
bIndicator: "++",
includeChangeCounts: true,
contextLines: 2,
expand: false,
} satisfies DiffOptions;
1 change: 1 addition & 0 deletions vitest.base.unit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

0 comments on commit c39b914

Please sign in to comment.