-
-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more tests #116
Merged
evenstensberg
merged 9 commits into
webpack:feature/init-ast
from
kalcifer:init-ast/tests
Apr 18, 2017
Merged
Add more tests #116
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26d86b8
Test watch transform
38869c6
Test watch transform (Doesnt look for existing obj)
90e6877
Test target transform (Doesnt look for existing obj)
e7dff36
Test plugins transform (Doesnt look for existing obj)
e97dcf6
Add failing test case for node
2a4a792
Add test case for node
4c69399
Add first instance of duplicate check and override
4c5d840
Extract a function
07a423d
Make a util to override object params
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
lib/creator/transformations/node/__snapshots__/node.test.js.snap
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`node transforms correctly using "node-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
node: { | ||
console: false, | ||
global: true, | ||
process: true, | ||
Buffer: true, | ||
__filename: mock, | ||
__dirname: mock, | ||
setImmediate: true | ||
} | ||
} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
lib/creator/transformations/node/__testfixtures__/node-0.input.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,6 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.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,11 @@ | ||
const defineTest = require('../../../transformations/defineTest'); | ||
|
||
defineTest(__dirname, 'node', 'node-0', {node : { | ||
console: false, | ||
global: true, | ||
process: true, | ||
Buffer: true, | ||
__filename: 'mock', | ||
__dirname: 'mock', | ||
setImmediate: true | ||
}}); |
15 changes: 15 additions & 0 deletions
15
lib/creator/transformations/plugins/__snapshots__/plugins.test.js.snap
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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`plugins transforms correctly using "plugins-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({name:'vendor',filename:'vendor-[hash].min.js'}) | ||
] | ||
} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
lib/creator/transformations/plugins/__testfixtures__/plugins-0.input.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,6 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.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,5 @@ | ||
const defineTest = require('../../../transformations/defineTest'); | ||
|
||
defineTest(__dirname, 'plugins', 'plugins-0', {plugins : [ | ||
'new webpack.optimize.CommonsChunkPlugin({name:' + '\'' + 'vendor' + '\'' + ',filename:' + '\'' + 'vendor' + '-[hash].min.js\'})' | ||
]}); |
26 changes: 26 additions & 0 deletions
26
lib/creator/transformations/target/__snapshots__/target.test.js.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`target transforms correctly using "target-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
target: async-node | ||
} | ||
" | ||
`; | ||
|
||
exports[`target transforms correctly using "target-1" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
target: 'node', | ||
target: async-node | ||
} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
lib/creator/transformations/target/__testfixtures__/target-0.input.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,6 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
lib/creator/transformations/target/__testfixtures__/target-1.input.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,7 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
target: 'node' | ||
} |
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,4 @@ | ||
const defineTest = require('../../../transformations/defineTest'); | ||
|
||
defineTest(__dirname, 'target', 'target-0', {target : 'async-node'}); | ||
defineTest(__dirname, 'target', 'target-1', {target : 'async-node'}); |
49 changes: 49 additions & 0 deletions
49
lib/creator/transformations/watch/__snapshots__/watch.test.js.snap
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,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`watch transforms correctly using "watch-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
watch: true | ||
} | ||
" | ||
`; | ||
|
||
exports[`watch transforms correctly using "watch-0" data 2`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
watch: false | ||
} | ||
" | ||
`; | ||
|
||
exports[`watch transforms correctly using "watch-1" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
watch: true, | ||
watchOptions: {} | ||
} | ||
" | ||
`; | ||
|
||
exports[`watch transforms correctly using "watch-1" data 2`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
watch: false, | ||
watchOptions: {} | ||
} | ||
" | ||
`; |
64 changes: 64 additions & 0 deletions
64
lib/creator/transformations/watch/__snapshots__/watchOptions.test.js.snap
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,64 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`watchOptions transforms correctly using "watch-0" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: /node_modules/ | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`watchOptions transforms correctly using "watch-1" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
watch: false, | ||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: /node_modules/ | ||
}, | ||
|
||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: /node_modules/ | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`watchOptions transforms correctly using "watch-2" data 1`] = ` | ||
"module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
|
||
watch: false, | ||
watchOptions: { | ||
aggregateTimeout: 320, | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: /node_modules/ | ||
}, | ||
|
||
watchOptions: { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: /node_modules/ | ||
} | ||
} | ||
" | ||
`; |
6 changes: 6 additions & 0 deletions
6
lib/creator/transformations/watch/__testfixtures__/watch-0.input.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,6 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
lib/creator/transformations/watch/__testfixtures__/watch-1.input.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,8 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
watch: false, | ||
watchOptions: {} | ||
} |
10 changes: 10 additions & 0 deletions
10
lib/creator/transformations/watch/__testfixtures__/watch-2.input.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,10 @@ | ||
module.exports = { | ||
entry: 'index.js', | ||
output: { | ||
filename: 'bundle.js' | ||
}, | ||
watch: false, | ||
watchOptions: { | ||
aggregateTimeout: 320 | ||
} | ||
} |
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,15 +1,17 @@ | ||
const isAssignment = require('../../utils/is-assignment'); | ||
const transformUtils = require('../../../transformations/utils'); | ||
|
||
module.exports = function(j, ast, yeomanConfig) { | ||
const webpackProperties = yeomanConfig.webpackOptions; | ||
function createWatchProperty(p) { | ||
return p.value.properties.push( | ||
j.property('init', j.identifier('watch'), j.literal(webpackProperties['watch'])) | ||
); | ||
const propValue = transformUtils.createIdentifierOrLiteral(j, webpackProperties['watch']); | ||
transformUtils.checkIfExistsAndAddValue(j, p, 'watch', propValue); | ||
} | ||
if(typeof(webpackProperties['watch']) === 'boolean') { | ||
return ast.find(j.ObjectExpression).filter(p => isAssignment(p, createWatchProperty)); | ||
} else { | ||
return ast; | ||
} | ||
}; | ||
|
||
|
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,6 @@ | ||
const defineTest = require('../../../transformations/defineTest'); | ||
|
||
defineTest(__dirname, 'watch', 'watch-0', {watch : true}); | ||
defineTest(__dirname, 'watch', 'watch-0', {watch : false}); | ||
defineTest(__dirname, 'watch', 'watch-1', {watch : true}); | ||
defineTest(__dirname, 'watch', 'watch-1', {watch : 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const defineTest = require('../../../transformations/defineTest'); | ||
|
||
defineTest(__dirname, 'watchOptions', 'watch-0', {watchOptions : { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: '/node_modules/' | ||
}}); | ||
|
||
defineTest(__dirname, 'watchOptions', 'watch-1', {watchOptions : { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: '/node_modules/' | ||
}}); | ||
|
||
defineTest(__dirname, 'watchOptions', 'watch-2', {watchOptions : { | ||
aggregateTimeout: 300, | ||
poll: 1000, | ||
ignored: '/node_modules/' | ||
}}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing test case