Skip to content

Commit

Permalink
Mocha tests + many other small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Aug 4, 2015
1 parent a09ed76 commit 7d369d7
Show file tree
Hide file tree
Showing 19 changed files with 940 additions and 4,935 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
*.gz
*.swp
boomerang-*.js
node_modules*
build/*
hint.log
tests/vendor/
tests/coverage/
*.diff
.project
.settings/
tests/vendor/
tests/coverage/
node_modules/
build/
166 changes: 43 additions & 123 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,174 +2,96 @@

"use strict";
module.exports = function (grunt) {

var src = [ "boomerang.js" ];
var plugins = grunt.file.readJSON("plugins.json");
src.push(plugins.plugins);
src.push("plugins/zzz_last_plugin.js");

grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
buildDate: Math.round(Date.now() / 1000),
builddate: Date.now(),
concat: {
options: {
stripBanners: false,
stripBanners: {
block : true,
line: true
},
seperator: ";"
},
debug: {
src: src,
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js"
dest: "build/<%= pkg.name %>-<%= builddate %>-debug.js"
},
release: {
src: src,
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js"
dest: "build/<%= pkg.name %>-<%= builddate %>.js"
}
},
eslint: {
target: [
"Gruntfile.js",
"boomerang.js",
"plugins/*.js",
"tests/library/*.js"
"plugins/*.js"
]
},
"string-replace": {
all: {
files: [
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js"
},
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js"
}
],
options: {
replacements: [
{
// Replace 0.9 with 0.9.[date]
pattern: /BOOMR.version\s*=\s*".*";/,
replacement: "BOOMR.version = \"<%= pkg.releaseVersion %>.<%= buildDate %>\";"
},
{
// strip out BOOMR = BOOMR || {}; in plugins
pattern: /BOOMR\s*=\s*BOOMR\s*\|\|\s*{};/g,
replacement: ""
},
{
// strip out BOOMR.plugins = BOOMR.plugins || {}; in plugins
pattern: /BOOMR\.plugins\s*=\s*BOOMR\.plugins\s*\|\|\s*{};/g,
replacement: ""
}
]
}
},
debug: {
files: [{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js"
}],
options: {
replacements: [
{
// Add &debug key to request
pattern: /key=%client_apikey%/,
replacement: "debug=\&key=%client_apikey%"
}
]
}
},
release: {
files: [{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js"
}],
options: {
// strip out some NOPs
replacements: [
{
pattern: /else{}/g,
replacement: ""
},
{
pattern: /\(window\)\);/g,
replacement: "\(window\)\);\n"
},
{
pattern: /\(\)\);\(function\(/g,
replacement: "\(\)\);\n(function("
}
]
}
files: [{
src: "build/<%= pkg.name %>-<%= builddate %>.js",
dest: "build/<%= pkg.name %>-<%= builddate %>.js"
}],
options: {
replacements: [{
pattern: /else{}/g,
replacement: ""
},{
pattern: /\(window\)\);/g,
replacement: "\(window\)\);\n"
},{
pattern: /\(\)\);\(function\(/g,
replacement: "\(\)\);\n(function("
}]
}
}
},
copy: {
// copy files to -latest so test/index.html points to the latest version always
latest: {
files: [
{
nonull: true,
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js",
dest: "build/<%= pkg.name %>-latest-debug.js"
src: "build/<%= pkg.name %>-<%= builddate %>-debug.js",
dest: "build/<%= pkg.name %>-latest-debug.js",
},
{
nonull: true,
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.min.js",
dest: "build/<%= pkg.name %>-latest-debug.min.js"
src: "build/<%= pkg.name %>-<%= builddate %>-debug.min.js",
dest: "build/<%= pkg.name %>-latest-debug.min.js",
},
{
nonull: true,
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.min.js.map",
dest: "build/<%= pkg.name %>-latest-debug.min.js.map"
}
src: "build/<%= pkg.name %>-<%= builddate %>-debug.min.js.map",
dest: "build/<%= pkg.name %>-latest-debug.min.js.map",
},
]
}
},
uglify: {
options: {
options : {
preserveComments: false,
mangle: true,
mangle: false,
sourceMap: true
},
min_release: {
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.min.js"
report: "gzip",
src: "build/<%= pkg.name %>-<%= builddate %>.js",
dest: "build/<%= pkg.name %>-<%= builddate %>.min.js"
},
min_debug: {
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.min.js"
report: "gzip",
src: "build/<%= pkg.name %>-<%= builddate %>-debug.js",
dest: "build/<%= pkg.name %>-<%= builddate %>-debug.min.js"
}
},
compress: {
main: {
options: {
mode: "gzip",
level: 9
},
files: [
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js.gz"
},
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.js.gz"
},
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.min.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.min.js.gz"
},
{
src: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.min.js",
dest: "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>-debug.min.js.gz"
}
]
}
},
filesize: {
files: [ "build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.min.js.gz" ]
},
clean: {
options: {},
build: ["build/"],
Expand All @@ -179,7 +101,7 @@ module.exports = function (grunt) {
options: {
configFile: "./karma.config.js",
preprocessors: {
"./build/*.js": ["coverage"]
"./build/*.js": ["coverage"],
},
basePath: "./",
files: [
Expand All @@ -188,7 +110,7 @@ module.exports = function (grunt) {
"tests/vendor/chai/chai.js",
"tests/vendor/expect/index.js",
"tests/library/*.js",
"./build/<%= pkg.name %>-<%= pkg.releaseVersion %>.<%= buildDate %>.js"
"./build/<%= pkg.name %>-<%= builddate %>.js"
]
},
unit: {
Expand All @@ -211,12 +133,10 @@ module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-filesize");

grunt.registerTask("lint", "eslint");
grunt.registerTask("build", ["concat", "string-replace", "uglify", "compress", "copy:latest", "filesize"]);
grunt.registerTask("build", ["concat", "string-replace", "uglify", "copy:latest"]);
grunt.registerTask("test", ["build", "karma:unit"]);
grunt.registerTask("test:dev", ["build", "karma:dev"]);
grunt.registerTask("default", ["lint", "test"]);
grunt.registerTask("default", ["lint", "build", "test"]);
};
7 changes: 5 additions & 2 deletions boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ boomr = {
},

cleanupURL: function(url) {
if (!url) {
if (!url || Object.prototype.toString.call(url) === "[object Array]") {
return "";
}
if(impl.strip_query_string) {
Expand Down Expand Up @@ -684,7 +684,10 @@ boomr = {
document.body.appendChild(iframe);
document.body.appendChild(form);

form.submit();
try {
form.submit();
} catch (ignore) {
}

if (urls.length) {
BOOMR.setImmediate(submit);
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"devDependencies": {
"chai": "~1.9.2",
"mocha": "~1.21.5"
"mocha": "~1.21.5",
"expect": "~0.3.1"
}
}
34 changes: 15 additions & 19 deletions karma.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
// Karma configuration
// Generated on %DATE%

module.exports = function(config) {
config.set({

basePath: "./",
config.set({
basePath: "./",

port: 4000,
runnerPort: 4001,
logLevel: config.LOG_INFO,
port: 4000,
runnerPort: 4001,
logLevel: config.LOG_INFO,

colors: false,
autoWatch: false,
colors: true,
autoWatch: false,

frameworks: ["mocha"],
reporters: ["progress","coverage"],
browsers: ['PhantomJS'],
frameworks: ["mocha"],
reporters: ["progress", "coverage"],
browsers: ["PhantomJS"],

coverageReporter: {
type : 'html',
dir : 'tests/coverage/'
}
});
coverageReporter: {
type : "html",
dir : "tests/coverage/"
}
});
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
"karma-chrome-launcher": "^0.1.5",
"karma-coverage": "^0.2.6",
"karma-mocha": "^0.1.9",
"karma-phantomjs-launcher": "^0.1.4"
"karma-phantomjs-launcher": "^0.1.4",
"karma-ie-launcher": "^0.1.5",
"karma-firefox-launcher": "^0.1.4",
"karma-opera-launcher": "^0.1.0",
"karma-safari-launcher": "^0.1.1",
"grunt-contrib-copy": "^0.7.0"
},
"scripts": {
"test": "grunt eslint"
Expand Down
2 changes: 1 addition & 1 deletion plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"plugins/ipv6.js",
"plugins/clicks.js",
"plugins/mobile.js",
"plugins/restiming.js",
"plugins/restiming.js",
"plugins/cache-test-plugin.js",
"plugins/cache_reload.js",
"plugins/md5.js",
Expand Down
9 changes: 8 additions & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- NOTE: If these change, update 04-plugins-restiming.js -->
<link rel="stylesheet" href="vendor/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="vendor/mocha/mocha.js"></script>
<script src="vendor/chai/chai.js"></script>
<script src="vendor/expect/index.js"></script>
<script>
mocha.setup('bdd');
</script>
<script src="../build/boomerang-0.9.0.js" type="text/javascript"></script>
<script src="library/00-logging.js"></script>
<script src="library/01-basic.js"></script>
<script src="library/02-utils.js"></script>
<script src="library/02-utils-cleanupurl.js"></script>
<script src="library/02-utils-hashquerystring.js"></script>
<script src="library/02-utils-objecttostring.js"></script>
<script src="library/02-utils-pluginconfig.js"></script>
<script src="library/02-utils-cookies.js"></script>
<script src="library/03-cookies.js"></script>
<script>
mocha.globals(["BOOMR"]);
mocha.globals(["BOOMR", "PageGroupVariable"]);
mocha.checkLeaks();
mocha.run();
</script>
Expand Down
Loading

0 comments on commit 7d369d7

Please sign in to comment.