-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support resolving webpack stats in subdirectory
- Loading branch information
1 parent
4263c19
commit c03175e
Showing
5 changed files
with
96 additions
and
6 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
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
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 |
---|---|---|
@@ -1,7 +1,85 @@ | ||
import path from 'path'; | ||
|
||
import { getDependentStoryFiles } from './getDependentStoryFiles'; | ||
import { getWorkingDir } from '../git/git'; | ||
|
||
jest.mock('../git/git'); | ||
|
||
const CSF_GLOB = './src sync ^\\.\\/(?:(?!\\.)(?=.)[^/]*?\\.stories\\.js)$'; | ||
|
||
const ctx = { | ||
log: { warn: jest.fn() }, | ||
}; | ||
|
||
describe('getDependentStoryFiles', () => { | ||
it('traverses the reasons to find affected CSF files', () => { | ||
// getDependentStoryFiles([], { idsByName: {}, reasonsById: {}, isCsfGlob: {} }); | ||
it('detects direct changes to CSF files', async () => { | ||
const changedFiles = ['./src/foo.stories.js']; | ||
const modules = [ | ||
{ | ||
id: 1, | ||
name: './src/foo.stories.js', | ||
reasons: [{ moduleName: CSF_GLOB }], | ||
}, | ||
{ | ||
id: 999, | ||
name: CSF_GLOB, | ||
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }], | ||
}, | ||
]; | ||
const res = await getDependentStoryFiles(ctx, { modules }, changedFiles); | ||
expect(res).toEqual({ | ||
1: './src/foo.stories.js', | ||
}); | ||
}); | ||
|
||
it('detects indirect changes to CSF files', async () => { | ||
const changedFiles = ['./src/foo.js']; | ||
const modules = [ | ||
{ | ||
id: 1, | ||
name: './src/foo.js', | ||
reasons: [{ moduleName: './src/foo.stories.js' }], | ||
}, | ||
{ | ||
id: 2, | ||
name: './src/foo.stories.js', | ||
reasons: [{ moduleName: CSF_GLOB }], | ||
}, | ||
{ | ||
id: 999, | ||
name: CSF_GLOB, | ||
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }], | ||
}, | ||
]; | ||
const res = await getDependentStoryFiles(ctx, { modules }, changedFiles); | ||
expect(res).toEqual({ | ||
2: './src/foo.stories.js', | ||
}); | ||
}); | ||
|
||
it('supports webpack root in git subdirectory', async () => { | ||
getWorkingDir.mockResolvedValueOnce('frontend'); | ||
const changedFiles = ['./frontend/src/foo.js']; | ||
const modules = [ | ||
{ | ||
id: 1, | ||
name: './src/foo.js', | ||
reasons: [{ moduleName: './src/foo.stories.js' }], | ||
}, | ||
{ | ||
id: 2, | ||
name: './src/foo.stories.js', | ||
reasons: [{ moduleName: CSF_GLOB }], | ||
}, | ||
{ | ||
id: 999, | ||
name: CSF_GLOB, | ||
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }], | ||
}, | ||
]; | ||
const res = await getDependentStoryFiles(ctx, { modules }, changedFiles); | ||
expect(res).toEqual({ | ||
2: './src/foo.stories.js', | ||
}); | ||
}); | ||
}); |
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
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