Skip to content
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 tests #94

Merged
merged 6 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
*.swp
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function haveBabelrc(functionsDir) {

function webpackConfig(dir, additionalConfig) {
var config = conf.load();
var envConfig = config.build.environment || config.build.Environment || {};
var envConfig = conf.loadContext(config).environment;
var babelOpts = { cacheDirectory: true };
if (!haveBabelrc(dir)) {
babelOpts.presets = [
Expand Down
27 changes: 27 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,30 @@ exports.load = function() {

return toml.parse(fs.readFileSync(configPath));
};

exports.loadContext = function(config) {
var buildConfig = config.build;
var contextConfig = (
process.env.CONTEXT &&
config.context &&
config.context[process.env.CONTEXT]
) || {};
var branchConfig = (
process.env.BRANCH &&
config.context &&
config.context[process.env.BRANCH]
) || {};
var buildEnv = buildConfig.environment || buildConfig.Environment || {};
var contextEnv = contextConfig.environment || contextConfig.Environment || {};
var branchEnv = branchConfig.environment || branchConfig.Environment || {};
return {
...buildConfig,
...contextConfig,
...branchConfig,
environment: {
...buildEnv,
...contextEnv,
...branchEnv,
}
};
};
41 changes: 41 additions & 0 deletions lib/config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var conf = require('./config');

beforeAll(function() {
process.env.CONTEXT = 'branch-deploy';
process.env.BRANCH = 'foo-branch';
});

describe('loadContext', function() {
it('should merge in context config', function() {
var config = {
build: {
publish: '/default',
environment: {
SOME_VAR: true,
},
},
context: {
'branch-deploy': {
publish: '/branch-deploy',
environment: {
SOME_VAR: false,
},
},
'foo-branch': {
publish: '/foo-branch',
environment: {
SOME_OTHER_VAR: 10,
},
},
},
};
var contextConfig = conf.loadContext(config);
expect(contextConfig).toEqual({
publish: '/foo-branch',
environment: {
SOME_VAR: false,
SOME_OTHER_VAR: 10,
},
});
});
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"netlify-lambda": "bin/cmd.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"author": "Mathias Biilmann Christensen",
"license": "MIT",
Expand All @@ -34,5 +34,8 @@
"toml": "^2.3.3",
"webpack": "^4.17.1",
"webpack-merge": "^4.1.4"
},
"devDependencies": {
"jest": "^23.6.0"
}
}
Loading