Skip to content

Commit

Permalink
chore: adding file nesting for tests snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienIzz committed Feb 2, 2024
1 parent 1edfd97 commit faf29f6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions packages/lib/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 11 additions & 0 deletions packages/lib/jestSnapshotResolver.js
Original file line number Diff line number Diff line change
@@ -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);
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RenderResult, act, cleanup, render, screen } from '@testing-library/react-native';
import { ItemWithIndex } from '../virtualizedList/VirtualizedList';
import { PropsTestButton, TestButton } from './TestButton';
import { ItemWithIndex } from './VirtualizedList';
import { PropsTestButton, TestButton } from '../tests/TestButton';
import { SpatialNavigationRoot } from '../Root';
import './helpers/configureTestRemoteControl';
import '../tests/helpers/configureTestRemoteControl';

import { DefaultFocus } from '../../context/DefaultFocusContext';
import { SpatialNavigationVirtualizedGrid } from '../virtualizedGrid/SpatialNavigationVirtualizedGrid';
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 });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RenderResult, act, cleanup, render, screen } from '@testing-library/react-native';
import { ItemWithIndex } from '../virtualizedList/VirtualizedList';
import { PropsTestButton, TestButton } from './TestButton';
import { ItemWithIndex } from './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 });
Expand Down

0 comments on commit faf29f6

Please sign in to comment.