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 #74 from herecydev/master
Added merge multiple that outputs an array
- Loading branch information
Showing
4 changed files
with
219 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* eslint-env mocha */ | ||
const assert = require('assert'); | ||
|
||
function multipleTests(merge) { | ||
it('should override objects', function () { | ||
const a = { | ||
client: { | ||
entry: './client.js' | ||
} | ||
}; | ||
const b = { | ||
client: { | ||
entry: './replaced.js' | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: './replaced.js' | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
|
||
it('should add new objects if not existing', function () { | ||
const a = { | ||
client: { | ||
entry: './client.js' | ||
}, | ||
server: { | ||
entry: './server.js' | ||
} | ||
}; | ||
const b = { | ||
client: { | ||
entry: './replaced.js' | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: './replaced.js' | ||
}, | ||
{ | ||
entry: './server.js' | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
|
||
it('should add different configurations without merging', function () { | ||
const a = { | ||
client: { | ||
entry: './client.js' | ||
} | ||
}; | ||
const b = { | ||
server: { | ||
entry: './server.js' | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: './client.js' | ||
}, | ||
{ | ||
entry: './server.js' | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
|
||
it('should work with an array of objects', function () { | ||
const a = { | ||
client: { | ||
entry: ['./client.js', './client2.js'] | ||
}, | ||
server: { | ||
entry: ['./server.js', './server2.js'] | ||
} | ||
}; | ||
const b = { | ||
client: { | ||
entry: ['./replaced.js', './replaced2.js'] | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: ['./client.js', './client2.js', './replaced.js', './replaced2.js'] | ||
}, | ||
{ | ||
entry: ['./server.js', './server2.js'] | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
|
||
it('should deeply merge objects', function () { | ||
const a = { | ||
client: { | ||
entry: { | ||
main: './client.js' | ||
} | ||
}, | ||
server: { | ||
entry: { | ||
main: './server.js' | ||
} | ||
} | ||
}; | ||
const b = { | ||
client: { | ||
entry: { | ||
main: './replaced.js' | ||
} | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: { | ||
main: './replaced.js' | ||
} | ||
}, | ||
{ | ||
entry: { | ||
main: './server.js' | ||
} | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
|
||
it('should merge where keys exist and add where not', function () { | ||
const a = { | ||
client: { | ||
entry: './client.js' | ||
}, | ||
server: { | ||
entry: './server.js' | ||
} | ||
}; | ||
const b = { | ||
server: { | ||
entry: './replaced.js' | ||
}, | ||
test: { | ||
entry: './test.js' | ||
} | ||
}; | ||
const result = [ | ||
{ | ||
entry: './client.js' | ||
}, | ||
{ | ||
entry: './replaced.js' | ||
}, | ||
{ | ||
entry: './test.js' | ||
} | ||
]; | ||
|
||
assert.deepEqual(merge(a, b), result); | ||
}); | ||
} | ||
|
||
module.exports = multipleTests; |
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,9 @@ | ||
/* eslint-env mocha */ | ||
const webpackMerge = require('..'); | ||
const mergeMultipleTests = require('./merge-multiple-tests'); | ||
|
||
describe('Multiple merge', function () { | ||
const merge = webpackMerge.multiple; | ||
|
||
mergeMultipleTests(merge); | ||
}); |