From be473cd1274035b58b4c5bc31dc2b8958fb0c2f9 Mon Sep 17 00:00:00 2001 From: JulienIzz Date: Thu, 1 Feb 2024 14:50:37 +0100 Subject: [PATCH] chore: adding file nesting for tests snapshots --- .vscode/settings.json | 8 ++++++++ packages/lib/jest.config.js | 1 + packages/lib/jestSnapshotResolver.js | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 packages/lib/jestSnapshotResolver.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..19516fb1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "*.test.ts": "${capture}.test.ts.snap", + "*.test.tsx": "${capture}.test.tsx.snap", + ".eslintrc.js": "*.eslintrc.js" + } +} diff --git a/packages/lib/jest.config.js b/packages/lib/jest.config.js index aeb9a99d..906061c2 100644 --- a/packages/lib/jest.config.js +++ b/packages/lib/jest.config.js @@ -47,6 +47,7 @@ const config = { // tools watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'], reporters: ['default', 'github-actions'], // Remove this line if your CI is not on Github actions + snapshotResolver: './jestSnapshotResolver.js', }; module.exports = config; diff --git a/packages/lib/jestSnapshotResolver.js b/packages/lib/jestSnapshotResolver.js new file mode 100644 index 00000000..e8e19480 --- /dev/null +++ b/packages/lib/jestSnapshotResolver.js @@ -0,0 +1,11 @@ +module.exports = { + testPathForConsistencyCheck: 'some/__tests__/example.test.js', + /** resolves from test to snapshot path */ + resolveSnapshotPath: (testPath, snapshotExtension) => { + return testPath + snapshotExtension; + }, + /** resolves from snapshot to test path */ + resolveTestPath: (snapshotFilePath, snapshotExtension) => { + return snapshotFilePath.slice(0, -snapshotExtension.length); + }, +};