From 4ea46c51642863c97e4fe5afea53dda726a96103 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 +++++++++++ .../SpatialNavigationVirtualizedGrid.test.tsx | 0 .../SpatialNavigationVirtualizedGrid.test.tsx.snap | 0 .../SpatialNavigationVirtualizedList.test.tsx | 6 +++--- .../SpatialNavigationVirtualizedList.test.tsx.snap | 0 7 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 packages/lib/jestSnapshotResolver.js rename packages/lib/src/spatial-navigation/components/{tests => virtualizedGrid}/SpatialNavigationVirtualizedGrid.test.tsx (100%) rename packages/lib/src/spatial-navigation/components/{tests/__snapshots__ => virtualizedGrid}/SpatialNavigationVirtualizedGrid.test.tsx.snap (100%) rename packages/lib/src/spatial-navigation/components/{tests => virtualizedList}/SpatialNavigationVirtualizedList.test.tsx (94%) rename packages/lib/src/spatial-navigation/components/{tests/__snapshots__ => virtualizedList}/SpatialNavigationVirtualizedList.test.tsx.snap (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..3eb29c53 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "*.ts": "${capture}.test.ts, ${capture}.test.ts.snap", + "*.tsx": "${capture}.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); + }, +}; diff --git a/packages/lib/src/spatial-navigation/components/tests/SpatialNavigationVirtualizedGrid.test.tsx b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx similarity index 100% rename from packages/lib/src/spatial-navigation/components/tests/SpatialNavigationVirtualizedGrid.test.tsx rename to packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx diff --git a/packages/lib/src/spatial-navigation/components/tests/__snapshots__/SpatialNavigationVirtualizedGrid.test.tsx.snap b/packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap similarity index 100% rename from packages/lib/src/spatial-navigation/components/tests/__snapshots__/SpatialNavigationVirtualizedGrid.test.tsx.snap rename to packages/lib/src/spatial-navigation/components/virtualizedGrid/SpatialNavigationVirtualizedGrid.test.tsx.snap diff --git a/packages/lib/src/spatial-navigation/components/tests/SpatialNavigationVirtualizedList.test.tsx b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx similarity index 94% rename from packages/lib/src/spatial-navigation/components/tests/SpatialNavigationVirtualizedList.test.tsx rename to packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx index 44c3a3f0..2813ef17 100644 --- a/packages/lib/src/spatial-navigation/components/tests/SpatialNavigationVirtualizedList.test.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx @@ -2,10 +2,10 @@ import { RenderResult, act, render, screen } from '@testing-library/react-native import { ItemWithIndex } from '../virtualizedList/VirtualizedList'; import { PropsTestButton, TestButton } from '../tests/TestButton'; import { SpatialNavigationRoot } from '../Root'; -import './helpers/configureTestRemoteControl'; -import { SpatialNavigationVirtualizedList } from '../virtualizedList/SpatialNavigationVirtualizedList'; +import '../tests/helpers/configureTestRemoteControl'; +import { SpatialNavigationVirtualizedList } from './SpatialNavigationVirtualizedList'; import { DefaultFocus } from '../../context/DefaultFocusContext'; -import testRemoteControlManager from './helpers/testRemoteControlManager'; +import testRemoteControlManager from '../tests/helpers/testRemoteControlManager'; export const expectButtonToHaveFocus = (component: RenderResult, text: string) => { const element = component.getByRole('button', { name: text }); diff --git a/packages/lib/src/spatial-navigation/components/tests/__snapshots__/SpatialNavigationVirtualizedList.test.tsx.snap b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap similarity index 100% rename from packages/lib/src/spatial-navigation/components/tests/__snapshots__/SpatialNavigationVirtualizedList.test.tsx.snap rename to packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedList.test.tsx.snap