-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9834 from davidgoli/support-jsx-preview-files
Storyshots: Fix support for jsx/tsx config files
- Loading branch information
Showing
3 changed files
with
64 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
addons/storyshots/storyshots-core/src/frameworks/configure.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getPreviewFile, getMainFile } from './configure'; | ||
|
||
// eslint-disable-next-line global-require, jest/no-mocks-import | ||
jest.mock('fs', () => require('../../../../../__mocks__/fs')); | ||
const setupFiles = (files: Record<string, string>) => { | ||
// eslint-disable-next-line no-underscore-dangle, global-require | ||
require('fs').__setMockFiles(files); | ||
}; | ||
|
||
describe('preview files', () => { | ||
it.each` | ||
filepath | ||
${'preview.ts'} | ||
${'preview.tsx'} | ||
${'preview.js'} | ||
${'preview.jsx'} | ||
${'config.ts'} | ||
${'config.tsx'} | ||
${'config.js'} | ||
${'config.jsx'} | ||
`('resolves a valid preview file from $filepath', ({ filepath }) => { | ||
setupFiles({ [`test/${filepath}`]: 'true' }); | ||
|
||
expect(getPreviewFile('test/')).toEqual(`test/${filepath}`); | ||
}); | ||
|
||
it('returns false when none of the paths exist', () => { | ||
setupFiles(Object.create(null)); | ||
|
||
expect(getPreviewFile('test/')).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('main files', () => { | ||
it.each` | ||
filepath | ||
${'main.ts'} | ||
${'main.tsx'} | ||
${'main.js'} | ||
${'main.jsx'} | ||
`('resolves a valid main file path from $filepath', ({ filepath }) => { | ||
setupFiles({ [`test/${filepath}`]: 'true' }); | ||
|
||
expect(getMainFile('test/')).toEqual(`test/${filepath}`); | ||
}); | ||
|
||
it('returns false when none of the paths exist', () => { | ||
setupFiles(Object.create(null)); | ||
|
||
expect(getPreviewFile('test/')).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters