Skip to content

Commit

Permalink
Merge pull request #9 from Turbo87/jest
Browse files Browse the repository at this point in the history
Use Jest for testing
  • Loading branch information
Turbo87 authored Jun 10, 2018
2 parents 3511697 + 970905d commit e4fb306
Show file tree
Hide file tree
Showing 14 changed files with 2,375 additions and 906 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ node_js:
- "8"
- "10"

after_script:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
script:
# --color and --runInBand are necessary to ensure that `colors` work correctly
- yarn test --coverage --runInBand --color
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ console.log(table.toString());

## Build Targets

Clone the repository and run `npm install` to install all its submodules, then run one of the following commands:
Clone the repository and run `yarn install` to install all its submodules, then run one of the following commands:

###### Run the tests with coverage reports.
```bash
$ gulp coverage
$ yarn test:coverage
```

###### Run the tests every time a file changes.
```bash
$ gulp watch-test
$ yarn test:watch
```

###### Run the examples and print the output to the command line.
Expand Down
51 changes: 0 additions & 51 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
var gulp = require('gulp');
var gutil = require('gulp-util');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var printExample = require('./lib/print-example');

gulp.task('test',mochaTask);
gulp.task('coverage',coverage());
gulp.task('coverage-api',coverage({grep:'@api'}));

gulp.task('watch-test',function(){
gulp.watch(['test/**','src/**','examples/**'],['test']);
mochaTask();
});

gulp.task('example',function(){
printExample.logExample(require('./examples/basic-usage-examples'));
printExample.logExample(require('./examples/col-and-row-span-examples'));
Expand All @@ -29,44 +19,3 @@ gulp.task('example-md-basic',function(cb){
gulp.task('example-md-advanced',function(cb){
printExample.mdExample(require('./examples/col-and-row-span-examples'),'advanced-usage.md',cb);
});

function coverage(opts){
opts = opts || {};

function coverageTask(cb){
gulp.src(['src/*.js'])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('error', logMochaError)
.on('finish', function () {
gulp.src(['test/*.js'])
.pipe(mocha(opts))
.on('error',function(err){
logMochaError(err);
if(cb) cb(err);
})
.pipe(istanbul.writeReports()) // Creating the reports after tests run
.on('end', function(){
if(cb) cb();
});
});
}

return coverageTask;
}

function mochaTask(){
return gulp.src(['test/*.js'],{read:false})
.pipe(mocha({
growl:true
}))
.on('error',logMochaError);
}

function logMochaError(err){
if(err && err.message){
gutil.log(err.message);
} else {
gutil.log.apply(gutil,arguments);
}
}
4 changes: 1 addition & 3 deletions lib/print-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var chai = require('chai');
var expect = chai.expect;
var colors = require('colors/safe');
var fs = require('fs');
var git = require('git-rev');
Expand Down Expand Up @@ -61,7 +59,7 @@ function mdExample(fn,file,cb){
function runTest(name,fn){
function testExample(name,fn,expected){
it(name,function(){
expect(fn().toString()).to.equal(expected.join('\n'));
expect(fn().toString()).toEqual(expected.join('\n'));
});
}

Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@
},
"devDependencies": {
"ansi-256-colors": "^1.1.0",
"chai": "^3.4.1",
"cli-table": "^0.3.1",
"coveralls": "^2.11.4",
"git-rev": "^0.2.1",
"growl": "^1.8.1",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"gulp-util": "^3.0.7",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
"jest": "^23.1.0"
},
"optionalDependencies": {
"colors": "^1.1.2"
},
"scripts": {
"test": "gulp coverage"
"test": "jest --color",
"test:watch": "jest --color --watchAll --notify"
},
"repository": {
"type": "git",
Expand All @@ -59,5 +53,10 @@
"homepage": "https://github.com/cli-table/cli-table3",
"engines": {
"node": ">=6"
},
"jest": {
"testMatch": [
"**/test/**/*-test(s)?.js"
]
}
}
Loading

0 comments on commit e4fb306

Please sign in to comment.