Skip to content

Commit 48c3baf

Browse files
committed
Auditor accepts arguments, update config and tests
- Use webpack and babel to package/transpile. - Use karma for running tests. - Use mocha/chai/sinon for testing and assertions. - Add test for auditor. - Auditor supports arguments to specify environment and exception behavior
1 parent 011fa23 commit 48c3baf

18 files changed

+317
-62
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
2-
build/*
3-
test/public/build*
2+
dist/*

.hound.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
javascript:
2+
enabled: false
3+
jshint:
4+
enabled: true
5+
config_file: .javascript-style.json

.javascript-style.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"asi": false,
3+
"bitwise": true,
4+
"browser": true,
5+
"camelcase": true,
6+
"curly": true,
7+
"esnext": true,
8+
"forin": true,
9+
"immed": true,
10+
"latedef": "nofunc",
11+
"maxlen": 80,
12+
"newcap": true,
13+
"noarg": true,
14+
"node": true,
15+
"noempty": true,
16+
"nonew": true,
17+
"predef": [
18+
"__dirname",
19+
"$",
20+
"jQuery",
21+
"beforeEach",
22+
"describe",
23+
"expect",
24+
"it",
25+
"angular",
26+
"inject",
27+
"module",
28+
"require"
29+
],
30+
"quotmark": true,
31+
"trailing": true,
32+
"undef": true,
33+
"unused": true
34+
}

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ node_js:
44
- stable
55
before_script:
66
- npm install -g gulp
7-
script:
8-
- gulp
97
notifications:
108
email: false

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,32 @@ NewRelic or Google Analytics in the way it is included and run on your website.
1616
When a visitor arrives at a page that has the script installed, an audit will
1717
run in the background automatically. If there are any accessibility issues on
1818
that page, AccessLint Monitor track the error for review.
19+
20+
## Development
21+
22+
AccessLint Monitor uses babel and webpack to transpile and package ES2105
23+
code for inclusion clientside. It uses karma and mocha to run tests.
24+
25+
### Setup
26+
27+
$ bin/setup
28+
29+
### Building
30+
31+
#### Development
32+
33+
$ gulp build-dev
34+
35+
#### Production
36+
37+
$ gulp build
38+
39+
### Testing
40+
41+
From the application root: `$ karma start`
42+
43+
#### Smoke testing
44+
45+
1. Start the node test app `$ DEBUG=express:* node test/integration/app.js`.
46+
1. Visit `localhost:3000`.
47+
1. Open the network panel and review the response from the host.

bin/setup

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
3+
npm install -g webpack gulp-cli
4+
npm install

gulpfile.js

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
11
var gulp = require("gulp");
2-
var sourcemaps = require("gulp-sourcemaps");
3-
var source = require("vinyl-source-stream");
4-
var buffer = require("vinyl-buffer");
5-
var browserify = require("browserify");
6-
var watchify = require("watchify");
7-
var babel = require("babelify");
8-
9-
function compile(watch) {
10-
var bundler = watchify(browserify("./src/index.js", { debug: true })
11-
.transform(babel));
12-
13-
function rebundle() {
14-
bundler.bundle()
15-
.on("error", function(err) { console.error(err); this.emit("end"); })
16-
.pipe(source("build.js"))
17-
.pipe(buffer())
18-
.pipe(sourcemaps.init({ loadMaps: true }))
19-
.pipe(sourcemaps.write("./"))
20-
.pipe(gulp.dest("./build"))
21-
.pipe(gulp.dest("./test/public"));
22-
}
23-
24-
if (watch) {
25-
bundler.on("update", function() {
26-
console.log("-> bundling...");
27-
rebundle();
28-
});
29-
}
30-
31-
rebundle();
32-
}
33-
34-
function watch() {
35-
return compile(true);
36-
};
37-
38-
gulp.task("build", function() { return compile(); });
39-
gulp.task("watch", function() { return watch(); });
40-
41-
gulp.task("default", ["watch"]);
2+
var gutil = require("gulp-util");
3+
var karma = require("karma").server;
4+
var path = require("path");
5+
var webpack = require("webpack");
6+
var webpackConfig = require("./webpack.config.js");
7+
8+
var devConfig = Object.create(webpackConfig);
9+
devConfig.devtool = "sourcemap";
10+
devConfig.debug = true;
11+
12+
var devCompiler = webpack(devConfig);
13+
14+
gulp.task("webpack:build-dev", function(callback) {
15+
devCompiler.run(function(err, stats) {
16+
if(err) {
17+
throw new gutil.PluginError("webpack:build-dev", err);
18+
}
19+
20+
gutil.log("[webpack:build-dev]", stats.toString({
21+
colors: true
22+
}));
23+
24+
callback();
25+
});
26+
});
27+
28+
gulp.task("webpack:build", function(callback) {
29+
var config = Object.create(webpackConfig);
30+
31+
config.plugins = config.plugins.concat(
32+
new webpack.DefinePlugin({
33+
"process.env": {
34+
"NODE_ENV": JSON.stringify("production")
35+
}
36+
}),
37+
new webpack.optimize.DedupePlugin(),
38+
new webpack.optimize.UglifyJsPlugin()
39+
);
40+
41+
webpack(config, function(err, stats) {
42+
if(err) {
43+
throw new gutil.PluginError("webpack:build", err);
44+
}
45+
46+
gutil.log("[webpack:build]", stats.toString({
47+
colors: true
48+
}));
49+
50+
callback();
51+
});
52+
});
53+
54+
gulp.task("test", function(callback) {
55+
karma.start({
56+
configFile: path.resolve("karma.conf.js"),
57+
singleRun: true
58+
}, callback);
59+
});
60+
61+
gulp.task("build", ["webpack:build"]);
62+
gulp.task("default", ["webpack:build-dev", "test"]);
63+
64+
gulp.task("build-dev", ["webpack:build-dev"], function() {
65+
gulp.watch(["src/**/*"], ["webpack:build-dev"]);
66+
});

karma.conf.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module.exports = function(config) {
2+
config.set({
3+
frameworks: [
4+
"chai",
5+
"mocha",
6+
],
7+
files: [
8+
"test/*_test.js",
9+
"test/**/*_test.js",
10+
],
11+
plugins: [
12+
require("karma-chai"),
13+
require("karma-phantomjs-launcher"),
14+
require("karma-mocha"),
15+
require("karma-webpack"),
16+
],
17+
preprocessors: {
18+
"test/*_test.js": ["webpack"],
19+
"test/**/*_test.js": ["webpack"],
20+
},
21+
webpack: {
22+
devtool: "source-map",
23+
module: {
24+
loaders: [
25+
{
26+
test: /\.js$/,
27+
exclude: /node_modules/,
28+
loader: "babel-loader",
29+
query: {
30+
presets: ["es2015"]
31+
}
32+
},
33+
{
34+
test: /\.json$/,
35+
loader: "json",
36+
}
37+
]
38+
},
39+
node: {
40+
console: true,
41+
fs: "empty",
42+
net: "empty",
43+
tls: "empty",
44+
},
45+
},
46+
webpackMiddleware: {
47+
stats: {
48+
colors: true,
49+
},
50+
},
51+
reporters: ["progress"],
52+
port: 9876,
53+
colors: true,
54+
logLevel: config.LOG_INFO,
55+
autoWatch: true,
56+
browsers: ["PhantomJS"],
57+
singleRun: false,
58+
concurrency: Infinity,
59+
});
60+
};

package.json

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,41 @@
1212
"testing",
1313
"a11y"
1414
],
15+
"script": {
16+
"test": "gulp build-dev && ./node_modules/.bin/karma start --single-run"
17+
},
1518
"author": "Cameron Cundiff",
1619
"license": "MIT",
1720
"bugs": {
1821
"url": "https://github.com/accesslint/monitor/issues"
1922
},
2023
"devDependencies": {
2124
"axe-core": "~1.1.0",
22-
"babelify": "^6.2.0",
23-
"browserify": "^11.0.1",
24-
"cors": "~2.7.1",
25+
"babel-core": "^6.2.1",
26+
"babel-loader": "^6.2.0",
27+
"babel-preset-es2015": "^6.1.18",
28+
"babel-runtime": "^6.2.0",
29+
"body-parser": "^1.14.1",
30+
"browser-request": "^0.3.3",
31+
"chai": "^3.4.1",
2532
"express": "~4.13.3",
2633
"gulp": "^3.9.0",
27-
"gulp-babel": "^5.2.1",
28-
"gulp-concat": "^2.6.0",
29-
"gulp-sourcemaps": "^1.5.2",
34+
"json-loader": "^0.5.4",
35+
"karma": "^0.13.15",
36+
"karma-babel-preprocessor": "^6.0.1",
37+
"karma-chai": "^0.1.0",
38+
"karma-mocha": "^0.2.1",
39+
"karma-phantomjs-launcher": "^0.2.1",
40+
"karma-webpack": "^1.7.0",
41+
"mocha": "^2.3.4",
42+
"phantomjs": "^1.9.19",
3043
"request": "~2.61.0",
31-
"vinyl-buffer": "^1.0.0",
32-
"vinyl-source-stream": "^1.1.0",
33-
"watchify": "^3.3.1"
44+
"sinon": "git://github.com/cjohansen/Sinon.JS#b672042043517b9f84e14ed0fb8265126168778a",
45+
"sinon-chai": "^2.8.0",
46+
"webpack": "^1.12.9"
47+
},
48+
"dependencies": {
49+
"babel-polyfill": "^6.2.0",
50+
"babel-runtime": "^6.2.0"
3451
}
3552
}

0 commit comments

Comments
 (0)