Skip to content

Commit 97c7f47

Browse files
sttkphated
authored andcommitted
Update: Switch test frameworks to mocha, expect and nyc (#99)
1 parent 66c67e1 commit 97c7f47

19 files changed

+164
-155
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
**/*.babel.js
2+
coverage

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ build
55
*.node
66
components
77
coverage
8+
.coveralls.yml
9+
.nyc_output
810
*.orig
911
.idea
1012
sandbox

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
test_script:
2525
- node --version
2626
- npm --version
27-
- for %%f in (test\*.js) do node_modules\.bin\lab %%f -v -m 5000 -I Reflect & if errorlevel 1 exit /b 1
27+
- npm test
2828

2929
build: off
3030

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
"gulp.1"
2424
],
2525
"scripts": {
26-
"coveralls": "lab -r lcov | coveralls",
2726
"lint": "eslint . && jscs index.js bin/ lib/ test/",
2827
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
2928
"pretest": "npm run lint",
30-
"test": "lab test/*.js -cv -I Reflect",
29+
"test": "mocha --async-only --timeout 3000",
30+
"cover": "nyc --reporter=lcov --reporter=text-summary npm test",
31+
"coveralls": "nyc --reporter=text-lcov npm test | coveralls",
3132
"changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body"
3233
},
3334
"dependencies": {
@@ -54,18 +55,20 @@
5455
"devDependencies": {
5556
"babel-preset-es2015": "^6.5.0",
5657
"babel-register": "^6.5.1",
57-
"code": "^1.2.1",
5858
"coveralls": "^2.7.0",
5959
"eslint": "^1.7.3",
6060
"eslint-config-gulp": "^2.0.0",
61+
"expect": "^1.20.2",
6162
"fs-extra": "^0.26.1",
6263
"github-changes": "^1.0.1",
6364
"gulp": "gulpjs/gulp#4.0",
64-
"gulp-test-tools": "^0.5.2",
65+
"gulp-test-tools": "^0.6.0",
66+
"istanbul": "^0.4.5",
6567
"jscs": "^2.3.5",
6668
"jscs-preset-gulp": "^1.0.0",
67-
"lab": "^6.2.0",
68-
"marked-man": "^0.1.3"
69+
"marked-man": "^0.1.3",
70+
"mocha": "^3.2.0",
71+
"nyc": "^10.0.0"
6972
},
7073
"keywords": [
7174
"build",

test/completion.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var runner = require('gulp-test-tools').gulpRunner;
5+
var path = require('path');
6+
var fs = require('fs');
67

7-
lab.experiment('flag: --completion', function() {
8+
describe('flag: --completion', function() {
89

910
['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) {
10-
lab.test('returns completion script for ' + type, function(done) {
11+
it('returns completion script for ' + type, function(done) {
12+
var file = path.resolve(__dirname, '../completion', type);
13+
var expected = fs.readFileSync(file, 'utf8') + '\n';
14+
1115
runner({ verbose: false })
1216
.gulp('--completion=' + type)
1317
.run(cb);
1418

1519
function cb(err, stdout) {
16-
expect(stdout).to.contain('gulp --completion=' + type);
20+
expect(stdout).toEqual(expected);
1721
done(err);
1822
}
1923
});
2024
});
2125

22-
lab.test('shows error message for unknown completion type', function(done) {
26+
it('shows error message for unknown completion type', function(done) {
27+
var expected =
28+
'echo "gulp autocompletion rules for \'unknown\' not found"\n';
29+
2330
runner({ verbose: false })
2431
.gulp('--completion=unknown')
2532
.run(cb);
2633

2734
function cb(err, stdout) {
28-
expect(stdout).to.contain('rules for \'unknown\' not found');
35+
expect(err).toExist();
36+
expect(stdout).toEqual(expected);
2937
done();
3038
}
3139
});

test/config.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var path = require('path');
65
var fs = require('fs');
76

@@ -12,10 +11,9 @@ var runner = require('gulp-test-tools').gulpRunner;
1211
var fixturesDir = path.join(__dirname, 'fixtures', 'config');
1312
var expectedDir = path.join(__dirname, 'expected', 'config');
1413

15-
lab.experiment('gulp configuration', function() {
14+
describe('gulp configuration', function() {
1615

17-
lab.test('Should configure with a .gulp.* file in cwd',
18-
function(done) {
16+
it('Should configure with a .gulp.* file in cwd', function(done) {
1917
runner({ verbose: false })
2018
.basedir(fixturesDir)
2119
.chdir('foo/bar')
@@ -26,13 +24,12 @@ lab.experiment('gulp configuration', function() {
2624
var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'),
2725
'utf-8');
2826
stdout = eraseTime(stdout);
29-
expect(stdout).to.equal(expected);
27+
expect(stdout).toEqual(expected);
3028
done(err);
3129
}
3230
});
3331

34-
lab.test('Should configure with a .gulp.* file in cwd found up',
35-
function(done) {
32+
it('Should configure with a .gulp.* file in cwd found up', function(done) {
3633
runner({ verbose: false })
3734
.basedir(fixturesDir)
3835
.chdir('foo/bar/baz')
@@ -43,13 +40,12 @@ lab.experiment('gulp configuration', function() {
4340
var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'),
4441
'utf-8');
4542
stdout = eraseTime(skipLines(stdout, 1));
46-
expect(stdout).to.equal(expected);
43+
expect(stdout).toEqual(expected);
4744
done(err);
4845
}
4946
});
5047

51-
lab.test('Should configure with a .gulp.* file in cwd by --cwd',
52-
function(done) {
48+
it('Should configure with a .gulp.* file in cwd by --cwd', function(done) {
5349
runner({ verbose: false })
5450
.basedir(fixturesDir)
5551
.chdir('qux')
@@ -60,7 +56,7 @@ lab.experiment('gulp configuration', function() {
6056
var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'),
6157
'utf-8');
6258
stdout = eraseTime(stdout);
63-
expect(stdout).to.equal(expected);
59+
expect(stdout).toEqual(expected);
6460
done(err);
6561
}
6662
});

test/exports-as-tasks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var fs = require('fs');
65
var path = require('path');
76
var skipLines = require('gulp-test-tools').skipLines;
@@ -11,9 +10,10 @@ var runner = require('gulp-test-tools').gulpRunner;
1110
var expectedDir = path.join(__dirname, 'expected');
1211

1312
// Long timeout is required because parse time is slow
14-
lab.experiment('exports as tasks', { timeout: 0 }, function() {
13+
describe('exports as tasks', function() {
14+
this.timeout(0);
1515

16-
lab.test('prints the task list', function(done) {
16+
it('prints the task list', function(done) {
1717
runner({ verbose: false })
1818
.gulp('--tasks',
1919
'--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js')
@@ -23,7 +23,7 @@ lab.experiment('exports as tasks', { timeout: 0 }, function() {
2323
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
2424
var expected = fs.readFileSync(filepath, 'utf-8');
2525
stdout = eraseTime(skipLines(stdout, 2));
26-
expect(stdout).to.equal(expected);
26+
expect(stdout).toEqual(expected);
2727
done();
2828
}
2929
});

test/flags-continue.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var runner = require('gulp-test-tools').gulpRunner;
65
var eraseTime = require('gulp-test-tools').eraseTime;
76
var eraseLapse = require('gulp-test-tools').eraseLapse;
87
var skipLines = require('gulp-test-tools').skipLines;
98
var headLines = require('gulp-test-tools').headLines;
109

11-
lab.experiment('flag: --continue', function() {
10+
describe('flag: --continue', function() {
1211

13-
lab.test('continues execution when flag is set', function(done) {
12+
it('continues execution when flag is set', function(done) {
1413
runner({ verbose: false })
1514
.gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles')
1615
.run(cb);
1716

1817
function cb(err, stdout, stderr) {
19-
expect(err).to.be.not.null();
18+
expect(err).toNotEqual(null);
2019

2120
stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
22-
expect(stdout).to.equal(
21+
expect(stdout).toEqual(
2322
'Starting \'test4\'...\n' +
2423
'Starting \'errorFunction\'...\n' +
2524
'Starting \'anon\'...\n' +
@@ -28,32 +27,32 @@ lab.experiment('flag: --continue', function() {
2827
);
2928

3029
stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
31-
expect(stderr).to.equal(
30+
expect(stderr).toEqual(
3231
'\'errorFunction\' errored after ?\n' +
3332
'Error: Error!'
3433
);
3534
done();
3635
}
3736
});
3837

39-
lab.test('stops execution when flag is not set', function(done) {
38+
it('stops execution when flag is not set', function(done) {
4039
runner({ verbose: false })
4140
.gulp('test4', '--cwd ./test/fixtures/gulpfiles')
4241
.run(cb);
4342

4443
function cb(err, stdout, stderr) {
45-
expect(err).to.be.not.null();
44+
expect(err).toNotEqual(null);
4645

47-
expect(stdout).to.not.contain('Starting \'anon\'');
46+
expect(stdout).toNotMatch('Starting \'anon\'');
4847
stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
49-
expect(stdout).to.equal(
48+
expect(stdout).toEqual(
5049
'Starting \'test4\'...\n' +
5150
'Starting \'errorFunction\'...\n' +
5251
''
5352
);
5453

5554
stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
56-
expect(stderr).to.equal(
55+
expect(stderr).toEqual(
5756
'\'errorFunction\' errored after ?\n' +
5857
'Error: Error!'
5958
);

test/flags-gulpfile.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var runner = require('gulp-test-tools').gulpRunner;
65
var skipLines = require('gulp-test-tools').skipLines;
76
var headLines = require('gulp-test-tools').headLines;
87
var eraseTime = require('gulp-test-tools').eraseTime;
98
var eraseLapse = require('gulp-test-tools').eraseLapse;
109
var path = require('path');
1110

12-
lab.experiment('flag: --gulpfile', function() {
11+
describe('flag: --gulpfile', function() {
1312

14-
lab.test('Manually set path of gulpfile', function(done) {
13+
it('Manually set path of gulpfile', function(done) {
1514
var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js';
1615

1716
runner({ verbose: false })
@@ -21,11 +20,11 @@ lab.experiment('flag: --gulpfile', function() {
2120
function cb(err, stdout) {
2221
var chgWorkdirLog = headLines(stdout, 1);
2322
var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep);
24-
expect(chgWorkdirLog).to.contain('Working directory changed to ');
25-
expect(chgWorkdirLog).to.contain(workdir);
23+
expect(chgWorkdirLog).toMatch('Working directory changed to ');
24+
expect(chgWorkdirLog).toMatch(workdir);
2625

2726
stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
28-
expect(stdout).to.equal(
27+
expect(stdout).toEqual(
2928
'Starting \'default\'...\n' +
3029
'Starting \'logGulpfilePath\'...\n' +
3130
path.resolve(gulpfilePath) + '\n' +

test/flags-help.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

3-
var lab = exports.lab = require('lab').script();
4-
var expect = require('code').expect;
3+
var expect = require('expect');
54
var runner = require('gulp-test-tools').gulpRunner;
65

76
var path = require('path');
@@ -15,28 +14,28 @@ function eraseFirstSpace(s) {
1514
var outputFile = path.join(__dirname, 'expected/flags-help.txt');
1615
var outputText = fs.readFileSync(outputFile, 'utf8');
1716

18-
lab.experiment('flag: --help', function() {
17+
describe('flag: --help', function() {
1918

20-
lab.test('shows help using --help', function(done) {
19+
it('shows help using --help', function(done) {
2120
runner({ verbose: false })
2221
.gulp('--help', '--cwd ./test/fixtures/gulpfiles')
2322
.run(cb);
2423

2524
function cb(err, stdout) {
2625
stdout = eraseFirstSpace(stdout);
27-
expect(stdout).to.equal(outputText);
26+
expect(stdout).toEqual(outputText);
2827
done(err);
2928
}
3029
});
3130

32-
lab.test('shows help using short --h', function(done) {
31+
it('shows help using short --h', function(done) {
3332
runner({ verbose: false })
3433
.gulp('--h', '--cwd ./test/fixtures/gulpfiles')
3534
.run(cb);
3635

3736
function cb(err, stdout) {
3837
stdout = eraseFirstSpace(stdout);
39-
expect(stdout).to.equal(outputText);
38+
expect(stdout).toEqual(outputText);
4039
done(err);
4140
}
4241
});

0 commit comments

Comments
 (0)