Skip to content

Commit

Permalink
test(envs): Add tests for `conditionally creating profiles based on N…
Browse files Browse the repository at this point in the history
…ODE_ENV`.

[BRANCH: master]
  • Loading branch information
thezimmee committed Apr 4, 2018
1 parent 16612e0 commit dbb9601
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/fixtures/configs/.stakcssrc-envs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const profiles = {
one: {
content: 'I am content from .stakcssrc-envs.js:' + process.env.NODE_ENV,
output: './.temp/one.js',
bundlers: [
(config = {}) => {
return new Promise((resolve) => {
setTimeout(() => {
config.testing = 'one';
config.array = [1];
resolve(config);
}, 20);
});
},
(config = {}) => {
config.array.push(2);
return config;
}
]
}
};

if (process.env.NODE_ENV === 'production') {
profiles.one_min = Object.assign({}, profiles.one);
profiles.one_min.content += ':minified';
profiles.one_min.output = profiles.one_min.output.replace('.js', '.min.js');
}

module.exports = profiles;
24 changes: 24 additions & 0 deletions test/stakcss-cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ describe('stakcss-cli()', function() {
);
});

it('runs a config with NODE_ENV=development', () => {
exec(
`NODE_ENV=development node ${cliPath} --config=test/fixtures/configs/.stakcssrc-envs.js:all`
);
assert.equal(
fs.readFileSync('.temp/one.js', 'utf8'),
'I am content from .stakcssrc-envs.js:development'
);
});

it('runs a config with NODE_ENV=production', () => {
exec(
`NODE_ENV=production node ${cliPath} --config=test/fixtures/configs/.stakcssrc-envs.js:all`
);
assert.equal(
fs.readFileSync('.temp/one.js', 'utf8'),
'I am content from .stakcssrc-envs.js:production'
);
assert.equal(
fs.readFileSync('.temp/one.min.js', 'utf8'),
'I am content from .stakcssrc-envs.js:production:minified'
);
});

it('runs with bundlers option', () => {
const result = exec(
`node ${cliPath} --content="Testing, testing..." --bundlers="./test/fixtures/runners/sample2.js, ./test/fixtures/runners/sample3.js" --output=.temp/sample.js`
Expand Down

0 comments on commit dbb9601

Please sign in to comment.