forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LOOM-1328]: Add test suite for backpack-addons/splitChunks remove un…
…stable from backpack chunk config (#185) * add tests for splitChunks addon & remove unstable from backpack chunk config * move where addon tests are executed * add docs for new config
- Loading branch information
1 parent
4e98f84
commit 98a04cb
Showing
5 changed files
with
82 additions
and
3 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
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
74 changes: 74 additions & 0 deletions
74
packages/react-scripts/backpack-addons/splitChunks.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
let mockPackageJson = {}; | ||
|
||
jest.mock('../package.json', () => ({ | ||
'backpack-react-scripts': mockPackageJson, | ||
})); | ||
|
||
describe('splitChunks addon', () => { | ||
let splitChunks; | ||
beforeEach(() => { | ||
mockPackageJson = {}; | ||
jest.isolateModules(() => { | ||
splitChunks = require('./splitChunks'); | ||
}); | ||
}); | ||
|
||
it('by default is {}', () => { | ||
expect(splitChunks()).toEqual({ splitChunks: {} }); | ||
}); | ||
|
||
it('enableBpkStylesChunk should define a bpkStyles cache group', () => { | ||
mockPackageJson.enableBpkStylesChunk = true; | ||
expect(splitChunks().splitChunks.cacheGroups.bpkStyles).toBeDefined(); | ||
}); | ||
|
||
it('enableAutomaticChunking should add chunks: all and have an empty cacheGroups', () => { | ||
mockPackageJson.enableAutomaticChunking = true; | ||
expect(splitChunks()).toEqual({ | ||
splitChunks: { | ||
chunks: 'all', | ||
cacheGroups: {}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('enableAutomaticChunking & vendorsChunkRegex should add chunks: all and have a user customised cacheGroup', () => { | ||
mockPackageJson.enableAutomaticChunking = true; | ||
mockPackageJson.vendorsChunkRegex = | ||
'[\\/]node_modules[\\/]((?!bpk-.*?)(?!@skyscanner.*?).*?)[\\/]'; | ||
expect(splitChunks()).toEqual({ | ||
splitChunks: { | ||
chunks: 'all', | ||
cacheGroups: { | ||
defaultVendors: { | ||
test: new RegExp(mockPackageJson.vendorsChunkRegex), | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('splitChunksConfig should allow custom cache groups to be defined by users', () => { | ||
mockPackageJson.splitChunksConfig = { | ||
chunks: 'async', | ||
cacheGroups: { | ||
myCacheGroup: { | ||
test: '/myModule/', | ||
}, | ||
}, | ||
}; | ||
|
||
expect(splitChunks()).toEqual({ | ||
splitChunks: { | ||
chunks: 'async', | ||
cacheGroups: { | ||
myCacheGroup: { | ||
test: /\/myModule\//, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |