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

Commit 753ee95

Browse files
authored
Merge pull request #62 from FountainJS/add-tests
Add tests
2 parents 08df3cf + fc49ece commit 753ee95

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
coverage
3+
.nyc_output

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
language: node_js
22
node_js:
33
- 'stable'
4+
after_success:
5+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
</p>
66

77
# Fountain Webapp Generator
8-
[![Build Status](https://travis-ci.org/FountainJS/fountain.svg?branch=master)](https://travis-ci.org/FountainJS/fountain)
8+
[![Build Status](https://travis-ci.org/FountainJS/generator-fountain-webapp.svg?branch=master)](https://travis-ci.org/FountainJS/generator-fountain-webapp)
9+
[![codecov](https://codecov.io/gh/FountainJS/generator-fountain-webapp/branch/master/graph/badge.svg)](https://codecov.io/gh/FountainJS/generator-fountain-webapp)
910
[![Slack](http://fountainjs.io/assets/imgs/slack_badge.png)](https://fountain-slack.herokuapp.com/)
1011
[![OpenCollective](https://opencollective.com/fountainjs/backers/badge.svg)](#backers)
1112
[![OpenCollective](https://opencollective.com/fountainjs/sponsors/badge.svg)](#sponsors)

gulpfile.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
const path = require('path');
44
const gulp = require('gulp');
55
const eslint = require('gulp-eslint');
6+
const spawn = require('cross-spawn');
67
const excludeGitignore = require('gulp-exclude-gitignore');
7-
const mocha = require('gulp-mocha');
8-
const istanbul = require('gulp-istanbul');
98
const nsp = require('gulp-nsp');
10-
const plumber = require('gulp-plumber');
119

1210
gulp.task('nsp', nodeSecurityProtocol);
1311
gulp.task('watch', watch);
1412
gulp.task('static', eslintCheck);
15-
gulp.task('pre-test', istanbulCover);
16-
gulp.task('test', gulp.series('pre-test', mochaTest));
13+
gulp.task('test', gulp.series([avaTest, nycReport]));
1714

1815
gulp.task('prepublish', gulp.series('nsp'));
1916
gulp.task('default', gulp.series('static', 'test'));
@@ -30,25 +27,14 @@ function eslintCheck() {
3027
.pipe(eslint.failAfterError());
3128
}
3229

33-
function istanbulCover() {
34-
return gulp.src(['**/*.js', '!**/templates/**'])
35-
.pipe(excludeGitignore())
36-
.pipe(istanbul({
37-
includeUntested: true
38-
}))
39-
.pipe(istanbul.hookRequire());
30+
function avaTest() {
31+
return spawn('./node_modules/.bin/nyc', ['--all', '--reporter=lcov', './node_modules/.bin/ava'], {stdio: 'inherit'});
4032
}
4133

42-
function mochaTest() {
43-
return gulp.src('test/**/*.js')
44-
.pipe(plumber())
45-
.pipe(mocha({reporter: 'spec'}))
46-
.once('error', () => {
47-
process.exit(1);
48-
})
49-
.pipe(istanbul.writeReports());
34+
function nycReport() {
35+
return spawn('./node_modules/.bin/nyc', ['report', '--colors'], {stdio: 'inherit'});
5036
}
5137

5238
function watch() {
53-
gulp.watch('**/*.js', ['test']);
39+
return spawn('./node_modules/.bin/nyc', ['--all', '--reporter=lcov', './node_modules/.bin/ava', '--watch'], {stdio: 'inherit'});
5440
}

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,27 @@
3333
"yosay": "^1.1.1"
3434
},
3535
"devDependencies": {
36+
"ava": "^0.15.2",
3637
"babel-eslint": "^6.0.2",
38+
"chai": "^3.5.0",
39+
"chai-spies": "^0.7.1",
40+
"cross-spawn": "^4.0.0",
3741
"eslint": "^2.7.0",
3842
"eslint-config-xo-space": "^0.12.0",
3943
"eslint-plugin-babel": "^3.2.0",
4044
"gulp": "gulpjs/gulp#4.0",
4145
"gulp-eslint": "^2.0.0",
4246
"gulp-exclude-gitignore": "^1.0.0",
43-
"gulp-istanbul": "^0.10.2",
44-
"gulp-mocha": "^2.1.3",
4547
"gulp-nsp": "^2.3.0",
46-
"gulp-plumber": "^1.0.1"
48+
"nyc": "^6.6.1"
49+
},
50+
"nyc": {
51+
"include": [
52+
"generators/**/*.js"
53+
],
54+
"exclude": [
55+
"generators/**/templates/**"
56+
]
4757
},
4858
"scripts": {
4959
"test": "gulp",

test/app/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const chai = require('chai');
2+
const spies = require('chai-spies');
3+
const expect = chai.expect;
4+
const should = chai.should(); // eslint-disable-line no-unused-vars
5+
chai.use(spies);
6+
const test = require('ava');
7+
const TestUtils = require('fountain-generator').TestUtils;
8+
9+
let context;
10+
11+
test.before(() => {
12+
context = TestUtils.mock('app');
13+
require('../../generators/app/index');
14+
process.chdir('../../');
15+
});
16+
17+
test(`Call this.log when 'skip-welcome-message' is undefined`, () => {
18+
context.log = () => {};
19+
const spy = chai.spy.on(context, 'log');
20+
TestUtils.call(context, 'initializing');
21+
expect(spy).to.have.been.called.twice();
22+
});
23+
24+
test(`Not call this.log when 'skip-welcome-message' is true`, () => {
25+
context.log = () => {};
26+
const spy = chai.spy.on(context, 'log');
27+
TestUtils.call(context, 'initializing', {'skip-welcome-message': true});
28+
spy.should.have.not.been.called();
29+
});
30+
31+
test('Call this.fountainPrompting', () => {
32+
context.fountainPrompting = () => {};
33+
const spy = chai.spy.on(context, 'fountainPrompting');
34+
TestUtils.call(context, 'prompting');
35+
expect(spy).to.have.been.called.once();
36+
});
37+
38+
test('composing(): Call this.composeWith', () => {
39+
context.composeWith = () => {};
40+
const spy = chai.spy.on(context, 'composeWith');
41+
TestUtils.call(context, 'composing', {framework: 'react'});
42+
expect(spy).to.have.been.called.with('fountain-react');
43+
});

0 commit comments

Comments
 (0)