Skip to content

Commit

Permalink
Build: Ensure all callback arguments are tested
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman authored and phated committed Jun 7, 2017
1 parent 80c0510 commit 0abb70d
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 36 deletions.
11 changes: 8 additions & 3 deletions test/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('flag: --completion', function() {
.gulp('--completion=' + type)
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toNotExist();
expect(stderr).toEqual('');
expect(stdout).toEqual(expected);
done(err);
}
Expand All @@ -31,8 +33,9 @@ describe('flag: --completion', function() {
.gulp('--completion=unknown')
.run(cb);

function cb(err, stdout) {
expect(err).toExist();
function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stderr).toEqual('');
expect(stdout).toEqual(expected);
done();
}
Expand All @@ -44,7 +47,9 @@ describe('flag: --completion', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);
expect(stderr).toMatch('Missing completion type');
expect(stdout).toEqual('');
done();
}
});
Expand Down
12 changes: 9 additions & 3 deletions test/config-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ describe('config: description', function() {
.gulp('--tasks')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'),
'utf-8');
stdout = eraseTime(stdout);
Expand All @@ -36,7 +38,9 @@ describe('config: description', function() {
.gulp('--tasks')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'),
'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
Expand All @@ -52,7 +56,9 @@ describe('config: description', function() {
.gulp('--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'),
'utf-8');
stdout = eraseTime(stdout);
Expand Down
12 changes: 8 additions & 4 deletions test/config-flags-gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ describe('config: flags.gulpfile', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = headLines(stdout, 2, 2);
expect(stdout).toEqual(
'This gulpfile : ' +
path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') +
'\n' +
'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile')
);
expect(stderr).toEqual('');
done(err);
}
});
Expand All @@ -36,14 +37,15 @@ describe('config: flags.gulpfile', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = headLines(stdout, 2, 3);
expect(stdout).toEqual(
'This gulpfile : ' +
path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') +
'\n' +
'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile')
);
expect(stderr).toEqual('');
done(err);
}
});
Expand All @@ -56,12 +58,13 @@ describe('config: flags.gulpfile', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = headLines(stdout, 1, 3);
expect(stdout).toEqual(
'Another gulpfile : ' +
path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js')
);
expect(stderr).toEqual('');
done(err);
}
});
Expand All @@ -74,12 +77,13 @@ describe('config: flags.gulpfile', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = headLines(stdout, 1, 3);
expect(stdout).toEqual(
'Another gulpfile : ' +
path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js')
);
expect(stderr).toEqual('');
done(err);
}
});
Expand Down
6 changes: 4 additions & 2 deletions test/config-flags-silent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ describe('config: flags.silent', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(stdout).toEqual('');
expect(err).toEqual(null);
expect(stderr).toEqual('');
expect(stdout).toEqual('');
done(err);
}
});
Expand All @@ -33,13 +34,14 @@ describe('config: flags.silent', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = eraseLapse(eraseTime(skipLines(stdout, 1)));
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Finished \'default\' after ?\n' +
''
);
expect(stderr).toEqual('');
done(err);
}
});
Expand Down
3 changes: 2 additions & 1 deletion test/exports-as-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ describe('exports as tasks', function() {
'--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
expect(stderr).toEqual('');
stdout = eraseTime(skipLines(stdout, 2));
expect(stdout).toEqual(expected);
done();
Expand Down
2 changes: 0 additions & 2 deletions test/flags-continue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('flag: --continue', function() {

function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
expect(stdout).toEqual(
'Starting \'test4\'...\n' +
Expand All @@ -42,7 +41,6 @@ describe('flag: --continue', function() {

function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

expect(stdout).toNotMatch('Starting \'anon\'');
stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
expect(stdout).toEqual(
Expand Down
5 changes: 4 additions & 1 deletion test/flags-gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ describe('flag: --gulpfile', function() {
.gulp('--gulpfile', gulpfilePath)
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');

var chgWorkdirLog = headLines(stdout, 1);
var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep);
expect(chgWorkdirLog).toMatch('Working directory changed to ');
Expand Down
8 changes: 6 additions & 2 deletions test/flags-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('flag: --help', function() {
.gulp('--help', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = eraseFirstSpace(stdout);
expect(stdout).toEqual(outputText);
done(err);
Expand All @@ -33,7 +35,9 @@ describe('flag: --help', function() {
.gulp('--h', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = eraseFirstSpace(stdout);
expect(stdout).toEqual(outputText);
done(err);
Expand Down
7 changes: 6 additions & 1 deletion test/flags-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('flag: --require', function() {
.gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var insideLog = headLines(stdout, 1);
expect(insideLog).toEqual('inside test module');

Expand Down Expand Up @@ -54,6 +56,9 @@ describe('flag: --require', function() {
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
stderr = eraseLapse(eraseTime(stderr));
expect(stderr).toMatch('Failed to load external module ./null-module.js');
expect(stdout).toNotMatch('inside test module');
expect(stdout).toNotMatch(
'Requiring external module ../test-module.js');
Expand Down
4 changes: 3 additions & 1 deletion test/flags-silent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe('flag: --silent', function() {
.gulp('--silent', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
expect(stdout).toEqual('');
done(err);
}
Expand Down
10 changes: 8 additions & 2 deletions test/flags-tasks-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('flag: --tasks-json', function() {
.gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile.js')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = skipLines(stdout, 1);
expect(JSON.parse(stdout)).toEqual(expected);
done();
Expand All @@ -33,7 +35,11 @@ describe('flag: --tasks-json', function() {
'--gulpfile ./test/fixtures/gulpfiles/gulpfile.js')
.run(cb);

function cb(err) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = skipLines(stdout, 1);
expect(stdout).toEqual('');
var file = fs.readFileSync(__dirname + '/output/tasks.json', 'utf8');
var parsedJson = JSON.parse(file);
expect(parsedJson).toEqual(expected);
Expand Down
4 changes: 3 additions & 1 deletion test/flags-tasks-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('flag: --tasks-simple', function() {
.gulp('--tasks-simple', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
expect(stdout).toEqual(outputText);
done(err);
}
Expand Down
12 changes: 9 additions & 3 deletions test/flags-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('flag: --tasks', function() {
.gulp('--tasks --cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var filepath = path.join(expectedDir, 'flags-tasks.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
Expand All @@ -32,7 +34,9 @@ describe('flag: --tasks', function() {
'--cwd ./test/fixtures')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var filepath = path.join(expectedDir, 'with-desc-and-flags.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
Expand All @@ -49,7 +53,9 @@ describe('flag: --tasks', function() {
'--cwd ./test/fixtures')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
var filepath = path.join(expectedDir, 'by-unwrap-and-not-by-unwrap.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
Expand Down
12 changes: 7 additions & 5 deletions test/flags-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('flag: --verify', function() {
.gulp('--verify invalid-package.json', '--cwd ./test/fixtures/packages/')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

expect(stderr).toEqual('');
stdout = eraseTime(stdout);
expect(stdout).toEqual(
'Verifying plugins in ' +
Expand All @@ -33,7 +33,9 @@ describe('flag: --verify', function() {
.gulp('--verify valid-package.json', '--cwd ./test/fixtures/packages/')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = eraseTime(stdout);
expect(stdout).toEqual(
'Verifying plugins in ' +
Expand All @@ -51,9 +53,9 @@ describe('flag: --verify', function() {
.gulp('--verify', '--cwd ./test/fixtures/packages/')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(err).toNotEqual(null);

expect(stderr).toEqual('');
stdout = eraseTime(stdout);
expect(stdout).toEqual(
'Verifying plugins in ' +
Expand Down
3 changes: 2 additions & 1 deletion test/flags-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe('flag: --version', function() {
.gulp('--version --cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout) {
function cb(err, stdout, stderr) {
expect(stderr).toEqual('');
stdout = eraseTime(stdout);
expect(stdout).toEqual(
'CLI version ' + cliVersion + '\n' +
Expand Down
Loading

0 comments on commit 0abb70d

Please sign in to comment.