Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #62 from FountainJS/add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
Swiip authored Jun 28, 2016
2 parents 08df3cf + fc49ece commit 753ee95
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
.nyc_output
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language: node_js
node_js:
- 'stable'
after_success:
- bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
</p>

# 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)
Expand Down
28 changes: 7 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'});
}
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions test/app/index.js
Original file line number Diff line number Diff line change
@@ -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');
});

0 comments on commit 753ee95

Please sign in to comment.