Skip to content

Commit a2a2f73

Browse files
committed
Fix: Improve integration tests, especially on Windows
1 parent f0866cc commit a2a2f73

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

test/integration.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var expect = require('expect');
44

5+
var os = require('os');
56
var fs = require('fs');
67
var path = require('path');
78
var vinyl = require('vinyl-fs');
@@ -14,6 +15,15 @@ var through = require('through2');
1415

1516
var Undertaker = require('../');
1617

18+
var isWindows = (os.platform() === 'win32');
19+
20+
function cleanup() {
21+
return del([
22+
path.join(__dirname, './fixtures/out/'),
23+
path.join(__dirname, './fixtures/tmp/'),
24+
]);
25+
}
26+
1727
describe('integrations', function() {
1828

1929
var taker;
@@ -23,6 +33,9 @@ describe('integrations', function() {
2333
done();
2434
});
2535

36+
beforeEach(cleanup);
37+
afterEach(cleanup);
38+
2639
it('should handle vinyl streams', function(done) {
2740
taker.task('test', function() {
2841
return vinyl.src('./fixtures/test.js', { cwd: __dirname })
@@ -51,6 +64,10 @@ describe('integrations', function() {
5164

5265
it('should handle a child process return', function(done) {
5366
taker.task('test', function() {
67+
if (isWindows) {
68+
return spawn('cmd', ['/c', 'dir']).on('error', console.log);
69+
}
70+
5471
return spawn('ls', ['-lh', __dirname]);
5572
});
5673

@@ -109,30 +126,27 @@ describe('integrations', function() {
109126
});
110127

111128
it('can use lastRun with vinyl.src `since` option', function(done) {
129+
this.timeout(5000);
130+
112131
var count = 0;
113-
var filepath = path.join(__dirname, './fixtures/tmp/testMore.js');
114132

115133
function setup() {
116134
return vinyl.src('./fixtures/test*.js', { cwd: __dirname })
117135
.pipe(vinyl.dest('./fixtures/tmp', { cwd: __dirname }));
118136
}
119137

138+
function delay(cb) {
139+
setTimeout(cb, 2000);
140+
}
141+
120142
// Some built
121143
taker.task('build', function() {
122144
return vinyl.src('./fixtures/tmp/*.js', { cwd: __dirname })
123145
.pipe(vinyl.dest('./fixtures/out', { cwd: __dirname }));
124146
});
125147

126-
function userWait(cd) {
127-
setTimeout(cd, 1100);
128-
}
129-
130148
function userEdit(cb) {
131-
fs.appendFile(filepath, ' ', cb);
132-
}
133-
134-
function cleanup(cb) {
135-
fs.unlink(filepath, cb);
149+
fs.appendFile(path.join(__dirname, './fixtures/tmp/testMore.js'), ' ', cb);
136150
}
137151

138152
function countEditedFiles() {
@@ -143,9 +157,9 @@ describe('integrations', function() {
143157
}));
144158
}
145159

146-
taker.series(setup, 'build', userWait, userEdit, countEditedFiles, cleanup, function(cb) {
160+
taker.series(setup, delay, 'build', delay, userEdit, countEditedFiles)(function(err) {
147161
expect(count).toEqual(1);
148-
cb();
149-
})(done);
162+
done(err);
163+
});
150164
});
151165
});

0 commit comments

Comments
 (0)