Skip to content

Commit

Permalink
Test confighash based on stamp of cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mzgoddard committed Sep 11, 2016
1 parent 5f896ed commit e798ecc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
33 changes: 15 additions & 18 deletions tests/hard-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@ var fs = require('fs');
var expect = require('chai').expect;

var itCompilesChange = require('./util').itCompilesChange;
var itCompiles = require('./util').itCompiles;
var writeFiles = require('./util').writeFiles;

describe('hard-source features', function() {

itCompilesChange('hard-source-confighash', {
'config-hash': 'a',
'fib.js': [
'module.exports = function(n) {',
' return n + (n > 0 ? n - 1 : 0);',
'};',
].join('\n'),
'fib/index.js': null,
}, {
'config-hash': 'b',
'fib.js': null,
'fib/index.js': [
'module.exports = function(n) {',
' return n + (n > 0 ? n - 2 : 0);',
'};',
].join('\n'),
itCompiles('compiles hard-source-confighash with fresh cache', 'hard-source-confighash', function() {
return writeFiles('hard-source-confighash', {
'config-hash': 'a',
});
}, function() {
return writeFiles('hard-source-confighash', {
'config-hash': 'b',
})
.then(function() {
return fs.readFileSync(__dirname + '/fixtures/hard-source-confighash/tmp/cache/stamp', 'utf8');
});
}, function(output) {
expect(fs.readdirSync(__dirname + '/fixtures/hard-source-confighash/tmp/cache'))
.to.have.length(6);
var stamp = fs.readFileSync(__dirname + '/fixtures/hard-source-confighash/tmp/cache/stamp', 'utf8');
expect(stamp).to.not.equal(output.setup2);
});

itCompilesChange('hard-source-confighash-dir', {
Expand Down
28 changes: 22 additions & 6 deletions tests/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,22 @@ exports.readFiles = function(outputPath) {
}, {});
};

exports.itCompilesChange = function(fixturePath, filesA, filesB, expectHandle) {
exports.itCompiles = function(name, fixturePath, fnA, fnB, expectHandle) {
before(function() {
return exports.clean(fixturePath);
});

it('builds changes in ' + fixturePath + ' fixture', function() {
it(name, function() {
this.timeout(20000);
this.slow(4000);
var run1;
var setup1, setup2;
return Promise.resolve()
.then(function() {
return exports.writeFiles(fixturePath, filesA);
return fnA();
})
.then(function() {
.then(function(_setup1) {
setup1 = _setup1;
run1 = exports.compile(fixturePath);
return run1;
})
Expand All @@ -168,21 +170,35 @@ exports.itCompilesChange = function(fixturePath, filesA, filesB, expectHandle) {
return new Promise(function(resolve) {setTimeout(resolve, 1000);});
})
.then(function() {
return exports.writeFiles(fixturePath, filesB);
return fnB();
})
.then(function() {
.then(function(_setup2) {
setup2 = _setup2;
var run2 = exports.compile(fixturePath);
return Promise.all([run1, run2]);
})
.then(function(runs) {
expectHandle({
run1: runs[0],
run2: runs[1],
setup1: setup1,
setup2: setup2,
});
});
});
};

exports.itCompilesChange = function(fixturePath, filesA, filesB, expectHandle) {
exports.itCompiles('builds changes in ' + fixturePath + ' fixture', fixturePath, function() {
return exports.writeFiles(fixturePath, filesA);
}, function() {
return exports.writeFiles(fixturePath, filesB);
}, expectHandle);
before(function() {
return exports.clean(fixturePath);
});
};

exports.clean = function(fixturePath) {
var tmpPath = path.join(__dirname, '..', 'fixtures', fixturePath, 'tmp');
return Promise.promisify(rimraf)(tmpPath);
Expand Down

0 comments on commit e798ecc

Please sign in to comment.