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

Commit

Permalink
Merge pull request #31 from FormidableLabs/chore-func-tests
Browse files Browse the repository at this point in the history
Feature: Functional tests.
  • Loading branch information
ryan-roemer committed Apr 18, 2015
2 parents e9f8f7e + 89c9ee1 commit 3d49963
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -179,7 +179,7 @@ rules:
func-names: 0 # require function expressions to have a name
func-style: 0 # enforces use of function declarations or expressions
key-spacing: 2 # enforces spacing between keys and values in object literal properties
max-nested-callbacks: [2, 4] # specify the maximum depth callbacks can be nested
max-nested-callbacks: [0, 4] # specify the maximum depth callbacks can be nested
new-cap: 2 # require a capital letter for constructors
new-parens: 2 # disallow the omission of parentheses when invoking a constructor with no arguments
no-array-constructor: 2 # disallow use of the Array constructor
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -28,5 +28,5 @@ script:
- ./node_modules/.bin/gulp check:ci:linux
# Manually send coverage reports to coveralls.
# - Aggregate client results
# - Single server result
- cat coverage/client/*/lcov.info coverage/server/lcov.info | ./node_modules/.bin/coveralls
# - Single server and func test results
- cat coverage/client/*/lcov.info coverage/{server,func}/lcov.info | ./node_modules/.bin/coveralls
18 changes: 11 additions & 7 deletions README.md
Expand Up @@ -66,10 +66,10 @@ tests. To run all the server-side tests, try:

```sh
# Mac/Linux
$ node_modules/.bin/mocha --require test/server/setup.js --recursive test/server
$ node_modules/.bin/mocha --opts test/server/mocha.opts test/server

# Windows
$ node_modules\.bin\mocha --require test\server\setup.js --recursive test\server
$ node_modules\.bin\mocha --opts test\server\mocha.opts test\server
```

#### Server-side Unit Tests
Expand All @@ -85,10 +85,10 @@ Run the tests with:

```sh
# Mac/Linux
$ node_modules/.bin/mocha --require test/server/setup.js --recursive test/server/spec
$ node_modules/.bin/mocha --opts test/server/mocha.opts test/server/spec

# Windows
$ node_modules\.bin\mocha --require test\server\setup.js --recursive test\server\spec
$ node_modules\.bin\mocha --opts test\server\mocha.opts test\server\spec
```

#### Server-side REST Tests
Expand All @@ -107,10 +107,10 @@ Run the tests with:

```sh
# Mac/Linux
$ node_modules/.bin/mocha --require test/server/setup.js --recursive test/server/rest
$ node_modules/.bin/mocha --opts test/server/mocha.opts test/server/rest

# Windows
$ node_modules\.bin\mocha --require test\server\setup.js --recursive test\server\rest
$ node_modules\.bin\mocha --opts test\server\mocha.opts test\server\rest
```

### Frontend Tests
Expand Down Expand Up @@ -154,7 +154,11 @@ instance of the entire web application. These tests typically:
Run the tests with:

```sh
TODO[RYAN]: NEED TESTS/COMMAND
# Mac/Linux
$ node_modules/.bin/mocha --opts test/func/mocha.opts test/func/spec

# Windows
$ node_modules\.bin\mocha --opts test\func\mocha.opts test\func\spec
```


Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -9,6 +9,7 @@ install:
# Install and use local, modern NPM
- npm install npm@next
- node_modules\.bin\npm install
- node_modules\.bin\npm install-selenium

build: off

Expand Down
2 changes: 1 addition & 1 deletion client/app.js
@@ -1,7 +1,7 @@
/**
* Client application entry point.
*/
var $ = require("jquery");
var $ = window.$ = require("jquery"); // Add jQuery to window for test ease.
require("bootstrap"); // Empty require to enable bootstrap JS

var Converter = require("./converter");
Expand Down
74 changes: 42 additions & 32 deletions gulpfile.js
Expand Up @@ -186,39 +186,42 @@ gulp.task("test:frontend:all", ["clean:coverage:client"], _karmaAll);
// ----------------------------------------------------------------------------
// Tests: Server, Functional
// ----------------------------------------------------------------------------
gulp.task("test:backend", ["clean:coverage:server"], function (done) {
// Global setup.
require("./test/server/setup");

// First, cover files.
gulp
.src(BACKEND_JS_APP_FILES)
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on("finish", function () {
// Second, run the tests
gulp
.src(BACKEND_JS_TEST_FILES, { read: false })
.pipe(mocha({
reporter: "spec"
}))
.pipe(istanbul.writeReports({
dir: "./coverage/server",
reportOpts: { dir: "./coverage/server" },
reporters: ["lcov", "json", "text-summary"] // "text",
}))
.on("end", done);
});
});
var _mocha = function (type, testFiles) {
return function (done) {
// First, cover files.
gulp
.src(BACKEND_JS_APP_FILES)
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on("finish", function () {
// Second, run the tests
require("./test/" + type + "/setup");

gulp
.src(testFiles, { read: false })
.pipe(mocha())
.pipe(istanbul.writeReports({
dir: "./coverage/" + type,
reportOpts: { dir: "./coverage/" + type },
reporters: ["lcov", "json", "text-summary"] // "text",
}))
.on("end", done);
});
};
};

// TODO[RYAN]: Func tests.
gulp.task("test:backend", ["clean:coverage:server"], _mocha("server", BACKEND_JS_TEST_FILES));
gulp.task("test:func", ["clean:coverage:func"], _mocha("func", FUNC_JS_TEST_FILES));

gulp.task("test", ["test:backend", "test:frontend"]);
gulp.task("test:ci:linux", ["test:backend", "test:frontend:ci:linux"]);
gulp.task("test:ci:win", ["test:backend", "test:frontend:ci:win"]);
gulp.task("test:all", ["test:backend", "test:frontend:all"]);
// TODO: More `test:func:MORE_OPTIONS` stuff...
// TODO: Maybe a base test:func/backend?

gulp.task("test", ["test:backend", "test:func", "test:frontend"]);
gulp.task("test:ci:linux", ["test:backend", "test:func", "test:frontend:ci:linux"]);
gulp.task("test:ci:win", ["test:backend", "test:func", "test:frontend:ci:win"]);
gulp.task("test:all", ["test:backend", "test:func", "test:frontend:all"]);

// ----------------------------------------------------------------------------
// Quality
Expand Down Expand Up @@ -290,10 +293,17 @@ gulp.task("clean:coverage:server", function () {
.pipe(rimraf());
});

gulp.task("clean:coverage:func", function () {
return gulp
.src(["coverage/func"], { read: false })
.pipe(rimraf());
});

gulp.task("clean", [
"clean:dist",
"clean:coverage:client",
"clean:coverage:server"
"clean:coverage:server",
"clean:coverage:func"
]);

// -----------
Expand Down
13 changes: 9 additions & 4 deletions package.json
Expand Up @@ -40,20 +40,25 @@
"mocha": "2.2.4",
"phantomjs": "1.9.16",
"recluster": "0.4.0",
"rowdy": "0.1.3",
"selenium-standalone": "4.2.2",
"sinon": "1.14.1",
"sinon-chai": "2.7.0",
"supertest": "0.15.0"
"supertest": "0.15.0",
"wd": "0.3.11"
},
"scripts": {
"test-frontend": "node node_modules/karma/bin/karma start test/client/karma.conf.js",
"test-backend": "mocha --require test/server/setup.js --recursive test/server",
"test": "npm run-script test-frontend && npm run-script test-backend",
"test-backend": "mocha --opts test/server/mocha.opts test/server",
"test-func": "mocha --opts test/func/mocha.opts test/func",
"test": "npm run-script test-frontend && npm run-script test-backend && npm run-script test-func",
"check": "npm run-script build-all && npm run-script test && gulp check",
"build": "webpack --config webpack.config.js",
"build-test": "webpack --config webpack.config.test.js",
"build-cov": "webpack --config webpack.config.coverage.js",
"build-all": "npm run-script build && npm run-script build-test && npm run-script build-cov",
"postinstall": "node app/heroku/not-heroku.js || (node app/heroku/install.js && npm run-script build-all)"
"install-selenium": "selenium-standalone install",
"postinstall": "npm run-script install-selenium && node app/heroku/not-heroku.js || (node app/heroku/install.js && npm run-script build-all)"
},
"repository": {
"type": "git",
Expand Down
9 changes: 7 additions & 2 deletions server/index.js
Expand Up @@ -5,6 +5,7 @@ var express = require("express");
var app = module.exports = express();
var converter = require("./converter");
var PORT = process.env.PORT || 3000;
var NODE_ENV = process.env.NODE_ENV;

// Application REST endpoints.
app.get("/api/camel", function (req, res) {
Expand All @@ -24,12 +25,16 @@ app.get("/api/dash", function (req, res) {
app.use("/app/js-dist", express.static("app/js-dist"));
app.use("/node_modules", express.static("node_modules"));

// Running this file as a script (the usual case).
// Only add root handler if script or a test environment.
/* istanbul ignore next */
if (require.main === module) {
if (require.main === module || NODE_ENV === "test" || NODE_ENV === "func") {
// Server static HTML page.
app.use("/", express.static("app/public"));
}

// Actually start server if script.
/* istanbul ignore next */
if (require.main === module) {
// Start application.
app.listen(PORT);
}
2 changes: 2 additions & 0 deletions test/func/mocha.opts
@@ -0,0 +1,2 @@
--require test/func/setup.js
--recursive
17 changes: 17 additions & 0 deletions test/func/setup.js
@@ -0,0 +1,17 @@
/**
* Test setup for server-side tests.
*/
var chai = require("chai");

// Add test lib globals.
global.expect = chai.expect;

// Configure Rowdy.
var rowdy = require("rowdy");
// Recommendation is to actually customize your configuration by copying and
// editing the example Rowdy config to `test/func/config.js`.
var config = require("rowdy/examples/mocha/config");
rowdy(config);

// Set test environment
process.env.NODE_ENV = "func";

0 comments on commit 3d49963

Please sign in to comment.