UNPKG

2.16 kBJavaScriptView Raw
1import { Stories2SnapsConverter } from './Stories2SnapsConverter';
2const target = new Stories2SnapsConverter();
3describe('getSnapshotFileName', () => {
4 it('fileName is provided - snapshot is stored in __snapshots__ dir', () => {
5 const context = { fileName: 'foo.js', kind: 'kind' };
6 const result = target.getSnapshotFileName(context);
7 const platformAgnosticResult = result?.replace(/\\|\//g, '/');
8 // This is an absolute path, so we need to use `toContain()`
9 expect(platformAgnosticResult).toContain('__snapshots__/foo.storyshot');
10 });
11 it('fileName with multiple extensions is provided - only the last extension is replaced', () => {
12 const context = { fileName: 'foo.web.stories.js', kind: 'kind' };
13 const result = target.getSnapshotFileName(context);
14 const platformAgnosticResult = result?.replace(/\\|\//g, '/');
15 // This is an absolute path, so we need to use `toContain()`
16 expect(platformAgnosticResult).toContain('__snapshots__/foo.web.stories.storyshot');
17 });
18 it('fileName with dir is provided - __snapshots__ dir is created inside another dir', () => {
19 const context = { fileName: 'test/foo.js', kind: 'kind' };
20 const result = target.getSnapshotFileName(context);
21 const platformAgnosticResult = result?.replace(/\\|\//g, '/');
22 // This is an absolute path, so we need to use `toContain()`
23 expect(platformAgnosticResult).toContain('test/__snapshots__/foo.storyshot');
24 });
25});
26describe('getPossibleStoriesFiles', () => {
27 it('storyshots is provided and all the posible stories file names are returned', () => {
28 const storyshots = 'test/__snapshots__/foo.web.stories.storyshot';
29 const result = target.getPossibleStoriesFiles(storyshots);
30 const platformAgnosticResult = result.map((path) => path.replace(/\\|\//g, '/'));
31 expect(platformAgnosticResult).toEqual([
32 'test/foo.web.stories.js',
33 'test/foo.web.stories.jsx',
34 'test/foo.web.stories.ts',
35 'test/foo.web.stories.tsx',
36 'test/foo.web.stories.mdx',
37 ]);
38 });
39});