├── README.md
├── jasmine
├── .travis.yml
├── Makefile
├── grunt.js
├── package.json
└── spec
│ ├── index.html
│ └── spec.js
├── mocha-chai
├── .travis.yml
├── Makefile
├── grunt.js
├── package.json
└── spec
│ ├── index.html
│ └── spec.js
├── mocha-express-chai
├── .travis.yml
├── Readme.md
├── app.js
├── app
│ ├── controllers
│ │ └── index.js
│ └── views
│ │ └── index.jade
├── grunt.js
├── package.json
└── test
│ ├── common.js
│ ├── phantom.test.js
│ ├── supertest.test.js
│ └── zombie.test.js
├── mocha-node-should
├── .travis.yml
├── Makefile
├── package.json
└── spec
│ └── spec.js
└── qunit
├── .travis.yml
├── Makefile
├── grunt.js
├── package.json
└── spec
├── index.html
└── spec.js
/README.md:
--------------------------------------------------------------------------------
1 | # JavaScript testing boilerplate
2 |
3 | JavaScript testing frameworks require a lot of boilerplate. I grew tired of of having to set up all the files for every project, thus I decided to maintain this repo to quickly `cp` them into my project.
4 |
5 | The different testing frameworks need different files, so I made a folder for each combination I used so far.
6 |
7 | ## Usage
8 |
9 | ```sh
10 | $ git clone https://github.com/js-coder/js-testing-boilerplates.git
11 | $ cd yourProject # A git repo
12 | $ cp -r ../js-testing-boilerplates/mocha-chai/* .
13 | $ make init-testing
14 | ```
15 |
16 | ## Submodules / NPM
17 |
18 | All vendor files are added with git submodules or NPM, so you can easily update them.
19 |
20 | ## Makefile
21 |
22 | Each boilerplate folder contains a Makefile with these tasks:
23 |
24 | - `make init-testing`: Initialise the git submodules. Run this after `cp`ing the boilerplate.
25 | - `make update-testing`: Updates the node packages and / or the git submodules.
26 | - `make test`: Run the test suite, with the framework's command line tool or grunt + PhantomJS.
27 |
28 | The folders also contain [grunt](https://github.com/gruntjs/grunt) files, so you can easily re-run the tests when files change.
29 |
30 | ```sh
31 | $ grunt watch
32 | ```
33 |
34 | `mocha-node-should` doesn't contain grunt, but a `make test-w` task.
35 |
36 | ## Travis
37 |
38 | Configuration for the [travis](https://travis-ci.org/) continuous integration service is on board too!
39 |
--------------------------------------------------------------------------------
/jasmine/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: [0.8]
3 | before_install:
4 | - git submodule update --init --recursive
--------------------------------------------------------------------------------
/jasmine/Makefile:
--------------------------------------------------------------------------------
1 | test:
2 | grunt test
3 |
4 | init-testing:
5 | git submodule add https://github.com/pivotal/jasmine.git spec/vendor/jasmine
6 | git submodule init
7 | npm install
8 |
9 | update-testing:
10 | git submodule update
11 | npm install
12 |
13 | .PHONY: test init-testing update-testing
--------------------------------------------------------------------------------
/jasmine/grunt.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 |
3 | grunt.initConfig({
4 |
5 | jasmine: {
6 | all: ['spec/index.html']
7 | },
8 |
9 | watch: {
10 | test: {
11 | files: ['spec/*'],
12 | tasks: 'test'
13 | }
14 | }
15 |
16 | });
17 |
18 | grunt.loadNpmTasks('grunt-jasmine-task');
19 | grunt.registerTask('test', 'jasmine');
20 |
21 | };
--------------------------------------------------------------------------------
/jasmine/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TODO",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "test": "grunt test"
7 | },
8 | "devDependencies": {
9 | "grunt": "~0.3",
10 | "grunt-jasmine-task": "~0.2"
11 | }
12 | }
--------------------------------------------------------------------------------
/jasmine/spec/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Jasmine Spec Runner
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/jasmine/spec/spec.js:
--------------------------------------------------------------------------------
1 | describe("A suite", function() {
2 | it("contains spec with an expectation", function() {
3 | expect(true).toBe(true);
4 | });
5 | });
--------------------------------------------------------------------------------
/mocha-chai/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: [0.8]
3 | before_install:
4 | - git submodule update --init --recursive
--------------------------------------------------------------------------------
/mocha-chai/Makefile:
--------------------------------------------------------------------------------
1 | test:
2 | grunt test
3 |
4 | init-testing:
5 | git submodule add https://github.com/visionmedia/mocha.git spec/vendor/mocha
6 | git submodule add https://github.com/chaijs/chai.git spec/vendor/chai
7 | git submodule init
8 | npm install
9 |
10 | update-testing:
11 | git submodule update
12 | npm install
13 |
14 | .PHONY: test init-testing update-testing
--------------------------------------------------------------------------------
/mocha-chai/grunt.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 |
3 | grunt.initConfig({
4 |
5 | mocha: {
6 | all: {
7 | src: 'spec/index.html',
8 | run: true
9 | }
10 | },
11 |
12 | watch: {
13 | test: {
14 | files: ['spec/*'],
15 | tasks: 'test'
16 | }
17 | }
18 |
19 | });
20 |
21 | grunt.loadNpmTasks('grunt-mocha');
22 | grunt.registerTask('test', 'mocha');
23 |
24 | };
--------------------------------------------------------------------------------
/mocha-chai/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TODO",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "test": "grunt test"
7 | },
8 | "devDependencies": {
9 | "grunt": "~0.3",
10 | "grunt-mocha": "~0.1"
11 | }
12 | }
--------------------------------------------------------------------------------
/mocha-chai/spec/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/mocha-chai/spec/spec.js:
--------------------------------------------------------------------------------
1 | describe("A suite", function() {
2 | it("contains spec with an expectation", function() {
3 | expect(true).to.be.true;
4 | });
5 | });
--------------------------------------------------------------------------------
/mocha-express-chai/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.8
4 |
--------------------------------------------------------------------------------
/mocha-express-chai/Readme.md:
--------------------------------------------------------------------------------
1 | # Express + Mocha & Co
2 |
3 | **Note**: `Grunt` is optional you can do all with `mocha` only
4 |
5 | ## Usage
6 |
7 | ```
8 | npm test
9 | ```
10 |
11 | or
12 |
13 | ```
14 | mocha
15 | ```
16 |
17 | or
18 |
19 | ```
20 | grunt test
21 | ```
22 |
23 | ## Travis Badge
24 |
25 | [](http://travis-ci.org//)
26 |
27 | ## Autotest
28 |
29 | ```
30 | mocha -w
31 | ```
32 | or
33 |
34 | ```
35 | grunt watch
36 | ```
37 |
38 | ## Coverage
39 |
40 | ```
41 | mocha -R html-cov > coverage.html
42 | ```
43 |
44 | ## Test Documentation
45 |
46 | ```
47 | mocha -R doc > doc.html
48 | ```
49 |
--------------------------------------------------------------------------------
/mocha-express-chai/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 |
3 | var index = require('./app/controllers/index');
4 |
5 | var app = express();
6 |
7 | // Config
8 | app.configure(function() {
9 | app.set('port', 8000);
10 | app.set('views', __dirname + '/app/views');
11 | app.set('view engine', 'jade');
12 | });
13 |
14 | app.configure('development', function() {
15 | app.use(express.logger('dev'));
16 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
17 | });
18 |
19 | app.configure('test', function () {
20 | });
21 |
22 | app.configure('production', function() {
23 | });
24 |
25 | index.init(app);
26 |
27 | module.exports = app;
28 |
29 | if (!module.parent) {
30 | app.listen(app.get('port'), function(){
31 | console.log('Server started on port ' + app.get('port'));
32 | })
33 | }
34 |
--------------------------------------------------------------------------------
/mocha-express-chai/app/controllers/index.js:
--------------------------------------------------------------------------------
1 | exports.init = function(app) {
2 | app.get('/', function (req, res, next) {
3 | res.render('index');
4 | });
5 |
6 | app.get('/hello', function (req, res, next) {
7 | res.send('Hello world!');
8 | });
9 |
10 | app.get('/form', function (req, res, next) {
11 | res.render('index');
12 | });
13 | }
--------------------------------------------------------------------------------
/mocha-express-chai/app/views/index.jade:
--------------------------------------------------------------------------------
1 | doctype 5
2 | html
3 | head
4 | title= 'Hello world'
5 | body
6 | form(method='GET',action='/form')
7 | input(type='text',name='email')
8 | input(type='submit',name='Save')
9 |
--------------------------------------------------------------------------------
/mocha-express-chai/grunt.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | // Add our custom tasks.
4 | grunt.loadNpmTasks('grunt-mocha-test');
5 | grunt.loadNpmTasks('grunt-exec');
6 |
7 | // Project configuration.
8 | grunt.initConfig({
9 | exec: {
10 | coverage: {
11 | command: 'node_modules/.bin/mocha -R html-cov > coverage.html',
12 | }
13 | },
14 | mochaTest: {
15 | files: ['test/**/*.test.js']
16 | },
17 | mochaTestConfig: {
18 | options: {
19 | reporter: 'dot',
20 | require: 'test/common'
21 | }
22 | },
23 | watch: {
24 | test: {
25 | files: ['test/**/*.js', 'app/**/*.js'],
26 | tasks: 'test'
27 | }
28 | }
29 | });
30 |
31 | grunt.registerTask('coverage', 'exec:coverage');
32 | grunt.registerTask('test', 'mochaTest');
33 | grunt.registerTask('default', 'test');
34 | }
35 |
--------------------------------------------------------------------------------
/mocha-express-chai/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TODO",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "node app.js",
7 | "test": "node_modules/.bin/mocha",
8 | "blanket": {
9 | "pattern": "/app/"
10 | }
11 | },
12 | "author": "TODO",
13 | "main": "./app.js",
14 | "engines": {
15 | "node": ">=0.8.x"
16 | },
17 | "dependencies": {
18 | "express": "3.x",
19 | "jade": "*"
20 | },
21 | "devDependencies": {
22 | "grunt": "*",
23 | "grunt-mocha-test": "*",
24 | "grunt-exec": "*",
25 | "chai": "*",
26 | "mocha": "*",
27 | "zombie": "*",
28 | "phantom": "*",
29 | "chai-supertest": "*",
30 | "blanket": ">= 1.0.3"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/mocha-express-chai/test/common.js:
--------------------------------------------------------------------------------
1 | // chai
2 | global.chai = require("chai");
3 |
4 | // should style
5 | global.should = require("chai").should();
6 |
7 | // expect style
8 | // global.expect = require("chai").expect;
9 |
10 | // assert style
11 | // global.assert = require('chai').assert;
12 |
13 | // chai-supertest
14 | var chaiSupertest = require('chai-supertest');
15 | var request = chaiSupertest.request;
16 | chai.use(chaiSupertest.httpAsserts);
17 |
18 | // sinon
19 | // global.sinon = require("sinon");
20 | // var sinonChai = require("sinon-chai");
21 | // chai.use(sinonChai);
22 |
23 | // use zombie.js as headless browser
24 | global.Browser = require('zombie');
25 |
26 | // get the phantom
27 | global.phantom = require('phantom')
28 |
29 | // force the test environment to 'test'
30 | process.env.NODE_ENV = 'test';
31 |
32 | // test coverage
33 | require('blanket');
34 |
35 | // get the application server module
36 | global.app = require('./../app');
37 |
38 | // get the super-agent
39 | global.user = request(app).agent();
40 |
--------------------------------------------------------------------------------
/mocha-express-chai/test/phantom.test.js:
--------------------------------------------------------------------------------
1 | describe("phantom suite", function() {
2 |
3 | before(function(done) {
4 | this.server = app.listen(3000);
5 | var self = this;
6 | phantom.create(function(ph){
7 | self.ph = ph;
8 | ph.createPage(function(page){
9 | self.page = page;
10 | done();
11 | })
12 | })
13 | });
14 |
15 | after(function(done){
16 | this.ph.exit();
17 | this.server.close(done);
18 | });
19 |
20 | it("testing with the help of phantom", function(done) {
21 | this.page.open("http://localhost:3000", function(status){
22 | status.should.be.eql("success");
23 | done();
24 | })
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/mocha-express-chai/test/supertest.test.js:
--------------------------------------------------------------------------------
1 | describe("supertest suite", function() {
2 | it("testing with the help of super-agen", function(done) {
3 | user
4 | .get('/hello')
5 | .end(function (res) {
6 | res.should.be.html;
7 | res.should.have.status(200);
8 | res.should.have.header('Content-Length', '12');
9 | res.text.should.equal('Hello world!');
10 | done();
11 | });
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/mocha-express-chai/test/zombie.test.js:
--------------------------------------------------------------------------------
1 | describe("zombie suite", function() {
2 |
3 | before(function() {
4 | this.server = app.listen(3000);
5 | // initialize the browser using the same port as the test application
6 | this.browser = new Browser({ site: 'http://localhost:3000' });
7 | });
8 |
9 | before(function(done) {
10 | // load the page
11 | this.browser.visit('/', function(){
12 | // if you pass done directly and error occurs
13 | // it will fail and spoil report with stack trace
14 | done();
15 | });
16 | });
17 |
18 | after(function(done){
19 | this.server.close(done);
20 | });
21 |
22 | it("testing with the help of zombie", function(done) {
23 | var browser = this.browser;
24 | browser.success.should.be.true;
25 | browser.text("title").should.eql('Hello world');
26 | browser
27 | .fill("email", "test@exmple.com")
28 | .pressButton("Save", function() {
29 | // Form submitted, new page loaded.
30 | browser.success.should.be.true;
31 | done();
32 | })
33 | });
34 | });
35 |
--------------------------------------------------------------------------------
/mocha-node-should/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: [0.8]
--------------------------------------------------------------------------------
/mocha-node-should/Makefile:
--------------------------------------------------------------------------------
1 | spec = spec/spec.js
2 |
3 | test:
4 | mocha spec
5 |
6 | test-w:
7 | mocha --watch --growl --reporter min spec
8 |
9 | init-testing update-testing:
10 | npm install
11 |
12 | .PHONY: test test-w init-testing update-testing
--------------------------------------------------------------------------------
/mocha-node-should/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TODO",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "test": "make test"
7 | },
8 | "devDependencies": {
9 | "grunt": "~0.3",
10 | "should": "1.2",
11 | "grunt-mocha": "~0.2"
12 | }
13 | }
--------------------------------------------------------------------------------
/mocha-node-should/spec/spec.js:
--------------------------------------------------------------------------------
1 | var should = require('should');
2 |
3 | describe("A suite", function() {
4 | it("contains spec with an expectation", function() {
5 | true.should.be.true;
6 | });
7 | });
--------------------------------------------------------------------------------
/qunit/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: [0.8]
3 | before_install:
4 | - git submodule update --init --recursive
--------------------------------------------------------------------------------
/qunit/Makefile:
--------------------------------------------------------------------------------
1 | test:
2 | grunt test
3 |
4 | init-testing:
5 | git submodule add https://github.com/jquery/qunit.git spec/vendor/qunit
6 | git submodule init
7 | npm install
8 |
9 | update-testing:
10 | git submodule update
11 | npm install
12 |
13 | .PHONY: test init-testing update-testing
--------------------------------------------------------------------------------
/qunit/grunt.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 |
3 | grunt.initConfig({
4 |
5 | qunit: {
6 | all: ['spec/index.html']
7 | },
8 |
9 | watch: {
10 | test: {
11 | files: ['spec/*'],
12 | tasks: 'test'
13 | }
14 | }
15 |
16 | });
17 |
18 | grunt.registerTask('test', 'qunit');
19 |
20 | };
--------------------------------------------------------------------------------
/qunit/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TODO",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "test": "grunt test"
7 | },
8 | "devDependencies": {
9 | "grunt": "~0.3"
10 | }
11 | }
--------------------------------------------------------------------------------
/qunit/spec/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | QUnit test suite
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/qunit/spec/spec.js:
--------------------------------------------------------------------------------
1 | module('Array');
2 |
3 | test('#length', function(){
4 | var arr = [1,2,3];
5 | ok(arr.length == 3);
6 | });
--------------------------------------------------------------------------------