Skip to content

Commit

Permalink
Update: Switch test frameworks to mocha, expect and nyc (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored and phated committed Dec 21, 2017
1 parent 66c67e1 commit 97c7f47
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 155 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/*.babel.js
coverage
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build
*.node
components
coverage
.coveralls.yml
.nyc_output
*.orig
.idea
sandbox
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install:
test_script:
- node --version
- npm --version
- for %%f in (test\*.js) do node_modules\.bin\lab %%f -v -m 5000 -I Reflect & if errorlevel 1 exit /b 1
- npm test

build: off

Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"gulp.1"
],
"scripts": {
"coveralls": "lab -r lcov | coveralls",
"lint": "eslint . && jscs index.js bin/ lib/ test/",
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
"pretest": "npm run lint",
"test": "lab test/*.js -cv -I Reflect",
"test": "mocha --async-only --timeout 3000",
"cover": "nyc --reporter=lcov --reporter=text-summary npm test",
"coveralls": "nyc --reporter=text-lcov npm test | coveralls",
"changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body"
},
"dependencies": {
Expand All @@ -54,18 +55,20 @@
"devDependencies": {
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.1",
"code": "^1.2.1",
"coveralls": "^2.7.0",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"expect": "^1.20.2",
"fs-extra": "^0.26.1",
"github-changes": "^1.0.1",
"gulp": "gulpjs/gulp#4.0",
"gulp-test-tools": "^0.5.2",
"gulp-test-tools": "^0.6.0",
"istanbul": "^0.4.5",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"lab": "^6.2.0",
"marked-man": "^0.1.3"
"marked-man": "^0.1.3",
"mocha": "^3.2.0",
"nyc": "^10.0.0"
},
"keywords": [
"build",
Expand Down
22 changes: 15 additions & 7 deletions test/completion.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var runner = require('gulp-test-tools').gulpRunner;
var path = require('path');
var fs = require('fs');

lab.experiment('flag: --completion', function() {
describe('flag: --completion', function() {

['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) {
lab.test('returns completion script for ' + type, function(done) {
it('returns completion script for ' + type, function(done) {
var file = path.resolve(__dirname, '../completion', type);
var expected = fs.readFileSync(file, 'utf8') + '\n';

runner({ verbose: false })
.gulp('--completion=' + type)
.run(cb);

function cb(err, stdout) {
expect(stdout).to.contain('gulp --completion=' + type);
expect(stdout).toEqual(expected);
done(err);
}
});
});

lab.test('shows error message for unknown completion type', function(done) {
it('shows error message for unknown completion type', function(done) {
var expected =
'echo "gulp autocompletion rules for \'unknown\' not found"\n';

runner({ verbose: false })
.gulp('--completion=unknown')
.run(cb);

function cb(err, stdout) {
expect(stdout).to.contain('rules for \'unknown\' not found');
expect(err).toExist();
expect(stdout).toEqual(expected);
done();
}
});
Expand Down
20 changes: 8 additions & 12 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var path = require('path');
var fs = require('fs');

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

lab.experiment('gulp configuration', function() {
describe('gulp configuration', function() {

lab.test('Should configure with a .gulp.* file in cwd',
function(done) {
it('Should configure with a .gulp.* file in cwd', function(done) {
runner({ verbose: false })
.basedir(fixturesDir)
.chdir('foo/bar')
Expand All @@ -26,13 +24,12 @@ lab.experiment('gulp configuration', function() {
var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'),
'utf-8');
stdout = eraseTime(stdout);
expect(stdout).to.equal(expected);
expect(stdout).toEqual(expected);
done(err);
}
});

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

lab.test('Should configure with a .gulp.* file in cwd by --cwd',
function(done) {
it('Should configure with a .gulp.* file in cwd by --cwd', function(done) {
runner({ verbose: false })
.basedir(fixturesDir)
.chdir('qux')
Expand All @@ -60,7 +56,7 @@ lab.experiment('gulp configuration', function() {
var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'),
'utf-8');
stdout = eraseTime(stdout);
expect(stdout).to.equal(expected);
expect(stdout).toEqual(expected);
done(err);
}
});
Expand Down
10 changes: 5 additions & 5 deletions test/exports-as-tasks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var fs = require('fs');
var path = require('path');
var skipLines = require('gulp-test-tools').skipLines;
Expand All @@ -11,9 +10,10 @@ var runner = require('gulp-test-tools').gulpRunner;
var expectedDir = path.join(__dirname, 'expected');

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

lab.test('prints the task list', function(done) {
it('prints the task list', function(done) {
runner({ verbose: false })
.gulp('--tasks',
'--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js')
Expand All @@ -23,7 +23,7 @@ lab.experiment('exports as tasks', { timeout: 0 }, function() {
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 2));
expect(stdout).to.equal(expected);
expect(stdout).toEqual(expected);
done();
}
});
Expand Down
23 changes: 11 additions & 12 deletions test/flags-continue.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var runner = require('gulp-test-tools').gulpRunner;
var eraseTime = require('gulp-test-tools').eraseTime;
var eraseLapse = require('gulp-test-tools').eraseLapse;
var skipLines = require('gulp-test-tools').skipLines;
var headLines = require('gulp-test-tools').headLines;

lab.experiment('flag: --continue', function() {
describe('flag: --continue', function() {

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

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

stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
expect(stdout).to.equal(
expect(stdout).toEqual(
'Starting \'test4\'...\n' +
'Starting \'errorFunction\'...\n' +
'Starting \'anon\'...\n' +
Expand All @@ -28,32 +27,32 @@ lab.experiment('flag: --continue', function() {
);

stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
expect(stderr).to.equal(
expect(stderr).toEqual(
'\'errorFunction\' errored after ?\n' +
'Error: Error!'
);
done();
}
});

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

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

expect(stdout).to.not.contain('Starting \'anon\'');
expect(stdout).toNotMatch('Starting \'anon\'');
stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
expect(stdout).to.equal(
expect(stdout).toEqual(
'Starting \'test4\'...\n' +
'Starting \'errorFunction\'...\n' +
''
);

stderr = eraseLapse(eraseTime(headLines(stderr, 2)));
expect(stderr).to.equal(
expect(stderr).toEqual(
'\'errorFunction\' errored after ?\n' +
'Error: Error!'
);
Expand Down
13 changes: 6 additions & 7 deletions test/flags-gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var runner = require('gulp-test-tools').gulpRunner;
var skipLines = require('gulp-test-tools').skipLines;
var headLines = require('gulp-test-tools').headLines;
var eraseTime = require('gulp-test-tools').eraseTime;
var eraseLapse = require('gulp-test-tools').eraseLapse;
var path = require('path');

lab.experiment('flag: --gulpfile', function() {
describe('flag: --gulpfile', function() {

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

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

stdout = eraseLapse(eraseTime(skipLines(stdout, 2)));
expect(stdout).to.equal(
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Starting \'logGulpfilePath\'...\n' +
path.resolve(gulpfilePath) + '\n' +
Expand Down
13 changes: 6 additions & 7 deletions test/flags-help.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var lab = exports.lab = require('lab').script();
var expect = require('code').expect;
var expect = require('expect');
var runner = require('gulp-test-tools').gulpRunner;

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

lab.experiment('flag: --help', function() {
describe('flag: --help', function() {

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

function cb(err, stdout) {
stdout = eraseFirstSpace(stdout);
expect(stdout).to.equal(outputText);
expect(stdout).toEqual(outputText);
done(err);
}
});

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

function cb(err, stdout) {
stdout = eraseFirstSpace(stdout);
expect(stdout).to.equal(outputText);
expect(stdout).toEqual(outputText);
done(err);
}
});
Expand Down
Loading

0 comments on commit 97c7f47

Please sign in to comment.