diff --git a/.gitignore b/.gitignore index ba2a97b..1fd04da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules coverage +.nyc_output diff --git a/.travis.yml b/.travis.yml index a4d679c..092d629 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: node_js node_js: - 'stable' +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index a89b658..49c7481 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@

# Fountain Webapp Generator -[![Build Status](https://travis-ci.org/FountainJS/fountain.svg?branch=master)](https://travis-ci.org/FountainJS/fountain) +[![Build Status](https://travis-ci.org/FountainJS/generator-fountain-webapp.svg?branch=master)](https://travis-ci.org/FountainJS/generator-fountain-webapp) +[![codecov](https://codecov.io/gh/FountainJS/generator-fountain-webapp/branch/master/graph/badge.svg)](https://codecov.io/gh/FountainJS/generator-fountain-webapp) [![Slack](http://fountainjs.io/assets/imgs/slack_badge.png)](https://fountain-slack.herokuapp.com/) [![OpenCollective](https://opencollective.com/fountainjs/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/fountainjs/sponsors/badge.svg)](#sponsors) diff --git a/gulpfile.js b/gulpfile.js index 92b8e13..a908fe6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,17 +3,14 @@ const path = require('path'); const gulp = require('gulp'); const eslint = require('gulp-eslint'); +const spawn = require('cross-spawn'); const excludeGitignore = require('gulp-exclude-gitignore'); -const mocha = require('gulp-mocha'); -const istanbul = require('gulp-istanbul'); const nsp = require('gulp-nsp'); -const plumber = require('gulp-plumber'); gulp.task('nsp', nodeSecurityProtocol); gulp.task('watch', watch); gulp.task('static', eslintCheck); -gulp.task('pre-test', istanbulCover); -gulp.task('test', gulp.series('pre-test', mochaTest)); +gulp.task('test', gulp.series([avaTest, nycReport])); gulp.task('prepublish', gulp.series('nsp')); gulp.task('default', gulp.series('static', 'test')); @@ -30,25 +27,14 @@ function eslintCheck() { .pipe(eslint.failAfterError()); } -function istanbulCover() { - return gulp.src(['**/*.js', '!**/templates/**']) - .pipe(excludeGitignore()) - .pipe(istanbul({ - includeUntested: true - })) - .pipe(istanbul.hookRequire()); +function avaTest() { + return spawn('./node_modules/.bin/nyc', ['--all', '--reporter=lcov', './node_modules/.bin/ava'], {stdio: 'inherit'}); } -function mochaTest() { - return gulp.src('test/**/*.js') - .pipe(plumber()) - .pipe(mocha({reporter: 'spec'})) - .once('error', () => { - process.exit(1); - }) - .pipe(istanbul.writeReports()); +function nycReport() { + return spawn('./node_modules/.bin/nyc', ['report', '--colors'], {stdio: 'inherit'}); } function watch() { - gulp.watch('**/*.js', ['test']); + return spawn('./node_modules/.bin/nyc', ['--all', '--reporter=lcov', './node_modules/.bin/ava', '--watch'], {stdio: 'inherit'}); } diff --git a/package.json b/package.json index 6692dfd..358f01b 100644 --- a/package.json +++ b/package.json @@ -33,17 +33,27 @@ "yosay": "^1.1.1" }, "devDependencies": { + "ava": "^0.15.2", "babel-eslint": "^6.0.2", + "chai": "^3.5.0", + "chai-spies": "^0.7.1", + "cross-spawn": "^4.0.0", "eslint": "^2.7.0", "eslint-config-xo-space": "^0.12.0", "eslint-plugin-babel": "^3.2.0", "gulp": "gulpjs/gulp#4.0", "gulp-eslint": "^2.0.0", "gulp-exclude-gitignore": "^1.0.0", - "gulp-istanbul": "^0.10.2", - "gulp-mocha": "^2.1.3", "gulp-nsp": "^2.3.0", - "gulp-plumber": "^1.0.1" + "nyc": "^6.6.1" + }, + "nyc": { + "include": [ + "generators/**/*.js" + ], + "exclude": [ + "generators/**/templates/**" + ] }, "scripts": { "test": "gulp", diff --git a/test/app/index.js b/test/app/index.js new file mode 100644 index 0000000..6fc7481 --- /dev/null +++ b/test/app/index.js @@ -0,0 +1,43 @@ +const chai = require('chai'); +const spies = require('chai-spies'); +const expect = chai.expect; +const should = chai.should(); // eslint-disable-line no-unused-vars +chai.use(spies); +const test = require('ava'); +const TestUtils = require('fountain-generator').TestUtils; + +let context; + +test.before(() => { + context = TestUtils.mock('app'); + require('../../generators/app/index'); + process.chdir('../../'); +}); + +test(`Call this.log when 'skip-welcome-message' is undefined`, () => { + context.log = () => {}; + const spy = chai.spy.on(context, 'log'); + TestUtils.call(context, 'initializing'); + expect(spy).to.have.been.called.twice(); +}); + +test(`Not call this.log when 'skip-welcome-message' is true`, () => { + context.log = () => {}; + const spy = chai.spy.on(context, 'log'); + TestUtils.call(context, 'initializing', {'skip-welcome-message': true}); + spy.should.have.not.been.called(); +}); + +test('Call this.fountainPrompting', () => { + context.fountainPrompting = () => {}; + const spy = chai.spy.on(context, 'fountainPrompting'); + TestUtils.call(context, 'prompting'); + expect(spy).to.have.been.called.once(); +}); + +test('composing(): Call this.composeWith', () => { + context.composeWith = () => {}; + const spy = chai.spy.on(context, 'composeWith'); + TestUtils.call(context, 'composing', {framework: 'react'}); + expect(spy).to.have.been.called.with('fountain-react'); +});