Skip to content

Commit

Permalink
add tests for others and new transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Dec 17, 2017
1 parent b416d9c commit 28680c9
Show file tree
Hide file tree
Showing 20 changed files with 921 additions and 64 deletions.
5 changes: 1 addition & 4 deletions lib/init/transformations/devServer/devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ module.exports = function devServerTransform(
});
return ast;
});
} else if (
devServerNode.size() !== 0 &&
typeof webpackProperties.length
) {
} else if (devServerNode.size() !== 0 && webpackProperties.length) {
return ast
.find(j.ObjectExpression)
.filter(
Expand Down
2 changes: 1 addition & 1 deletion lib/init/transformations/entry/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function entryTransform(j, ast, webpackProperties, action) {
});
return ast;
});
} else if (entryNode.size() !== 0 && typeof webpackProperties.length) {
} else if (entryNode.size() !== 0 && webpackProperties.length) {
return ast
.find(j.ObjectExpression)
.filter(
Expand Down
2 changes: 1 addition & 1 deletion lib/init/transformations/externals/externals.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function externalsTransform(
Array.isArray(webpackProperties)
) {
// Todo
} else if (externalNode.size() !== 0 && typeof webpackProperties.length) {
} else if (externalNode.size() !== 0 && webpackProperties.length) {
return ast
.find(j.ObjectExpression)
.filter(
Expand Down
10 changes: 9 additions & 1 deletion lib/init/transformations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const bailTransform = require("./other/bail");
const cacheTransform = require("./other/cache");
const profileTransform = require("./other/profile");
const mergeTransform = require("./other/merge");
const parallelismTransform = require("./other/parallelism");
const recordsInputPathTransform = require("./other/recordsInputPath");
const recordsOutputPathTransform = require("./other/recordsOutputPath");
const recordsPathTransform = require("./other/recordsPath");
const moduleTransform = require("./module/module");
const pluginsTransform = require("./plugins/plugins");
const topScopeTransform = require("./top-scope/top-scope");
Expand Down Expand Up @@ -62,7 +66,11 @@ const transformsObject = {
topScopeTransform,
mergeTransform,
devServerTransform,
modeTransform
modeTransform,
parallelismTransform,
recordsInputPathTransform,
recordsOutputPathTransform,
recordsPathTransform
};

module.exports = function runTransform(webpackProperties, action) {
Expand Down
237 changes: 237 additions & 0 deletions lib/init/transformations/other/__snapshots__/other.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ exports[`amd transforms correctly using "other-0" data 1`] = `
"
`;

exports[`amd transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: false,
kQuery: true
}
};
"
`;

exports[`bail transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
Expand All @@ -29,6 +47,25 @@ exports[`bail transforms correctly using "other-0" data 1`] = `
"
`;

exports[`bail transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: false,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false,
bail: false
}
};
"
`;

exports[`cache transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
Expand All @@ -55,6 +92,44 @@ exports[`cache transforms correctly using "other-0" data 2`] = `
"
`;

exports[`cache transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: false,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false,
cache: false
}
};
"
`;

exports[`cache transforms correctly using "other-1" data 2`] = `
"module.exports = {
bail: true,
cache: cacheKey,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false,
cache: cacheKey
}
};
"
`;

exports[`merge transforms correctly using "other-0" data 1`] = `
"module.exports = merge(myConfig, {
entry: 'index.js',
Expand All @@ -65,6 +140,56 @@ exports[`merge transforms correctly using "other-0" data 1`] = `
"
`;

exports[`merge transforms correctly using "other-1" data 1`] = `
"module.exports = merge(TheirConfig, {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false
}
});
"
`;

exports[`parallelism transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
output: {
filename: 'bundle.js'
},
parallelism: 10
}
"
`;

exports[`parallelism transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 20,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false,
parallelism: 20
}
};
"
`;

exports[`profile transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
Expand All @@ -77,3 +202,115 @@ exports[`profile transforms correctly using "other-0" data 1`] = `
}
"
`;

exports[`profile transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: false,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false,
profile: false
}
};
"
`;

exports[`recordsInputPath transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
output: {
filename: 'bundle.js'
},
recordsInputPath: path.join('dist', mine)
}
"
`;

exports[`recordsInputPath transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: path.join('dist', ours),
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false
}
};
"
`;

exports[`recordsOutputPath transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
output: {
filename: 'bundle.js'
},
recordsOutputPath: path.join('src', yours)
}
"
`;

exports[`recordsOutputPath transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: path.join('src', theirs),
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false
}
};
"
`;

exports[`recordsPath transforms correctly using "other-0" data 1`] = `
"module.exports = {
entry: 'index.js',
output: {
filename: 'bundle.js'
},
recordsPath: path.join(__dirname, 'records.json')
}
"
`;

exports[`recordsPath transforms correctly using "other-1" data 1`] = `
"module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: path.resolve(__dirname, 'gradle.json'),
amd: {
jQuery: true,
kQuery: false
}
};
"
`;
14 changes: 14 additions & 0 deletions lib/init/transformations/other/__testfixtures__/other-1.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
bail: true,
cache: true,
profile: true,
merge: 'NotMuch',
parallelism: 69,
recordsInputPath: 'somethign',
recordsOutputPath: 'else',
recordsPath: 'Brooklyn',
amd: {
jQuery: true,
kQuery: false
}
};
Loading

0 comments on commit 28680c9

Please sign in to comment.