Skip to content

Commit

Permalink
Keep array-based entries relative-order during injectRefreshEntry (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-silva authored and pmmmwh committed Jul 27, 2020
1 parent 899b28a commit 31b8b92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/utils/injectRefreshEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ function injectRefreshEntry(originalEntry, options) {
if (Array.isArray(originalEntry)) {
const socketEntryIndex = originalEntry.findIndex(isSocketEntry);

let socketEntry = [];
let socketAndPreceedingEntries = [];
if (socketEntryIndex !== -1) {
socketEntry = originalEntry.splice(socketEntryIndex, 1);
socketAndPreceedingEntries = originalEntry.splice(0, socketEntryIndex + 1);
}

return [...prependEntries, ...socketEntry, ...overlayEntries, ...originalEntry];
return [...prependEntries, ...socketAndPreceedingEntries, ...overlayEntries, ...originalEntry];
}
// Multiple entry points
if (typeof originalEntry === 'object') {
Expand Down
12 changes: 9 additions & 3 deletions test/unit/injectRefreshEntry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,16 @@ describe('injectRefreshEntry', () => {
]);
});

it('should append overlay entry for an array after socket-related entries', () => {
it('should append overlay entry for an array after socket-related entries, while keeping relative order on the original entries', () => {
expect(
injectRefreshEntry(['webpack-dev-server/client', 'test.js'], DEFAULT_OPTIONS)
).toStrictEqual([ReactRefreshEntry, 'webpack-dev-server/client', ErrorOverlayEntry, 'test.js']);
injectRefreshEntry(['setup-env.js', 'webpack-dev-server/client', 'test.js'], DEFAULT_OPTIONS)
).toStrictEqual([
ReactRefreshEntry,
'setup-env.js',
'webpack-dev-server/client',
ErrorOverlayEntry,
'test.js',
]);
});

it('should throw when non-parsable entry is received', () => {
Expand Down

0 comments on commit 31b8b92

Please sign in to comment.