From 3af4c42dee5d459b2aa7747e81a320aeae619f86 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 24 Dec 2016 22:42:14 +0900 Subject: [PATCH 1/6] Changes the test framework to mocha and expect --- .eslintignore | 1 + package.json | 11 +++--- test/completion.js | 13 ++++--- test/config.js | 20 +++++------ test/exports-as-tasks.js | 10 +++--- test/flags-continue.js | 23 ++++++------ test/flags-gulpfile.js | 13 ++++--- test/flags-help.js | 13 ++++--- test/flags-require.js | 31 ++++++++-------- test/flags-silent.js | 9 +++-- test/flags-tasks-json.js | 13 ++++--- test/flags-tasks-simple.js | 9 +++-- test/flags-tasks.js | 17 +++++---- test/flags-verify.js | 21 ++++++----- test/flags-version.js | 9 +++-- test/logging.js | 72 ++++++++++++++++++++++---------------- test/taskTree.js | 17 +++++---- 17 files changed, 149 insertions(+), 153 deletions(-) diff --git a/.eslintignore b/.eslintignore index 257888c9..c8fc7f56 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ **/*.babel.js +coverage diff --git a/package.json b/package.json index 2e826648..d76721e1 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "gulp.1" ], "scripts": { - "coveralls": "lab -r lcov | coveralls", + "coveralls": "istanbul cover _mocha --report --lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", "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 --reporter spec", "changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body" }, "dependencies": { @@ -54,18 +54,19 @@ "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", + "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" }, "keywords": [ "build", diff --git a/test/completion.js b/test/completion.js index d633ee01..0e3579ea 100644 --- a/test/completion.js +++ b/test/completion.js @@ -1,31 +1,30 @@ '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; -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) { runner({ verbose: false }) .gulp('--completion=' + type) .run(cb); function cb(err, stdout) { - expect(stdout).to.contain('gulp --completion=' + type); + expect(stdout).toMatch('gulp --completion=' + type); done(err); } }); }); - lab.test('shows error message for unknown completion type', function(done) { + it('shows error message for unknown completion type', function(done) { runner({ verbose: false }) .gulp('--completion=unknown') .run(cb); function cb(err, stdout) { - expect(stdout).to.contain('rules for \'unknown\' not found'); + expect(stdout).toMatch('rules for \'unknown\' not found'); done(); } }); diff --git a/test/config.js b/test/config.js index da14bb47..e2ce6c48 100644 --- a/test/config.js +++ b/test/config.js @@ -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'); @@ -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') @@ -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') @@ -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') @@ -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); } }); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 5b64f6fe..708287ac 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -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; @@ -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') @@ -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(); } }); diff --git a/test/flags-continue.js b/test/flags-continue.js index 331dccc8..1accdb8a 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -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).toNotBe(null); stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).to.equal( + expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + 'Starting \'anon\'...\n' + @@ -28,7 +27,7 @@ lab.experiment('flag: --continue', function() { ); stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).to.equal( + expect(stderr).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); @@ -36,24 +35,24 @@ lab.experiment('flag: --continue', function() { } }); - 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).toNotBe(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!' ); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 965130ff..f51b93e7 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -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 skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; @@ -9,9 +8,9 @@ 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 }) @@ -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' + diff --git a/test/flags-help.js b/test/flags-help.js index 01202bde..05f20f61 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -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'); @@ -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); } }); diff --git a/test/flags-require.js b/test/flags-require.js index 91ccd3a6..8af8ce88 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -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 skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; @@ -9,28 +8,28 @@ var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); -lab.experiment('flag: --require', function() { +describe('flag: --require', function() { - lab.test('requires module before running gulpfile', function(done) { + it('requires module before running gulpfile', function(done) { runner({ verbose: false }) .gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles') .run(cb); function cb(err, stdout) { var insideLog = headLines(stdout, 1); - expect(insideLog).to.equal('inside test module'); + expect(insideLog).toEqual('inside test module'); var requireLog = eraseTime(headLines(stdout, 1, 1)); - expect(requireLog).to.equal( + expect(requireLog).toEqual( 'Requiring external module ../test-module.js'); var chgWorkdirLog = headLines(stdout, 1, 2); var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).to.contains('Working directory changed to '); - expect(chgWorkdirLog).to.contains(workdir); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).to.equal( + expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + 'Starting \'noop\'...\n' + @@ -49,23 +48,23 @@ lab.experiment('flag: --require', function() { } }); - lab.test('errors if module doesn\'t exist', function(done) { + it('errors if module doesn\'t exist', function(done) { runner({ verbose: false }) .gulp('--require ./null-module.js', '--cwd ./test/fixtures/gulpfiles') .run(cb); function cb(err, stdout, stderr) { - expect(stdout).to.not.contain('inside test module'); - expect(stdout).to.not.contain( + expect(stdout).toNotMatch('inside test module'); + expect(stdout).toNotMatch( 'Requiring external module ../test-module.js'); var chgWorkdirLog = headLines(stdout, 1); var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).to.contains('Working directory changed to '); - expect(chgWorkdirLog).to.contains(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 \'test1\'...\n' + 'Starting \'noop\'...\n' + @@ -82,7 +81,7 @@ lab.experiment('flag: --require', function() { ); stderr = eraseTime(stderr); - expect(stderr).to.equal( + expect(stderr).toEqual( 'Failed to load external module ./null-module.js\n'); done(err); } diff --git a/test/flags-silent.js b/test/flags-silent.js index b524b770..4e422a27 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -1,18 +1,17 @@ '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; -lab.experiment('flag: --silent', function() { +describe('flag: --silent', function() { - lab.test('prints nothing when silent flag is set', function(done) { + it('prints nothing when silent flag is set', function(done) { runner({ verbose: false }) .gulp('--silent', '--cwd ./test/fixtures/gulpfiles') .run(cb); function cb(err, stdout) { - expect(stdout).to.equal(''); + expect(stdout).toEqual(''); done(err); } }); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 5ebd09a5..3816b02b 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -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-extra'); var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; @@ -9,21 +8,21 @@ var runner = require('gulp-test-tools').gulpRunner; var expected = require(path.join(__dirname, 'expected/flags-tasks-json.json')); -lab.experiment('flag: --tasks-json', function() { +describe('flag: --tasks-json', function() { - lab.test('prints the task list with no args', function(done) { + it('prints the task list with no args', function(done) { runner({ verbose: false }) .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile.js') .run(cb); function cb(err, stdout) { stdout = skipLines(stdout, 1); - expect(JSON.parse(stdout)).to.deep.equal(expected); + expect(JSON.parse(stdout)).toEqual(expected); done(); } }); - lab.test('writes the task list to file with path', function(done) { + it('writes the task list to file with path', function(done) { fs.emptyDir(__dirname + '/output/', function(err) { if (err) { return done(err); @@ -37,7 +36,7 @@ lab.experiment('flag: --tasks-json', function() { function cb(err) { var file = fs.readFileSync(__dirname + '/output/tasks.json', 'utf8'); var parsedJson = JSON.parse(file); - expect(parsedJson).to.deep.equal(expected); + expect(parsedJson).toEqual(expected); fs.removeSync(__dirname + '/output/'); done(err); } diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index 793620bf..3cc796e1 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -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'); var fs = require('fs'); @@ -9,15 +8,15 @@ var fs = require('fs'); var outputFile = path.join(__dirname, 'expected/flags-tasks-simple.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); -lab.experiment('flag: --tasks-simple', function() { +describe('flag: --tasks-simple', function() { - lab.test('prints the task list in simple format', function(done) { + it('prints the task list in simple format', function(done) { runner({ verbose: false }) .gulp('--tasks-simple', '--cwd ./test/fixtures/gulpfiles') .run(cb); function cb(err, stdout) { - expect(stdout).to.equal(outputText); + expect(stdout).toEqual(outputText); done(err); } }); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index c706c4e9..dc3959ba 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -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; @@ -10,9 +9,9 @@ var runner = require('gulp-test-tools').gulpRunner; var expectedDir = path.join(__dirname, 'expected'); -lab.experiment('flag: --tasks', function() { +describe('flag: --tasks', function() { - lab.test('prints the task list', function(done) { + it('prints the task list', function(done) { runner({ verbose: false }) .gulp('--tasks --cwd ./test/fixtures/gulpfiles') .run(cb); @@ -21,12 +20,12 @@ lab.experiment('flag: --tasks', function() { var filepath = path.join(expectedDir, 'flags-tasks.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).to.equal(expected); + expect(stdout).toEqual(expected); done(); } }); - lab.test('print the task list with description and flags', function(done) { + it('print the task list with description and flags', function(done) { runner({ verbose: false }) .gulp('--tasks', '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', @@ -37,12 +36,12 @@ lab.experiment('flag: --tasks', function() { var filepath = path.join(expectedDir, 'with-desc-and-flags.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).to.equal(expected); + expect(stdout).toEqual(expected); done(); } }); - lab.test('print the task list by gulp.task(s).unwrap and gulp.task(s)', + it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { runner({ verbose: false }) .gulp('--tasks', @@ -54,7 +53,7 @@ lab.experiment('flag: --tasks', function() { var filepath = path.join(expectedDir, 'by-unwrap-and-not-by-unwrap.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).to.equal(expected); + expect(stdout).toEqual(expected); done(); } }); diff --git a/test/flags-verify.js b/test/flags-verify.js index 27c9926a..493faf04 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -1,23 +1,22 @@ '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 path = require('path'); -lab.experiment('flag: --verify', function() { +describe('flag: --verify', function() { - lab.test('dependencies with invalid dependency', function(done) { + it('dependencies with invalid dependency', function(done) { runner({ verbose: false }) .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/packages/') .run(cb); function cb(err, stdout) { - expect(err).to.be.not.null(); + expect(err).toNotBe(null); stdout = eraseTime(stdout); - expect(stdout).to.equal( + expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/invalid-package.json') + '\n' + @@ -29,14 +28,14 @@ lab.experiment('flag: --verify', function() { } }); - lab.test('dependencies with valid dependency', function(done) { + it('dependencies with valid dependency', function(done) { runner({ verbose: false }) .gulp('--verify valid-package.json', '--cwd ./test/fixtures/packages/') .run(cb); function cb(err, stdout) { stdout = eraseTime(stdout); - expect(stdout).to.equal( + expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/valid-package.json') + '\n' + @@ -47,16 +46,16 @@ lab.experiment('flag: --verify', function() { } }); - lab.test('default args with invalid dependency', function(done) { + it('default args with invalid dependency', function(done) { runner({ verbose: false }) .gulp('--verify', '--cwd ./test/fixtures/packages/') .run(cb); function cb(err, stdout) { - expect(err).to.be.not.null(); + expect(err).toNotBe(null); stdout = eraseTime(stdout); - expect(stdout).to.equal( + expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + diff --git a/test/flags-version.js b/test/flags-version.js index 792a3cf7..4186a7c7 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -1,23 +1,22 @@ '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 cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; -lab.experiment('flag: --version', function() { +describe('flag: --version', function() { - lab.test('prints the version of CLI and local gulp', function(done) { + it('prints the version of CLI and local gulp', function(done) { runner({ verbose: false }) .gulp('--version --cwd ./test/fixtures/gulpfiles') .run(cb); function cb(err, stdout) { stdout = eraseTime(stdout); - expect(stdout).to.equal( + expect(stdout).toEqual( 'CLI version ' + cliVersion + '\n' + 'Local version ' + gulpVersion + '\n' + '' diff --git a/test/logging.js b/test/logging.js index eb12e681..17127996 100644 --- a/test/logging.js +++ b/test/logging.js @@ -1,54 +1,64 @@ 'use strict'; -var lab = exports.lab = require('lab').script(); -var code = require('code'); +var expect = require('expect'); var child = require('child_process'); -lab.experiment('logging', function() { - lab.test('log-level flag for debug: -LLLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', function(err, stdout, stderr) { +describe('logging', function() { + + it('log-level flag for debug: -LLLL', function(done) { + child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); + + function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); - code.expect(stdout[0]).to.contain('test debug'); - code.expect(stdout[1]).to.contain('test info'); - code.expect(stdout[2]).to.contain('test warn'); - code.expect(stderr).to.contain('test error'); + expect(stdout[0]).toMatch('test debug'); + expect(stdout[1]).toMatch('test info'); + expect(stdout[2]).toMatch('test warn'); + expect(stderr).toMatch('test error'); done(err); - }); + } }); - lab.test('no log-level flag: defaults to -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js', function(err, stdout, stderr) { + it('no log-level flag: defaults to -LLL', function(done) { + child.exec('node ' + __dirname + '/fixtures/logging.js', cb); + + function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); - code.expect(stdout[0]).to.contain('test info'); - code.expect(stdout[1]).to.contain('test warn'); - code.expect(stderr).to.contain('test error'); + expect(stdout[0]).toMatch('test info'); + expect(stdout[1]).toMatch('test warn'); + expect(stderr).toMatch('test error'); done(err); - }); + } }); - lab.test('log-level flag for info: -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', function(err, stdout, stderr) { + it('log-level flag for info: -LLL', function(done) { + child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); + + function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); - code.expect(stdout[0]).to.contain('test info'); - code.expect(stdout[1]).to.contain('test warn'); - code.expect(stderr).to.contain('test error'); + expect(stdout[0]).toMatch('test info'); + expect(stdout[1]).toMatch('test warn'); + expect(stderr).toMatch('test error'); done(err); - }); + } }); - lab.test('log-level flag for warn: -LL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LL', function(err, stdout, stderr) { + it('log-level flag for warn: -LL', function(done) { + child.exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); + + function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); - code.expect(stdout[0]).to.contain('test warn'); - code.expect(stderr).to.contain('test error'); + expect(stdout[0]).toMatch('test warn'); + expect(stderr).toMatch('test error'); done(err); - }); + } }); - lab.test('log-level flag for error: -L', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -L', function(err, stdout, stderr) { - code.expect(stderr).to.contain('test error'); + it('log-level flag for error: -L', function(done) { + child.exec('node ' + __dirname + '/fixtures/logging.js -L', cb); + + function cb(err, stdout, stderr) { + expect(stderr).toMatch('test error'); done(err); - }); + } }); }); diff --git a/test/taskTree.js b/test/taskTree.js index 7b4e4276..8345c7a9 100644 --- a/test/taskTree.js +++ b/test/taskTree.js @@ -1,14 +1,13 @@ 'use strict'; -var lab = exports.lab = require('lab').script(); -var code = require('code'); +var expect = require('expect'); var taskTree = require('../lib/versioned/^3.7.0/taskTree'); -lab.experiment('taskTree()', function() { +describe('taskTree', function() { - lab.test('forms a tree properly', function(done) { - code.expect(taskTree).to.exist(); // Lol shutup jshint + it('forms a tree properly', function(done) { + expect(taskTree).toExist(); // Lol shutup jshint var tasks = { test: { @@ -45,11 +44,11 @@ lab.experiment('taskTree()', function() { ], }; - code.expect(taskTree(tasks)).to.deep.equal(expectTree); + expect(taskTree(tasks)).toEqual(expectTree); done(); }); - lab.test('processes children recursively.', function(done) { + it('processes children recursively.', function(done) { var tasks = { test: { dep: ['test2', 'test3'], @@ -87,7 +86,7 @@ lab.experiment('taskTree()', function() { label: 'test2', nodes: [ { - label: 'dep3', + label: 'test3', nodes: [], }, ], @@ -99,7 +98,7 @@ lab.experiment('taskTree()', function() { ], }; - code.expect(taskTree(tasks)).to.deep.equal(expectTree); + expect(taskTree(tasks)).toEqual(expectTree); done(); }); }); From 445395c6c338c67a28d201478de2ef7ebb50ffe3 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 25 Dec 2016 19:48:35 +0900 Subject: [PATCH 2/6] Enables to measure coverage of executions on child processes --- .gitignore | 1 + package.json | 5 +++-- test/logging.js | 28 +++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a8e1073d..3459bf3a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build *.node components coverage +.coveralls.yml *.orig .idea sandbox diff --git a/package.json b/package.json index d76721e1..79901205 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,12 @@ "gulp.1" ], "scripts": { - "coveralls": "istanbul cover _mocha --report --lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", "lint": "eslint . && jscs index.js bin/ lib/ test/", "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --reporter spec", + "coverage": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcov text-summary", + "coveralls": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", "changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body" }, "dependencies": { @@ -61,7 +62,7 @@ "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", diff --git a/test/logging.js b/test/logging.js index 17127996..406726bc 100644 --- a/test/logging.js +++ b/test/logging.js @@ -2,11 +2,29 @@ var expect = require('expect'); var child = require('child_process'); +var path = require('path'); + +// jscs:disable requireCamelCaseOrUpperCaseIdentifiers +var isIstanbul = process.env.running_under_istanbul; +// jscs:enable + +var cmd; +if (isIstanbul) { + cmd = path.resolve(__dirname, '../node_modules/.bin/istanbul') + + ' cover --root ' + path.dirname(__dirname) + + ' ' + __dirname + '/fixtures/logging.js' + + ' --dir ' + path.dirname(__dirname) + '/coverage/logging' + + ' --print none' + + ' --'; +} else { + cmd = 'node ' + __dirname + '/fixtures/logging.js'; +} + describe('logging', function() { it('log-level flag for debug: -LLLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); + child.exec(cmd + ' -LLLL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -19,7 +37,7 @@ describe('logging', function() { }); it('no log-level flag: defaults to -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js', cb); + child.exec(cmd, cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -31,7 +49,7 @@ describe('logging', function() { }); it('log-level flag for info: -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); + child.exec(cmd + ' -LLL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -43,7 +61,7 @@ describe('logging', function() { }); it('log-level flag for warn: -LL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); + child.exec(cmd + ' -LL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -54,7 +72,7 @@ describe('logging', function() { }); it('log-level flag for error: -L', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -L', cb); + child.exec(cmd + ' -L', cb); function cb(err, stdout, stderr) { expect(stderr).toMatch('test error'); From 87c3b7425d5a99f2a14e2f366cb71e04b432445b Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 25 Dec 2016 22:41:44 +0900 Subject: [PATCH 3/6] Modify appveyor.yml for test on Windows --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index f6c6f3e3..ab5e2da0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 From de4045fce50cc461bd7713d612a89abf323d3b59 Mon Sep 17 00:00:00 2001 From: sttk Date: Thu, 29 Dec 2016 19:19:10 +0900 Subject: [PATCH 4/6] Modify some matters pointed out --- package.json | 2 +- test/completion.js | 13 +++++++++++-- test/flags-continue.js | 4 ++-- test/flags-verify.js | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 79901205..c1324bb6 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lint": "eslint . && jscs index.js bin/ lib/ test/", "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", - "test": "mocha --reporter spec", + "test": "mocha --async-only", "coverage": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcov text-summary", "coveralls": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", "changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body" diff --git a/test/completion.js b/test/completion.js index 0e3579ea..47aa8d02 100644 --- a/test/completion.js +++ b/test/completion.js @@ -2,29 +2,38 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; +var path = require('path'); +var fs = require('fs'); describe('flag: --completion', function() { ['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) { 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).toMatch('gulp --completion=' + type); + expect(stdout).toEqual(expected); done(err); } }); }); 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).toMatch('rules for \'unknown\' not found'); + expect(err).toExist(); + expect(stdout).toEqual(expected); done(); } }); diff --git a/test/flags-continue.js b/test/flags-continue.js index 1accdb8a..b5013d1c 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -15,7 +15,7 @@ describe('flag: --continue', function() { .run(cb); function cb(err, stdout, stderr) { - expect(err).toNotBe(null); + expect(err).toNotEqual(null); stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( @@ -41,7 +41,7 @@ describe('flag: --continue', function() { .run(cb); function cb(err, stdout, stderr) { - expect(err).toNotBe(null); + expect(err).toNotEqual(null); expect(stdout).toNotMatch('Starting \'anon\''); stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); diff --git a/test/flags-verify.js b/test/flags-verify.js index 493faf04..9a3a0af5 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -13,7 +13,7 @@ describe('flag: --verify', function() { .run(cb); function cb(err, stdout) { - expect(err).toNotBe(null); + expect(err).toNotEqual(null); stdout = eraseTime(stdout); expect(stdout).toEqual( @@ -52,7 +52,7 @@ describe('flag: --verify', function() { .run(cb); function cb(err, stdout) { - expect(err).toNotBe(null); + expect(err).toNotEqual(null); stdout = eraseTime(stdout); expect(stdout).toEqual( From ce893f0591541d682c9d3e34ea10f259d7a1b6c1 Mon Sep 17 00:00:00 2001 From: sttk Date: Wed, 4 Jan 2017 23:41:13 +0900 Subject: [PATCH 5/6] Use nyc for coverage --- .gitignore | 1 + package.json | 7 ++++--- test/logging.js | 28 +++++----------------------- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 3459bf3a..f2f8f37a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build components coverage .coveralls.yml +.nyc_output *.orig .idea sandbox diff --git a/package.json b/package.json index c1324bb6..e464f174 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only", - "coverage": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcov text-summary", - "coveralls": "rm -rf ./coverage && istanbul cover _mocha --print none && istanbul report lcovonly && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", + "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": { @@ -67,7 +67,8 @@ "jscs": "^2.3.5", "jscs-preset-gulp": "^1.0.0", "marked-man": "^0.1.3", - "mocha": "^3.2.0" + "mocha": "^3.2.0", + "nyc": "^10.0.0" }, "keywords": [ "build", diff --git a/test/logging.js b/test/logging.js index 406726bc..17127996 100644 --- a/test/logging.js +++ b/test/logging.js @@ -2,29 +2,11 @@ var expect = require('expect'); var child = require('child_process'); -var path = require('path'); - -// jscs:disable requireCamelCaseOrUpperCaseIdentifiers -var isIstanbul = process.env.running_under_istanbul; -// jscs:enable - -var cmd; -if (isIstanbul) { - cmd = path.resolve(__dirname, '../node_modules/.bin/istanbul') + - ' cover --root ' + path.dirname(__dirname) + - ' ' + __dirname + '/fixtures/logging.js' + - ' --dir ' + path.dirname(__dirname) + '/coverage/logging' + - ' --print none' + - ' --'; -} else { - cmd = 'node ' + __dirname + '/fixtures/logging.js'; -} - describe('logging', function() { it('log-level flag for debug: -LLLL', function(done) { - child.exec(cmd + ' -LLLL', cb); + child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -37,7 +19,7 @@ describe('logging', function() { }); it('no log-level flag: defaults to -LLL', function(done) { - child.exec(cmd, cb); + child.exec('node ' + __dirname + '/fixtures/logging.js', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -49,7 +31,7 @@ describe('logging', function() { }); it('log-level flag for info: -LLL', function(done) { - child.exec(cmd + ' -LLL', cb); + child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -61,7 +43,7 @@ describe('logging', function() { }); it('log-level flag for warn: -LL', function(done) { - child.exec(cmd + ' -LL', cb); + child.exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); function cb(err, stdout, stderr) { stdout = stdout.replace(/\\/g, '/').split('\n'); @@ -72,7 +54,7 @@ describe('logging', function() { }); it('log-level flag for error: -L', function(done) { - child.exec(cmd + ' -L', cb); + child.exec('node ' + __dirname + '/fixtures/logging.js -L', cb); function cb(err, stdout, stderr) { expect(stderr).toMatch('test error'); From 6f308698a47ce071918e53641842f726c78d4f01 Mon Sep 17 00:00:00 2001 From: sttk Date: Thu, 5 Jan 2017 00:29:06 +0900 Subject: [PATCH 6/6] Change timeout to 3000ms --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e464f174..5e316222 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lint": "eslint . && jscs index.js bin/ lib/ test/", "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", - "test": "mocha --async-only", + "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"