diff --git a/ghu.js b/ghu.js
index 5c45de1a..441b3c56 100644
--- a/ghu.js
+++ b/ghu.js
@@ -7,7 +7,6 @@ const {
const ROOT = resolve(__dirname);
const SRC = join(ROOT, 'src');
const TEST = join(ROOT, 'test');
-const TEST_SCAR = join(ROOT, 'test-scar');
const BUILD = join(ROOT, 'build');
const mapper = mapfn.p(SRC, BUILD).s('.less', '.css').s('.jade', '');
@@ -120,43 +119,12 @@ ghu.task('build:copy', runtime => {
]);
});
-ghu.task('build:tests', ['build:scripts', 'build:styles'], 'build the test suite', runtime => {
- return Promise.all([
- read(`${TEST}/scripts.js`)
- .then(newerThan(`${BUILD}/test/scripts.js`))
- .then(includeit())
- .then(write(`${BUILD}/test/scripts.js`, {overwrite: true})),
-
- read(`${TEST}/styles.less`)
- .then(newerThan(`${BUILD}/test/styles.css`))
- .then(includeit())
- .then(less())
- .then(autoprefixer())
- .then(write(`${BUILD}/test/styles.css`, {overwrite: true})),
-
- read(`${TEST}/index.html.jade`)
- .then(newerThan(`${BUILD}/test/index.html`))
- .then(pug({pkg: runtime.pkg}))
- .then(write(`${BUILD}/test/index.html`, {overwrite: true})),
-
- read(`${BUILD}/_h5ai/public/js/scripts.js`)
- .then(newerThan(`${BUILD}/test/h5ai-scripts.js`))
- .then(write(`${BUILD}/test/h5ai-scripts.js`, {overwrite: true})),
-
- read(`${BUILD}/_h5ai/public/css/styles.css`)
- .then(newerThan(`${BUILD}/test/h5ai-styles.css`))
- .then(write(`${BUILD}/test/h5ai-styles.css`, {overwrite: true}))
- ]).then(() => {
- console.log(`browse to file://${BUILD}/test/index.html to run the test suite`);
- });
-});
-
-ghu.task('build:tests-scar', ['build:scripts', 'build:styles'], 'build the test suite', () => {
+ghu.task('build:tests', ['build:styles'], 'build the test suite', () => {
const webpackConfig = {
module: {
loaders: [
{
- include: [TEST_SCAR],
+ include: [TEST],
loader: 'babel',
query: {cacheDirectory: true}
}
@@ -165,27 +133,25 @@ ghu.task('build:tests-scar', ['build:scripts', 'build:styles'], 'build the test
};
return Promise.all([
- read(`${BUILD}/_h5ai/public/js/scripts.js`)
- .then(newerThan(`${BUILD}/test-scar/h5ai-scripts.js`))
- .then(write(`${BUILD}/test-scar/h5ai-scripts.js`, {overwrite: true})),
-
read(`${BUILD}/_h5ai/public/css/styles.css`)
- .then(newerThan(`${BUILD}/test-scar/h5ai-styles.css`))
- .then(write(`${BUILD}/test-scar/h5ai-styles.css`, {overwrite: true})),
+ .then(newerThan(`${BUILD}/test/h5ai-styles.css`))
+ .then(write(`${BUILD}/test/h5ai-styles.css`, {overwrite: true})),
- read(`${TEST_SCAR}/tests.html`)
- .then(newerThan(`${BUILD}/test-scar/tests.html`))
- .then(write(`${BUILD}/test-scar/tests.html`, {overwrite: true})),
+ read(`${TEST}/tests.html`)
+ .then(newerThan(`${BUILD}/test/tests.html`))
+ .then(write(`${BUILD}/test/tests.html`, {overwrite: true})),
- read(`${TEST_SCAR}: tests.js`)
+ read(`${TEST}: tests.js`)
.then(webpack(webpackConfig, {showStats: false}))
- .then(write(mapfn.p(TEST_SCAR, `${BUILD}/test-scar`), {overwrite: true}))
+ .then(wrap(`\n\n// @include "${SRC}/**/js/global.js"\n\n`))
+ .then(includeit())
+ .then(write(mapfn.p(TEST, `${BUILD}/test`), {overwrite: true}))
]).then(() => {
- console.log(`browse to file://${BUILD}/test-scar/tests.html to run the test suite`);
+ console.log(`browse to file://${BUILD}/test/tests.html to run the test suite`);
});
});
-ghu.task('build', ['build:scripts', 'build:styles', 'build:pages', 'build:copy', 'build:tests', 'build:tests-scar'],
+ghu.task('build', ['build:scripts', 'build:styles', 'build:pages', 'build:copy', 'build:tests'],
'build all updated files, optionally use :production');
ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path', runtime => {
@@ -202,7 +168,7 @@ ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path'
});
ghu.task('watch', runtime => {
- return watch([SRC, TEST, TEST_SCAR], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true));
+ return watch([SRC, TEST], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true));
});
ghu.task('release', ['force-production', 'clean', 'build'], 'create a zipball', runtime => {
diff --git a/test-scar/.eslintrc b/test-scar/.eslintrc
deleted file mode 100644
index 34d009c4..00000000
--- a/test-scar/.eslintrc
+++ /dev/null
@@ -1,3 +0,0 @@
----
- env:
- browser: true
diff --git a/test-scar/tests.js b/test-scar/tests.js
deleted file mode 100644
index 2d3319f9..00000000
--- a/test-scar/tests.js
+++ /dev/null
@@ -1,16 +0,0 @@
-const {test} = require('scar');
-const {clearModulejs, mockConfigModule} = require('./util/modjs');
-const {pinHtml} = require('./util/pin');
-
-mockConfigModule();
-clearModulejs();
-
-require('./tests/premisses');
-require('./tests/unit/boot');
-require('./tests/unit/config');
-require('./tests/unit/libs');
-require('./tests/unit/modulejs');
-
-pinHtml();
-
-test.cli({sync: true});
diff --git a/test-scar/tests/premisses.js b/test-scar/tests/premisses.js
deleted file mode 100644
index e5e25cf5..00000000
--- a/test-scar/tests/premisses.js
+++ /dev/null
@@ -1,21 +0,0 @@
-const {test, assert} = require('scar');
-
-test('window is global object', () => {
- assert.equal(typeof window, 'object');
- assert.equal(window, window.window);
-});
-
-test('document is global object', () => {
- assert.equal(typeof window.document, 'object');
-});
-
-test('jQuery and $ are global functions', () => {
- assert.equal(typeof window.jQuery, 'function');
- assert.equal(window.jQuery.fn.jquery, '2.2.4');
- assert.equal(window.jQuery, window.$);
-});
-
-test('_ is global function', () => {
- assert.equal(typeof window._, 'function');
- assert.equal(window._.VERSION, '4.13.1');
-});
diff --git a/test-scar/tests/unit/boot.js b/test-scar/tests/unit/boot.js
deleted file mode 100644
index c49ed768..00000000
--- a/test-scar/tests/unit/boot.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const {test, assert} = require('scar');
-const sinon = require('sinon');
-
-const ID = 'boot';
-const DEPS = ['$', 'core/server'];
-
-const getDef = () => window.modulejs._private.definitions[ID];
-const createInst = () => getDef().fn.call(null, window.jQuery, {});
-
-test(`module '${ID}' is defined`, () => {
- assert.ok(getDef());
-});
-
-test(`module '${ID}' has correct id`, () => {
- assert.equal(getDef().id, ID);
-});
-
-test(`module '${ID}' has correct deps`, () => {
- assert.deepEqual(getDef().deps, DEPS);
-});
-
-test(`module '${ID}' has args for each dependency`, () => {
- const def = getDef();
- assert.deepEqual(def.deps.length, def.fn.length);
-});
-
-test(`module '${ID}' inits without errors`, () => {
- createInst();
-});
-
-test(`module '${ID}' instance is undefined`, () => {
- assert.equal(createInst(), undefined);
-});
diff --git a/test-scar/tests/unit/config.js b/test-scar/tests/unit/config.js
deleted file mode 100644
index 6ac18eee..00000000
--- a/test-scar/tests/unit/config.js
+++ /dev/null
@@ -1,32 +0,0 @@
-const {test, assert} = require('scar');
-
-const ID = 'config';
-const DEPS = [];
-
-const getDef = () => window.modulejs._private.definitions[ID];
-const createInst = () => getDef().fn();
-
-test(`module '${ID}' is defined`, () => {
- assert.ok(getDef());
-});
-
-test(`module '${ID}' has correct id`, () => {
- assert.equal(getDef().id, ID);
-});
-
-test(`module '${ID}' has correct deps`, () => {
- assert.deepEqual(getDef().deps, DEPS);
-});
-
-test(`module '${ID}' has args for each dependency`, () => {
- const def = getDef();
- assert.deepEqual(def.deps.length, def.fn.length);
-});
-
-test(`module '${ID}' inits without errors`, () => {
- createInst();
-});
-
-test(`module '${ID}' is only dummy definiton`, () => {
- assert.deepEqual(createInst(), {_dummyConfig: true});
-});
diff --git a/test-scar/tests/unit/libs.js b/test-scar/tests/unit/libs.js
deleted file mode 100644
index 0140d2e5..00000000
--- a/test-scar/tests/unit/libs.js
+++ /dev/null
@@ -1,25 +0,0 @@
-const {test, assert} = require('scar');
-
-const libs = {
- _: window._,
- $: window.jQuery,
- marked: window.marked,
- prism: window.Prism
-};
-
-Object.keys(libs).forEach(id => {
- test(`module '${id}' is defined`, () => {
- assert.ok(window.modulejs._private.definitions[id]);
- });
-
- test(`module '${id}' has no instance`, () => {
- assert.equal(window.modulejs._private.instances[id], undefined);
- });
-
- test(`module '${id}' returns global lib`, () => {
- const definition = window.modulejs._private.definitions[id];
- const instance = definition.fn();
- assert.ok(instance);
- assert.equal(instance, libs[id]);
- });
-});
diff --git a/test-scar/tests/unit/modulejs.js b/test-scar/tests/unit/modulejs.js
deleted file mode 100644
index 7fc11fba..00000000
--- a/test-scar/tests/unit/modulejs.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const {test, assert} = require('scar');
-
-test('modulejs is global object', () => {
- assert.equal(typeof window.modulejs, 'object');
-});
-
-test('modulejs.define() is function', () => {
- assert.equal(typeof window.modulejs.define, 'function');
-});
-
-test('modulejs.require() is function', () => {
- assert.equal(typeof window.modulejs.require, 'function');
-});
-
-test('modulejs.state() is function', () => {
- assert.equal(typeof window.modulejs.state, 'function');
-});
-
-test('modulejs.log() is function', () => {
- assert.equal(typeof window.modulejs.log, 'function');
-});
-
-test('modulejs._private is object', () => {
- assert.equal(typeof window.modulejs._private, 'object');
-});
-
-test('modulejs has definitions', () => {
- assert.ok(Object.keys(window.modulejs._private.definitions).length >= 0);
-});
-
-test('modulejs has no instances', () => {
- assert.equal(Object.keys(window.modulejs._private.instances).length, 0);
-});
diff --git a/test-scar/util/modjs.js b/test-scar/util/modjs.js
deleted file mode 100644
index 49de5244..00000000
--- a/test-scar/util/modjs.js
+++ /dev/null
@@ -1,17 +0,0 @@
-const lodash = window._;
-const modjs = window.modulejs;
-
-function clearModulejs() {
- lodash.each(modjs._private.instances, (val, key) => {
- delete modjs._private.instances[key]; // eslint-disable-line prefer-reflect
- });
-}
-
-function mockConfigModule() {
- modjs.define('config', {_dummyConfig: true});
-}
-
-module.exports = {
- clearModulejs,
- mockConfigModule
-};
diff --git a/test-scar/util/pin.js b/test-scar/util/pin.js
deleted file mode 100644
index 1419ffca..00000000
--- a/test-scar/util/pin.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const jq = window.jQuery;
-let title;
-let htmlId;
-let htmlClasses;
-let bodyId;
-let bodyClasses;
-let $pinnedElements;
-
-function pinHtml() {
- title = document.title;
- htmlId = jq('html').attr('id');
- htmlClasses = jq('html').attr('class');
- bodyId = jq('body').attr('id');
- bodyClasses = jq('body').attr('class');
- $pinnedElements = jq('head,body').children();
-}
-
-function restoreHtml() {
- document.title = title;
- jq('html').attr('id', htmlId);
- jq('html').attr('class', htmlClasses);
- jq('body').attr('id', bodyId);
- jq('body').attr('class', bodyClasses);
- jq('head,body').children().not($pinnedElements).remove();
- if (window.localStorage && window.localStorage.clear) {
- window.localStorage.clear();
- }
-}
-
-module.exports = {
- pinHtml,
- restoreHtml
-};
diff --git a/test/.eslintrc b/test/.eslintrc
deleted file mode 100644
index 65cfb122..00000000
--- a/test/.eslintrc
+++ /dev/null
@@ -1,30 +0,0 @@
----
- env:
- es6: false
- node: false
- browser: true
- mocha: true
-
- globals:
- modulejs: false
- jQuery: false
- $: false
- _: false
- util: false
- assert: false
- uniq: false
- sinon: false
-
- parserOptions:
- ecmaVersion: 6
-
- rules:
- consistent-this: 0
- func-names: 0
- max-nested-callbacks: [1, 5]
- max-params: [1, 10]
- no-invalid-this: 0
- no-var: 0
- object-shorthand: 0
- prefer-arrow-callback: 0
- prefer-reflect: 0
diff --git a/test/index.html.jade b/test/index.html.jade
deleted file mode 100644
index f6137360..00000000
--- a/test/index.html.jade
+++ /dev/null
@@ -1,14 +0,0 @@
-doctype html
-html
- head
- meta(charset="utf-8")
- meta(http-equiv="x-ua-compatible", content="ie=edge")
- title h5ai test suite - v#{pkg.version}
- meta(name="viewport", content="width=device-width, initial-scale=1")
- link(rel="stylesheet", href="h5ai-styles.css")
- link(rel="stylesheet", href="styles.css")
- script(src="h5ai-scripts.js")
- script(src="scripts.js")
-
- body
- div#mocha
diff --git a/test/scripts.js b/test/scripts.js
deleted file mode 100644
index 43b14689..00000000
--- a/test/scripts.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// @include "vendor/*.js"
-
-(function () {
- 'use strict'; // eslint-disable-line strict
- // @include "util/*.js"
-}());
-
-jQuery(function () {
- 'use strict'; // eslint-disable-line strict
-
- util.mockConfigModule();
- util.clearModulejs();
- util.setupMocha();
-
- describe('all tests', function () {
- // @include "tests/premisses.js"
-
- describe('unit tests', function () {
- // @include "tests/unit/modulejs.js"
- // @include "tests/unit/libs.js"
- // @include "tests/unit/boot.js"
- // @include "tests/unit/config.js"
-
- // @include "tests/unit/*/*.js"
- });
-
- describe('integration tests', function () {
- // @include "tests/integration/*.js"
- // @-include "tests/integration/*/*.js"
- });
- });
-
- util.pinHtml();
- util.runMocha();
-});
diff --git a/test/styles.less b/test/styles.less
deleted file mode 100644
index 5f478833..00000000
--- a/test/styles.less
+++ /dev/null
@@ -1,230 +0,0 @@
-@charset 'utf-8';
-
-@col-white: #ffffff;
-@col-red-500: #f44336;
-@col-red-800: #c62828;
-@col-amber-800: #ff8f00;
-@col-green-500: #4caf50;
-@col-grey-200: #eeeeee;
-@col-grey-800: #424242;
-
-@col-text: @col-grey-800;
-@col-text-fail: @col-red-800;
-@col-back-hover: @col-grey-200;
-@col-pending: @col-grey-800;
-@col-pass: @col-green-500;
-@col-fail: @col-red-500;
-@col-medium: @col-amber-800;
-@col-slow: @col-red-800;
-@col-progress: rgba(255,255,255,0.2);
-
-#mocha {
- position: fixed;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- z-index: 10000;
- font-family: "Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif";
- background: @col-white;
-
- #mocha-bar {
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- height: 32px;
- color: @col-white;
- background: @col-pending;
- font-size: 14px;
- font-weight: bold;
- line-height: 32px;
- padding: 0 8px;
- text-shadow: 0 0 4px @col-text;
-
- &.pass {
- background: @col-pass;
- }
- &.fail {
- background: @col-fail;
- }
- .stats {
- display: block;
- position: absolute;
- right: 8px;
- top: 0;
- cursor: pointer;
- }
- .progress {
- display: block;
- position: absolute;
- right: 0;
- top: 0;
- height: 100%;
- background: @col-progress;
- }
- }
-
- #mocha-stats {
- display: none;
- }
-
- #mocha-report {
- position: absolute;
- left: 0;
- top: 32px;
- right: 0;
- bottom: 0;
- overflow-x: auto;
- overflow-y: scroll;
-
- > .suite {
- margin: 0 auto;
- padding: 32px;
- max-width: 900px;
-
- > .toggle {
- display: none;
- }
- }
- }
-
- a, a:active, a:visited, a:hover {
- display: block;
- color: inherit;
- text-decoration: none;
- }
-
- ul, li, h1, h2 {
- margin: 0;
- padding: 0;
- }
-
- ul {
- list-style: none;
- }
-
- h1 {
- color: @col-text;
- height: 24px;
- line-height: 24px;
- font-size: 16px;
- font-weight: bold;
-
- &:hover {
- background: @col-back-hover;
- }
- a, a:active, a:visited, a:hover {
- padding: 0 8px;
- }
- .count {
- font-size: 0.85em;
- }
- .passed {
- color: @col-pass;
- margin-left: 1em;
- }
- .failed {
- color: @col-fail;
- margin-left: 0.5em;
- }
- }
-
- h2 {
- font-size: 12px;
- font-weight: normal;
- cursor: pointer;
- }
-
- pre {
- display: block;
- font-family: "Ubuntu Mono", "Monaco", "Lucida Sans Typewriter", "monospace";
- font-size: 12px;
- margin: 4px 0 16px 18px;
- padding: 0 8px;
- word-wrap: break-word;
- border-left: 2px solid @col-text;
-
- &.error {
- color: @col-text-fail;
- }
- }
-
- .suite {
- position: relative;
- margin: 16px 0 8px 24px;
-
- .toggle {
- position: absolute;
- left: -24px;
- top: 0;
- width: 24px;
- height: 24px;
- line-height: 24px;
- color: @col-text;
- font-size: 16px;
- font-weight: bold;
- text-align: center;
- cursor: pointer;
-
- &:hover {
- background: @col-back-hover;
- }
- }
- }
-
- .test {
- margin-left: 15px;
- padding: 2px 4px;
- overflow: hidden;
-
- &:hover {
- background: @col-back-hover;
- }
- &.fail {
- color: @col-text-fail;
- }
-
- &::before {
- content: ' ';
- display: block;
- width: 10px;
- height: 10px;
- float: left;
- margin-right: 8px;
- background: @col-pending;
- border-radius: 20px;
- position: relative;
- top: 3px;
- }
- &.pass::before {
- background: @col-pass;
- }
- &.fail::before {
- background: @col-fail;
- }
- &.pending::before {
- background: @col-pending;
- }
-
- .duration {
- display: inline-block;
- color: @col-text;
- border: none;
- box-shadow: none;
- font-size: 10px;
- margin-left: 12px;
- float: right;
- }
- &.medium .duration {
- color: @col-medium;
- }
- &.slow .duration {
- color: @col-slow;
- }
- }
-
- .replay {
- display: none;
- }
-}
diff --git a/test-scar/tests.html b/test/tests.html
similarity index 66%
rename from test-scar/tests.html
rename to test/tests.html
index 26434ba4..aeb9e917 100644
--- a/test-scar/tests.html
+++ b/test/tests.html
@@ -2,9 +2,8 @@
- h5ai test suite - scar
+ h5ai test suite
-
diff --git a/test/tests.js b/test/tests.js
new file mode 100644
index 00000000..a9401423
--- /dev/null
+++ b/test/tests.js
@@ -0,0 +1,8 @@
+const {test} = require('scar');
+const {pinHtml} = require('./util/pin');
+
+require('./tests/premisses');
+
+pinHtml();
+
+test.cli({sync: true});
diff --git a/test/tests/integration/view.js b/test/tests/integration/view.js
deleted file mode 100644
index 98f6e02d..00000000
--- a/test/tests/integration/view.js
+++ /dev/null
@@ -1,106 +0,0 @@
-(function () {
- describe('view', function () {
- before(function () {
- this.configBackup = modulejs._private.definitions.config;
- this.storeKey = '_h5ai';
- this.xConfig = {
- setup: {
- PUBLIC_HREF: uniq.path('-PUBLIC/'),
- ROOT_HREF: uniq.path('-ROOT/')
- }
- };
- });
-
- after(function () {
- modulejs._private.definitions.config = this.configBackup;
- util.clearModulejs();
- util.restoreHtml();
- });
-
- beforeEach(function () {
- delete modulejs._private.definitions.config;
- modulejs.define('config', this.xConfig);
- util.clearModulejs();
- util.restoreHtml();
- $('
').appendTo('body');
- $('
').appendTo('body');
- });
-
- describe('requiring \'view/viewmode\' sets up basic HTML', function () {
- it('runs without errors', function () {
- modulejs.require('view/viewmode');
- });
-
- it('adds id root to body', function () {
- modulejs.require('view/viewmode');
- assert.strictEqual($('body').attr('id'), 'root');
- });
-
- it('removes HTML #fallback', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#fallback'), 0);
- });
-
- it('removes HTML #fallback-hints', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#fallback-hints'), 0);
- });
-
- it('adds HTML #mainrow to #root', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#root > #mainrow'), 1);
- });
-
- it('adds HTML #content to #mainrow', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#mainrow > #content'), 1);
- });
-
- it('adds HTML #view to #content', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#content > #view'), 1);
- });
-
- it('adds HTML #items to #view', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#view > #items'), 1);
- });
-
- it('adds HTML #topbar to #root', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#root > #topbar'), 1);
- });
-
- it('adds HTML #toolbar to #topbar', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#topbar > #toolbar'), 1);
- });
-
- it('adds HTML #flowbar to #topbar', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#topbar > #flowbar'), 1);
- });
-
- it('adds HTML #backlink to #topbar', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#topbar > #backlink'), 1);
- });
-
- it('adds HTML #sidebar-toggle to #toolbar', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
- });
-
- it('adds HTML #viewmode-settings to #sidebar', function () {
- modulejs.require('view/viewmode');
- assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
- });
-
- it('adds style to head', function () {
- var styleTagCount = $('head > style').length;
- modulejs.require('view/viewmode');
- assert.lengthOf($('head > style'), styleTagCount + 1);
- });
- });
- });
-}());
diff --git a/test/tests/premisses.js b/test/tests/premisses.js
index 770f8ff7..43ba34d2 100644
--- a/test/tests/premisses.js
+++ b/test/tests/premisses.js
@@ -1,69 +1,21 @@
-(function () {
- describe('premisses', function () {
- it('window is global object', function () {
- assert.isObject(window);
- assert.strictEqual(window, window.window);
- });
+const {test, assert} = require('scar');
- it('document is global object', function () {
- assert.isObject(document);
- assert.strictEqual(document, window.document);
- });
+test('window is global object', () => {
+ assert.equal(typeof global, 'object');
+ assert.equal(global, global.window);
+});
- it('jQuery and $ are global functions', function () {
- assert.isFunction(jQuery);
- assert.strictEqual(jQuery, window.jQuery);
- assert.strictEqual(jQuery.fn.jquery, '2.2.4');
+test('document is global object', () => {
+ assert.equal(typeof global.document, 'object');
+});
- assert.strictEqual($, jQuery);
- assert.strictEqual($, window.$);
- });
+test('jQuery and $ are global functions', () => {
+ assert.equal(typeof global.jQuery, 'function');
+ assert.equal(global.jQuery.fn.jquery, '2.2.4');
+ assert.equal(global.jQuery, global.$);
+});
- it('_ is global function', function () {
- assert.isFunction(_);
- assert.strictEqual(_, window._);
- assert.strictEqual(_.VERSION, '4.13.1');
- });
-
- it('util is global object', function () {
- assert.isPlainObject(util);
- assert.strictEqual(util, window.util);
- });
-
- it('uniq is global object', function () {
- assert.isPlainObject(uniq);
- assert.strictEqual(uniq, window.uniq);
- });
-
- it('assert.isPlainObject() works', function () {
- assert.isFunction(assert.isPlainObject);
-
- assert.isPlainObject({});
- assert.isPlainObject({a: 1});
- assert.isPlainObject(Object());
- assert.isPlainObject(new Object()); // eslint-disable-line no-new-object
-
- assert.throws(function () { assert.isPlainObject(); });
- assert.throws(function () { assert.isPlainObject(1); });
- assert.throws(function () { assert.isPlainObject('a'); });
- assert.throws(function () { assert.isPlainObject(new Date()); });
- assert.throws(function () { assert.isPlainObject(/a/); });
- assert.throws(function () { assert.isPlainObject(function () {}); });
- assert.throws(function () { assert.isPlainObject(new function A() {}); });
- });
-
- it('assert.lengthOfKeys() works', function () {
- assert.isFunction(assert.lengthOfKeys);
-
- assert.lengthOfKeys({}, 0);
- assert.lengthOfKeys({a: true}, 1);
- assert.lengthOfKeys({a: true, b: 0, c: undefined}, 3);
-
- assert.throws(function () { assert.lengthOfKeys(); });
- assert.throws(function () { assert.lengthOfKeys(1); });
- assert.throws(function () { assert.lengthOfKeys('a'); });
- assert.throws(function () { assert.lengthOfKeys({}); });
- assert.throws(function () { assert.lengthOfKeys({}, 1); });
- });
- });
-}());
+test('_ is global function', () => {
+ assert.equal(typeof global._, 'function');
+ assert.equal(global._.VERSION, '4.13.1');
+});
diff --git a/test/tests/unit/boot.js b/test/tests/unit/boot.js
deleted file mode 100644
index 2e0e684f..00000000
--- a/test/tests/unit/boot.js
+++ /dev/null
@@ -1,134 +0,0 @@
-(function () {
- var ID = 'boot';
- var DEPS = ['$', 'core/server'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = uniq.obj();
- this.xDefine = sinon.stub(modulejs, 'define');
- this.xRequire = sinon.stub(modulejs, 'require');
- this.xServer = {
- request: sinon.stub().callsArgWith(1, this.xConfig)
- };
-
- this.applyFn = function () {
- this.xDefine.reset();
- this.xRequire.reset();
- this.xServer.request.reset();
-
- return this.definition.fn($, this.xServer);
- };
- });
-
- after(function () {
- this.xDefine.restore();
- this.xRequire.restore();
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns undefined', function () {
- var instance = this.applyFn();
- assert.isUndefined(instance);
- });
-
- it('no data-module', function () {
- this.applyFn();
- assert.isFalse(this.xServer.request.called);
- assert.isFalse(this.xDefine.called);
- assert.isFalse(this.xRequire.called);
- });
-
- it('data-module=\'test\'', function () {
- $('').attr('data-module', 'test').appendTo('head');
- this.applyFn();
- assert.isFalse(this.xServer.request.called);
- assert.isFalse(this.xDefine.called);
- assert.isFalse(this.xRequire.called);
- });
-
- it('data-module=\'info\'', function () {
- var expectedData = {
- action: 'get',
- setup: true,
- options: true,
- types: true,
- refresh: true
- };
-
- $('').attr('data-module', 'info').appendTo('head');
-
- this.applyFn();
-
- assert.isTrue(this.xServer.request.calledOnce);
- assert.isPlainObject(this.xServer.request.lastCall.args[0]);
- assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
- assert.isFunction(this.xServer.request.lastCall.args[1]);
-
- assert.isTrue(this.xDefine.calledOnce);
- assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
-
- assert.isTrue(this.xRequire.calledOnce);
- assert.deepEqual(this.xRequire.lastCall.args, ['main/info']);
- });
-
- it('data-module=\'index\'', function () {
- var expectedData = {
- action: 'get',
- setup: true,
- options: true,
- types: true,
- theme: true,
- langs: true
- };
-
- $('').attr('data-module', 'index').appendTo('head');
-
- this.applyFn();
-
- assert.isTrue(this.xServer.request.calledOnce);
- assert.isPlainObject(this.xServer.request.lastCall.args[0]);
- assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
- assert.isFunction(this.xServer.request.lastCall.args[1]);
-
- assert.isTrue(this.xDefine.calledOnce);
- assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
-
- assert.isTrue(this.xRequire.calledOnce);
- assert.deepEqual(this.xRequire.lastCall.args, ['main/index']);
- });
- });
- });
-}());
diff --git a/test/tests/unit/config.js b/test/tests/unit/config.js
deleted file mode 100644
index 2eb72079..00000000
--- a/test/tests/unit/config.js
+++ /dev/null
@@ -1,47 +0,0 @@
-(function () {
- var ID = 'config';
- var DEPS = [];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn($);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
-
- it('is only dummy definition', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- assert.isTrue(uniq.isId(instance._uniq_id));
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/event.js b/test/tests/unit/core/event.js
deleted file mode 100644
index 8d01a8d4..00000000
--- a/test/tests/unit/core/event.js
+++ /dev/null
@@ -1,104 +0,0 @@
-(function () {
- var ID = 'core/event';
- var DEPS = ['_'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn(_);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 3 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 3);
- });
- });
-
- describe('.sub()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.sub);
- });
- });
-
- describe('.unsub()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.unsub);
- });
- });
-
- describe('.pub()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.pub);
- });
- });
-
- describe('works', function () {
- it('works', function () {
- var topic = 'topic';
- var arg1 = 'arg1';
- var arg2 = 'arg2';
- var arg3 = 'arg3';
- var subSpy = sinon.spy();
-
- var instance = this.applyFn();
- instance.sub(topic, subSpy);
- instance.pub(topic, arg1, arg2, arg3);
-
- assert.isTrue(subSpy.calledOnce);
- assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
-
- instance.pub(topic, arg1, arg2);
-
- assert.isTrue(subSpy.calledTwice);
- assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
- assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
-
- instance.unsub(topic, subSpy);
-
- assert.isTrue(subSpy.calledTwice);
- assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
- assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
-
- instance.pub(topic, arg1);
-
- assert.isTrue(subSpy.calledTwice);
- assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
- assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/format.js b/test/tests/unit/core/format.js
deleted file mode 100644
index cc8b6725..00000000
--- a/test/tests/unit/core/format.js
+++ /dev/null
@@ -1,188 +0,0 @@
-(function () {
- var ID = 'core/format';
- var DEPS = ['_'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn(_);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 4 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 4);
- });
- });
-
- describe('.setDefaultMetric()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.setDefaultMetric);
- });
- });
-
- describe('.formatSize()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.formatSize);
- });
-
- it('defaults to decimal metric', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.formatSize(1024), '1 KB');
- instance.setDefaultMetric(true);
- assert.strictEqual(instance.formatSize(1024), '1 KiB');
- instance.setDefaultMetric(false);
- assert.strictEqual(instance.formatSize(1024), '1 KB');
- });
-
- describe('decimal metric', function () {
- _.each([
- [0, '0 B'],
- [10, '10 B'],
- [999, '999 B'],
- [1000, '1 KB'],
- [1001, '1 KB'],
- [1499, '1 KB'],
- [1500, '2 KB'],
- [999999, '1000 KB'],
- [1000000, '1.0 MB'],
- [1000001, '1.0 MB'],
- [1230000, '1.2 MB'],
- [1250000, '1.3 MB'],
- [999999999, '1000.0 MB'],
- [1000000000, '1.0 GB'],
- [1250000000, '1.3 GB'],
- [999999999999, '1000.0 GB'],
- [1000000000000, '1.0 TB'],
- [1250000000000, '1.3 TB']
- ], function (data) {
- var arg = data[0];
- var exp = data[1];
-
- it(arg + ' => ' + exp, function () {
- var instance = this.applyFn();
- instance.setDefaultMetric(false);
- assert.strictEqual(instance.formatSize(arg), exp);
- });
- });
- });
-
- describe('binary metric', function () {
- _.each([
- [0, '0 B'],
- [10, '10 B'],
- [999, '999 B'],
- [1000, '1000 B'],
- [1001, '1001 B'],
- [1024, '1 KiB'],
- [1499, '1 KiB'],
- [1500, '1 KiB'],
- [999999, '977 KiB'],
- [1000000, '977 KiB'],
- [1000001, '977 KiB'],
- [1230000, '1.2 MiB'],
- [1250000, '1.2 MiB'],
- [999999999, '953.7 MiB'],
- [1000000000, '953.7 MiB'],
- [1250000000, '1.2 GiB'],
- [999999999999, '931.3 GiB'],
- [1000000000000, '931.3 GiB'],
- [1250000000000, '1.1 TiB']
- ], function (data) {
- var arg = data[0];
- var exp = data[1];
-
- it(arg + ' => ' + exp, function () {
- var instance = this.applyFn();
- instance.setDefaultMetric(true);
- assert.strictEqual(instance.formatSize(arg), exp);
- });
- });
- });
- });
-
- describe('.setDefaultDateFormat()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.setDefaultDateFormat);
- });
- });
-
- describe('.formatDate()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.formatDate);
- });
-
- it('default format', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.formatDate(0), '');
- assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00');
- assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59');
- assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53');
-
- instance.setDefaultDateFormat('YYYY-MM-DD HH:mm:ss');
- assert.strictEqual(instance.formatDate(0), '');
- assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00:01');
- assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59:59');
- assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53:20');
-
- instance.setDefaultDateFormat('H YY s');
- assert.strictEqual(instance.formatDate(0), '');
- assert.strictEqual(instance.formatDate(1000), '1 70 1');
- assert.strictEqual(instance.formatDate(-1000), '0 70 59');
- assert.strictEqual(instance.formatDate(1400000000000), '18 14 20');
- });
-
- _.each([
- [0, 'YYYY-MM-DD HH:mm:ss', ''],
- [1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 01:00:01'],
- [-1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 00:59:59'],
- [1400000000000, 'YYYY-MM-DD HH:mm:ss', '2014-05-13 18:53:20'],
- [1400000000000, 'XYYYYXMMXDDXHHXmmXssX', 'X2014X05X13X18X53X20X'],
- [1400000000000, 'YYYY YY Y MM M DD D HH H mm m ss s', '2014 14 2014 05 5 13 13 18 18 53 53 20 20']
- ], function (data) {
- var arg1 = data[0];
- var arg2 = data[1];
- var exp = data[2];
-
- it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.formatDate(arg1, arg2), exp);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/langs.js b/test/tests/unit/core/langs.js
deleted file mode 100644
index a6c181e4..00000000
--- a/test/tests/unit/core/langs.js
+++ /dev/null
@@ -1,49 +0,0 @@
-(function () {
- var ID = 'core/langs';
- var DEPS = ['_', 'config'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = {langs: uniq.obj()};
- this.applyFn = function () {
- return this.definition.fn(_, this.xConfig);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with right content', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.deepEqual(instance, this.xConfig.langs);
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/location.js b/test/tests/unit/core/location.js
deleted file mode 100644
index ea95c1bb..00000000
--- a/test/tests/unit/core/location.js
+++ /dev/null
@@ -1,266 +0,0 @@
-(function () {
- var ID = 'core/location';
- var DEPS = ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xModernizr = {
- history: true
- };
- this.xSettings = {view: {
- fastBrowsing: true,
- unmanagedInNewWindow: true
- }};
- this.xEvent = {
- pub: sinon.stub(),
- sub: sinon.stub()
- };
- this.xNotification = {
- set: sinon.stub()
- };
- this.applyFn = function () {
- this.xEvent.pub.reset();
- this.xEvent.sub.reset();
- this.xNotification.set.reset();
-
- return this.definition.fn(_, this.xEvent, this.xModernizr, this.xSettings, this.xNotification);
- };
- });
-
- after(function () {
- window.onpopstate = null;
- });
-
- beforeEach(function () {
- window.onpopstate = null;
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 7 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 7);
- });
-
- it('sets window.onpopstate function when history and fastBrowsing', function () {
- this.xModernizr.history = true;
- this.xSettings.view.fastBrowsing = true;
-
- assert.isNull(window.onpopstate);
- this.applyFn();
- assert.isFunction(window.onpopstate);
- });
-
- it('sets window.onpopstate to null when not history and fastBrowsing', function () {
- this.xModernizr.history = false;
- this.xSettings.view.fastBrowsing = true;
-
- assert.isNull(window.onpopstate);
- this.applyFn();
- assert.isNull(window.onpopstate);
- });
-
- it('sets window.onpopstate to null when history and not fastBrowsing', function () {
- this.xModernizr.history = true;
- this.xSettings.view.fastBrowsing = false;
-
- assert.isNull(window.onpopstate);
- this.applyFn();
- assert.isNull(window.onpopstate);
- });
-
- it('sets window.onpopstate to null when not history and not fastBrowsing', function () {
- this.xModernizr.history = false;
- this.xSettings.view.fastBrowsing = false;
-
- assert.isNull(window.onpopstate);
- this.applyFn();
- assert.isNull(window.onpopstate);
- });
- });
-
- describe('.forceEncoding()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.forceEncoding);
- });
-
- _.each([
- ['', ''],
- ['//', '/'],
- ['////', '/'],
- ['//a///b////c//', '/a/b/c/'],
- ['a b', 'a%20b'],
- ['ab ', 'ab%20'],
- [' ab', '%20ab'],
- ['a!b', 'a%21b'],
- ['a#b', 'a%23b'],
- ['a$b', 'a%24b'],
- ['a&b', 'a%26b'],
- ['a\'b', 'a%27b'],
- ['a(b', 'a%28b'],
- ['a)b', 'a%29b'],
- ['a*b', 'a%2Ab'],
- ['a+b', 'a%2Bb'],
- ['a,b', 'a%2Cb'],
- ['a:b', 'a%3Ab'],
- ['a;b', 'a%3Bb'],
- ['a=b', 'a%3Db'],
- ['a?b', 'a%3Fb'],
- ['a@b', 'a%40b'],
- ['a[b', 'a%5Bb'],
- ['a]b', 'a%5Db']
- ], function (data) {
- var arg = data[0];
- var exp = data[1];
-
- it(arg + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.forceEncoding(arg), exp);
- });
- });
- });
-
- describe('.getDomain()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.getDomain);
- });
-
- it('returns document.domain', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.getDomain(), window.document.domain);
- });
- });
-
- describe('.getAbsHref()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.getAbsHref);
- });
-
- it('returns null before .setLocation()', function () {
- var instance = this.applyFn();
- assert.isNull(instance.getAbsHref());
- });
- });
-
- describe('.getItem()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.getItem);
- });
- });
-
- describe('.setLocation()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.setLocation);
- });
- });
-
- describe('.refresh()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.refresh);
- });
- });
-
- describe('.setLink()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.setLink);
- });
-
- it('sets href correct', function () {
- var $el = $(' ');
- var item = {
- absHref: uniq.id(),
- isManaged: false,
- isFolder: sinon.stub().returns(false)
- };
-
- var setLink = this.applyFn().setLink;
- setLink($el, item);
-
- assert.strictEqual($el.attr('href'), item.absHref);
- });
-
- it('sets target=\'_blank\' for unmanaged folders', function () {
- this.xSettings.view.unmanagedInNewWindow = true;
-
- var $el = $(' ');
- var item = {
- absHref: uniq.id(),
- isManaged: false,
- isFolder: sinon.stub().returns(true)
- };
-
- var setLink = this.applyFn().setLink;
- setLink($el, item);
-
- assert.strictEqual($el.attr('target'), '_blank');
- });
-
- it('does not set target=\'_blank\' for managed folders', function () {
- this.xSettings.view.unmanagedInNewWindow = true;
-
- var $el = $(' ');
- var item = {
- absHref: uniq.id(),
- isManaged: true,
- isFolder: sinon.stub().returns(true)
- };
-
- var setLink = this.applyFn().setLink;
- setLink($el, item);
-
- assert.isUndefined($el.attr('target'));
- });
-
- it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
- this.xSettings.view.unmanagedInNewWindow = false;
-
- var $el = $(' ');
- var item = {
- absHref: uniq.id(),
- isManaged: true,
- isFolder: sinon.stub().returns(true)
- };
-
- var setLink = this.applyFn().setLink;
- setLink($el, item);
-
- assert.isUndefined($el.attr('target'));
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/modernizr.js b/test/tests/unit/core/modernizr.js
deleted file mode 100644
index 5556a51e..00000000
--- a/test/tests/unit/core/modernizr.js
+++ /dev/null
@@ -1,69 +0,0 @@
-(function () {
- var ID = 'core/modernizr';
- var DEPS = [];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn();
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 3 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOf(_.keys(instance), 3);
- });
- });
-
- describe('.canvas', function () {
- it('is boolean', function () {
- var instance = this.applyFn();
- assert.isBoolean(instance.canvas);
- });
- });
-
- describe('.history', function () {
- it('is boolean', function () {
- var instance = this.applyFn();
- assert.isBoolean(instance.history);
- });
- });
-
- describe('.localstorage', function () {
- it('is boolean', function () {
- var instance = this.applyFn();
- assert.isBoolean(instance.localstorage);
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/resource.js b/test/tests/unit/core/resource.js
deleted file mode 100644
index 4504870e..00000000
--- a/test/tests/unit/core/resource.js
+++ /dev/null
@@ -1,92 +0,0 @@
-(function () {
- var ID = 'core/resource';
- var DEPS = ['_', 'config', 'core/settings'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = {
- theme: {
- a: 'myTheme/a.svg',
- b: 'myTheme/b.jpg'
- }
- };
- this.xSettings = {publicHref: uniq.path('/publicHref/')};
- this.applyFn = function () {
- return this.definition.fn(_, this.xConfig, this.xSettings);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 2 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 2);
- });
- });
-
- describe('.image()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.image);
- });
-
- it('works', function () {
- var instance = this.applyFn();
- var ui = this.xSettings.publicHref + 'images/ui/';
-
- assert.strictEqual(instance.image(), ui + 'undefined.svg');
- assert.strictEqual(instance.image(1), ui + '1.svg');
- assert.strictEqual(instance.image(''), ui + '.svg');
- assert.strictEqual(instance.image('a'), ui + 'a.svg');
- });
- });
-
- describe('.icon()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.icon);
- });
-
- it('works', function () {
- var instance = this.applyFn();
- var themes = this.xSettings.publicHref + 'images/themes/';
-
- assert.strictEqual(instance.icon(''), themes + 'default/file.svg');
- assert.strictEqual(instance.icon('a'), themes + 'myTheme/a.svg');
- assert.strictEqual(instance.icon('a-sub'), themes + 'myTheme/a.svg');
- assert.strictEqual(instance.icon('b'), themes + 'myTheme/b.jpg');
- assert.strictEqual(instance.icon('x'), themes + 'default/x.svg');
- assert.strictEqual(instance.icon('y'), themes + 'default/file.svg');
- assert.strictEqual(instance.icon('y-sub'), themes + 'default/file.svg');
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/server.js b/test/tests/unit/core/server.js
deleted file mode 100644
index 4cb9d19d..00000000
--- a/test/tests/unit/core/server.js
+++ /dev/null
@@ -1,169 +0,0 @@
-(function () {
- var ID = 'core/server';
- var DEPS = ['_', '$'];
- var $submitEl;
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xAjaxResult = {
- done: sinon.stub().returnsThis(),
- fail: sinon.stub().returnsThis(),
- always: sinon.stub().returnsThis()
- };
- this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
- this.xSubmit = sinon.stub($.fn, 'submit', function () {
- $submitEl = this;
- return this;
- });
-
- this.applyFn = function () {
- this.xAjaxResult.done.reset();
- this.xAjaxResult.fail.reset();
- this.xAjaxResult.always.reset();
- this.xAjax.reset();
- this.xSubmit.reset();
- $submitEl = undefined;
-
- return this.definition.fn(_, $);
- };
- });
-
- after(function () {
- this.xAjax.restore();
- this.xSubmit.restore();
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 2 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 2);
- });
- });
-
- describe('.request()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.request);
- });
-
- it('done() works', function () {
- var instance = this.applyFn();
-
- var xData = uniq.obj();
- var xResult = uniq.obj();
- var spy = sinon.spy();
- var res = instance.request(xData, spy);
-
- assert.isUndefined(res);
- assert.isTrue(this.xAjax.calledOnce);
- assert.deepEqual(this.xAjax.lastCall.args, [{
- url: '?',
- data: xData,
- type: 'post',
- dataType: 'json'
- }]);
- assert.isTrue(this.xAjaxResult.done.calledOnce);
- assert.isTrue(this.xAjaxResult.fail.calledOnce);
- assert.isFalse(spy.called);
-
- this.xAjaxResult.done.callArgWith(0, xResult);
-
- assert.isTrue(spy.calledOnce);
- assert.deepEqual(spy.firstCall.args, [xResult]);
- });
-
- it('fail() works', function () {
- var instance = this.applyFn();
-
- var xData = uniq.obj();
- var spy = sinon.spy();
- var res = instance.request(xData, spy);
-
- assert.isUndefined(res);
- assert.isTrue(this.xAjax.calledOnce);
- assert.deepEqual(this.xAjax.lastCall.args, [{
- url: '?',
- data: xData,
- type: 'post',
- dataType: 'json'
- }]);
- assert.isTrue(this.xAjaxResult.done.calledOnce);
- assert.isTrue(this.xAjaxResult.fail.calledOnce);
- assert.isFalse(spy.called);
-
- this.xAjaxResult.fail.callArg(0);
-
- assert.isTrue(spy.calledOnce);
- assert.deepEqual(spy.firstCall.args, []);
- });
- });
-
- describe('.formRequest()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.formRequest);
- });
-
- it('works', function () {
- var instance = this.applyFn();
-
- var xData = {
- a: uniq.id(),
- b: uniq.id()
- };
- var res = instance.formRequest(xData);
-
- assert.isUndefined(res);
-
- assert.isTrue(this.xSubmit.calledOnce);
-
- assert.lengthOf($submitEl, 1);
- assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
- assert.strictEqual($submitEl.attr('method'), 'post');
- assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
- assert.strictEqual($submitEl.attr('action'), '?');
-
- var $children = $submitEl.children();
-
- assert.lengthOf($children, 2);
-
- assert.strictEqual($children.eq(0).attr('type'), 'hidden');
- assert.strictEqual($children.eq(0).attr('name'), 'a');
- assert.strictEqual($children.eq(0).attr('value'), xData.a);
-
- assert.strictEqual($children.eq(1).attr('type'), 'hidden');
- assert.strictEqual($children.eq(1).attr('name'), 'b');
- assert.strictEqual($children.eq(1).attr('value'), xData.b);
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/settings.js b/test/tests/unit/core/settings.js
deleted file mode 100644
index a48792a7..00000000
--- a/test/tests/unit/core/settings.js
+++ /dev/null
@@ -1,83 +0,0 @@
-(function () {
- var ID = 'core/settings';
- var DEPS = ['_', 'config'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = {
- options: {
- someOptions: uniq.obj(),
- otherOptions: uniq.obj(),
- more: uniq.obj()
- },
- setup: {
- PUBLIC_HREF: uniq.id(),
- ROOT_HREF: uniq.id()
- }
- };
- this.applyFn = function () {
- return this.definition.fn(_, this.xConfig);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.isAbove(_.keys(instance).length, 0);
- });
- });
-
- describe('publics', function () {
- it('extended from options', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.someOptions, this.xConfig.options.someOptions);
- assert.strictEqual(instance.otherOptions, this.xConfig.options.otherOptions);
- assert.strictEqual(instance.more, this.xConfig.options.more);
- assert.strictEqual(_.keys(instance).length, _.keys(this.xConfig.options).length + 2);
- });
- });
-
- describe('.publicHref', function () {
- it('set correct', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.publicHref, this.xConfig.setup.PUBLIC_HREF);
- });
- });
-
- describe('.rootHref', function () {
- it('set correct', function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.rootHref, this.xConfig.setup.ROOT_HREF);
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/store.js b/test/tests/unit/core/store.js
deleted file mode 100644
index b078cfd3..00000000
--- a/test/tests/unit/core/store.js
+++ /dev/null
@@ -1,108 +0,0 @@
-(function () {
- var ID = 'core/store';
- var DEPS = ['core/modernizr'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.storeKey = '_h5ai';
- this.xModernizr = {localstorage: true};
- this.applyFn = function () {
- return this.definition.fn(this.xModernizr);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 2 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 2);
- });
- });
-
- describe('.put()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.put);
- });
- });
-
- describe('.get()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.get);
- });
- });
-
- describe('works', function () {
- it('works', function () {
- var key1 = 'test1';
- var value1 = '1234';
- var key2 = 'test2';
- var value2 = '5678';
- var instance = this.applyFn();
-
- assert.isNull(window.localStorage.getItem(this.storeKey));
-
- assert.isUndefined(instance.get(key1));
- assert.isNull(window.localStorage.getItem(this.storeKey));
-
- assert.isUndefined(instance.put(key1, value1));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
-
- assert.strictEqual(instance.get(key1), value1);
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
-
- assert.isUndefined(instance.put(key1, undefined));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
-
- assert.isUndefined(instance.get(key1));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
-
- assert.isUndefined(instance.put(key1, value1));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
-
- assert.isUndefined(instance.put(key2, value2));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234","test2":"5678"}');
-
- assert.isUndefined(instance.put(key1, undefined));
- assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test2":"5678"}');
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/types.js b/test/tests/unit/core/types.js
deleted file mode 100644
index 97834daa..00000000
--- a/test/tests/unit/core/types.js
+++ /dev/null
@@ -1,84 +0,0 @@
-(function () {
- var ID = 'core/types';
- var DEPS = ['_', 'config'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = {types: {
- a: ['*.a', '*.aa'],
- b: ['*.b'],
- c: ['*.c']
- }};
- this.applyFn = function () {
- return this.definition.fn(_, this.xConfig);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 1 property', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- });
- });
-
- describe('.getType()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.getType);
- });
-
- _.each([
- ['file.a', 'a'],
- ['file.aa', 'a'],
- ['foo.b', 'b'],
- ['some/path/file.c', 'c'],
- ['/some/abs/path/file.c', 'c'],
- ['file.x', 'file'],
- ['foo', 'file'],
- ['some/path/foo', 'file'],
- ['/some/path/foo', 'file'],
- ['foo/', 'folder'],
- ['/', 'folder'],
- ['some/path/foo/', 'folder'],
- ['/some/path/foo/', 'folder']
- ], function (data) {
- var arg = data[0];
- var exp = data[1];
-
- it(arg + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.getType(arg), exp);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/core/util.js b/test/tests/unit/core/util.js
deleted file mode 100644
index bb5252d5..00000000
--- a/test/tests/unit/core/util.js
+++ /dev/null
@@ -1,201 +0,0 @@
-(function () {
- var ID = 'core/util';
- var DEPS = ['_'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn(_);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 4 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 4);
- });
- });
-
- describe('.regularCmpFn()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.regularCmpFn);
- });
-
- _.each([
- [0, 0, 0],
- [1, 0, 1],
- [1, 2, -1],
- ['a', 'a', 0],
- ['b', 'a', 1],
- ['a', 'b', -1],
- ['a 2', 'a 10', 1]
- ], function (data) {
- var arg1 = data[0];
- var arg2 = data[1];
- var exp = data[2];
-
- it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
- });
- });
- });
-
- describe('.naturalCmpFn()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.naturalCmpFn);
- });
-
- _.each([
- [0, 0, 0],
- [1, 0, 1],
- [1, 2, -1],
- ['a', 'a', 0],
- ['b', 'a', 1],
- ['a', 'b', -1],
- ['a 2', 'a 10', -1]
- ], function (data) {
- var arg1 = data[0];
- var arg2 = data[1];
- var exp = data[2];
-
- it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
- });
- });
- });
-
- describe('.escapePattern()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.escapePattern);
- });
-
- _.each([
- ['a', 'a'],
- ['1', '1'],
- ['ä', 'ä'],
- ['~', '~'],
- [':', ':'],
- ['_', '_'],
- ['<', '<'],
- ['-', '\\-'],
- ['[', '\\['],
- [']', '\\]'],
- ['{', '\\{'],
- ['}', '\\}'],
- ['(', '\\('],
- [')', '\\)'],
- ['*', '\\*'],
- ['+', '\\+'],
- ['?', '\\?'],
- ['.', '\\.'],
- [',', '\\,'],
- ['\\', '\\\\'],
- ['$', '\\$'],
- ['^', '\\^'],
- ['|', '\\|'],
- ['#', '\\#'],
- [' ', '\\ '],
- ['-[]{}()*+?.,\\$^|# ', '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
- ['abc123', 'abc123'],
- ['a.b+c*1', 'a\\.b\\+c\\*1']
- ], function (data) {
- var arg = data[0];
- var exp = data[1];
-
- it(arg + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.escapePattern(arg), exp);
- });
- });
- });
-
- describe('.parsePattern()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.parsePattern);
- });
-
- _.each([
- ['a', false, 'a'],
- ['1', false, '1'],
- ['ä', false, 'ä'],
- ['~', false, '~'],
- [':', false, ':'],
- ['_', false, '_'],
- ['<', false, '<'],
- ['-', false, '\\-'],
- ['[', false, '\\['],
- [']', false, '\\]'],
- ['{', false, '\\{'],
- ['}', false, '\\}'],
- ['(', false, '\\('],
- [')', false, '\\)'],
- ['*', false, '\\*'],
- ['+', false, '\\+'],
- ['?', false, '\\?'],
- ['.', false, '\\.'],
- [',', false, '\\,'],
- ['\\', false, '\\\\'],
- ['$', false, '\\$'],
- ['^', false, '\\^'],
- ['|', false, '\\|'],
- ['#', false, '\\#'],
- [' ', false, '\\ '],
- ['-[]{}()*+?.,\\$^|# ', false, '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
- ['abc123', false, 'abc123'],
- ['a.b+c*1', false, 'a\\.b\\+c\\*1'],
-
- ['abc', true, 'a.*?b.*?c'],
- ['abc def', true, 'a.*?b.*?c|d.*?e.*?f'],
- ['*#a b.=', true, '\\*.*?\\#.*?a|b.*?\\..*?='],
- ['re:.', true, '.'],
- [' .', true, '\\.'],
- ['re: .', true, ' .']
-
- ], function (data) {
- var arg1 = data[0];
- var arg2 = data[1];
- var exp = data[2];
-
- it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
- var instance = this.applyFn();
- assert.strictEqual(instance.parsePattern(arg1, arg2), exp);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/ext/title.js b/test/tests/unit/ext/title.js
deleted file mode 100644
index 24ed3ea2..00000000
--- a/test/tests/unit/ext/title.js
+++ /dev/null
@@ -1,104 +0,0 @@
-(function () {
- var ID = 'ext/title';
- var DEPS = ['_', 'core/event', 'core/settings'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xEvent = {
- sub: sinon.stub()
- };
- this.xSettings = {title: {
- enabled: true
- }};
-
- this.applyFn = function () {
- this.xEvent.sub.reset();
-
- return this.definition.fn(_, this.xEvent, this.xSettings);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns undefined', function () {
- var instance = this.applyFn();
- assert.isUndefined(instance);
- });
-
- it('subscribes to location.changed', function () {
- this.xSettings.title.enabled = true;
-
- this.applyFn();
- assert.isTrue(this.xEvent.sub.calledOnce);
- assert.strictEqual(this.xEvent.sub.lastCall.args[0], 'location.changed');
- });
-
- it('does not subscribe to events if disabled', function () {
- this.xSettings.title.enabled = false;
-
- this.applyFn();
- assert.isFalse(this.xEvent.sub.called);
- });
- });
-
- describe('sets title on location.changed', function () {
- _.each([
- [''],
- ['a', 'a'],
- ['a', 'b', 'b - a > b'],
- ['a', 'b', 'c', 'c - a > b > c']
- ], function (data) {
- var labels = data.slice(0, -1);
- var exp = data.slice(-1)[0];
-
- it(labels + ' => ' + exp, function () {
- this.xSettings.title.enabled = true;
-
- this.applyFn();
-
- var fn = this.xEvent.sub.lastCall.args[1];
- var crumb = _.map(labels, function (x) { return {label: x}; });
- var item = {
- getCrumb: sinon.stub().returns(crumb)
- };
-
- fn(item);
-
- assert.isTrue(item.getCrumb.calledOnce);
- assert.strictEqual(document.title, exp);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/libs.js b/test/tests/unit/libs.js
deleted file mode 100644
index 09600806..00000000
--- a/test/tests/unit/libs.js
+++ /dev/null
@@ -1,29 +0,0 @@
-(function () {
- describe('libs', function () {
- var libs = {
- _: window._,
- $: window.jQuery,
- marked: window.marked,
- prism: window.Prism
- };
-
- _.each(libs, function (lib, id) {
- describe('module \'' + id + '\'', function () {
- it('is defined', function () {
- assert.isDefined(modulejs._private.definitions[id]);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, id);
- });
-
- it('returns global lib', function () {
- var definition = modulejs._private.definitions[id];
- var instance = definition.fn();
- assert.isDefined(instance);
- assert.strictEqual(instance, lib);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/main/index.js b/test/tests/unit/main/index.js
deleted file mode 100644
index 75e5d436..00000000
--- a/test/tests/unit/main/index.js
+++ /dev/null
@@ -1,102 +0,0 @@
-(function () {
- var ID = 'main/index';
- var DEPS = ['_', 'core/location'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xLocation = {setLocation: sinon.stub()};
- this.xRequire = sinon.stub(modulejs, 'require');
-
- this.applyFn = function () {
- this.xLocation.setLocation.reset();
- this.xRequire.reset();
- return this.definition.fn(_, this.xLocation);
- };
- });
-
- after(function () {
- this.xRequire.restore();
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns undefined', function () {
- var instance = this.applyFn();
- assert.isUndefined(instance);
- });
-
- it('requires view/viewmode', function () {
- this.applyFn();
- assert.isTrue(this.xRequire.calledWithExactly('view/viewmode'));
- });
-
- it('requires all extensions', function () {
- this.applyFn();
- var re = /^ext\//;
- var self = this;
-
- _.each(modulejs.state(), function (state, id) {
- if (re.test(id)) {
- assert.isTrue(self.xRequire.calledWithExactly(id));
- }
- });
- });
-
- it('requires only views and extensions', function () {
- this.applyFn();
- assert.isTrue(this.xRequire.alwaysCalledWithMatch(/^(view|ext)\//));
- });
-
- it('requires views before extensions', function () {
- this.applyFn();
- var foundExtension = false;
- var reView = /^view\//;
- var reExt = /^ext\//;
-
- _.each(this.xRequire.args, function (args) {
- if (foundExtension) {
- assert.match(args[0], reExt);
- } else if (reExt.test(args[0])) {
- foundExtension = true;
- } else {
- assert.match(args[0], reView);
- }
- });
- });
-
- it('calls setLocation with current href, keeping browser url', function () {
- this.applyFn();
- assert.isTrue(this.xLocation.setLocation.calledOnce);
- assert.deepEqual(this.xLocation.setLocation.firstCall.args, [document.location.href, true]);
- assert.isTrue(this.xLocation.setLocation.calledAfter(this.xRequire));
- });
- });
- });
-}());
diff --git a/test/tests/unit/main/info.js b/test/tests/unit/main/info.js
deleted file mode 100644
index 33ad4d0e..00000000
--- a/test/tests/unit/main/info.js
+++ /dev/null
@@ -1,180 +0,0 @@
-(function () {
- var ID = 'main/info';
- var DEPS = ['$', 'config', 'core/resource', 'core/server'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xConfig = {
- setup: {
- VERSION: uniq.id()
- },
- options: {}
- };
- this.xResource = {
- image: sinon.stub()
- };
- this.xServer = {
- request: sinon.stub()
- };
-
- this.applyFn = function () {
- this.xServer.request.reset();
-
- return this.definition.fn($, this.xConfig, this.xResource, this.xServer);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns undefined', function () {
- var instance = this.applyFn();
- assert.isUndefined(instance);
- });
-
- it('adds HTML #support to #content', function () {
- this.applyFn();
- assert.lengthOf($('#content > #support'), 1);
- assert.lengthOf($('#support > .paypal'), 1);
- assert.lengthOf($('.paypal > form'), 1);
- });
-
- it('adds HTML #login-wrapper to #content', function () {
- this.applyFn();
- assert.lengthOf($('#content > #login-wrapper'), 1);
- });
-
- describe('no admin', function () {
- it('adds HTML #pass to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #pass'), 1);
- });
-
- it('sets #pass val to empty string', function () {
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- assert.strictEqual($('#login-wrapper > #pass').val(), '');
- });
-
- it('adds HTML #login to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #login'), 1);
- });
-
- it('does not add HTML #logout to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #logout'), 0);
- });
-
- it('does not add HTML #tests to #content', function () {
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- assert.lengthOf($('#content > #tests'), 0);
- });
-
- it('login works', function () {
- var pass = uniq.id();
- var expectedData = {
- action: 'login',
- pass: pass
- };
-
- this.xConfig.setup.AS_ADMIN = false;
- this.applyFn();
- $('#pass').val(pass);
- $('#login').trigger('click');
-
- assert.isTrue(this.xServer.request.calledOnce);
- assert.isPlainObject(this.xServer.request.lastCall.args[0]);
- assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
- assert.isFunction(this.xServer.request.lastCall.args[1]);
- });
- });
-
- describe('as admin', function () {
- it('does not add HTML #pass to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #pass'), 0);
- });
-
- it('does not add #login to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #login'), 0);
- });
-
- it('adds HTML #logout to #login-wrapper', function () {
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- assert.lengthOf($('#login-wrapper > #logout'), 1);
- });
-
- it('adds HTML #tests to #content', function () {
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- assert.lengthOf($('#content > #tests'), 1);
- });
-
- it('adds HTML #test 15x to #tests', function () {
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- assert.strictEqual($('#tests > .test').length, 15);
- });
-
- it('logout works', function () {
- var expectedData = {
- action: 'logout'
- };
-
- this.xConfig.setup.AS_ADMIN = true;
- this.applyFn();
- $('#logout').trigger('click');
-
- assert.isTrue(this.xServer.request.calledOnce);
- assert.isPlainObject(this.xServer.request.lastCall.args[0]);
- assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
- assert.isFunction(this.xServer.request.lastCall.args[1]);
- });
- });
- });
- });
-}());
diff --git a/test/tests/unit/model/item.js b/test/tests/unit/model/item.js
deleted file mode 100644
index e6851278..00000000
--- a/test/tests/unit/model/item.js
+++ /dev/null
@@ -1,356 +0,0 @@
-(function () {
- var ID = 'model/item';
- var DEPS = ['_', 'core/event', 'core/location', 'core/server', 'core/settings', 'core/types'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xRootName = uniq.id();
- this.xTypes = {
- getType: sinon.stub().returns(uniq.id())
- };
- this.xEvent = uniq.obj();
- this.xSettings = {
- rootHref: uniq.path('/' + this.xRootName + '/')
- };
- this.xServer = uniq.obj();
- this.xLocation = {
- forceEncoding: sinon.stub().returnsArg(0),
- getDomain: sinon.stub().returns(uniq.id()),
- getAbsHref: sinon.stub().returns(uniq.id())
- };
- this.applyFn = function () {
- return this.definition.fn(_, this.xEvent, this.xLocation, this.xServer, this.xSettings, this.xTypes);
- };
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 2 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 2);
- });
- });
-
- describe('.get()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.get);
- });
-
- it('returns null with no argument', function () {
- var instance = this.applyFn();
- assert.isNull(instance.get());
- });
-
- it('returns null for no string argument', function () {
- var instance = this.applyFn();
- assert.isNull(instance.get(1));
- });
-
- it('returns null for href not starting with rootHref', function () {
- var instance = this.applyFn();
- assert.isNull(instance.get('/a/'));
- });
-
- describe('for rootHref', function () {
- beforeEach(function () {
- var instance = this.applyFn();
- this.item = instance.get(this.xSettings.rootHref);
- });
-
- it('returns object', function () {
- assert.isObject(this.item);
- });
-
- it('sets href correct', function () {
- assert.strictEqual(this.item.absHref, this.xSettings.rootHref);
- });
-
- it('sets type correct', function () {
- assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
- });
-
- it('sets label correct', function () {
- assert.strictEqual(this.item.label, this.xRootName);
- });
-
- it('sets time to null', function () {
- assert.isNull(this.item.time);
- });
-
- it('sets size to null', function () {
- assert.isNull(this.item.size);
- });
-
- it('sets parent to null', function () {
- assert.isNull(this.item.parent);
- });
-
- it('sets isManaged to null', function () {
- assert.isNull(this.item.isManaged);
- });
-
- it('sets content correct', function () {
- assert.isPlainObject(this.item.content);
- assert.lengthOfKeys(this.item.content, 0);
- });
-
- it('.isFolder() returns true', function () {
- assert.isTrue(this.item.isFolder());
- });
-
- it('.isCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentFolder());
- });
-
- it('.isInCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isInCurrentFolder());
- });
-
- it('.isCurrentParentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentParentFolder());
- });
-
- it('.isDomain() returns false', function () {
- assert.isFalse(this.item.isDomain());
- });
-
- it('.isRoot() returns true', function () {
- assert.isTrue(this.item.isRoot());
- });
-
- it('.isEmpty() returns true', function () {
- assert.isTrue(this.item.isEmpty());
- });
- });
-
- describe('for folder href other than rootHref', function () {
- beforeEach(function () {
- var instance = this.applyFn();
- this.item = instance.get(this.xSettings.rootHref + 'a/');
- });
-
- it('returns object', function () {
- assert.isObject(this.item);
- });
-
- it('sets href correct', function () {
- assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a/');
- });
-
- it('sets type correct', function () {
- assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
- });
-
- it('sets label correct', function () {
- assert.strictEqual(this.item.label, 'a');
- });
-
- it('sets time to null', function () {
- assert.isNull(this.item.time);
- });
-
- it('sets size to null', function () {
- assert.isNull(this.item.size);
- });
-
- it('sets parent to object', function () {
- assert.isObject(this.item.parent);
- });
-
- it('parent has same constructor', function () {
- assert.strictEqual(this.item.constructor, this.item.parent.constructor);
- });
-
- it('sets isManaged to null', function () {
- assert.isNull(this.item.isManaged);
- });
-
- it('sets content correct', function () {
- assert.isPlainObject(this.item.content);
- assert.lengthOfKeys(this.item.content, 0);
- });
-
- it('.isFolder() returns true', function () {
- assert.isTrue(this.item.isFolder());
- });
-
- it('.isCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentFolder());
- });
-
- it('.isInCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isInCurrentFolder());
- });
-
- it('.isCurrentParentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentParentFolder());
- });
-
- it('.isDomain() returns false', function () {
- assert.isFalse(this.item.isDomain());
- });
-
- it('.isRoot() returns false', function () {
- assert.isFalse(this.item.isRoot());
- });
-
- it('.isEmpty() returns true', function () {
- assert.isTrue(this.item.isEmpty());
- });
- });
-
- describe('for file href', function () {
- beforeEach(function () {
- var instance = this.applyFn();
- this.item = instance.get(this.xSettings.rootHref + 'a');
- });
-
- it('returns object', function () {
- assert.isObject(this.item);
- });
-
- it('sets href correct', function () {
- assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a');
- });
-
- it('sets type correct', function () {
- assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
- });
-
- it('sets label correct', function () {
- assert.strictEqual(this.item.label, 'a');
- });
-
- it('sets time to null', function () {
- assert.isNull(this.item.time);
- });
-
- it('sets size to null', function () {
- assert.isNull(this.item.size);
- });
-
- it('sets parent to object', function () {
- assert.isObject(this.item.parent);
- });
-
- it('parent has same constructor', function () {
- assert.strictEqual(this.item.constructor, this.item.parent.constructor);
- });
-
- it('sets isManaged to null', function () {
- assert.isNull(this.item.isManaged);
- });
-
- it('sets content correct', function () {
- assert.isPlainObject(this.item.content);
- assert.lengthOfKeys(this.item.content, 0);
- });
-
- it('.isFolder() returns false', function () {
- assert.isFalse(this.item.isFolder());
- });
-
- it('.isCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentFolder());
- });
-
- it('.isInCurrentFolder() returns false', function () {
- assert.isFalse(this.item.isInCurrentFolder());
- });
-
- it('.isCurrentParentFolder() returns false', function () {
- assert.isFalse(this.item.isCurrentParentFolder());
- });
-
- it('.isDomain() returns false', function () {
- assert.isFalse(this.item.isDomain());
- });
-
- it('.isRoot() returns false', function () {
- assert.isFalse(this.item.isRoot());
- });
-
- it('.isEmpty() returns true', function () {
- assert.isTrue(this.item.isEmpty());
- });
- });
-
- describe('parents', function () {
- beforeEach(function () {
- var instance = this.applyFn();
- this.item = instance.get(this.xSettings.rootHref + 'p/a/');
- this.parent = this.item.parent;
- this.grandpa = this.parent.parent;
- });
-
- it('parent is object', function () {
- assert.isObject(this.parent);
- });
-
- it('parent has correct href', function () {
- assert.strictEqual(this.parent.absHref, this.xSettings.rootHref + 'p/');
- });
-
- it('parent has correct label', function () {
- assert.strictEqual(this.parent.label, 'p');
- });
-
- it('parent .isEmpty() returns false', function () {
- assert.isFalse(this.parent.isEmpty());
- });
-
- it('grandpa is object', function () {
- assert.isObject(this.grandpa);
- });
-
- it('grandpa has correct href', function () {
- assert.strictEqual(this.grandpa.absHref, this.xSettings.rootHref);
- });
-
- it('grandpa has correct label', function () {
- assert.strictEqual(this.grandpa.label, this.xRootName);
- });
-
- it('grandpa .isEmpty() returns false', function () {
- assert.isFalse(this.grandpa.isEmpty());
- });
- });
- });
-
- describe('.remove()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isFunction(instance.remove);
- });
- });
- });
-}());
diff --git a/test/tests/unit/modulejs.js b/test/tests/unit/modulejs.js
deleted file mode 100644
index 03dfb9cf..00000000
--- a/test/tests/unit/modulejs.js
+++ /dev/null
@@ -1,36 +0,0 @@
-(function () {
- describe('modulejs', function () {
- it('is global object', function () {
- assert.isPlainObject(modulejs);
- assert.strictEqual(modulejs, window.modulejs);
- });
-
- it('.define() is function', function () {
- assert.isFunction(modulejs.define);
- });
-
- it('.require() is function', function () {
- assert.isFunction(modulejs.require);
- });
-
- it('.state() is function', function () {
- assert.isFunction(modulejs.state);
- });
-
- it('.log() is function', function () {
- assert.isFunction(modulejs.log);
- });
-
- it('._private is object', function () {
- assert.isObject(modulejs._private);
- });
-
- it('has definitions', function () {
- assert.isAbove(_.keys(modulejs._private.definitions).length, 0);
- });
-
- it('has no instances', function () {
- assert.lengthOfKeys(modulejs._private.instances, 0);
- });
- });
-}());
diff --git a/test/tests/unit/view/content.js b/test/tests/unit/view/content.js
deleted file mode 100644
index eecce7f0..00000000
--- a/test/tests/unit/view/content.js
+++ /dev/null
@@ -1,73 +0,0 @@
-(function () {
- var ID = 'view/content';
- var DEPS = ['$', 'view/mainrow'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xMainrow = {$el: null};
- this.applyFn = function () {
- return this.definition.fn($, this.xMainrow);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xMainrow.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 1 property', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- });
-
- it('adds HTML #content to #mainrow', function () {
- this.applyFn();
- assert.lengthOf($('#mainrow > #content'), 1);
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#content\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'content');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/mainrow.js b/test/tests/unit/view/mainrow.js
deleted file mode 100644
index 66f58f10..00000000
--- a/test/tests/unit/view/mainrow.js
+++ /dev/null
@@ -1,73 +0,0 @@
-(function () {
- var ID = 'view/mainrow';
- var DEPS = ['$', 'view/root'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xRoot = {$el: null};
- this.applyFn = function () {
- return this.definition.fn($, this.xRoot);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xRoot.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 1 property', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- });
-
- it('adds HTML #mainrow to #root', function () {
- this.applyFn();
- assert.lengthOf($('#root > #mainrow'), 1);
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#mainrow\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'mainrow');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/notification.js b/test/tests/unit/view/notification.js
deleted file mode 100644
index 8eb726d8..00000000
--- a/test/tests/unit/view/notification.js
+++ /dev/null
@@ -1,102 +0,0 @@
-(function () {
- var ID = 'view/notification';
- var DEPS = ['$', 'view/root'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xRoot = {$el: null};
- this.applyFn = function () {
- return this.definition.fn($, this.xRoot);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xRoot.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns plain object with 2 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 2);
- });
-
- it('adds HTML #notification to #root (hidden)', function () {
- this.applyFn();
- assert.lengthOf($('#root > #notification'), 1);
- assert.lengthOf($('#notification:visible'), 0);
- assert.strictEqual($('#notification').text(), '');
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#notification\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'notification');
- });
- });
-
- describe('.set()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.set));
- });
-
- it('works', function () {
- var instance = this.applyFn();
-
- instance.set();
- assert.lengthOf($('#notification:visible'), 0);
- assert.strictEqual($('#notification').text(), '');
-
- instance.set('hello');
- assert.lengthOf($('#notification:visible'), 1);
- assert.strictEqual($('#notification').text(), 'hello');
-
- instance.set('world');
- assert.lengthOf($('#notification:visible'), 1);
- assert.strictEqual($('#notification').text(), 'world');
-
- instance.set();
- // assert.lengthOf($('#notification:visible'), 0);
- assert.strictEqual($('#notification').text(), 'world');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/root.js b/test/tests/unit/view/root.js
deleted file mode 100644
index f2c66358..00000000
--- a/test/tests/unit/view/root.js
+++ /dev/null
@@ -1,83 +0,0 @@
-(function () {
- var ID = 'view/root';
- var DEPS = ['$'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.applyFn = function () {
- return this.definition.fn($);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- $('
').appendTo('body');
- $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 1 property', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- });
-
- it('adds id root to body', function () {
- this.applyFn();
- assert.strictEqual($('body').attr('id'), 'root');
- });
-
- it('removes HTML #fallback', function () {
- this.applyFn();
- assert.lengthOf($('#fallback'), 0);
- });
-
- it('removes HTML #fallback-hints', function () {
- this.applyFn();
- assert.lengthOf($('#fallback-hints'), 0);
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#root\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'root');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/sidebar.js b/test/tests/unit/view/sidebar.js
deleted file mode 100644
index 6fc498aa..00000000
--- a/test/tests/unit/view/sidebar.js
+++ /dev/null
@@ -1,121 +0,0 @@
-(function () {
- var ID = 'view/sidebar';
- var DEPS = ['$', 'core/resource', 'core/store', 'view/mainrow', 'view/topbar'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xResource = {
- image: sinon.stub().throws('invalid image request')
- };
- this.xResource.image.withArgs('back').returns(uniq.path('-back.png'));
- this.xResource.image.withArgs('sidebar').returns(uniq.path('-sidebar.png'));
- this.xStore = {
- get: sinon.stub().returns(false),
- put: sinon.stub()
- };
- this.xStore.get.returns(false);
- this.xMainrow = {$el: null};
- this.xTopbar = {$toolbar: null};
- this.applyFn = function () {
- this.xResource.image.reset();
- this.xStore.get.reset();
- this.xStore.put.reset();
-
- return this.definition.fn($, this.xResource, this.xStore, this.xMainrow, this.xTopbar);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xMainrow.$el = $('
').appendTo('body');
- this.xTopbar.$toolbar = $('
').appendTo('body');
- });
-
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.instance = this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 1 property', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 1);
- });
-
- it('adds HTML #sidebar-toggle to #toolbar', function () {
- this.applyFn();
- assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
- });
-
- it('toggle works', function () {
- this.applyFn();
- assert.lengthOf($('#sidebar:visible'), 0);
-
- this.xStore.get.returns(false).reset();
- this.xStore.put.reset();
-
- $('#sidebar-toggle').trigger('click');
-
- assert.isTrue(this.xStore.get.calledOnce);
- assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
- assert.isTrue(this.xStore.put.calledOnce);
- assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
- assert.isTrue(this.xStore.put.lastCall.args[1]);
-
- assert.lengthOf($('#sidebar:visible'), 1);
-
- this.xStore.get.returns(true).reset();
- this.xStore.put.reset();
-
- $('#sidebar-toggle').trigger('click');
-
- assert.isTrue(this.xStore.get.calledOnce);
- assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
- assert.isTrue(this.xStore.put.calledOnce);
- assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
- assert.isFalse(this.xStore.put.lastCall.args[1]);
-
- assert.lengthOf($('#sidebar:visible'), 0);
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#sidebar\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'sidebar');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/topbar.js b/test/tests/unit/view/topbar.js
deleted file mode 100644
index 9b5747d6..00000000
--- a/test/tests/unit/view/topbar.js
+++ /dev/null
@@ -1,124 +0,0 @@
-(function () {
- var ID = 'view/topbar';
- var DEPS = ['$', 'view/root'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xRoot = {$el: null};
- this.applyFn = function () {
- return this.definition.fn($, this.xRoot);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xRoot.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 3 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 3);
- });
-
- it('adds HTML #topbar to #root', function () {
- this.applyFn();
- assert.lengthOf($('#root > #topbar'), 1);
- });
-
- it('adds HTML #toolbar to #topbar', function () {
- this.applyFn();
- assert.lengthOf($('#topbar > #toolbar'), 1);
- });
-
- it('adds HTML #flowbar to #topbar', function () {
- this.applyFn();
- assert.lengthOf($('#topbar > #flowbar'), 1);
- });
-
- it('adds HTML #backlink to #topbar', function () {
- this.applyFn();
- assert.lengthOf($('#topbar > #backlink'), 1);
- });
-
- it('#backlink has correct href', function () {
- this.applyFn();
- assert.strictEqual($('#backlink').attr('href'), 'https://larsjung.de/h5ai/');
- });
-
- it('#backlink has correct title', function () {
- this.applyFn();
- assert.strictEqual($('#backlink').attr('title'), 'powered by h5ai - https://larsjung.de/h5ai/');
- });
-
- it('#backlink has correct text', function () {
- this.applyFn();
- assert.strictEqual($('#backlink > div').eq(0).text(), 'powered');
- assert.strictEqual($('#backlink > div').eq(1).text(), 'by h5ai');
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#topbar\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'topbar');
- });
- });
-
- describe('.$toolbar', function () {
- it('is $(\'#toolbar\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$toolbar);
- assert.lengthOf(instance.$toolbar, 1);
- assert.isString(instance.$toolbar.jquery);
- assert.strictEqual(instance.$toolbar.attr('id'), 'toolbar');
- });
- });
-
- describe('.$flowbar', function () {
- it('is $(\'#flowbar\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$flowbar);
- assert.lengthOf(instance.$flowbar, 1);
- assert.isString(instance.$flowbar.jquery);
- assert.strictEqual(instance.$flowbar.attr('id'), 'flowbar');
- });
- });
- });
-}());
diff --git a/test/tests/unit/view/view.js b/test/tests/unit/view/view.js
deleted file mode 100644
index a5cef8a7..00000000
--- a/test/tests/unit/view/view.js
+++ /dev/null
@@ -1,385 +0,0 @@
-(function () {
- var ID = 'view/view';
- var DEPS = ['_', '$', 'core/event', 'core/format', 'core/location', 'core/resource', 'core/settings', 'core/store', 'view/content'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xEvent = {
- sub: sinon.stub(),
- pub: sinon.stub()
- };
- this.xFormat = {
- setDefaultMetric: sinon.stub(),
- formatDate: sinon.stub().returns(uniq.id()),
- formatSize: sinon.stub().returns(uniq.id())
- };
- this.xLocation = {
- setLink: sinon.stub().returns(uniq.id())
- };
- this.xResource = {
- icon: sinon.stub().returns(uniq.id())
- };
- this.xSettings = {view: {
- binaryPrefix: false,
- hideFolders: false,
- hideParentFolder: false,
- modes: ['details', 'grid', 'icons'],
- setParentFolderLabels: false,
- sizes: [20, 40, 60, 80, 100, 150, 200, 250, 300, 350, 400]
- }};
- this.xStore = {
- get: sinon.stub(),
- put: sinon.stub()
- };
- this.xContent = {$el: null};
-
- this.applyFn = function () {
- this.xEvent.sub.reset();
- this.xEvent.pub.reset();
- this.xFormat.setDefaultMetric.reset();
- this.xFormat.formatDate.reset();
- this.xFormat.formatSize.reset();
- this.xLocation.setLink.reset();
- this.xResource.icon.reset();
-
- return this.definition.fn(_, $, this.xEvent, this.xFormat, this.xLocation, this.xResource, this.xSettings, this.xStore, this.xContent);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xContent.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns object with 12 properties', function () {
- var instance = this.applyFn();
- assert.isPlainObject(instance);
- assert.lengthOfKeys(instance, 12);
- });
-
- it('adds HTML #view to #content', function () {
- this.applyFn();
- assert.lengthOf($('#content > #view'), 1);
- });
-
- it('adds HTML #items to #view', function () {
- this.applyFn();
- assert.lengthOf($('#view > #items'), 1);
- });
-
- it('adds HTML #view-hint to #view', function () {
- this.applyFn();
- assert.lengthOf($('#view > #view-hint'), 1);
- });
-
- it('adds style to head', function () {
- var styleTagCount = $('head > style').length;
- this.applyFn();
- assert.lengthOf($('head > style'), styleTagCount + 1);
- });
-
- it('style contains possibly correct text', function () {
- this.xSettings.sizes = [20];
- this.applyFn();
- var text = $('head > style').eq(0).text();
- assert.isTrue(text.indexOf('#view.view-details.view-size-20 ') >= 0);
- assert.isTrue(text.indexOf('#view.view-grid.view-size-20 ') >= 0);
- assert.isTrue(text.indexOf('#view.view-icons.view-size-20 ') >= 0);
- });
-
- it('sets default metric', function () {
- this.applyFn();
- assert.isTrue(this.xFormat.setDefaultMetric.calledOnce);
- });
-
- it('subscribes to 2 events', function () {
- this.applyFn();
- assert.isTrue(this.xEvent.sub.calledTwice);
- });
-
- it('subscribes to location.changed', function () {
- this.applyFn();
- assert.strictEqual(this.xEvent.sub.firstCall.args[0], 'location.changed');
- assert.isFunction(this.xEvent.sub.firstCall.args[1]);
- });
-
- it('subscribes to location.refreshed', function () {
- this.applyFn();
- assert.strictEqual(this.xEvent.sub.secondCall.args[0], 'location.refreshed');
- assert.isFunction(this.xEvent.sub.secondCall.args[1]);
- });
- });
-
- describe('.$el', function () {
- it('is $(\'#view\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$el);
- assert.lengthOf(instance.$el, 1);
- assert.isString(instance.$el.jquery);
- assert.strictEqual(instance.$el.attr('id'), 'view');
- });
- });
-
- describe('.$items', function () {
- it('is $(\'#items\')', function () {
- var instance = this.applyFn();
- assert.isObject(instance.$items);
- assert.lengthOf(instance.$items, 1);
- assert.isString(instance.$items.jquery);
- assert.strictEqual(instance.$items.attr('id'), 'items');
- });
- });
-
- describe('.setItems()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.setItems));
- });
-
- it('publishes view.changed', function () {
- var instance = this.applyFn();
- instance.setItems();
- assert.isTrue(this.xEvent.pub.calledTwice);
- assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
- });
- });
-
- describe('.changeItems()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.changeItems));
- });
-
- it('publishes view.changed', function () {
- var instance = this.applyFn();
- instance.setItems();
- assert.isTrue(this.xEvent.pub.calledTwice);
- assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
- });
- });
-
- describe('.setLocation()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.setLocation));
- });
-
- it('publishes view.changed', function () {
- var instance = this.applyFn();
- instance.setItems();
- assert.isTrue(this.xEvent.pub.calledTwice);
- assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
- });
- });
-
- describe('.setHint()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.setHint));
- });
-
- it('sets correct class to #view-hint', function () {
- var key = uniq.id();
- var instance = this.applyFn();
- instance.setHint(key);
- assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
- });
-
- it('removes all other classes from #view-hint', function () {
- var key = uniq.id();
- var instance = this.applyFn();
- $('#view-hint').addClass('a');
- instance.setHint(key);
- assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
- });
- });
-
- describe('.getModes()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.getModes));
- });
- });
-
- describe('.getMode()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.getMode));
- });
- });
-
- describe('.setMode()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.setMode));
- });
-
- it('.setMode(\'details\') changes #view class to .view-details', function () {
- this.xSettings.view.modes = ['details', 'grid', 'icons'];
- var instance = this.applyFn();
- instance.setMode('details');
- assert.isTrue($('#view').hasClass('view-details'));
- assert.isFalse($('#view').hasClass('view-grid'));
- assert.isFalse($('#view').hasClass('view-icons'));
- });
-
- it('.setMode(\'grid\') changes #view class to .view-grid', function () {
- this.xSettings.view.modes = ['details', 'grid', 'icons'];
- var instance = this.applyFn();
- instance.setMode('grid');
- assert.isFalse($('#view').hasClass('view-details'));
- assert.isTrue($('#view').hasClass('view-grid'));
- assert.isFalse($('#view').hasClass('view-icons'));
- });
-
- it('.setMode(\'icons\') changes #view class to .view-icons', function () {
- this.xSettings.view.modes = ['details', 'grid', 'icons'];
- var instance = this.applyFn();
- instance.setMode('icons');
- assert.isFalse($('#view').hasClass('view-details'));
- assert.isFalse($('#view').hasClass('view-grid'));
- assert.isTrue($('#view').hasClass('view-icons'));
- });
- });
-
- describe('.getSizes()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.getSizes));
- });
-
- it('returns sorted sizes', function () {
- this.xSettings.view.sizes = [20, 60, 40];
- var instance = this.applyFn();
- assert.deepEqual(instance.getSizes(), [20, 40, 60]);
- });
-
- it('returns sorted sizes', function () {
- this.xSettings.view.sizes = [60, 40, 20];
- var instance = this.applyFn();
- assert.deepEqual(instance.getSizes(), [20, 40, 60]);
- });
- });
-
- describe('.getSize()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.getSize));
- });
- });
-
- describe('.setSize()', function () {
- it('is function', function () {
- var instance = this.applyFn();
- assert.isTrue(_.isFunction(instance.setSize));
- });
-
- it('.setSize(20) changes #view class to .view-size-20', function () {
- this.xSettings.view.sizes = [20, 40, 60];
- var instance = this.applyFn();
- instance.setSize(20);
- assert.isTrue($('#view').hasClass('view-size-20'), 20);
- assert.isFalse($('#view').hasClass('view-size-40'), 40);
- assert.isFalse($('#view').hasClass('view-size-60'), 60);
- });
-
- it('.setSize(40) changes #view class to .view-size-40', function () {
- this.xSettings.view.sizes = [20, 40, 60];
- var instance = this.applyFn();
- instance.setSize(20);
- instance.setSize(40);
- assert.isFalse($('#view').hasClass('view-size-20'), 20);
- assert.isTrue($('#view').hasClass('view-size-40'), 40);
- assert.isFalse($('#view').hasClass('view-size-60'), 60);
- });
-
- it('.setSize(60) changes #view class to .view-size-60', function () {
- this.xSettings.view.sizes = [20, 40, 60];
- var instance = this.applyFn();
- instance.setSize(20);
- instance.setSize(60);
- assert.isFalse($('#view').hasClass('view-size-20'), 20);
- assert.isFalse($('#view').hasClass('view-size-40'), 40);
- assert.isTrue($('#view').hasClass('view-size-60'), 60);
- });
- });
-
- // describe('._.createHtml()', function () {
- // before(function () {
- // this.createItem = function () {
- // return {
- // isFolder: sinon.stub().returns(false),
- // label: uniq.id(),
- // time: 0,
- // size: 0,
- // type: uniq.id(),
- // isManaged: false,
- // icon: null,
- // isCurrentParentFolder: sinon.stub().returns(false)
- // };
- // };
- // });
-
- // it('is function', function () {
- // var instance = this.applyFn();
- // assert.isFunction(instance._.createHtml);
- // });
-
- // it('returns jQuery instance of single HTML element', function () {
- // var item = this.createItem();
- // var instance = this.applyFn();
- // var $item = instance._.createHtml(item);
- // assert.isObject($item);
- // assert.lengthOf($item, 1);
- // assert.isString($item.jquery);
- // });
-
- // it('$item.data(\'item\') is back reference to item', function () {
- // var item = this.createItem();
- // var instance = this.applyFn();
- // var $item = instance._.createHtml(item);
- // assert.strictEqual($item.data('item'), item);
- // });
-
- // it('sets item.$view as reference to $item', function () {
- // var item = this.createItem();
- // var instance = this.applyFn();
- // var $item = instance._.createHtml(item);
- // assert.strictEqual(item.$view, $item);
- // });
- // });
- });
-}());
diff --git a/test/tests/unit/view/viewmode.js b/test/tests/unit/view/viewmode.js
deleted file mode 100644
index ad0dd6a2..00000000
--- a/test/tests/unit/view/viewmode.js
+++ /dev/null
@@ -1,189 +0,0 @@
-(function () {
- var ID = 'view/viewmode';
- var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'view/sidebar', 'view/topbar', 'view/view'];
-
- describe('module \'' + ID + '\'', function () {
- before(function () {
- this.definition = modulejs._private.definitions[ID];
-
- this.xEvent = {
- sub: sinon.stub(),
- pub: sinon.stub()
- };
- this.xResource = {
- image: sinon.stub().returns(uniq.path('-image.png'))
- };
- this.xSettings = {view: {
- modeToggle: false
- }};
- this.xSidebar = {$el: null};
- this.xTopbar = {$el: null};
- this.xView = {
- $el: null,
- getModes: sinon.stub().returns(['details', 'grid', 'icons']),
- getMode: sinon.stub(),
- setMode: sinon.stub(),
- getSizes: sinon.stub().returns([20, 30, 40]),
- getSize: sinon.stub(),
- setSize: sinon.stub()
- };
-
- this.applyFn = function () {
- this.xEvent.sub.reset();
- this.xEvent.pub.reset();
- this.xResource.image.reset();
- this.xView.getModes.reset();
- this.xView.getMode.reset();
- this.xView.setMode.reset();
- this.xView.getSizes.reset();
- this.xView.getSize.reset();
- this.xView.setSize.reset();
-
- return this.definition.fn(_, $, this.xEvent, this.xResource, this.xSettings, this.xSidebar, this.xTopbar, this.xView);
- };
- });
-
- after(function () {
- util.restoreHtml();
- });
-
- beforeEach(function () {
- util.restoreHtml();
- this.xSidebar.$el = $('').appendTo('body');
- this.xTopbar.$el = $('
').appendTo('body');
- this.xView.$el = $('
').appendTo('body');
- });
-
- describe('definition', function () {
- it('is defined', function () {
- assert.isPlainObject(this.definition);
- });
-
- it('has correct id', function () {
- assert.strictEqual(this.definition.id, ID);
- });
-
- it('requires correct', function () {
- assert.deepEqual(this.definition.deps, DEPS);
- });
-
- it('args for each request', function () {
- assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
- });
-
- it('has no instance', function () {
- assert.notProperty(modulejs._private.instances, ID);
- });
-
- it('inits without errors', function () {
- this.applyFn();
- });
- });
-
- describe('application', function () {
- it('returns undefined', function () {
- var instance = this.applyFn();
- assert.isUndefined(instance);
- });
-
- it('adds HTML #viewmode-settings to #sidebar', function () {
- this.applyFn();
- assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
- });
-
- it('adds HTML #viewmode-details to #viewmode-settings', function () {
- this.applyFn();
- assert.lengthOf($('#viewmode-settings > #viewmode-details'), 1);
- });
-
- it('adds HTML #viewmode-grid to #viewmode-settings', function () {
- this.applyFn();
- assert.lengthOf($('#viewmode-settings > #viewmode-grid'), 1);
- });
-
- it('adds HTML #viewmode-icons to #viewmode-settings', function () {
- this.applyFn();
- assert.lengthOf($('#viewmode-settings > #viewmode-icons'), 1);
- });
-
- it('adds HTML #viewmode-size to #viewmode-settings', function () {
- this.applyFn();
- assert.lengthOf($('#viewmode-settings > #viewmode-size'), 1);
- });
-
- it('does not add HTML #viewmode-details, #viewmode-grid, #viewmode-icons when only one mode', function () {
- this.xView.getModes.returns(['details']);
- this.applyFn();
- assert.lengthOf($('#viewmode-details'), 0);
- assert.lengthOf($('#viewmode-grid'), 0);
- assert.lengthOf($('#viewmode-icons'), 0);
- });
-
- it('does not add HTML #viewmode-size when only one size', function () {
- this.xView.getSizes.returns([20]);
- this.applyFn();
- assert.lengthOf($('#viewmode-size'), 0);
- });
- });
-
- describe('works', function () {
- it('clicking #viewmode-details triggers view.setMode(\'details\')', function () {
- this.xView.getModes.returns(['details', 'grid', 'icons']);
- this.applyFn();
- $('#viewmode-details').trigger('click');
- assert.isTrue(this.xView.setMode.calledOnce);
- assert.deepEqual(this.xView.setMode.lastCall.args, ['details']);
- });
-
- it('clicking #viewmode-grid triggers view.setMode(\'grid\')', function () {
- this.xView.getModes.returns(['details', 'grid', 'icons']);
- this.applyFn();
- $('#viewmode-grid').trigger('click');
- assert.isTrue(this.xView.setMode.calledOnce);
- assert.deepEqual(this.xView.setMode.lastCall.args, ['grid']);
- });
-
- it('clicking #viewmode-icons triggers view.setMode(\'icons\')', function () {
- this.xView.getModes.returns(['details', 'grid', 'icons']);
- this.applyFn();
- $('#viewmode-icons').trigger('click');
- assert.isTrue(this.xView.setMode.calledOnce);
- assert.deepEqual(this.xView.setMode.lastCall.args, ['icons']);
- });
-
- it('changing #viewmode-size triggers view.setSize(*)', function () {
- this.xView.getSizes.returns([20, 40, 60]);
- this.applyFn();
-
- $('#viewmode-size').val(0).trigger('change');
- assert.isTrue(this.xView.setSize.calledOnce);
- assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
-
- $('#viewmode-size').val(1).trigger('change');
- assert.isTrue(this.xView.setSize.calledTwice);
- assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
-
- $('#viewmode-size').val(2).trigger('change');
- assert.isTrue(this.xView.setSize.calledThrice);
- assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
- });
-
- it('inputing #viewmode-size triggers view.setSize(*)', function () {
- this.xView.getSizes.returns([20, 40, 60]);
- this.applyFn();
-
- $('#viewmode-size').val(0).trigger('input');
- assert.isTrue(this.xView.setSize.calledOnce);
- assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
-
- $('#viewmode-size').val(1).trigger('input');
- assert.isTrue(this.xView.setSize.calledTwice);
- assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
-
- $('#viewmode-size').val(2).trigger('input');
- assert.isTrue(this.xView.setSize.calledThrice);
- assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
- });
- });
- });
-}());
diff --git a/test/util/assert.js b/test/util/assert.js
deleted file mode 100644
index 88264001..00000000
--- a/test/util/assert.js
+++ /dev/null
@@ -1,12 +0,0 @@
-(function () {
- var assert = window.chai.assert;
-
- assert.lengthOfKeys = function (val, count, msg) {
- var keyCount = _.keys(val).length;
- assert(keyCount === count, msg ? msg : 'expected ' + val + ' to have ' + count + ' keys, but has ' + keyCount);
- };
-
- assert.isPlainObject = function (val, msg) {
- assert($.isPlainObject(val), msg ? msg : 'expected ' + val + ' to be a plain Object');
- };
-}());
diff --git a/test/util/mocha.js b/test/util/mocha.js
deleted file mode 100644
index 862d74e2..00000000
--- a/test/util/mocha.js
+++ /dev/null
@@ -1,107 +0,0 @@
-(function () {
- var showOnlyFailures = false;
- var template =
- '';
- var $mochaBar = $(template);
- var $mochaStats = $mochaBar.find('.stats');
- var $mochaProgress = $mochaBar.find('.progress');
-
- function toggleFailureFilter(ev) {
- ev.stopImmediatePropagation();
-
- showOnlyFailures = !showOnlyFailures;
- if (showOnlyFailures) {
- $('.suite, .test').hide();
- $('.suite.fail, .test.fail').show();
- } else {
- $('.suite, .test').show();
- }
- }
-
- function addSuiteStats() {
- var $suite = $(this);
-
- var tests = $suite.find('.test').length;
- var passed = $suite.find('.test.pass').length;
- var failed = tests - passed;
-
- var $header = $suite.find('> h1 a');
- var $list = $suite.find('> ul');
- var $count = $('' + passed + ' ' + failed + ' ');
- var $toggle = $('- ');
- var visible = true;
-
- $toggle.on('click', function (ev) {
- ev.stopImmediatePropagation();
-
- visible = !visible;
- if (visible) {
- $toggle.text('-');
- $list.show();
- } else {
- $toggle.text('+');
- $list.hide();
- }
- });
-
- if (!failed) {
- $count.find('.failed').remove();
- }
-
- $suite.addClass(tests === passed ? 'pass' : 'fail');
- // $suite.append($toggle);
- $header.append($count);
- }
-
- function fixCodeFormatting() {
- var $code = $(this);
- $code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
- }
-
-
- function onEnd() {
- var runner = this;
- var failed = runner.stats.failures > 0;
- var stats = (runner.stats.duration / 1000.0).toFixed(3) + 's';
-
- if (failed) {
- $mochaStats.on('click', toggleFailureFilter);
- }
-
- $mochaBar.addClass(failed ? 'fail' : 'pass');
- $mochaProgress.hide();
- $mochaStats.text(stats);
- $('#mocha-report .suite').each(addSuiteStats);
- $('#mocha-report code').each(fixCodeFormatting);
- }
-
- function onTest() {
- var runner = this;
- var percent = 100.0 * runner.stats.tests / runner.total;
- var stats = ((new Date().getTime() - runner.stats.start) / 1000.0).toFixed(3) + 's';
-
- if (runner.stats.failures) {
- $mochaBar.addClass('fail');
- }
- $mochaProgress.css('width', 100 - percent + '%');
- $mochaStats.text(stats);
- }
-
- function setupMocha() {
- window.assert = window.chai.assert;
- mocha.setup('bdd');
- $(function () { $mochaBar.appendTo('#mocha'); });
- }
-
- function runMocha() {
- mocha.run().on('test', onTest).on('end', onEnd);
- }
-
- window.util = window.util || {};
- window.util.setupMocha = setupMocha;
- window.util.runMocha = runMocha;
-}());
diff --git a/test/util/modulejs.js b/test/util/modulejs.js
deleted file mode 100644
index 7cc9a111..00000000
--- a/test/util/modulejs.js
+++ /dev/null
@@ -1,15 +0,0 @@
-(function () {
- function clearModulejs() {
- _.each(modulejs._private.instances, function (val, key) {
- delete modulejs._private.instances[key];
- });
- }
-
- function mockConfigModule() {
- modulejs.define('config', window.uniq.obj());
- }
-
- window.util = window.util || {};
- window.util.clearModulejs = clearModulejs;
- window.util.mockConfigModule = mockConfigModule;
-}());
diff --git a/test/util/pin.js b/test/util/pin.js
index 831d3f1e..952e57d5 100644
--- a/test/util/pin.js
+++ b/test/util/pin.js
@@ -1,33 +1,33 @@
-(function () {
- var title;
- var htmlId;
- var htmlClasses;
- var bodyId;
- var bodyClasses;
- var $pinnedElements;
+const win = global.window;
+const doc = win.document;
+const jq = win.jQuery;
+let title;
+let htmlId;
+let htmlClasses;
+let bodyId;
+let bodyClasses;
+let $pinnedElements;
- function pinHtml() {
- title = document.title;
- htmlId = $('html').attr('id');
- htmlClasses = $('html').attr('class');
- bodyId = $('body').attr('id');
- bodyClasses = $('body').attr('class');
- $pinnedElements = $('head,body').children();
- }
+function pinHtml() {
+ title = doc.title;
+ htmlId = jq('html').attr('id');
+ htmlClasses = jq('html').attr('class');
+ bodyId = jq('body').attr('id');
+ bodyClasses = jq('body').attr('class');
+ $pinnedElements = jq('head,body').children();
+}
- function restoreHtml() {
- document.title = title;
- $('html').attr('id', htmlId);
- $('html').attr('class', htmlClasses);
- $('body').attr('id', bodyId);
- $('body').attr('class', bodyClasses);
- $('head,body').children().not($pinnedElements).remove();
- if (window.localStorage && window.localStorage.clear) {
- window.localStorage.clear();
- }
- }
+function restoreHtml() {
+ doc.title = title;
+ jq('html').attr('id', htmlId);
+ jq('html').attr('class', htmlClasses);
+ jq('body').attr('id', bodyId);
+ jq('body').attr('class', bodyClasses);
+ jq('head,body').children().not($pinnedElements).remove();
+ win.localStorage.clear();
+}
- window.util = window.util || {};
- window.util.pinHtml = pinHtml;
- window.util.restoreHtml = restoreHtml;
-}());
+module.exports = {
+ pinHtml,
+ restoreHtml
+};
diff --git a/test/vendor/chai.js b/test/vendor/chai.js
deleted file mode 100644
index ffe12c42..00000000
--- a/test/vendor/chai.js
+++ /dev/null
@@ -1,5332 +0,0 @@
-
-;(function(){
-
-/**
- * Require the module at `name`.
- *
- * @param {String} name
- * @return {Object} exports
- * @api public
- */
-
-function require(name) {
- var module = require.modules[name];
- if (!module) throw new Error('failed to require "' + name + '"');
-
- if (!('exports' in module) && typeof module.definition === 'function') {
- module.client = module.component = true;
- module.definition.call(this, module.exports = {}, module);
- delete module.definition;
- }
-
- return module.exports;
-}
-
-/**
- * Meta info, accessible in the global scope unless you use AMD option.
- */
-
-require.loader = 'component';
-
-/**
- * Internal helper object, contains a sorting function for semantiv versioning
- */
-require.helper = {};
-require.helper.semVerSort = function(a, b) {
- var aArray = a.version.split('.');
- var bArray = b.version.split('.');
- for (var i=0; i bLex ? 1 : -1;
- continue;
- } else if (aInt > bInt) {
- return 1;
- } else {
- return -1;
- }
- }
- return 0;
-}
-
-/**
- * Find and require a module which name starts with the provided name.
- * If multiple modules exists, the highest semver is used.
- * This function can only be used for remote dependencies.
-
- * @param {String} name - module name: `user~repo`
- * @param {Boolean} returnPath - returns the canonical require path if true,
- * otherwise it returns the epxorted module
- */
-require.latest = function (name, returnPath) {
- function showError(name) {
- throw new Error('failed to find latest module of "' + name + '"');
- }
- // only remotes with semvers, ignore local files conataining a '/'
- var versionRegexp = /(.*)~(.*)@v?(\d+\.\d+\.\d+[^\/]*)$/;
- var remoteRegexp = /(.*)~(.*)/;
- if (!remoteRegexp.test(name)) showError(name);
- var moduleNames = Object.keys(require.modules);
- var semVerCandidates = [];
- var otherCandidates = []; // for instance: name of the git branch
- for (var i=0; i 0) {
- var module = semVerCandidates.sort(require.helper.semVerSort).pop().name;
- if (returnPath === true) {
- return module;
- }
- return require(module);
- }
- // if the build contains more than one branch of the same module
- // you should not use this funciton
- var module = otherCandidates.sort(function(a, b) {return a.name > b.name})[0].name;
- if (returnPath === true) {
- return module;
- }
- return require(module);
-}
-
-/**
- * Registered modules.
- */
-
-require.modules = {};
-
-/**
- * Register module at `name` with callback `definition`.
- *
- * @param {String} name
- * @param {Function} definition
- * @api private
- */
-
-require.register = function (name, definition) {
- require.modules[name] = {
- definition: definition
- };
-};
-
-/**
- * Define a module's exports immediately with `exports`.
- *
- * @param {String} name
- * @param {Generic} exports
- * @api private
- */
-
-require.define = function (name, exports) {
- require.modules[name] = {
- exports: exports
- };
-};
-require.register("chaijs~assertion-error@1.0.0", function (exports, module) {
-/*!
- * assertion-error
- * Copyright(c) 2013 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Return a function that will copy properties from
- * one object to another excluding any originally
- * listed. Returned function will create a new `{}`.
- *
- * @param {String} excluded properties ...
- * @return {Function}
- */
-
-function exclude () {
- var excludes = [].slice.call(arguments);
-
- function excludeProps (res, obj) {
- Object.keys(obj).forEach(function (key) {
- if (!~excludes.indexOf(key)) res[key] = obj[key];
- });
- }
-
- return function extendExclude () {
- var args = [].slice.call(arguments)
- , i = 0
- , res = {};
-
- for (; i < args.length; i++) {
- excludeProps(res, args[i]);
- }
-
- return res;
- };
-};
-
-/*!
- * Primary Exports
- */
-
-module.exports = AssertionError;
-
-/**
- * ### AssertionError
- *
- * An extension of the JavaScript `Error` constructor for
- * assertion and validation scenarios.
- *
- * @param {String} message
- * @param {Object} properties to include (optional)
- * @param {callee} start stack function (optional)
- */
-
-function AssertionError (message, _props, ssf) {
- var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
- , props = extend(_props || {});
-
- // default values
- this.message = message || 'Unspecified AssertionError';
- this.showDiff = false;
-
- // copy from properties
- for (var key in props) {
- this[key] = props[key];
- }
-
- // capture stack trace
- ssf = ssf || arguments.callee;
- if (ssf && Error.captureStackTrace) {
- Error.captureStackTrace(this, ssf);
- }
-}
-
-/*!
- * Inherit from Error.prototype
- */
-
-AssertionError.prototype = Object.create(Error.prototype);
-
-/*!
- * Statically set name
- */
-
-AssertionError.prototype.name = 'AssertionError';
-
-/*!
- * Ensure correct constructor
- */
-
-AssertionError.prototype.constructor = AssertionError;
-
-/**
- * Allow errors to be converted to JSON for static transfer.
- *
- * @param {Boolean} include stack (default: `true`)
- * @return {Object} object that can be `JSON.stringify`
- */
-
-AssertionError.prototype.toJSON = function (stack) {
- var extend = exclude('constructor', 'toJSON', 'stack')
- , props = extend({ name: this.name }, this);
-
- // include stack if exists and not turned off
- if (false !== stack && this.stack) {
- props.stack = this.stack;
- }
-
- return props;
-};
-
-});
-
-require.register("chaijs~type-detect@0.1.1", function (exports, module) {
-/*!
- * type-detect
- * Copyright(c) 2013 jake luer
- * MIT Licensed
- */
-
-/*!
- * Primary Exports
- */
-
-var exports = module.exports = getType;
-
-/*!
- * Detectable javascript natives
- */
-
-var natives = {
- '[object Array]': 'array'
- , '[object RegExp]': 'regexp'
- , '[object Function]': 'function'
- , '[object Arguments]': 'arguments'
- , '[object Date]': 'date'
-};
-
-/**
- * ### typeOf (obj)
- *
- * Use several different techniques to determine
- * the type of object being tested.
- *
- *
- * @param {Mixed} object
- * @return {String} object type
- * @api public
- */
-
-function getType (obj) {
- var str = Object.prototype.toString.call(obj);
- if (natives[str]) return natives[str];
- if (obj === null) return 'null';
- if (obj === undefined) return 'undefined';
- if (obj === Object(obj)) return 'object';
- return typeof obj;
-}
-
-exports.Library = Library;
-
-/**
- * ### Library
- *
- * Create a repository for custom type detection.
- *
- * ```js
- * var lib = new type.Library;
- * ```
- *
- */
-
-function Library () {
- this.tests = {};
-}
-
-/**
- * #### .of (obj)
- *
- * Expose replacement `typeof` detection to the library.
- *
- * ```js
- * if ('string' === lib.of('hello world')) {
- * // ...
- * }
- * ```
- *
- * @param {Mixed} object to test
- * @return {String} type
- */
-
-Library.prototype.of = getType;
-
-/**
- * #### .define (type, test)
- *
- * Add a test to for the `.test()` assertion.
- *
- * Can be defined as a regular expression:
- *
- * ```js
- * lib.define('int', /^[0-9]+$/);
- * ```
- *
- * ... or as a function:
- *
- * ```js
- * lib.define('bln', function (obj) {
- * if ('boolean' === lib.of(obj)) return true;
- * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
- * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
- * return !! ~blns.indexOf(obj);
- * });
- * ```
- *
- * @param {String} type
- * @param {RegExp|Function} test
- * @api public
- */
-
-Library.prototype.define = function (type, test) {
- if (arguments.length === 1) return this.tests[type];
- this.tests[type] = test;
- return this;
-};
-
-/**
- * #### .test (obj, test)
- *
- * Assert that an object is of type. Will first
- * check natives, and if that does not pass it will
- * use the user defined custom tests.
- *
- * ```js
- * assert(lib.test('1', 'int'));
- * assert(lib.test('yes', 'bln'));
- * ```
- *
- * @param {Mixed} object
- * @param {String} type
- * @return {Boolean} result
- * @api public
- */
-
-Library.prototype.test = function (obj, type) {
- if (type === getType(obj)) return true;
- var test = this.tests[type];
-
- if (test && 'regexp' === getType(test)) {
- return test.test(obj);
- } else if (test && 'function' === getType(test)) {
- return test(obj);
- } else {
- throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
- }
-};
-
-});
-
-require.register("chaijs~deep-eql@0.1.3", function (exports, module) {
-/*!
- * deep-eql
- * Copyright(c) 2013 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Module dependencies
- */
-
-var type = require('chaijs~type-detect@0.1.1');
-
-/*!
- * Buffer.isBuffer browser shim
- */
-
-var Buffer;
-try { Buffer = require('buffer').Buffer; }
-catch(ex) {
- Buffer = {};
- Buffer.isBuffer = function() { return false; }
-}
-
-/*!
- * Primary Export
- */
-
-module.exports = deepEqual;
-
-/**
- * Assert super-strict (egal) equality between
- * two objects of any type.
- *
- * @param {Mixed} a
- * @param {Mixed} b
- * @param {Array} memoised (optional)
- * @return {Boolean} equal match
- */
-
-function deepEqual(a, b, m) {
- if (sameValue(a, b)) {
- return true;
- } else if ('date' === type(a)) {
- return dateEqual(a, b);
- } else if ('regexp' === type(a)) {
- return regexpEqual(a, b);
- } else if (Buffer.isBuffer(a)) {
- return bufferEqual(a, b);
- } else if ('arguments' === type(a)) {
- return argumentsEqual(a, b, m);
- } else if (!typeEqual(a, b)) {
- return false;
- } else if (('object' !== type(a) && 'object' !== type(b))
- && ('array' !== type(a) && 'array' !== type(b))) {
- return sameValue(a, b);
- } else {
- return objectEqual(a, b, m);
- }
-}
-
-/*!
- * Strict (egal) equality test. Ensures that NaN always
- * equals NaN and `-0` does not equal `+0`.
- *
- * @param {Mixed} a
- * @param {Mixed} b
- * @return {Boolean} equal match
- */
-
-function sameValue(a, b) {
- if (a === b) return a !== 0 || 1 / a === 1 / b;
- return a !== a && b !== b;
-}
-
-/*!
- * Compare the types of two given objects and
- * return if they are equal. Note that an Array
- * has a type of `array` (not `object`) and arguments
- * have a type of `arguments` (not `array`/`object`).
- *
- * @param {Mixed} a
- * @param {Mixed} b
- * @return {Boolean} result
- */
-
-function typeEqual(a, b) {
- return type(a) === type(b);
-}
-
-/*!
- * Compare two Date objects by asserting that
- * the time values are equal using `saveValue`.
- *
- * @param {Date} a
- * @param {Date} b
- * @return {Boolean} result
- */
-
-function dateEqual(a, b) {
- if ('date' !== type(b)) return false;
- return sameValue(a.getTime(), b.getTime());
-}
-
-/*!
- * Compare two regular expressions by converting them
- * to string and checking for `sameValue`.
- *
- * @param {RegExp} a
- * @param {RegExp} b
- * @return {Boolean} result
- */
-
-function regexpEqual(a, b) {
- if ('regexp' !== type(b)) return false;
- return sameValue(a.toString(), b.toString());
-}
-
-/*!
- * Assert deep equality of two `arguments` objects.
- * Unfortunately, these must be sliced to arrays
- * prior to test to ensure no bad behavior.
- *
- * @param {Arguments} a
- * @param {Arguments} b
- * @param {Array} memoize (optional)
- * @return {Boolean} result
- */
-
-function argumentsEqual(a, b, m) {
- if ('arguments' !== type(b)) return false;
- a = [].slice.call(a);
- b = [].slice.call(b);
- return deepEqual(a, b, m);
-}
-
-/*!
- * Get enumerable properties of a given object.
- *
- * @param {Object} a
- * @return {Array} property names
- */
-
-function enumerable(a) {
- var res = [];
- for (var key in a) res.push(key);
- return res;
-}
-
-/*!
- * Simple equality for flat iterable objects
- * such as Arrays or Node.js buffers.
- *
- * @param {Iterable} a
- * @param {Iterable} b
- * @return {Boolean} result
- */
-
-function iterableEqual(a, b) {
- if (a.length !== b.length) return false;
-
- var i = 0;
- var match = true;
-
- for (; i < a.length; i++) {
- if (a[i] !== b[i]) {
- match = false;
- break;
- }
- }
-
- return match;
-}
-
-/*!
- * Extension to `iterableEqual` specifically
- * for Node.js Buffers.
- *
- * @param {Buffer} a
- * @param {Mixed} b
- * @return {Boolean} result
- */
-
-function bufferEqual(a, b) {
- if (!Buffer.isBuffer(b)) return false;
- return iterableEqual(a, b);
-}
-
-/*!
- * Block for `objectEqual` ensuring non-existing
- * values don't get in.
- *
- * @param {Mixed} object
- * @return {Boolean} result
- */
-
-function isValue(a) {
- return a !== null && a !== undefined;
-}
-
-/*!
- * Recursively check the equality of two objects.
- * Once basic sameness has been established it will
- * defer to `deepEqual` for each enumerable key
- * in the object.
- *
- * @param {Mixed} a
- * @param {Mixed} b
- * @return {Boolean} result
- */
-
-function objectEqual(a, b, m) {
- if (!isValue(a) || !isValue(b)) {
- return false;
- }
-
- if (a.prototype !== b.prototype) {
- return false;
- }
-
- var i;
- if (m) {
- for (i = 0; i < m.length; i++) {
- if ((m[i][0] === a && m[i][1] === b)
- || (m[i][0] === b && m[i][1] === a)) {
- return true;
- }
- }
- } else {
- m = [];
- }
-
- try {
- var ka = enumerable(a);
- var kb = enumerable(b);
- } catch (ex) {
- return false;
- }
-
- ka.sort();
- kb.sort();
-
- if (!iterableEqual(ka, kb)) {
- return false;
- }
-
- m.push([ a, b ]);
-
- var key;
- for (i = ka.length - 1; i >= 0; i--) {
- key = ka[i];
- if (!deepEqual(a[key], b[key], m)) {
- return false;
- }
- }
-
- return true;
-}
-
-});
-
-require.register("chai", function (exports, module) {
-module.exports = require('chai/lib/chai.js');
-
-});
-
-require.register("chai/lib/chai.js", function (exports, module) {
-/*!
- * chai
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-var used = []
- , exports = module.exports = {};
-
-/*!
- * Chai version
- */
-
-exports.version = '2.1.0';
-
-/*!
- * Assertion Error
- */
-
-exports.AssertionError = require('chaijs~assertion-error@1.0.0');
-
-/*!
- * Utils for plugins (not exported)
- */
-
-var util = require('chai/lib/chai/utils/index.js');
-
-/**
- * # .use(function)
- *
- * Provides a way to extend the internals of Chai
- *
- * @param {Function}
- * @returns {this} for chaining
- * @api public
- */
-
-exports.use = function (fn) {
- if (!~used.indexOf(fn)) {
- fn(this, util);
- used.push(fn);
- }
-
- return this;
-};
-
-/*!
- * Utility Functions
- */
-
-exports.util = util;
-
-/*!
- * Configuration
- */
-
-var config = require('chai/lib/chai/config.js');
-exports.config = config;
-
-/*!
- * Primary `Assertion` prototype
- */
-
-var assertion = require('chai/lib/chai/assertion.js');
-exports.use(assertion);
-
-/*!
- * Core Assertions
- */
-
-var core = require('chai/lib/chai/core/assertions.js');
-exports.use(core);
-
-/*!
- * Expect interface
- */
-
-var expect = require('chai/lib/chai/interface/expect.js');
-exports.use(expect);
-
-/*!
- * Should interface
- */
-
-var should = require('chai/lib/chai/interface/should.js');
-exports.use(should);
-
-/*!
- * Assert interface
- */
-
-var assert = require('chai/lib/chai/interface/assert.js');
-exports.use(assert);
-
-});
-
-require.register("chai/lib/chai/assertion.js", function (exports, module) {
-/*!
- * chai
- * http://chaijs.com
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-var config = require('chai/lib/chai/config.js');
-
-module.exports = function (_chai, util) {
- /*!
- * Module dependencies.
- */
-
- var AssertionError = _chai.AssertionError
- , flag = util.flag;
-
- /*!
- * Module export.
- */
-
- _chai.Assertion = Assertion;
-
- /*!
- * Assertion Constructor
- *
- * Creates object for chaining.
- *
- * @api private
- */
-
- function Assertion (obj, msg, stack) {
- flag(this, 'ssfi', stack || arguments.callee);
- flag(this, 'object', obj);
- flag(this, 'message', msg);
- }
-
- Object.defineProperty(Assertion, 'includeStack', {
- get: function() {
- console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
- return config.includeStack;
- },
- set: function(value) {
- console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
- config.includeStack = value;
- }
- });
-
- Object.defineProperty(Assertion, 'showDiff', {
- get: function() {
- console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
- return config.showDiff;
- },
- set: function(value) {
- console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
- config.showDiff = value;
- }
- });
-
- Assertion.addProperty = function (name, fn) {
- util.addProperty(this.prototype, name, fn);
- };
-
- Assertion.addMethod = function (name, fn) {
- util.addMethod(this.prototype, name, fn);
- };
-
- Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
- util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
- };
-
- Assertion.overwriteProperty = function (name, fn) {
- util.overwriteProperty(this.prototype, name, fn);
- };
-
- Assertion.overwriteMethod = function (name, fn) {
- util.overwriteMethod(this.prototype, name, fn);
- };
-
- Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
- util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
- };
-
- /*!
- * ### .assert(expression, message, negateMessage, expected, actual)
- *
- * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
- *
- * @name assert
- * @param {Philosophical} expression to be tested
- * @param {String or Function} message or function that returns message to display if fails
- * @param {String or Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
- * @param {Mixed} expected value (remember to check for negation)
- * @param {Mixed} actual (optional) will default to `this.obj`
- * @api private
- */
-
- Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
- var ok = util.test(this, arguments);
- if (true !== showDiff) showDiff = false;
- if (true !== config.showDiff) showDiff = false;
-
- if (!ok) {
- var msg = util.getMessage(this, arguments)
- , actual = util.getActual(this, arguments);
- throw new AssertionError(msg, {
- actual: actual
- , expected: expected
- , showDiff: showDiff
- }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
- }
- };
-
- /*!
- * ### ._obj
- *
- * Quick reference to stored `actual` value for plugin developers.
- *
- * @api private
- */
-
- Object.defineProperty(Assertion.prototype, '_obj',
- { get: function () {
- return flag(this, 'object');
- }
- , set: function (val) {
- flag(this, 'object', val);
- }
- });
-};
-
-});
-
-require.register("chai/lib/chai/config.js", function (exports, module) {
-module.exports = {
-
- /**
- * ### config.includeStack
- *
- * User configurable property, influences whether stack trace
- * is included in Assertion error message. Default of false
- * suppresses stack trace in the error message.
- *
- * chai.config.includeStack = true; // enable stack on error
- *
- * @param {Boolean}
- * @api public
- */
-
- includeStack: false,
-
- /**
- * ### config.showDiff
- *
- * User configurable property, influences whether or not
- * the `showDiff` flag should be included in the thrown
- * AssertionErrors. `false` will always be `false`; `true`
- * will be true when the assertion has requested a diff
- * be shown.
- *
- * @param {Boolean}
- * @api public
- */
-
- showDiff: true,
-
- /**
- * ### config.truncateThreshold
- *
- * User configurable property, sets length threshold for actual and
- * expected values in assertion errors. If this threshold is exceeded,
- * the value is truncated.
- *
- * Set it to zero if you want to disable truncating altogether.
- *
- * chai.config.truncateThreshold = 0; // disable truncating
- *
- * @param {Number}
- * @api public
- */
-
- truncateThreshold: 40
-
-};
-
-});
-
-require.register("chai/lib/chai/core/assertions.js", function (exports, module) {
-/*!
- * chai
- * http://chaijs.com
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-module.exports = function (chai, _) {
- var Assertion = chai.Assertion
- , toString = Object.prototype.toString
- , flag = _.flag;
-
- /**
- * ### Language Chains
- *
- * The following are provided as chainable getters to
- * improve the readability of your assertions. They
- * do not provide testing capabilities unless they
- * have been overwritten by a plugin.
- *
- * **Chains**
- *
- * - to
- * - be
- * - been
- * - is
- * - that
- * - which
- * - and
- * - has
- * - have
- * - with
- * - at
- * - of
- * - same
- *
- * @name language chains
- * @api public
- */
-
- [ 'to', 'be', 'been'
- , 'is', 'and', 'has', 'have'
- , 'with', 'that', 'which', 'at'
- , 'of', 'same' ].forEach(function (chain) {
- Assertion.addProperty(chain, function () {
- return this;
- });
- });
-
- /**
- * ### .not
- *
- * Negates any of assertions following in the chain.
- *
- * expect(foo).to.not.equal('bar');
- * expect(goodFn).to.not.throw(Error);
- * expect({ foo: 'baz' }).to.have.property('foo')
- * .and.not.equal('bar');
- *
- * @name not
- * @api public
- */
-
- Assertion.addProperty('not', function () {
- flag(this, 'negate', true);
- });
-
- /**
- * ### .deep
- *
- * Sets the `deep` flag, later used by the `equal` and
- * `property` assertions.
- *
- * expect(foo).to.deep.equal({ bar: 'baz' });
- * expect({ foo: { bar: { baz: 'quux' } } })
- * .to.have.deep.property('foo.bar.baz', 'quux');
- *
- * @name deep
- * @api public
- */
-
- Assertion.addProperty('deep', function () {
- flag(this, 'deep', true);
- });
-
- /**
- * ### .any
- *
- * Sets the `any` flag, (opposite of the `all` flag)
- * later used in the `keys` assertion.
- *
- * expect(foo).to.have.any.keys('bar', 'baz');
- *
- * @name any
- * @api public
- */
-
- Assertion.addProperty('any', function () {
- flag(this, 'any', true);
- flag(this, 'all', false)
- });
-
-
- /**
- * ### .all
- *
- * Sets the `all` flag (opposite of the `any` flag)
- * later used by the `keys` assertion.
- *
- * expect(foo).to.have.all.keys('bar', 'baz');
- *
- * @name all
- * @api public
- */
-
- Assertion.addProperty('all', function () {
- flag(this, 'all', true);
- flag(this, 'any', false);
- });
-
- /**
- * ### .a(type)
- *
- * The `a` and `an` assertions are aliases that can be
- * used either as language chains or to assert a value's
- * type.
- *
- * // typeof
- * expect('test').to.be.a('string');
- * expect({ foo: 'bar' }).to.be.an('object');
- * expect(null).to.be.a('null');
- * expect(undefined).to.be.an('undefined');
- *
- * // language chain
- * expect(foo).to.be.an.instanceof(Foo);
- *
- * @name a
- * @alias an
- * @param {String} type
- * @param {String} message _optional_
- * @api public
- */
-
- function an (type, msg) {
- if (msg) flag(this, 'message', msg);
- type = type.toLowerCase();
- var obj = flag(this, 'object')
- , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
-
- this.assert(
- type === _.type(obj)
- , 'expected #{this} to be ' + article + type
- , 'expected #{this} not to be ' + article + type
- );
- }
-
- Assertion.addChainableMethod('an', an);
- Assertion.addChainableMethod('a', an);
-
- /**
- * ### .include(value)
- *
- * The `include` and `contain` assertions can be used as either property
- * based language chains or as methods to assert the inclusion of an object
- * in an array or a substring in a string. When used as language chains,
- * they toggle the `contains` flag for the `keys` assertion.
- *
- * expect([1,2,3]).to.include(2);
- * expect('foobar').to.contain('foo');
- * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
- *
- * @name include
- * @alias contain
- * @alias includes
- * @alias contains
- * @param {Object|String|Number} obj
- * @param {String} message _optional_
- * @api public
- */
-
- function includeChainingBehavior () {
- flag(this, 'contains', true);
- }
-
- function include (val, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- var expected = false;
- if (_.type(obj) === 'array' && _.type(val) === 'object') {
- for (var i in obj) {
- if (_.eql(obj[i], val)) {
- expected = true;
- break;
- }
- }
- } else if (_.type(val) === 'object') {
- if (!flag(this, 'negate')) {
- for (var k in val) new Assertion(obj).property(k, val[k]);
- return;
- }
- var subset = {};
- for (var k in val) subset[k] = obj[k];
- expected = _.eql(subset, val);
- } else {
- expected = obj && ~obj.indexOf(val);
- }
- this.assert(
- expected
- , 'expected #{this} to include ' + _.inspect(val)
- , 'expected #{this} to not include ' + _.inspect(val));
- }
-
- Assertion.addChainableMethod('include', include, includeChainingBehavior);
- Assertion.addChainableMethod('contain', include, includeChainingBehavior);
- Assertion.addChainableMethod('contains', include, includeChainingBehavior);
- Assertion.addChainableMethod('includes', include, includeChainingBehavior);
-
- /**
- * ### .ok
- *
- * Asserts that the target is truthy.
- *
- * expect('everthing').to.be.ok;
- * expect(1).to.be.ok;
- * expect(false).to.not.be.ok;
- * expect(undefined).to.not.be.ok;
- * expect(null).to.not.be.ok;
- *
- * @name ok
- * @api public
- */
-
- Assertion.addProperty('ok', function () {
- this.assert(
- flag(this, 'object')
- , 'expected #{this} to be truthy'
- , 'expected #{this} to be falsy');
- });
-
- /**
- * ### .true
- *
- * Asserts that the target is `true`.
- *
- * expect(true).to.be.true;
- * expect(1).to.not.be.true;
- *
- * @name true
- * @api public
- */
-
- Assertion.addProperty('true', function () {
- this.assert(
- true === flag(this, 'object')
- , 'expected #{this} to be true'
- , 'expected #{this} to be false'
- , this.negate ? false : true
- );
- });
-
- /**
- * ### .false
- *
- * Asserts that the target is `false`.
- *
- * expect(false).to.be.false;
- * expect(0).to.not.be.false;
- *
- * @name false
- * @api public
- */
-
- Assertion.addProperty('false', function () {
- this.assert(
- false === flag(this, 'object')
- , 'expected #{this} to be false'
- , 'expected #{this} to be true'
- , this.negate ? true : false
- );
- });
-
- /**
- * ### .null
- *
- * Asserts that the target is `null`.
- *
- * expect(null).to.be.null;
- * expect(undefined).not.to.be.null;
- *
- * @name null
- * @api public
- */
-
- Assertion.addProperty('null', function () {
- this.assert(
- null === flag(this, 'object')
- , 'expected #{this} to be null'
- , 'expected #{this} not to be null'
- );
- });
-
- /**
- * ### .undefined
- *
- * Asserts that the target is `undefined`.
- *
- * expect(undefined).to.be.undefined;
- * expect(null).to.not.be.undefined;
- *
- * @name undefined
- * @api public
- */
-
- Assertion.addProperty('undefined', function () {
- this.assert(
- undefined === flag(this, 'object')
- , 'expected #{this} to be undefined'
- , 'expected #{this} not to be undefined'
- );
- });
-
- /**
- * ### .exist
- *
- * Asserts that the target is neither `null` nor `undefined`.
- *
- * var foo = 'hi'
- * , bar = null
- * , baz;
- *
- * expect(foo).to.exist;
- * expect(bar).to.not.exist;
- * expect(baz).to.not.exist;
- *
- * @name exist
- * @api public
- */
-
- Assertion.addProperty('exist', function () {
- this.assert(
- null != flag(this, 'object')
- , 'expected #{this} to exist'
- , 'expected #{this} to not exist'
- );
- });
-
-
- /**
- * ### .empty
- *
- * Asserts that the target's length is `0`. For arrays, it checks
- * the `length` property. For objects, it gets the count of
- * enumerable keys.
- *
- * expect([]).to.be.empty;
- * expect('').to.be.empty;
- * expect({}).to.be.empty;
- *
- * @name empty
- * @api public
- */
-
- Assertion.addProperty('empty', function () {
- var obj = flag(this, 'object')
- , expected = obj;
-
- if (Array.isArray(obj) || 'string' === typeof object) {
- expected = obj.length;
- } else if (typeof obj === 'object') {
- expected = Object.keys(obj).length;
- }
-
- this.assert(
- !expected
- , 'expected #{this} to be empty'
- , 'expected #{this} not to be empty'
- );
- });
-
- /**
- * ### .arguments
- *
- * Asserts that the target is an arguments object.
- *
- * function test () {
- * expect(arguments).to.be.arguments;
- * }
- *
- * @name arguments
- * @alias Arguments
- * @api public
- */
-
- function checkArguments () {
- var obj = flag(this, 'object')
- , type = Object.prototype.toString.call(obj);
- this.assert(
- '[object Arguments]' === type
- , 'expected #{this} to be arguments but got ' + type
- , 'expected #{this} to not be arguments'
- );
- }
-
- Assertion.addProperty('arguments', checkArguments);
- Assertion.addProperty('Arguments', checkArguments);
-
- /**
- * ### .equal(value)
- *
- * Asserts that the target is strictly equal (`===`) to `value`.
- * Alternately, if the `deep` flag is set, asserts that
- * the target is deeply equal to `value`.
- *
- * expect('hello').to.equal('hello');
- * expect(42).to.equal(42);
- * expect(1).to.not.equal(true);
- * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
- * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
- *
- * @name equal
- * @alias equals
- * @alias eq
- * @alias deep.equal
- * @param {Mixed} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertEqual (val, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- if (flag(this, 'deep')) {
- return this.eql(val);
- } else {
- this.assert(
- val === obj
- , 'expected #{this} to equal #{exp}'
- , 'expected #{this} to not equal #{exp}'
- , val
- , this._obj
- , true
- );
- }
- }
-
- Assertion.addMethod('equal', assertEqual);
- Assertion.addMethod('equals', assertEqual);
- Assertion.addMethod('eq', assertEqual);
-
- /**
- * ### .eql(value)
- *
- * Asserts that the target is deeply equal to `value`.
- *
- * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
- * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
- *
- * @name eql
- * @alias eqls
- * @param {Mixed} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertEql(obj, msg) {
- if (msg) flag(this, 'message', msg);
- this.assert(
- _.eql(obj, flag(this, 'object'))
- , 'expected #{this} to deeply equal #{exp}'
- , 'expected #{this} to not deeply equal #{exp}'
- , obj
- , this._obj
- , true
- );
- }
-
- Assertion.addMethod('eql', assertEql);
- Assertion.addMethod('eqls', assertEql);
-
- /**
- * ### .above(value)
- *
- * Asserts that the target is greater than `value`.
- *
- * expect(10).to.be.above(5);
- *
- * Can also be used in conjunction with `length` to
- * assert a minimum length. The benefit being a
- * more informative error message than if the length
- * was supplied directly.
- *
- * expect('foo').to.have.length.above(2);
- * expect([ 1, 2, 3 ]).to.have.length.above(2);
- *
- * @name above
- * @alias gt
- * @alias greaterThan
- * @param {Number} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertAbove (n, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- if (flag(this, 'doLength')) {
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
- this.assert(
- len > n
- , 'expected #{this} to have a length above #{exp} but got #{act}'
- , 'expected #{this} to not have a length above #{exp}'
- , n
- , len
- );
- } else {
- this.assert(
- obj > n
- , 'expected #{this} to be above ' + n
- , 'expected #{this} to be at most ' + n
- );
- }
- }
-
- Assertion.addMethod('above', assertAbove);
- Assertion.addMethod('gt', assertAbove);
- Assertion.addMethod('greaterThan', assertAbove);
-
- /**
- * ### .least(value)
- *
- * Asserts that the target is greater than or equal to `value`.
- *
- * expect(10).to.be.at.least(10);
- *
- * Can also be used in conjunction with `length` to
- * assert a minimum length. The benefit being a
- * more informative error message than if the length
- * was supplied directly.
- *
- * expect('foo').to.have.length.of.at.least(2);
- * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
- *
- * @name least
- * @alias gte
- * @param {Number} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertLeast (n, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- if (flag(this, 'doLength')) {
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
- this.assert(
- len >= n
- , 'expected #{this} to have a length at least #{exp} but got #{act}'
- , 'expected #{this} to have a length below #{exp}'
- , n
- , len
- );
- } else {
- this.assert(
- obj >= n
- , 'expected #{this} to be at least ' + n
- , 'expected #{this} to be below ' + n
- );
- }
- }
-
- Assertion.addMethod('least', assertLeast);
- Assertion.addMethod('gte', assertLeast);
-
- /**
- * ### .below(value)
- *
- * Asserts that the target is less than `value`.
- *
- * expect(5).to.be.below(10);
- *
- * Can also be used in conjunction with `length` to
- * assert a maximum length. The benefit being a
- * more informative error message than if the length
- * was supplied directly.
- *
- * expect('foo').to.have.length.below(4);
- * expect([ 1, 2, 3 ]).to.have.length.below(4);
- *
- * @name below
- * @alias lt
- * @alias lessThan
- * @param {Number} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertBelow (n, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- if (flag(this, 'doLength')) {
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
- this.assert(
- len < n
- , 'expected #{this} to have a length below #{exp} but got #{act}'
- , 'expected #{this} to not have a length below #{exp}'
- , n
- , len
- );
- } else {
- this.assert(
- obj < n
- , 'expected #{this} to be below ' + n
- , 'expected #{this} to be at least ' + n
- );
- }
- }
-
- Assertion.addMethod('below', assertBelow);
- Assertion.addMethod('lt', assertBelow);
- Assertion.addMethod('lessThan', assertBelow);
-
- /**
- * ### .most(value)
- *
- * Asserts that the target is less than or equal to `value`.
- *
- * expect(5).to.be.at.most(5);
- *
- * Can also be used in conjunction with `length` to
- * assert a maximum length. The benefit being a
- * more informative error message than if the length
- * was supplied directly.
- *
- * expect('foo').to.have.length.of.at.most(4);
- * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
- *
- * @name most
- * @alias lte
- * @param {Number} value
- * @param {String} message _optional_
- * @api public
- */
-
- function assertMost (n, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- if (flag(this, 'doLength')) {
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
- this.assert(
- len <= n
- , 'expected #{this} to have a length at most #{exp} but got #{act}'
- , 'expected #{this} to have a length above #{exp}'
- , n
- , len
- );
- } else {
- this.assert(
- obj <= n
- , 'expected #{this} to be at most ' + n
- , 'expected #{this} to be above ' + n
- );
- }
- }
-
- Assertion.addMethod('most', assertMost);
- Assertion.addMethod('lte', assertMost);
-
- /**
- * ### .within(start, finish)
- *
- * Asserts that the target is within a range.
- *
- * expect(7).to.be.within(5,10);
- *
- * Can also be used in conjunction with `length` to
- * assert a length range. The benefit being a
- * more informative error message than if the length
- * was supplied directly.
- *
- * expect('foo').to.have.length.within(2,4);
- * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
- *
- * @name within
- * @param {Number} start lowerbound inclusive
- * @param {Number} finish upperbound inclusive
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('within', function (start, finish, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object')
- , range = start + '..' + finish;
- if (flag(this, 'doLength')) {
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
- this.assert(
- len >= start && len <= finish
- , 'expected #{this} to have a length within ' + range
- , 'expected #{this} to not have a length within ' + range
- );
- } else {
- this.assert(
- obj >= start && obj <= finish
- , 'expected #{this} to be within ' + range
- , 'expected #{this} to not be within ' + range
- );
- }
- });
-
- /**
- * ### .instanceof(constructor)
- *
- * Asserts that the target is an instance of `constructor`.
- *
- * var Tea = function (name) { this.name = name; }
- * , Chai = new Tea('chai');
- *
- * expect(Chai).to.be.an.instanceof(Tea);
- * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
- *
- * @name instanceof
- * @param {Constructor} constructor
- * @param {String} message _optional_
- * @alias instanceOf
- * @api public
- */
-
- function assertInstanceOf (constructor, msg) {
- if (msg) flag(this, 'message', msg);
- var name = _.getName(constructor);
- this.assert(
- flag(this, 'object') instanceof constructor
- , 'expected #{this} to be an instance of ' + name
- , 'expected #{this} to not be an instance of ' + name
- );
- };
-
- Assertion.addMethod('instanceof', assertInstanceOf);
- Assertion.addMethod('instanceOf', assertInstanceOf);
-
- /**
- * ### .property(name, [value])
- *
- * Asserts that the target has a property `name`, optionally asserting that
- * the value of that property is strictly equal to `value`.
- * If the `deep` flag is set, you can use dot- and bracket-notation for deep
- * references into objects and arrays.
- *
- * // simple referencing
- * var obj = { foo: 'bar' };
- * expect(obj).to.have.property('foo');
- * expect(obj).to.have.property('foo', 'bar');
- *
- * // deep referencing
- * var deepObj = {
- * green: { tea: 'matcha' }
- * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
- * };
-
- * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
- * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
- * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
- *
- * You can also use an array as the starting point of a `deep.property`
- * assertion, or traverse nested arrays.
- *
- * var arr = [
- * [ 'chai', 'matcha', 'konacha' ]
- * , [ { tea: 'chai' }
- * , { tea: 'matcha' }
- * , { tea: 'konacha' } ]
- * ];
- *
- * expect(arr).to.have.deep.property('[0][1]', 'matcha');
- * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
- *
- * Furthermore, `property` changes the subject of the assertion
- * to be the value of that property from the original object. This
- * permits for further chainable assertions on that property.
- *
- * expect(obj).to.have.property('foo')
- * .that.is.a('string');
- * expect(deepObj).to.have.property('green')
- * .that.is.an('object')
- * .that.deep.equals({ tea: 'matcha' });
- * expect(deepObj).to.have.property('teas')
- * .that.is.an('array')
- * .with.deep.property('[2]')
- * .that.deep.equals({ tea: 'konacha' });
- *
- * @name property
- * @alias deep.property
- * @param {String} name
- * @param {Mixed} value (optional)
- * @param {String} message _optional_
- * @returns value of property for chaining
- * @api public
- */
-
- Assertion.addMethod('property', function (name, val, msg) {
- if (msg) flag(this, 'message', msg);
-
- var isDeep = !!flag(this, 'deep')
- , descriptor = isDeep ? 'deep property ' : 'property '
- , negate = flag(this, 'negate')
- , obj = flag(this, 'object')
- , pathInfo = isDeep ? _.getPathInfo(name, obj) : null
- , hasProperty = isDeep
- ? pathInfo.exists
- : _.hasProperty(name, obj)
- , value = isDeep
- ? pathInfo.value
- : obj[name];
-
- if (negate && undefined !== val) {
- if (undefined === value) {
- msg = (msg != null) ? msg + ': ' : '';
- throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
- }
- } else {
- this.assert(
- hasProperty
- , 'expected #{this} to have a ' + descriptor + _.inspect(name)
- , 'expected #{this} to not have ' + descriptor + _.inspect(name));
- }
-
- if (undefined !== val) {
- this.assert(
- val === value
- , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
- , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
- , val
- , value
- );
- }
-
- flag(this, 'object', value);
- });
-
-
- /**
- * ### .ownProperty(name)
- *
- * Asserts that the target has an own property `name`.
- *
- * expect('test').to.have.ownProperty('length');
- *
- * @name ownProperty
- * @alias haveOwnProperty
- * @param {String} name
- * @param {String} message _optional_
- * @api public
- */
-
- function assertOwnProperty (name, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- this.assert(
- obj.hasOwnProperty(name)
- , 'expected #{this} to have own property ' + _.inspect(name)
- , 'expected #{this} to not have own property ' + _.inspect(name)
- );
- }
-
- Assertion.addMethod('ownProperty', assertOwnProperty);
- Assertion.addMethod('haveOwnProperty', assertOwnProperty);
-
- /**
- * ### .length(value)
- *
- * Asserts that the target's `length` property has
- * the expected value.
- *
- * expect([ 1, 2, 3]).to.have.length(3);
- * expect('foobar').to.have.length(6);
- *
- * Can also be used as a chain precursor to a value
- * comparison for the length property.
- *
- * expect('foo').to.have.length.above(2);
- * expect([ 1, 2, 3 ]).to.have.length.above(2);
- * expect('foo').to.have.length.below(4);
- * expect([ 1, 2, 3 ]).to.have.length.below(4);
- * expect('foo').to.have.length.within(2,4);
- * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
- *
- * @name length
- * @alias lengthOf
- * @param {Number} length
- * @param {String} message _optional_
- * @api public
- */
-
- function assertLengthChain () {
- flag(this, 'doLength', true);
- }
-
- function assertLength (n, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- new Assertion(obj, msg).to.have.property('length');
- var len = obj.length;
-
- this.assert(
- len == n
- , 'expected #{this} to have a length of #{exp} but got #{act}'
- , 'expected #{this} to not have a length of #{act}'
- , n
- , len
- );
- }
-
- Assertion.addChainableMethod('length', assertLength, assertLengthChain);
- Assertion.addMethod('lengthOf', assertLength);
-
- /**
- * ### .match(regexp)
- *
- * Asserts that the target matches a regular expression.
- *
- * expect('foobar').to.match(/^foo/);
- *
- * @name match
- * @param {RegExp} RegularExpression
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('match', function (re, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- this.assert(
- re.exec(obj)
- , 'expected #{this} to match ' + re
- , 'expected #{this} not to match ' + re
- );
- });
-
- /**
- * ### .string(string)
- *
- * Asserts that the string target contains another string.
- *
- * expect('foobar').to.have.string('bar');
- *
- * @name string
- * @param {String} string
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('string', function (str, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- new Assertion(obj, msg).is.a('string');
-
- this.assert(
- ~obj.indexOf(str)
- , 'expected #{this} to contain ' + _.inspect(str)
- , 'expected #{this} to not contain ' + _.inspect(str)
- );
- });
-
-
- /**
- * ### .keys(key1, [key2], [...])
- *
- * Asserts that the target contains any or all of the passed-in keys.
- * Use in combination with `any`, `all`, `contains`, or `have` will affect
- * what will pass.
- *
- * When used in conjunction with `any`, at least one key that is passed
- * in must exist in the target object. This is regardless whether or not
- * the `have` or `contain` qualifiers are used. Note, either `any` or `all`
- * should be used in the assertion. If neither are used, the assertion is
- * defaulted to `all`.
- *
- * When both `all` and `contain` are used, the target object must have at
- * least all of the passed-in keys but may have more keys not listed.
- *
- * When both `all` and `have` are used, the target object must both contain
- * all of the passed-in keys AND the number of keys in the target object must
- * match the number of keys passed in (in other words, a target object must
- * have all and only all of the passed-in keys).
- *
- * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
- * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
- * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
- * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
- * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
- * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
- * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo', 7});
- * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
- * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys([{'bar': 6}}]);
- *
- *
- * @name keys
- * @alias key
- * @param {String...|Array|Object} keys
- * @api public
- */
-
- function assertKeys (keys) {
- var obj = flag(this, 'object')
- , str
- , ok = true
- , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';
-
- switch (_.type(keys)) {
- case "array":
- if (arguments.length > 1) throw (new Error(mixedArgsMsg));
- break;
- case "object":
- if (arguments.length > 1) throw (new Error(mixedArgsMsg));
- keys = Object.keys(keys);
- break;
- default:
- keys = Array.prototype.slice.call(arguments);
- }
-
- if (!keys.length) throw new Error('keys required');
-
- var actual = Object.keys(obj)
- , expected = keys
- , len = keys.length
- , any = flag(this, 'any')
- , all = flag(this, 'all');
-
- if (!any && !all) {
- all = true;
- }
-
- // Has any
- if (any) {
- var intersection = expected.filter(function(key) {
- return ~actual.indexOf(key);
- });
- ok = intersection.length > 0;
- }
-
- // Has all
- if (all) {
- ok = keys.every(function(key){
- return ~actual.indexOf(key);
- });
- if (!flag(this, 'negate') && !flag(this, 'contains')) {
- ok = ok && keys.length == actual.length;
- }
- }
-
- // Key string
- if (len > 1) {
- keys = keys.map(function(key){
- return _.inspect(key);
- });
- var last = keys.pop();
- if (all) {
- str = keys.join(', ') + ', and ' + last;
- }
- if (any) {
- str = keys.join(', ') + ', or ' + last;
- }
- } else {
- str = _.inspect(keys[0]);
- }
-
- // Form
- str = (len > 1 ? 'keys ' : 'key ') + str;
-
- // Have / include
- str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
-
- // Assertion
- this.assert(
- ok
- , 'expected #{this} to ' + str
- , 'expected #{this} to not ' + str
- , expected.slice(0).sort()
- , actual.sort()
- , true
- );
- }
-
- Assertion.addMethod('keys', assertKeys);
- Assertion.addMethod('key', assertKeys);
-
- /**
- * ### .throw(constructor)
- *
- * Asserts that the function target will throw a specific error, or specific type of error
- * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
- * for the error's message.
- *
- * var err = new ReferenceError('This is a bad function.');
- * var fn = function () { throw err; }
- * expect(fn).to.throw(ReferenceError);
- * expect(fn).to.throw(Error);
- * expect(fn).to.throw(/bad function/);
- * expect(fn).to.not.throw('good function');
- * expect(fn).to.throw(ReferenceError, /bad function/);
- * expect(fn).to.throw(err);
- * expect(fn).to.not.throw(new RangeError('Out of range.'));
- *
- * Please note that when a throw expectation is negated, it will check each
- * parameter independently, starting with error constructor type. The appropriate way
- * to check for the existence of a type of error but for a message that does not match
- * is to use `and`.
- *
- * expect(fn).to.throw(ReferenceError)
- * .and.not.throw(/good function/);
- *
- * @name throw
- * @alias throws
- * @alias Throw
- * @param {ErrorConstructor} constructor
- * @param {String|RegExp} expected error message
- * @param {String} message _optional_
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
- * @returns error for chaining (null if no error)
- * @api public
- */
-
- function assertThrows (constructor, errMsg, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- new Assertion(obj, msg).is.a('function');
-
- var thrown = false
- , desiredError = null
- , name = null
- , thrownError = null;
-
- if (arguments.length === 0) {
- errMsg = null;
- constructor = null;
- } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
- errMsg = constructor;
- constructor = null;
- } else if (constructor && constructor instanceof Error) {
- desiredError = constructor;
- constructor = null;
- errMsg = null;
- } else if (typeof constructor === 'function') {
- name = constructor.prototype.name || constructor.name;
- if (name === 'Error' && constructor !== Error) {
- name = (new constructor()).name;
- }
- } else {
- constructor = null;
- }
-
- try {
- obj();
- } catch (err) {
- // first, check desired error
- if (desiredError) {
- this.assert(
- err === desiredError
- , 'expected #{this} to throw #{exp} but #{act} was thrown'
- , 'expected #{this} to not throw #{exp}'
- , (desiredError instanceof Error ? desiredError.toString() : desiredError)
- , (err instanceof Error ? err.toString() : err)
- );
-
- flag(this, 'object', err);
- return this;
- }
-
- // next, check constructor
- if (constructor) {
- this.assert(
- err instanceof constructor
- , 'expected #{this} to throw #{exp} but #{act} was thrown'
- , 'expected #{this} to not throw #{exp} but #{act} was thrown'
- , name
- , (err instanceof Error ? err.toString() : err)
- );
-
- if (!errMsg) {
- flag(this, 'object', err);
- return this;
- }
- }
-
- // next, check message
- var message = 'object' === _.type(err) && "message" in err
- ? err.message
- : '' + err;
-
- if ((message != null) && errMsg && errMsg instanceof RegExp) {
- this.assert(
- errMsg.exec(message)
- , 'expected #{this} to throw error matching #{exp} but got #{act}'
- , 'expected #{this} to throw error not matching #{exp}'
- , errMsg
- , message
- );
-
- flag(this, 'object', err);
- return this;
- } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
- this.assert(
- ~message.indexOf(errMsg)
- , 'expected #{this} to throw error including #{exp} but got #{act}'
- , 'expected #{this} to throw error not including #{act}'
- , errMsg
- , message
- );
-
- flag(this, 'object', err);
- return this;
- } else {
- thrown = true;
- thrownError = err;
- }
- }
-
- var actuallyGot = ''
- , expectedThrown = name !== null
- ? name
- : desiredError
- ? '#{exp}' //_.inspect(desiredError)
- : 'an error';
-
- if (thrown) {
- actuallyGot = ' but #{act} was thrown'
- }
-
- this.assert(
- thrown === true
- , 'expected #{this} to throw ' + expectedThrown + actuallyGot
- , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
- , (desiredError instanceof Error ? desiredError.toString() : desiredError)
- , (thrownError instanceof Error ? thrownError.toString() : thrownError)
- );
-
- flag(this, 'object', thrownError);
- };
-
- Assertion.addMethod('throw', assertThrows);
- Assertion.addMethod('throws', assertThrows);
- Assertion.addMethod('Throw', assertThrows);
-
- /**
- * ### .respondTo(method)
- *
- * Asserts that the object or class target will respond to a method.
- *
- * Klass.prototype.bar = function(){};
- * expect(Klass).to.respondTo('bar');
- * expect(obj).to.respondTo('bar');
- *
- * To check if a constructor will respond to a static function,
- * set the `itself` flag.
- *
- * Klass.baz = function(){};
- * expect(Klass).itself.to.respondTo('baz');
- *
- * @name respondTo
- * @param {String} method
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('respondTo', function (method, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object')
- , itself = flag(this, 'itself')
- , context = ('function' === _.type(obj) && !itself)
- ? obj.prototype[method]
- : obj[method];
-
- this.assert(
- 'function' === typeof context
- , 'expected #{this} to respond to ' + _.inspect(method)
- , 'expected #{this} to not respond to ' + _.inspect(method)
- );
- });
-
- /**
- * ### .itself
- *
- * Sets the `itself` flag, later used by the `respondTo` assertion.
- *
- * function Foo() {}
- * Foo.bar = function() {}
- * Foo.prototype.baz = function() {}
- *
- * expect(Foo).itself.to.respondTo('bar');
- * expect(Foo).itself.not.to.respondTo('baz');
- *
- * @name itself
- * @api public
- */
-
- Assertion.addProperty('itself', function () {
- flag(this, 'itself', true);
- });
-
- /**
- * ### .satisfy(method)
- *
- * Asserts that the target passes a given truth test.
- *
- * expect(1).to.satisfy(function(num) { return num > 0; });
- *
- * @name satisfy
- * @param {Function} matcher
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('satisfy', function (matcher, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
- var result = matcher(obj);
- this.assert(
- result
- , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
- , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
- , this.negate ? false : true
- , result
- );
- });
-
- /**
- * ### .closeTo(expected, delta)
- *
- * Asserts that the target is equal `expected`, to within a +/- `delta` range.
- *
- * expect(1.5).to.be.closeTo(1, 0.5);
- *
- * @name closeTo
- * @param {Number} expected
- * @param {Number} delta
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('closeTo', function (expected, delta, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
-
- new Assertion(obj, msg).is.a('number');
- if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
- throw new Error('the arguments to closeTo must be numbers');
- }
-
- this.assert(
- Math.abs(obj - expected) <= delta
- , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
- , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
- );
- });
-
- function isSubsetOf(subset, superset, cmp) {
- return subset.every(function(elem) {
- if (!cmp) return superset.indexOf(elem) !== -1;
-
- return superset.some(function(elem2) {
- return cmp(elem, elem2);
- });
- })
- }
-
- /**
- * ### .members(set)
- *
- * Asserts that the target is a superset of `set`,
- * or that the target and `set` have the same strictly-equal (===) members.
- * Alternately, if the `deep` flag is set, set members are compared for deep
- * equality.
- *
- * expect([1, 2, 3]).to.include.members([3, 2]);
- * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
- *
- * expect([4, 2]).to.have.members([2, 4]);
- * expect([5, 2]).to.not.have.members([5, 2, 1]);
- *
- * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
- *
- * @name members
- * @param {Array} set
- * @param {String} message _optional_
- * @api public
- */
-
- Assertion.addMethod('members', function (subset, msg) {
- if (msg) flag(this, 'message', msg);
- var obj = flag(this, 'object');
-
- new Assertion(obj).to.be.an('array');
- new Assertion(subset).to.be.an('array');
-
- var cmp = flag(this, 'deep') ? _.eql : undefined;
-
- if (flag(this, 'contains')) {
- return this.assert(
- isSubsetOf(subset, obj, cmp)
- , 'expected #{this} to be a superset of #{act}'
- , 'expected #{this} to not be a superset of #{act}'
- , obj
- , subset
- );
- }
-
- this.assert(
- isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
- , 'expected #{this} to have the same members as #{act}'
- , 'expected #{this} to not have the same members as #{act}'
- , obj
- , subset
- );
- });
-
- /**
- * ### .change(function)
- *
- * Asserts that a function changes an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val += 3 };
- * var noChangeFn = function() { return 'foo' + 'bar'; }
- * expect(fn).to.change(obj, 'val');
- * expect(noChangFn).to.not.change(obj, 'val')
- *
- * @name change
- * @alias changes
- * @alias Change
- * @param {String} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- function assertChanges (object, prop, msg) {
- if (msg) flag(this, 'message', msg);
- var fn = flag(this, 'object');
- new Assertion(object, msg).to.have.property(prop);
- new Assertion(fn).is.a('function');
-
- var initial = object[prop];
- fn();
-
- this.assert(
- initial !== object[prop]
- , 'expected .' + prop + ' to change'
- , 'expected .' + prop + ' to not change'
- );
- }
-
- Assertion.addChainableMethod('change', assertChanges);
- Assertion.addChainableMethod('changes', assertChanges);
-
- /**
- * ### .increase(function)
- *
- * Asserts that a function increases an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 15 };
- * expect(fn).to.increase(obj, 'val');
- *
- * @name increase
- * @alias increases
- * @alias Increase
- * @param {String} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- function assertIncreases (object, prop, msg) {
- if (msg) flag(this, 'message', msg);
- var fn = flag(this, 'object');
- new Assertion(object, msg).to.have.property(prop);
- new Assertion(fn).is.a('function');
-
- var initial = object[prop];
- fn();
-
- this.assert(
- object[prop] - initial > 0
- , 'expected .' + prop + ' to increase'
- , 'expected .' + prop + ' to not increase'
- );
- }
-
- Assertion.addChainableMethod('increase', assertIncreases);
- Assertion.addChainableMethod('increases', assertIncreases);
-
- /**
- * ### .decrease(function)
- *
- * Asserts that a function decreases an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 5 };
- * expect(fn).to.decrease(obj, 'val');
- *
- * @name decrease
- * @alias decreases
- * @alias Decrease
- * @param {String} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- function assertDecreases (object, prop, msg) {
- if (msg) flag(this, 'message', msg);
- var fn = flag(this, 'object');
- new Assertion(object, msg).to.have.property(prop);
- new Assertion(fn).is.a('function');
-
- var initial = object[prop];
- fn();
-
- this.assert(
- object[prop] - initial < 0
- , 'expected .' + prop + ' to decrease'
- , 'expected .' + prop + ' to not decrease'
- );
- }
-
- Assertion.addChainableMethod('decrease', assertDecreases);
- Assertion.addChainableMethod('decreases', assertDecreases);
-
-};
-
-});
-
-require.register("chai/lib/chai/interface/assert.js", function (exports, module) {
-/*!
- * chai
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-
-module.exports = function (chai, util) {
-
- /*!
- * Chai dependencies.
- */
-
- var Assertion = chai.Assertion
- , flag = util.flag;
-
- /*!
- * Module export.
- */
-
- /**
- * ### assert(expression, message)
- *
- * Write your own test expressions.
- *
- * assert('foo' !== 'bar', 'foo is not bar');
- * assert(Array.isArray([]), 'empty arrays are arrays');
- *
- * @param {Mixed} expression to test for truthiness
- * @param {String} message to display on error
- * @name assert
- * @api public
- */
-
- var assert = chai.assert = function (express, errmsg) {
- var test = new Assertion(null, null, chai.assert);
- test.assert(
- express
- , errmsg
- , '[ negation message unavailable ]'
- );
- };
-
- /**
- * ### .fail(actual, expected, [message], [operator])
- *
- * Throw a failure. Node.js `assert` module-compatible.
- *
- * @name fail
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @param {String} operator
- * @api public
- */
-
- assert.fail = function (actual, expected, message, operator) {
- message = message || 'assert.fail()';
- throw new chai.AssertionError(message, {
- actual: actual
- , expected: expected
- , operator: operator
- }, assert.fail);
- };
-
- /**
- * ### .ok(object, [message])
- *
- * Asserts that `object` is truthy.
- *
- * assert.ok('everything', 'everything is ok');
- * assert.ok(false, 'this will fail');
- *
- * @name ok
- * @param {Mixed} object to test
- * @param {String} message
- * @api public
- */
-
- assert.ok = function (val, msg) {
- new Assertion(val, msg).is.ok;
- };
-
- /**
- * ### .notOk(object, [message])
- *
- * Asserts that `object` is falsy.
- *
- * assert.notOk('everything', 'this will fail');
- * assert.notOk(false, 'this will pass');
- *
- * @name notOk
- * @param {Mixed} object to test
- * @param {String} message
- * @api public
- */
-
- assert.notOk = function (val, msg) {
- new Assertion(val, msg).is.not.ok;
- };
-
- /**
- * ### .equal(actual, expected, [message])
- *
- * Asserts non-strict equality (`==`) of `actual` and `expected`.
- *
- * assert.equal(3, '3', '== coerces values to strings');
- *
- * @name equal
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.equal = function (act, exp, msg) {
- var test = new Assertion(act, msg, assert.equal);
-
- test.assert(
- exp == flag(test, 'object')
- , 'expected #{this} to equal #{exp}'
- , 'expected #{this} to not equal #{act}'
- , exp
- , act
- );
- };
-
- /**
- * ### .notEqual(actual, expected, [message])
- *
- * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
- *
- * assert.notEqual(3, 4, 'these numbers are not equal');
- *
- * @name notEqual
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.notEqual = function (act, exp, msg) {
- var test = new Assertion(act, msg, assert.notEqual);
-
- test.assert(
- exp != flag(test, 'object')
- , 'expected #{this} to not equal #{exp}'
- , 'expected #{this} to equal #{act}'
- , exp
- , act
- );
- };
-
- /**
- * ### .strictEqual(actual, expected, [message])
- *
- * Asserts strict equality (`===`) of `actual` and `expected`.
- *
- * assert.strictEqual(true, true, 'these booleans are strictly equal');
- *
- * @name strictEqual
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.strictEqual = function (act, exp, msg) {
- new Assertion(act, msg).to.equal(exp);
- };
-
- /**
- * ### .notStrictEqual(actual, expected, [message])
- *
- * Asserts strict inequality (`!==`) of `actual` and `expected`.
- *
- * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
- *
- * @name notStrictEqual
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.notStrictEqual = function (act, exp, msg) {
- new Assertion(act, msg).to.not.equal(exp);
- };
-
- /**
- * ### .deepEqual(actual, expected, [message])
- *
- * Asserts that `actual` is deeply equal to `expected`.
- *
- * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
- *
- * @name deepEqual
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.deepEqual = function (act, exp, msg) {
- new Assertion(act, msg).to.eql(exp);
- };
-
- /**
- * ### .notDeepEqual(actual, expected, [message])
- *
- * Assert that `actual` is not deeply equal to `expected`.
- *
- * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
- *
- * @name notDeepEqual
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @api public
- */
-
- assert.notDeepEqual = function (act, exp, msg) {
- new Assertion(act, msg).to.not.eql(exp);
- };
-
- /**
- * ### .isTrue(value, [message])
- *
- * Asserts that `value` is true.
- *
- * var teaServed = true;
- * assert.isTrue(teaServed, 'the tea has been served');
- *
- * @name isTrue
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isAbove = function (val, abv, msg) {
- new Assertion(val, msg).to.be.above(abv);
- };
-
- /**
- * ### .isAbove(valueToCheck, valueToBeAbove, [message])
- *
- * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
- *
- * assert.isAbove(5, 2, '5 is strictly greater than 2');
- *
- * @name isAbove
- * @param {Mixed} valueToCheck
- * @param {Mixed} valueToBeAbove
- * @param {String} message
- * @api public
- */
-
- assert.isBelow = function (val, blw, msg) {
- new Assertion(val, msg).to.be.below(blw);
- };
-
- /**
- * ### .isBelow(valueToCheck, valueToBeBelow, [message])
- *
- * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`
- *
- * assert.isBelow(3, 6, '3 is strictly less than 6');
- *
- * @name isBelow
- * @param {Mixed} valueToCheck
- * @param {Mixed} valueToBeBelow
- * @param {String} message
- * @api public
- */
-
- assert.isTrue = function (val, msg) {
- new Assertion(val, msg).is['true'];
- };
-
- /**
- * ### .isFalse(value, [message])
- *
- * Asserts that `value` is false.
- *
- * var teaServed = false;
- * assert.isFalse(teaServed, 'no tea yet? hmm...');
- *
- * @name isFalse
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isFalse = function (val, msg) {
- new Assertion(val, msg).is['false'];
- };
-
- /**
- * ### .isNull(value, [message])
- *
- * Asserts that `value` is null.
- *
- * assert.isNull(err, 'there was no error');
- *
- * @name isNull
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNull = function (val, msg) {
- new Assertion(val, msg).to.equal(null);
- };
-
- /**
- * ### .isNotNull(value, [message])
- *
- * Asserts that `value` is not null.
- *
- * var tea = 'tasty chai';
- * assert.isNotNull(tea, 'great, time for tea!');
- *
- * @name isNotNull
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotNull = function (val, msg) {
- new Assertion(val, msg).to.not.equal(null);
- };
-
- /**
- * ### .isUndefined(value, [message])
- *
- * Asserts that `value` is `undefined`.
- *
- * var tea;
- * assert.isUndefined(tea, 'no tea defined');
- *
- * @name isUndefined
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isUndefined = function (val, msg) {
- new Assertion(val, msg).to.equal(undefined);
- };
-
- /**
- * ### .isDefined(value, [message])
- *
- * Asserts that `value` is not `undefined`.
- *
- * var tea = 'cup of chai';
- * assert.isDefined(tea, 'tea has been defined');
- *
- * @name isDefined
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isDefined = function (val, msg) {
- new Assertion(val, msg).to.not.equal(undefined);
- };
-
- /**
- * ### .isFunction(value, [message])
- *
- * Asserts that `value` is a function.
- *
- * function serveTea() { return 'cup of tea'; };
- * assert.isFunction(serveTea, 'great, we can have tea now');
- *
- * @name isFunction
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isFunction = function (val, msg) {
- new Assertion(val, msg).to.be.a('function');
- };
-
- /**
- * ### .isNotFunction(value, [message])
- *
- * Asserts that `value` is _not_ a function.
- *
- * var serveTea = [ 'heat', 'pour', 'sip' ];
- * assert.isNotFunction(serveTea, 'great, we have listed the steps');
- *
- * @name isNotFunction
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotFunction = function (val, msg) {
- new Assertion(val, msg).to.not.be.a('function');
- };
-
- /**
- * ### .isObject(value, [message])
- *
- * Asserts that `value` is an object (as revealed by
- * `Object.prototype.toString`).
- *
- * var selection = { name: 'Chai', serve: 'with spices' };
- * assert.isObject(selection, 'tea selection is an object');
- *
- * @name isObject
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isObject = function (val, msg) {
- new Assertion(val, msg).to.be.a('object');
- };
-
- /**
- * ### .isNotObject(value, [message])
- *
- * Asserts that `value` is _not_ an object.
- *
- * var selection = 'chai'
- * assert.isNotObject(selection, 'tea selection is not an object');
- * assert.isNotObject(null, 'null is not an object');
- *
- * @name isNotObject
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotObject = function (val, msg) {
- new Assertion(val, msg).to.not.be.a('object');
- };
-
- /**
- * ### .isArray(value, [message])
- *
- * Asserts that `value` is an array.
- *
- * var menu = [ 'green', 'chai', 'oolong' ];
- * assert.isArray(menu, 'what kind of tea do we want?');
- *
- * @name isArray
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isArray = function (val, msg) {
- new Assertion(val, msg).to.be.an('array');
- };
-
- /**
- * ### .isNotArray(value, [message])
- *
- * Asserts that `value` is _not_ an array.
- *
- * var menu = 'green|chai|oolong';
- * assert.isNotArray(menu, 'what kind of tea do we want?');
- *
- * @name isNotArray
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotArray = function (val, msg) {
- new Assertion(val, msg).to.not.be.an('array');
- };
-
- /**
- * ### .isString(value, [message])
- *
- * Asserts that `value` is a string.
- *
- * var teaOrder = 'chai';
- * assert.isString(teaOrder, 'order placed');
- *
- * @name isString
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isString = function (val, msg) {
- new Assertion(val, msg).to.be.a('string');
- };
-
- /**
- * ### .isNotString(value, [message])
- *
- * Asserts that `value` is _not_ a string.
- *
- * var teaOrder = 4;
- * assert.isNotString(teaOrder, 'order placed');
- *
- * @name isNotString
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotString = function (val, msg) {
- new Assertion(val, msg).to.not.be.a('string');
- };
-
- /**
- * ### .isNumber(value, [message])
- *
- * Asserts that `value` is a number.
- *
- * var cups = 2;
- * assert.isNumber(cups, 'how many cups');
- *
- * @name isNumber
- * @param {Number} value
- * @param {String} message
- * @api public
- */
-
- assert.isNumber = function (val, msg) {
- new Assertion(val, msg).to.be.a('number');
- };
-
- /**
- * ### .isNotNumber(value, [message])
- *
- * Asserts that `value` is _not_ a number.
- *
- * var cups = '2 cups please';
- * assert.isNotNumber(cups, 'how many cups');
- *
- * @name isNotNumber
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotNumber = function (val, msg) {
- new Assertion(val, msg).to.not.be.a('number');
- };
-
- /**
- * ### .isBoolean(value, [message])
- *
- * Asserts that `value` is a boolean.
- *
- * var teaReady = true
- * , teaServed = false;
- *
- * assert.isBoolean(teaReady, 'is the tea ready');
- * assert.isBoolean(teaServed, 'has tea been served');
- *
- * @name isBoolean
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isBoolean = function (val, msg) {
- new Assertion(val, msg).to.be.a('boolean');
- };
-
- /**
- * ### .isNotBoolean(value, [message])
- *
- * Asserts that `value` is _not_ a boolean.
- *
- * var teaReady = 'yep'
- * , teaServed = 'nope';
- *
- * assert.isNotBoolean(teaReady, 'is the tea ready');
- * assert.isNotBoolean(teaServed, 'has tea been served');
- *
- * @name isNotBoolean
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.isNotBoolean = function (val, msg) {
- new Assertion(val, msg).to.not.be.a('boolean');
- };
-
- /**
- * ### .typeOf(value, name, [message])
- *
- * Asserts that `value`'s type is `name`, as determined by
- * `Object.prototype.toString`.
- *
- * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
- * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
- * assert.typeOf('tea', 'string', 'we have a string');
- * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
- * assert.typeOf(null, 'null', 'we have a null');
- * assert.typeOf(undefined, 'undefined', 'we have an undefined');
- *
- * @name typeOf
- * @param {Mixed} value
- * @param {String} name
- * @param {String} message
- * @api public
- */
-
- assert.typeOf = function (val, type, msg) {
- new Assertion(val, msg).to.be.a(type);
- };
-
- /**
- * ### .notTypeOf(value, name, [message])
- *
- * Asserts that `value`'s type is _not_ `name`, as determined by
- * `Object.prototype.toString`.
- *
- * assert.notTypeOf('tea', 'number', 'strings are not numbers');
- *
- * @name notTypeOf
- * @param {Mixed} value
- * @param {String} typeof name
- * @param {String} message
- * @api public
- */
-
- assert.notTypeOf = function (val, type, msg) {
- new Assertion(val, msg).to.not.be.a(type);
- };
-
- /**
- * ### .instanceOf(object, constructor, [message])
- *
- * Asserts that `value` is an instance of `constructor`.
- *
- * var Tea = function (name) { this.name = name; }
- * , chai = new Tea('chai');
- *
- * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
- *
- * @name instanceOf
- * @param {Object} object
- * @param {Constructor} constructor
- * @param {String} message
- * @api public
- */
-
- assert.instanceOf = function (val, type, msg) {
- new Assertion(val, msg).to.be.instanceOf(type);
- };
-
- /**
- * ### .notInstanceOf(object, constructor, [message])
- *
- * Asserts `value` is not an instance of `constructor`.
- *
- * var Tea = function (name) { this.name = name; }
- * , chai = new String('chai');
- *
- * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
- *
- * @name notInstanceOf
- * @param {Object} object
- * @param {Constructor} constructor
- * @param {String} message
- * @api public
- */
-
- assert.notInstanceOf = function (val, type, msg) {
- new Assertion(val, msg).to.not.be.instanceOf(type);
- };
-
- /**
- * ### .include(haystack, needle, [message])
- *
- * Asserts that `haystack` includes `needle`. Works
- * for strings and arrays.
- *
- * assert.include('foobar', 'bar', 'foobar contains string "bar"');
- * assert.include([ 1, 2, 3 ], 3, 'array contains value');
- *
- * @name include
- * @param {Array|String} haystack
- * @param {Mixed} needle
- * @param {String} message
- * @api public
- */
-
- assert.include = function (exp, inc, msg) {
- new Assertion(exp, msg, assert.include).include(inc);
- };
-
- /**
- * ### .notInclude(haystack, needle, [message])
- *
- * Asserts that `haystack` does not include `needle`. Works
- * for strings and arrays.
- *i
- * assert.notInclude('foobar', 'baz', 'string not include substring');
- * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
- *
- * @name notInclude
- * @param {Array|String} haystack
- * @param {Mixed} needle
- * @param {String} message
- * @api public
- */
-
- assert.notInclude = function (exp, inc, msg) {
- new Assertion(exp, msg, assert.notInclude).not.include(inc);
- };
-
- /**
- * ### .match(value, regexp, [message])
- *
- * Asserts that `value` matches the regular expression `regexp`.
- *
- * assert.match('foobar', /^foo/, 'regexp matches');
- *
- * @name match
- * @param {Mixed} value
- * @param {RegExp} regexp
- * @param {String} message
- * @api public
- */
-
- assert.match = function (exp, re, msg) {
- new Assertion(exp, msg).to.match(re);
- };
-
- /**
- * ### .notMatch(value, regexp, [message])
- *
- * Asserts that `value` does not match the regular expression `regexp`.
- *
- * assert.notMatch('foobar', /^foo/, 'regexp does not match');
- *
- * @name notMatch
- * @param {Mixed} value
- * @param {RegExp} regexp
- * @param {String} message
- * @api public
- */
-
- assert.notMatch = function (exp, re, msg) {
- new Assertion(exp, msg).to.not.match(re);
- };
-
- /**
- * ### .property(object, property, [message])
- *
- * Asserts that `object` has a property named by `property`.
- *
- * assert.property({ tea: { green: 'matcha' }}, 'tea');
- *
- * @name property
- * @param {Object} object
- * @param {String} property
- * @param {String} message
- * @api public
- */
-
- assert.property = function (obj, prop, msg) {
- new Assertion(obj, msg).to.have.property(prop);
- };
-
- /**
- * ### .notProperty(object, property, [message])
- *
- * Asserts that `object` does _not_ have a property named by `property`.
- *
- * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
- *
- * @name notProperty
- * @param {Object} object
- * @param {String} property
- * @param {String} message
- * @api public
- */
-
- assert.notProperty = function (obj, prop, msg) {
- new Assertion(obj, msg).to.not.have.property(prop);
- };
-
- /**
- * ### .deepProperty(object, property, [message])
- *
- * Asserts that `object` has a property named by `property`, which can be a
- * string using dot- and bracket-notation for deep reference.
- *
- * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
- *
- * @name deepProperty
- * @param {Object} object
- * @param {String} property
- * @param {String} message
- * @api public
- */
-
- assert.deepProperty = function (obj, prop, msg) {
- new Assertion(obj, msg).to.have.deep.property(prop);
- };
-
- /**
- * ### .notDeepProperty(object, property, [message])
- *
- * Asserts that `object` does _not_ have a property named by `property`, which
- * can be a string using dot- and bracket-notation for deep reference.
- *
- * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
- *
- * @name notDeepProperty
- * @param {Object} object
- * @param {String} property
- * @param {String} message
- * @api public
- */
-
- assert.notDeepProperty = function (obj, prop, msg) {
- new Assertion(obj, msg).to.not.have.deep.property(prop);
- };
-
- /**
- * ### .propertyVal(object, property, value, [message])
- *
- * Asserts that `object` has a property named by `property` with value given
- * by `value`.
- *
- * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
- *
- * @name propertyVal
- * @param {Object} object
- * @param {String} property
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.propertyVal = function (obj, prop, val, msg) {
- new Assertion(obj, msg).to.have.property(prop, val);
- };
-
- /**
- * ### .propertyNotVal(object, property, value, [message])
- *
- * Asserts that `object` has a property named by `property`, but with a value
- * different from that given by `value`.
- *
- * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
- *
- * @name propertyNotVal
- * @param {Object} object
- * @param {String} property
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.propertyNotVal = function (obj, prop, val, msg) {
- new Assertion(obj, msg).to.not.have.property(prop, val);
- };
-
- /**
- * ### .deepPropertyVal(object, property, value, [message])
- *
- * Asserts that `object` has a property named by `property` with value given
- * by `value`. `property` can use dot- and bracket-notation for deep
- * reference.
- *
- * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
- *
- * @name deepPropertyVal
- * @param {Object} object
- * @param {String} property
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.deepPropertyVal = function (obj, prop, val, msg) {
- new Assertion(obj, msg).to.have.deep.property(prop, val);
- };
-
- /**
- * ### .deepPropertyNotVal(object, property, value, [message])
- *
- * Asserts that `object` has a property named by `property`, but with a value
- * different from that given by `value`. `property` can use dot- and
- * bracket-notation for deep reference.
- *
- * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
- *
- * @name deepPropertyNotVal
- * @param {Object} object
- * @param {String} property
- * @param {Mixed} value
- * @param {String} message
- * @api public
- */
-
- assert.deepPropertyNotVal = function (obj, prop, val, msg) {
- new Assertion(obj, msg).to.not.have.deep.property(prop, val);
- };
-
- /**
- * ### .lengthOf(object, length, [message])
- *
- * Asserts that `object` has a `length` property with the expected value.
- *
- * assert.lengthOf([1,2,3], 3, 'array has length of 3');
- * assert.lengthOf('foobar', 5, 'string has length of 6');
- *
- * @name lengthOf
- * @param {Mixed} object
- * @param {Number} length
- * @param {String} message
- * @api public
- */
-
- assert.lengthOf = function (exp, len, msg) {
- new Assertion(exp, msg).to.have.length(len);
- };
-
- /**
- * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
- *
- * Asserts that `function` will throw an error that is an instance of
- * `constructor`, or alternately that it will throw an error with message
- * matching `regexp`.
- *
- * assert.throw(fn, 'function throws a reference error');
- * assert.throw(fn, /function throws a reference error/);
- * assert.throw(fn, ReferenceError);
- * assert.throw(fn, ReferenceError, 'function throws a reference error');
- * assert.throw(fn, ReferenceError, /function throws a reference error/);
- *
- * @name throws
- * @alias throw
- * @alias Throw
- * @param {Function} function
- * @param {ErrorConstructor} constructor
- * @param {RegExp} regexp
- * @param {String} message
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
- * @api public
- */
-
- assert.Throw = function (fn, errt, errs, msg) {
- if ('string' === typeof errt || errt instanceof RegExp) {
- errs = errt;
- errt = null;
- }
-
- var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
- return flag(assertErr, 'object');
- };
-
- /**
- * ### .doesNotThrow(function, [constructor/regexp], [message])
- *
- * Asserts that `function` will _not_ throw an error that is an instance of
- * `constructor`, or alternately that it will not throw an error with message
- * matching `regexp`.
- *
- * assert.doesNotThrow(fn, Error, 'function does not throw');
- *
- * @name doesNotThrow
- * @param {Function} function
- * @param {ErrorConstructor} constructor
- * @param {RegExp} regexp
- * @param {String} message
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
- * @api public
- */
-
- assert.doesNotThrow = function (fn, type, msg) {
- if ('string' === typeof type) {
- msg = type;
- type = null;
- }
-
- new Assertion(fn, msg).to.not.Throw(type);
- };
-
- /**
- * ### .operator(val1, operator, val2, [message])
- *
- * Compares two values using `operator`.
- *
- * assert.operator(1, '<', 2, 'everything is ok');
- * assert.operator(1, '>', 2, 'this will fail');
- *
- * @name operator
- * @param {Mixed} val1
- * @param {String} operator
- * @param {Mixed} val2
- * @param {String} message
- * @api public
- */
-
- assert.operator = function (val, operator, val2, msg) {
- if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
- throw new Error('Invalid operator "' + operator + '"');
- }
- var test = new Assertion(eval(val + operator + val2), msg);
- test.assert(
- true === flag(test, 'object')
- , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
- , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
- };
-
- /**
- * ### .closeTo(actual, expected, delta, [message])
- *
- * Asserts that the target is equal `expected`, to within a +/- `delta` range.
- *
- * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
- *
- * @name closeTo
- * @param {Number} actual
- * @param {Number} expected
- * @param {Number} delta
- * @param {String} message
- * @api public
- */
-
- assert.closeTo = function (act, exp, delta, msg) {
- new Assertion(act, msg).to.be.closeTo(exp, delta);
- };
-
- /**
- * ### .sameMembers(set1, set2, [message])
- *
- * Asserts that `set1` and `set2` have the same members.
- * Order is not taken into account.
- *
- * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
- *
- * @name sameMembers
- * @param {Array} set1
- * @param {Array} set2
- * @param {String} message
- * @api public
- */
-
- assert.sameMembers = function (set1, set2, msg) {
- new Assertion(set1, msg).to.have.same.members(set2);
- }
-
- /**
- * ### .sameDeepMembers(set1, set2, [message])
- *
- * Asserts that `set1` and `set2` have the same members - using a deep equality checking.
- * Order is not taken into account.
- *
- * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
- *
- * @name sameDeepMembers
- * @param {Array} set1
- * @param {Array} set2
- * @param {String} message
- * @api public
- */
-
- assert.sameDeepMembers = function (set1, set2, msg) {
- new Assertion(set1, msg).to.have.same.deep.members(set2);
- }
-
- /**
- * ### .includeMembers(superset, subset, [message])
- *
- * Asserts that `subset` is included in `superset`.
- * Order is not taken into account.
- *
- * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
- *
- * @name includeMembers
- * @param {Array} superset
- * @param {Array} subset
- * @param {String} message
- * @api public
- */
-
- assert.includeMembers = function (superset, subset, msg) {
- new Assertion(superset, msg).to.include.members(subset);
- }
-
- /**
- * ### .changes(function, object, property)
- *
- * Asserts that a function changes the value of a property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 22 };
- * assert.changes(fn, obj, 'val');
- *
- * @name changes
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.changes = function (fn, obj, prop) {
- new Assertion(fn).to.change(obj, prop);
- }
-
- /**
- * ### .doesNotChange(function, object, property)
- *
- * Asserts that a function does not changes the value of a property
- *
- * var obj = { val: 10 };
- * var fn = function() { console.log('foo'); };
- * assert.doesNotChange(fn, obj, 'val');
- *
- * @name doesNotChange
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.doesNotChange = function (fn, obj, prop) {
- new Assertion(fn).to.not.change(obj, prop);
- }
-
- /**
- * ### .increases(function, object, property)
- *
- * Asserts that a function increases an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 13 };
- * assert.increases(fn, obj, 'val');
- *
- * @name increases
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.increases = function (fn, obj, prop) {
- new Assertion(fn).to.increase(obj, prop);
- }
-
- /**
- * ### .doesNotIncrease(function, object, property)
- *
- * Asserts that a function does not increase object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 8 };
- * assert.doesNotIncrease(fn, obj, 'val');
- *
- * @name doesNotIncrease
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.doesNotIncrease = function (fn, obj, prop) {
- new Assertion(fn).to.not.increase(obj, prop);
- }
-
- /**
- * ### .decreases(function, object, property)
- *
- * Asserts that a function decreases an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 5 };
- * assert.decreases(fn, obj, 'val');
- *
- * @name decreases
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.decreases = function (fn, obj, prop) {
- new Assertion(fn).to.decrease(obj, prop);
- }
-
- /**
- * ### .doesNotDecrease(function, object, property)
- *
- * Asserts that a function does not decreases an object property
- *
- * var obj = { val: 10 };
- * var fn = function() { obj.val = 15 };
- * assert.doesNotDecrease(fn, obj, 'val');
- *
- * @name doesNotDecrease
- * @param {Function} modifier function
- * @param {Object} object
- * @param {String} property name
- * @param {String} message _optional_
- * @api public
- */
-
- assert.doesNotDecrease = function (fn, obj, prop) {
- new Assertion(fn).to.not.decrease(obj, prop);
- }
-
- /*!
- * Undocumented / untested
- */
-
- assert.ifError = function (val, msg) {
- new Assertion(val, msg).to.not.be.ok;
- };
-
- /*!
- * Aliases.
- */
-
- (function alias(name, as){
- assert[as] = assert[name];
- return alias;
- })
- ('Throw', 'throw')
- ('Throw', 'throws');
-};
-
-});
-
-require.register("chai/lib/chai/interface/expect.js", function (exports, module) {
-/*!
- * chai
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-module.exports = function (chai, util) {
- chai.expect = function (val, message) {
- return new chai.Assertion(val, message);
- };
-
- /**
- * ### .fail(actual, expected, [message], [operator])
- *
- * Throw a failure.
- *
- * @name fail
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @param {String} operator
- * @api public
- */
-
- chai.expect.fail = function (actual, expected, message, operator) {
- message = message || 'expect.fail()';
- throw new chai.AssertionError(message, {
- actual: actual
- , expected: expected
- , operator: operator
- }, chai.expect.fail);
- };
-};
-
-});
-
-require.register("chai/lib/chai/interface/should.js", function (exports, module) {
-/*!
- * chai
- * Copyright(c) 2011-2014 Jake Luer
- * MIT Licensed
- */
-
-module.exports = function (chai, util) {
- var Assertion = chai.Assertion;
-
- function loadShould () {
- // explicitly define this method as function as to have it's name to include as `ssfi`
- function shouldGetter() {
- if (this instanceof String || this instanceof Number) {
- return new Assertion(this.constructor(this), null, shouldGetter);
- } else if (this instanceof Boolean) {
- return new Assertion(this == true, null, shouldGetter);
- }
- return new Assertion(this, null, shouldGetter);
- }
- function shouldSetter(value) {
- // See https://github.com/chaijs/chai/issues/86: this makes
- // `whatever.should = someValue` actually set `someValue`, which is
- // especially useful for `global.should = require('chai').should()`.
- //
- // Note that we have to use [[DefineProperty]] instead of [[Put]]
- // since otherwise we would trigger this very setter!
- Object.defineProperty(this, 'should', {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- }
- // modify Object.prototype to have `should`
- Object.defineProperty(Object.prototype, 'should', {
- set: shouldSetter
- , get: shouldGetter
- , configurable: true
- });
-
- var should = {};
-
- /**
- * ### .fail(actual, expected, [message], [operator])
- *
- * Throw a failure.
- *
- * @name fail
- * @param {Mixed} actual
- * @param {Mixed} expected
- * @param {String} message
- * @param {String} operator
- * @api public
- */
-
- should.fail = function (actual, expected, message, operator) {
- message = message || 'should.fail()';
- throw new chai.AssertionError(message, {
- actual: actual
- , expected: expected
- , operator: operator
- }, should.fail);
- };
-
- should.equal = function (val1, val2, msg) {
- new Assertion(val1, msg).to.equal(val2);
- };
-
- should.Throw = function (fn, errt, errs, msg) {
- new Assertion(fn, msg).to.Throw(errt, errs);
- };
-
- should.exist = function (val, msg) {
- new Assertion(val, msg).to.exist;
- }
-
- // negation
- should.not = {}
-
- should.not.equal = function (val1, val2, msg) {
- new Assertion(val1, msg).to.not.equal(val2);
- };
-
- should.not.Throw = function (fn, errt, errs, msg) {
- new Assertion(fn, msg).to.not.Throw(errt, errs);
- };
-
- should.not.exist = function (val, msg) {
- new Assertion(val, msg).to.not.exist;
- }
-
- should['throw'] = should['Throw'];
- should.not['throw'] = should.not['Throw'];
-
- return should;
- };
-
- chai.should = loadShould;
- chai.Should = loadShould;
-};
-
-});
-
-require.register("chai/lib/chai/utils/addChainableMethod.js", function (exports, module) {
-/*!
- * Chai - addChainingMethod utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Module dependencies
- */
-
-var transferFlags = require('chai/lib/chai/utils/transferFlags.js');
-var flag = require('chai/lib/chai/utils/flag.js');
-var config = require('chai/lib/chai/config.js');
-
-/*!
- * Module variables
- */
-
-// Check whether `__proto__` is supported
-var hasProtoSupport = '__proto__' in Object;
-
-// Without `__proto__` support, this module will need to add properties to a function.
-// However, some Function.prototype methods cannot be overwritten,
-// and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
-var excludeNames = /^(?:length|name|arguments|caller)$/;
-
-// Cache `Function` properties
-var call = Function.prototype.call,
- apply = Function.prototype.apply;
-
-/**
- * ### addChainableMethod (ctx, name, method, chainingBehavior)
- *
- * Adds a method to an object, such that the method can also be chained.
- *
- * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
- * var obj = utils.flag(this, 'object');
- * new chai.Assertion(obj).to.be.equal(str);
- * });
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
- *
- * The result can then be used as both a method assertion, executing both `method` and
- * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
- *
- * expect(fooStr).to.be.foo('bar');
- * expect(fooStr).to.be.foo.equal('foo');
- *
- * @param {Object} ctx object to which the method is added
- * @param {String} name of method to add
- * @param {Function} method function to be used for `name`, when called
- * @param {Function} chainingBehavior function to be called every time the property is accessed
- * @name addChainableMethod
- * @api public
- */
-
-module.exports = function (ctx, name, method, chainingBehavior) {
- if (typeof chainingBehavior !== 'function') {
- chainingBehavior = function () { };
- }
-
- var chainableBehavior = {
- method: method
- , chainingBehavior: chainingBehavior
- };
-
- // save the methods so we can overwrite them later, if we need to.
- if (!ctx.__methods) {
- ctx.__methods = {};
- }
- ctx.__methods[name] = chainableBehavior;
-
- Object.defineProperty(ctx, name,
- { get: function () {
- chainableBehavior.chainingBehavior.call(this);
-
- var assert = function assert() {
- var old_ssfi = flag(this, 'ssfi');
- if (old_ssfi && config.includeStack === false)
- flag(this, 'ssfi', assert);
- var result = chainableBehavior.method.apply(this, arguments);
- return result === undefined ? this : result;
- };
-
- // Use `__proto__` if available
- if (hasProtoSupport) {
- // Inherit all properties from the object by replacing the `Function` prototype
- var prototype = assert.__proto__ = Object.create(this);
- // Restore the `call` and `apply` methods from `Function`
- prototype.call = call;
- prototype.apply = apply;
- }
- // Otherwise, redefine all properties (slow!)
- else {
- var asserterNames = Object.getOwnPropertyNames(ctx);
- asserterNames.forEach(function (asserterName) {
- if (!excludeNames.test(asserterName)) {
- var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
- Object.defineProperty(assert, asserterName, pd);
- }
- });
- }
-
- transferFlags(this, assert);
- return assert;
- }
- , configurable: true
- });
-};
-
-});
-
-require.register("chai/lib/chai/utils/addMethod.js", function (exports, module) {
-/*!
- * Chai - addMethod utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-var config = require('chai/lib/chai/config.js');
-
-/**
- * ### .addMethod (ctx, name, method)
- *
- * Adds a method to the prototype of an object.
- *
- * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
- * var obj = utils.flag(this, 'object');
- * new chai.Assertion(obj).to.be.equal(str);
- * });
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.addMethod('foo', fn);
- *
- * Then can be used as any other assertion.
- *
- * expect(fooStr).to.be.foo('bar');
- *
- * @param {Object} ctx object to which the method is added
- * @param {String} name of method to add
- * @param {Function} method function to be used for name
- * @name addMethod
- * @api public
- */
-var flag = require('chai/lib/chai/utils/flag.js');
-
-module.exports = function (ctx, name, method) {
- ctx[name] = function () {
- var old_ssfi = flag(this, 'ssfi');
- if (old_ssfi && config.includeStack === false)
- flag(this, 'ssfi', ctx[name]);
- var result = method.apply(this, arguments);
- return result === undefined ? this : result;
- };
-};
-
-});
-
-require.register("chai/lib/chai/utils/addProperty.js", function (exports, module) {
-/*!
- * Chai - addProperty utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### addProperty (ctx, name, getter)
- *
- * Adds a property to the prototype of an object.
- *
- * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
- * var obj = utils.flag(this, 'object');
- * new chai.Assertion(obj).to.be.instanceof(Foo);
- * });
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.addProperty('foo', fn);
- *
- * Then can be used as any other assertion.
- *
- * expect(myFoo).to.be.foo;
- *
- * @param {Object} ctx object to which the property is added
- * @param {String} name of property to add
- * @param {Function} getter function to be used for name
- * @name addProperty
- * @api public
- */
-
-module.exports = function (ctx, name, getter) {
- Object.defineProperty(ctx, name,
- { get: function () {
- var result = getter.call(this);
- return result === undefined ? this : result;
- }
- , configurable: true
- });
-};
-
-});
-
-require.register("chai/lib/chai/utils/flag.js", function (exports, module) {
-/*!
- * Chai - flag utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### flag(object, key, [value])
- *
- * Get or set a flag value on an object. If a
- * value is provided it will be set, else it will
- * return the currently set value or `undefined` if
- * the value is not set.
- *
- * utils.flag(this, 'foo', 'bar'); // setter
- * utils.flag(this, 'foo'); // getter, returns `bar`
- *
- * @param {Object} object constructed Assertion
- * @param {String} key
- * @param {Mixed} value (optional)
- * @name flag
- * @api private
- */
-
-module.exports = function (obj, key, value) {
- var flags = obj.__flags || (obj.__flags = Object.create(null));
- if (arguments.length === 3) {
- flags[key] = value;
- } else {
- return flags[key];
- }
-};
-
-});
-
-require.register("chai/lib/chai/utils/getActual.js", function (exports, module) {
-/*!
- * Chai - getActual utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * # getActual(object, [actual])
- *
- * Returns the `actual` value for an Assertion
- *
- * @param {Object} object (constructed Assertion)
- * @param {Arguments} chai.Assertion.prototype.assert arguments
- */
-
-module.exports = function (obj, args) {
- return args.length > 4 ? args[4] : obj._obj;
-};
-
-});
-
-require.register("chai/lib/chai/utils/getEnumerableProperties.js", function (exports, module) {
-/*!
- * Chai - getEnumerableProperties utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### .getEnumerableProperties(object)
- *
- * This allows the retrieval of enumerable property names of an object,
- * inherited or not.
- *
- * @param {Object} object
- * @returns {Array}
- * @name getEnumerableProperties
- * @api public
- */
-
-module.exports = function getEnumerableProperties(object) {
- var result = [];
- for (var name in object) {
- result.push(name);
- }
- return result;
-};
-
-});
-
-require.register("chai/lib/chai/utils/getMessage.js", function (exports, module) {
-/*!
- * Chai - message composition utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Module dependancies
- */
-
-var flag = require('chai/lib/chai/utils/flag.js')
- , getActual = require('chai/lib/chai/utils/getActual.js')
- , inspect = require('chai/lib/chai/utils/inspect.js')
- , objDisplay = require('chai/lib/chai/utils/objDisplay.js');
-
-/**
- * ### .getMessage(object, message, negateMessage)
- *
- * Construct the error message based on flags
- * and template tags. Template tags will return
- * a stringified inspection of the object referenced.
- *
- * Message template tags:
- * - `#{this}` current asserted object
- * - `#{act}` actual value
- * - `#{exp}` expected value
- *
- * @param {Object} object (constructed Assertion)
- * @param {Arguments} chai.Assertion.prototype.assert arguments
- * @name getMessage
- * @api public
- */
-
-module.exports = function (obj, args) {
- var negate = flag(obj, 'negate')
- , val = flag(obj, 'object')
- , expected = args[3]
- , actual = getActual(obj, args)
- , msg = negate ? args[2] : args[1]
- , flagMsg = flag(obj, 'message');
-
- if(typeof msg === "function") msg = msg();
- msg = msg || '';
- msg = msg
- .replace(/#{this}/g, objDisplay(val))
- .replace(/#{act}/g, objDisplay(actual))
- .replace(/#{exp}/g, objDisplay(expected));
-
- return flagMsg ? flagMsg + ': ' + msg : msg;
-};
-
-});
-
-require.register("chai/lib/chai/utils/getName.js", function (exports, module) {
-/*!
- * Chai - getName utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * # getName(func)
- *
- * Gets the name of a function, in a cross-browser way.
- *
- * @param {Function} a function (usually a constructor)
- */
-
-module.exports = function (func) {
- if (func.name) return func.name;
-
- var match = /^\s?function ([^(]*)\(/.exec(func);
- return match && match[1] ? match[1] : "";
-};
-
-});
-
-require.register("chai/lib/chai/utils/getPathValue.js", function (exports, module) {
-/*!
- * Chai - getPathValue utility
- * Copyright(c) 2012-2014 Jake Luer
- * @see https://github.com/logicalparadox/filtr
- * MIT Licensed
- */
-
-var getPathInfo = require('chai/lib/chai/utils/getPathInfo.js');
-
-/**
- * ### .getPathValue(path, object)
- *
- * This allows the retrieval of values in an
- * object given a string path.
- *
- * var obj = {
- * prop1: {
- * arr: ['a', 'b', 'c']
- * , str: 'Hello'
- * }
- * , prop2: {
- * arr: [ { nested: 'Universe' } ]
- * , str: 'Hello again!'
- * }
- * }
- *
- * The following would be the results.
- *
- * getPathValue('prop1.str', obj); // Hello
- * getPathValue('prop1.att[2]', obj); // b
- * getPathValue('prop2.arr[0].nested', obj); // Universe
- *
- * @param {String} path
- * @param {Object} object
- * @returns {Object} value or `undefined`
- * @name getPathValue
- * @api public
- */
-module.exports = function(path, obj) {
- var info = getPathInfo(path, obj);
- return info.value;
-};
-
-});
-
-require.register("chai/lib/chai/utils/getPathInfo.js", function (exports, module) {
-/*!
- * Chai - getPathInfo utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-var hasProperty = require('chai/lib/chai/utils/hasProperty.js');
-
-/**
- * ### .getPathInfo(path, object)
- *
- * This allows the retrieval of property info in an
- * object given a string path.
- *
- * The path info consists of an object with the
- * following properties:
- *
- * * parent - The parent object of the property referenced by `path`
- * * name - The name of the final property, a number if it was an array indexer
- * * value - The value of the property, if it exists, otherwise `undefined`
- * * exists - Whether the property exists or not
- *
- * @param {String} path
- * @param {Object} object
- * @returns {Object} info
- * @name getPathInfo
- * @api public
- */
-
-module.exports = function getPathInfo(path, obj) {
- var parsed = parsePath(path),
- last = parsed[parsed.length - 1];
-
- var info = {
- parent: _getPathValue(parsed, obj, parsed.length - 1),
- name: last.p || last.i,
- value: _getPathValue(parsed, obj),
- };
- info.exists = hasProperty(info.name, info.parent);
-
- return info;
-};
-
-
-/*!
- * ## parsePath(path)
- *
- * Helper function used to parse string object
- * paths. Use in conjunction with `_getPathValue`.
- *
- * var parsed = parsePath('myobject.property.subprop');
- *
- * ### Paths:
- *
- * * Can be as near infinitely deep and nested
- * * Arrays are also valid using the formal `myobject.document[3].property`.
- *
- * @param {String} path
- * @returns {Object} parsed
- * @api private
- */
-
-function parsePath (path) {
- var str = path.replace(/\[/g, '.[')
- , parts = str.match(/(\\\.|[^.]+?)+/g);
- return parts.map(function (value) {
- var re = /\[(\d+)\]$/
- , mArr = re.exec(value);
- if (mArr) return { i: parseFloat(mArr[1]) };
- else return { p: value };
- });
-}
-
-
-/*!
- * ## _getPathValue(parsed, obj)
- *
- * Helper companion function for `.parsePath` that returns
- * the value located at the parsed address.
- *
- * var value = getPathValue(parsed, obj);
- *
- * @param {Object} parsed definition from `parsePath`.
- * @param {Object} object to search against
- * @param {Number} object to search against
- * @returns {Object|Undefined} value
- * @api private
- */
-
-function _getPathValue (parsed, obj, index) {
- var tmp = obj
- , res;
-
- index = (index === undefined ? parsed.length : index);
-
- for (var i = 0, l = index; i < l; i++) {
- var part = parsed[i];
- if (tmp) {
- if ('undefined' !== typeof part.p)
- tmp = tmp[part.p];
- else if ('undefined' !== typeof part.i)
- tmp = tmp[part.i];
- if (i == (l - 1)) res = tmp;
- } else {
- res = undefined;
- }
- }
- return res;
-}
-
-});
-
-require.register("chai/lib/chai/utils/hasProperty.js", function (exports, module) {
-/*!
- * Chai - hasProperty utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-var type = require('chai/lib/chai/utils/type.js');
-
-/**
- * ### .hasProperty(object, name)
- *
- * This allows checking whether an object has
- * named property or numeric array index.
- *
- * Basically does the same thing as the `in`
- * operator but works properly with natives
- * and null/undefined values.
- *
- * var obj = {
- * arr: ['a', 'b', 'c']
- * , str: 'Hello'
- * }
- *
- * The following would be the results.
- *
- * hasProperty('str', obj); // true
- * hasProperty('constructor', obj); // true
- * hasProperty('bar', obj); // false
- *
- * hasProperty('length', obj.str); // true
- * hasProperty(1, obj.str); // true
- * hasProperty(5, obj.str); // false
- *
- * hasProperty('length', obj.arr); // true
- * hasProperty(2, obj.arr); // true
- * hasProperty(3, obj.arr); // false
- *
- * @param {Objuect} object
- * @param {String|Number} name
- * @returns {Boolean} whether it exists
- * @name getPathInfo
- * @api public
- */
-
-var literals = {
- 'number': Number
- , 'string': String
-};
-
-module.exports = function hasProperty(name, obj) {
- var ot = type(obj);
-
- // Bad Object, obviously no props at all
- if(ot === 'null' || ot === 'undefined')
- return false;
-
- // The `in` operator does not work with certain literals
- // box these before the check
- if(literals[ot] && typeof obj !== 'object')
- obj = new literals[ot](obj);
-
- return name in obj;
-};
-
-});
-
-require.register("chai/lib/chai/utils/getProperties.js", function (exports, module) {
-/*!
- * Chai - getProperties utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### .getProperties(object)
- *
- * This allows the retrieval of property names of an object, enumerable or not,
- * inherited or not.
- *
- * @param {Object} object
- * @returns {Array}
- * @name getProperties
- * @api public
- */
-
-module.exports = function getProperties(object) {
- var result = Object.getOwnPropertyNames(subject);
-
- function addProperty(property) {
- if (result.indexOf(property) === -1) {
- result.push(property);
- }
- }
-
- var proto = Object.getPrototypeOf(subject);
- while (proto !== null) {
- Object.getOwnPropertyNames(proto).forEach(addProperty);
- proto = Object.getPrototypeOf(proto);
- }
-
- return result;
-};
-
-});
-
-require.register("chai/lib/chai/utils/index.js", function (exports, module) {
-/*!
- * chai
- * Copyright(c) 2011 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Main exports
- */
-
-var exports = module.exports = {};
-
-/*!
- * test utility
- */
-
-exports.test = require('chai/lib/chai/utils/test.js');
-
-/*!
- * type utility
- */
-
-exports.type = require('chai/lib/chai/utils/type.js');
-
-/*!
- * message utility
- */
-
-exports.getMessage = require('chai/lib/chai/utils/getMessage.js');
-
-/*!
- * actual utility
- */
-
-exports.getActual = require('chai/lib/chai/utils/getActual.js');
-
-/*!
- * Inspect util
- */
-
-exports.inspect = require('chai/lib/chai/utils/inspect.js');
-
-/*!
- * Object Display util
- */
-
-exports.objDisplay = require('chai/lib/chai/utils/objDisplay.js');
-
-/*!
- * Flag utility
- */
-
-exports.flag = require('chai/lib/chai/utils/flag.js');
-
-/*!
- * Flag transferring utility
- */
-
-exports.transferFlags = require('chai/lib/chai/utils/transferFlags.js');
-
-/*!
- * Deep equal utility
- */
-
-exports.eql = require('chaijs~deep-eql@0.1.3');
-
-/*!
- * Deep path value
- */
-
-exports.getPathValue = require('chai/lib/chai/utils/getPathValue.js');
-
-/*!
- * Deep path info
- */
-
-exports.getPathInfo = require('chai/lib/chai/utils/getPathInfo.js');
-
-/*!
- * Check if a property exists
- */
-
-exports.hasProperty = require('chai/lib/chai/utils/hasProperty.js');
-
-/*!
- * Function name
- */
-
-exports.getName = require('chai/lib/chai/utils/getName.js');
-
-/*!
- * add Property
- */
-
-exports.addProperty = require('chai/lib/chai/utils/addProperty.js');
-
-/*!
- * add Method
- */
-
-exports.addMethod = require('chai/lib/chai/utils/addMethod.js');
-
-/*!
- * overwrite Property
- */
-
-exports.overwriteProperty = require('chai/lib/chai/utils/overwriteProperty.js');
-
-/*!
- * overwrite Method
- */
-
-exports.overwriteMethod = require('chai/lib/chai/utils/overwriteMethod.js');
-
-/*!
- * Add a chainable method
- */
-
-exports.addChainableMethod = require('chai/lib/chai/utils/addChainableMethod.js');
-
-/*!
- * Overwrite chainable method
- */
-
-exports.overwriteChainableMethod = require('chai/lib/chai/utils/overwriteChainableMethod.js');
-
-
-});
-
-require.register("chai/lib/chai/utils/inspect.js", function (exports, module) {
-// This is (almost) directly from Node.js utils
-// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
-
-var getName = require('chai/lib/chai/utils/getName.js');
-var getProperties = require('chai/lib/chai/utils/getProperties.js');
-var getEnumerableProperties = require('chai/lib/chai/utils/getEnumerableProperties.js');
-
-module.exports = inspect;
-
-/**
- * Echos the value of a value. Trys to print the value out
- * in the best way possible given the different types.
- *
- * @param {Object} obj The object to print out.
- * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
- * properties of objects.
- * @param {Number} depth Depth in which to descend in object. Default is 2.
- * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
- * output. Default is false (no coloring).
- */
-function inspect(obj, showHidden, depth, colors) {
- var ctx = {
- showHidden: showHidden,
- seen: [],
- stylize: function (str) { return str; }
- };
- return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
-}
-
-// Returns true if object is a DOM element.
-var isDOMElement = function (object) {
- if (typeof HTMLElement === 'object') {
- return object instanceof HTMLElement;
- } else {
- return object &&
- typeof object === 'object' &&
- object.nodeType === 1 &&
- typeof object.nodeName === 'string';
- }
-};
-
-function formatValue(ctx, value, recurseTimes) {
- // Provide a hook for user-specified inspect functions.
- // Check that value is an object with an inspect function on it
- if (value && typeof value.inspect === 'function' &&
- // Filter out the util module, it's inspect function is special
- value.inspect !== exports.inspect &&
- // Also filter out any prototype objects using the circular check.
- !(value.constructor && value.constructor.prototype === value)) {
- var ret = value.inspect(recurseTimes);
- if (typeof ret !== 'string') {
- ret = formatValue(ctx, ret, recurseTimes);
- }
- return ret;
- }
-
- // Primitive types cannot have properties
- var primitive = formatPrimitive(ctx, value);
- if (primitive) {
- return primitive;
- }
-
- // If this is a DOM element, try to get the outer HTML.
- if (isDOMElement(value)) {
- if ('outerHTML' in value) {
- return value.outerHTML;
- // This value does not have an outerHTML attribute,
- // it could still be an XML element
- } else {
- // Attempt to serialize it
- try {
- if (document.xmlVersion) {
- var xmlSerializer = new XMLSerializer();
- return xmlSerializer.serializeToString(value);
- } else {
- // Firefox 11- do not support outerHTML
- // It does, however, support innerHTML
- // Use the following to render the element
- var ns = "http://www.w3.org/1999/xhtml";
- var container = document.createElementNS(ns, '_');
-
- container.appendChild(value.cloneNode(false));
- html = container.innerHTML
- .replace('><', '>' + value.innerHTML + '<');
- container.innerHTML = '';
- return html;
- }
- } catch (err) {
- // This could be a non-native DOM implementation,
- // continue with the normal flow:
- // printing the element as if it is an object.
- }
- }
- }
-
- // Look up the keys of the object.
- var visibleKeys = getEnumerableProperties(value);
- var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
-
- // Some type of object without properties can be shortcutted.
- // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
- // a `stack` plus `description` property; ignore those for consistency.
- if (keys.length === 0 || (isError(value) && (
- (keys.length === 1 && keys[0] === 'stack') ||
- (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
- ))) {
- if (typeof value === 'function') {
- var name = getName(value);
- var nameSuffix = name ? ': ' + name : '';
- return ctx.stylize('[Function' + nameSuffix + ']', 'special');
- }
- if (isRegExp(value)) {
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
- }
- if (isDate(value)) {
- return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
- }
- if (isError(value)) {
- return formatError(value);
- }
- }
-
- var base = '', array = false, braces = ['{', '}'];
-
- // Make Array say that they are Array
- if (isArray(value)) {
- array = true;
- braces = ['[', ']'];
- }
-
- // Make functions say that they are functions
- if (typeof value === 'function') {
- var name = getName(value);
- var nameSuffix = name ? ': ' + name : '';
- base = ' [Function' + nameSuffix + ']';
- }
-
- // Make RegExps say that they are RegExps
- if (isRegExp(value)) {
- base = ' ' + RegExp.prototype.toString.call(value);
- }
-
- // Make dates with properties first say the date
- if (isDate(value)) {
- base = ' ' + Date.prototype.toUTCString.call(value);
- }
-
- // Make error with message first say the error
- if (isError(value)) {
- return formatError(value);
- }
-
- if (keys.length === 0 && (!array || value.length == 0)) {
- return braces[0] + base + braces[1];
- }
-
- if (recurseTimes < 0) {
- if (isRegExp(value)) {
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
- } else {
- return ctx.stylize('[Object]', 'special');
- }
- }
-
- ctx.seen.push(value);
-
- var output;
- if (array) {
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
- } else {
- output = keys.map(function(key) {
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
- });
- }
-
- ctx.seen.pop();
-
- return reduceToSingleString(output, base, braces);
-}
-
-
-function formatPrimitive(ctx, value) {
- switch (typeof value) {
- case 'undefined':
- return ctx.stylize('undefined', 'undefined');
-
- case 'string':
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
- .replace(/'/g, "\\'")
- .replace(/\\"/g, '"') + '\'';
- return ctx.stylize(simple, 'string');
-
- case 'number':
- if (value === 0 && (1/value) === -Infinity) {
- return ctx.stylize('-0', 'number');
- }
- return ctx.stylize('' + value, 'number');
-
- case 'boolean':
- return ctx.stylize('' + value, 'boolean');
- }
- // For some reason typeof null is "object", so special case here.
- if (value === null) {
- return ctx.stylize('null', 'null');
- }
-}
-
-
-function formatError(value) {
- return '[' + Error.prototype.toString.call(value) + ']';
-}
-
-
-function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
- var output = [];
- for (var i = 0, l = value.length; i < l; ++i) {
- if (Object.prototype.hasOwnProperty.call(value, String(i))) {
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
- String(i), true));
- } else {
- output.push('');
- }
- }
- keys.forEach(function(key) {
- if (!key.match(/^\d+$/)) {
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
- key, true));
- }
- });
- return output;
-}
-
-
-function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
- var name, str;
- if (value.__lookupGetter__) {
- if (value.__lookupGetter__(key)) {
- if (value.__lookupSetter__(key)) {
- str = ctx.stylize('[Getter/Setter]', 'special');
- } else {
- str = ctx.stylize('[Getter]', 'special');
- }
- } else {
- if (value.__lookupSetter__(key)) {
- str = ctx.stylize('[Setter]', 'special');
- }
- }
- }
- if (visibleKeys.indexOf(key) < 0) {
- name = '[' + key + ']';
- }
- if (!str) {
- if (ctx.seen.indexOf(value[key]) < 0) {
- if (recurseTimes === null) {
- str = formatValue(ctx, value[key], null);
- } else {
- str = formatValue(ctx, value[key], recurseTimes - 1);
- }
- if (str.indexOf('\n') > -1) {
- if (array) {
- str = str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n').substr(2);
- } else {
- str = '\n' + str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n');
- }
- }
- } else {
- str = ctx.stylize('[Circular]', 'special');
- }
- }
- if (typeof name === 'undefined') {
- if (array && key.match(/^\d+$/)) {
- return str;
- }
- name = JSON.stringify('' + key);
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
- name = name.substr(1, name.length - 2);
- name = ctx.stylize(name, 'name');
- } else {
- name = name.replace(/'/g, "\\'")
- .replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'");
- name = ctx.stylize(name, 'string');
- }
- }
-
- return name + ': ' + str;
-}
-
-
-function reduceToSingleString(output, base, braces) {
- var numLinesEst = 0;
- var length = output.reduce(function(prev, cur) {
- numLinesEst++;
- if (cur.indexOf('\n') >= 0) numLinesEst++;
- return prev + cur.length + 1;
- }, 0);
-
- if (length > 60) {
- return braces[0] +
- (base === '' ? '' : base + '\n ') +
- ' ' +
- output.join(',\n ') +
- ' ' +
- braces[1];
- }
-
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
-}
-
-function isArray(ar) {
- return Array.isArray(ar) ||
- (typeof ar === 'object' && objectToString(ar) === '[object Array]');
-}
-
-function isRegExp(re) {
- return typeof re === 'object' && objectToString(re) === '[object RegExp]';
-}
-
-function isDate(d) {
- return typeof d === 'object' && objectToString(d) === '[object Date]';
-}
-
-function isError(e) {
- return typeof e === 'object' && objectToString(e) === '[object Error]';
-}
-
-function objectToString(o) {
- return Object.prototype.toString.call(o);
-}
-
-});
-
-require.register("chai/lib/chai/utils/objDisplay.js", function (exports, module) {
-/*!
- * Chai - flag utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Module dependancies
- */
-
-var inspect = require('chai/lib/chai/utils/inspect.js');
-var config = require('chai/lib/chai/config.js');
-
-/**
- * ### .objDisplay (object)
- *
- * Determines if an object or an array matches
- * criteria to be inspected in-line for error
- * messages or should be truncated.
- *
- * @param {Mixed} javascript object to inspect
- * @name objDisplay
- * @api public
- */
-
-module.exports = function (obj) {
- var str = inspect(obj)
- , type = Object.prototype.toString.call(obj);
-
- if (config.truncateThreshold && str.length >= config.truncateThreshold) {
- if (type === '[object Function]') {
- return !obj.name || obj.name === ''
- ? '[Function]'
- : '[Function: ' + obj.name + ']';
- } else if (type === '[object Array]') {
- return '[ Array(' + obj.length + ') ]';
- } else if (type === '[object Object]') {
- var keys = Object.keys(obj)
- , kstr = keys.length > 2
- ? keys.splice(0, 2).join(', ') + ', ...'
- : keys.join(', ');
- return '{ Object (' + kstr + ') }';
- } else {
- return str;
- }
- } else {
- return str;
- }
-};
-
-});
-
-require.register("chai/lib/chai/utils/overwriteMethod.js", function (exports, module) {
-/*!
- * Chai - overwriteMethod utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### overwriteMethod (ctx, name, fn)
- *
- * Overwites an already existing method and provides
- * access to previous function. Must return function
- * to be used for name.
- *
- * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
- * return function (str) {
- * var obj = utils.flag(this, 'object');
- * if (obj instanceof Foo) {
- * new chai.Assertion(obj.value).to.equal(str);
- * } else {
- * _super.apply(this, arguments);
- * }
- * }
- * });
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.overwriteMethod('foo', fn);
- *
- * Then can be used as any other assertion.
- *
- * expect(myFoo).to.equal('bar');
- *
- * @param {Object} ctx object whose method is to be overwritten
- * @param {String} name of method to overwrite
- * @param {Function} method function that returns a function to be used for name
- * @name overwriteMethod
- * @api public
- */
-
-module.exports = function (ctx, name, method) {
- var _method = ctx[name]
- , _super = function () { return this; };
-
- if (_method && 'function' === typeof _method)
- _super = _method;
-
- ctx[name] = function () {
- var result = method(_super).apply(this, arguments);
- return result === undefined ? this : result;
- }
-};
-
-});
-
-require.register("chai/lib/chai/utils/overwriteProperty.js", function (exports, module) {
-/*!
- * Chai - overwriteProperty utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### overwriteProperty (ctx, name, fn)
- *
- * Overwites an already existing property getter and provides
- * access to previous value. Must return function to use as getter.
- *
- * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
- * return function () {
- * var obj = utils.flag(this, 'object');
- * if (obj instanceof Foo) {
- * new chai.Assertion(obj.name).to.equal('bar');
- * } else {
- * _super.call(this);
- * }
- * }
- * });
- *
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.overwriteProperty('foo', fn);
- *
- * Then can be used as any other assertion.
- *
- * expect(myFoo).to.be.ok;
- *
- * @param {Object} ctx object whose property is to be overwritten
- * @param {String} name of property to overwrite
- * @param {Function} getter function that returns a getter function to be used for name
- * @name overwriteProperty
- * @api public
- */
-
-module.exports = function (ctx, name, getter) {
- var _get = Object.getOwnPropertyDescriptor(ctx, name)
- , _super = function () {};
-
- if (_get && 'function' === typeof _get.get)
- _super = _get.get
-
- Object.defineProperty(ctx, name,
- { get: function () {
- var result = getter(_super).call(this);
- return result === undefined ? this : result;
- }
- , configurable: true
- });
-};
-
-});
-
-require.register("chai/lib/chai/utils/overwriteChainableMethod.js", function (exports, module) {
-/*!
- * Chai - overwriteChainableMethod utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
- *
- * Overwites an already existing chainable method
- * and provides access to the previous function or
- * property. Must return functions to be used for
- * name.
- *
- * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
- * function (_super) {
- * }
- * , function (_super) {
- * }
- * );
- *
- * Can also be accessed directly from `chai.Assertion`.
- *
- * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
- *
- * Then can be used as any other assertion.
- *
- * expect(myFoo).to.have.length(3);
- * expect(myFoo).to.have.length.above(3);
- *
- * @param {Object} ctx object whose method / property is to be overwritten
- * @param {String} name of method / property to overwrite
- * @param {Function} method function that returns a function to be used for name
- * @param {Function} chainingBehavior function that returns a function to be used for property
- * @name overwriteChainableMethod
- * @api public
- */
-
-module.exports = function (ctx, name, method, chainingBehavior) {
- var chainableBehavior = ctx.__methods[name];
-
- var _chainingBehavior = chainableBehavior.chainingBehavior;
- chainableBehavior.chainingBehavior = function () {
- var result = chainingBehavior(_chainingBehavior).call(this);
- return result === undefined ? this : result;
- };
-
- var _method = chainableBehavior.method;
- chainableBehavior.method = function () {
- var result = method(_method).apply(this, arguments);
- return result === undefined ? this : result;
- };
-};
-
-});
-
-require.register("chai/lib/chai/utils/test.js", function (exports, module) {
-/*!
- * Chai - test utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Module dependancies
- */
-
-var flag = require('chai/lib/chai/utils/flag.js');
-
-/**
- * # test(object, expression)
- *
- * Test and object for expression.
- *
- * @param {Object} object (constructed Assertion)
- * @param {Arguments} chai.Assertion.prototype.assert arguments
- */
-
-module.exports = function (obj, args) {
- var negate = flag(obj, 'negate')
- , expr = args[0];
- return negate ? !expr : expr;
-};
-
-});
-
-require.register("chai/lib/chai/utils/transferFlags.js", function (exports, module) {
-/*!
- * Chai - transferFlags utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/**
- * ### transferFlags(assertion, object, includeAll = true)
- *
- * Transfer all the flags for `assertion` to `object`. If
- * `includeAll` is set to `false`, then the base Chai
- * assertion flags (namely `object`, `ssfi`, and `message`)
- * will not be transferred.
- *
- *
- * var newAssertion = new Assertion();
- * utils.transferFlags(assertion, newAssertion);
- *
- * var anotherAsseriton = new Assertion(myObj);
- * utils.transferFlags(assertion, anotherAssertion, false);
- *
- * @param {Assertion} assertion the assertion to transfer the flags from
- * @param {Object} object the object to transfer the flags to; usually a new assertion
- * @param {Boolean} includeAll
- * @name transferFlags
- * @api private
- */
-
-module.exports = function (assertion, object, includeAll) {
- var flags = assertion.__flags || (assertion.__flags = Object.create(null));
-
- if (!object.__flags) {
- object.__flags = Object.create(null);
- }
-
- includeAll = arguments.length === 3 ? includeAll : true;
-
- for (var flag in flags) {
- if (includeAll ||
- (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
- object.__flags[flag] = flags[flag];
- }
- }
-};
-
-});
-
-require.register("chai/lib/chai/utils/type.js", function (exports, module) {
-/*!
- * Chai - type utility
- * Copyright(c) 2012-2014 Jake Luer
- * MIT Licensed
- */
-
-/*!
- * Detectable javascript natives
- */
-
-var natives = {
- '[object Arguments]': 'arguments'
- , '[object Array]': 'array'
- , '[object Date]': 'date'
- , '[object Function]': 'function'
- , '[object Number]': 'number'
- , '[object RegExp]': 'regexp'
- , '[object String]': 'string'
-};
-
-/**
- * ### type(object)
- *
- * Better implementation of `typeof` detection that can
- * be used cross-browser. Handles the inconsistencies of
- * Array, `null`, and `undefined` detection.
- *
- * utils.type({}) // 'object'
- * utils.type(null) // `null'
- * utils.type(undefined) // `undefined`
- * utils.type([]) // `array`
- *
- * @param {Mixed} object to detect type of
- * @name type
- * @api private
- */
-
-module.exports = function (obj) {
- var str = Object.prototype.toString.call(obj);
- if (natives[str]) return natives[str];
- if (obj === null) return 'null';
- if (obj === undefined) return 'undefined';
- if (obj === Object(obj)) return 'object';
- return typeof obj;
-};
-
-});
-
-if (typeof exports == "object") {
- module.exports = require("chai");
-} else if (typeof define == "function" && define.amd) {
- define("chai", [], function(){ return require("chai"); });
-} else {
- (this || window)["chai"] = require("chai");
-}
-})()
diff --git a/test/vendor/mocha.js b/test/vendor/mocha.js
deleted file mode 100644
index 5ff13857..00000000
--- a/test/vendor/mocha.js
+++ /dev/null
@@ -1,6564 +0,0 @@
-;(function(){
-
-// CommonJS require()
-
-function require(p){
- var path = require.resolve(p)
- , mod = require.modules[path];
- if (!mod) throw new Error('failed to require "' + p + '"');
- if (!mod.exports) {
- mod.exports = {};
- mod.call(mod.exports, mod, mod.exports, require.relative(path));
- }
- return mod.exports;
- }
-
-require.modules = {};
-
-require.resolve = function (path){
- var orig = path
- , reg = path + '.js'
- , index = path + '/index.js';
- return require.modules[reg] && reg
- || require.modules[index] && index
- || orig;
- };
-
-require.register = function (path, fn){
- require.modules[path] = fn;
- };
-
-require.relative = function (parent) {
- return function(p){
- if ('.' != p.charAt(0)) return require(p);
-
- var path = parent.split('/')
- , segs = p.split('/');
- path.pop();
-
- for (var i = 0; i < segs.length; i++) {
- var seg = segs[i];
- if ('..' == seg) path.pop();
- else if ('.' != seg) path.push(seg);
- }
-
- return require(path.join('/'));
- };
- };
-
-
-require.register("browser/debug.js", function(module, exports, require){
-module.exports = function(type){
- return function(){
- }
-};
-
-}); // module: browser/debug.js
-
-require.register("browser/diff.js", function(module, exports, require){
-/* See LICENSE file for terms of use */
-
-/*
- * Text diff implementation.
- *
- * This library supports the following APIS:
- * JsDiff.diffChars: Character by character diff
- * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
- * JsDiff.diffLines: Line based diff
- *
- * JsDiff.diffCss: Diff targeted at CSS content
- *
- * These methods are based on the implementation proposed in
- * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
- * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
- */
-var JsDiff = (function() {
- /*jshint maxparams: 5*/
- function clonePath(path) {
- return { newPos: path.newPos, components: path.components.slice(0) };
- }
- function removeEmpty(array) {
- var ret = [];
- for (var i = 0; i < array.length; i++) {
- if (array[i]) {
- ret.push(array[i]);
- }
- }
- return ret;
- }
- function escapeHTML(s) {
- var n = s;
- n = n.replace(/&/g, '&');
- n = n.replace(//g, '>');
- n = n.replace(/"/g, '"');
-
- return n;
- }
-
- var Diff = function(ignoreWhitespace) {
- this.ignoreWhitespace = ignoreWhitespace;
- };
- Diff.prototype = {
- diff: function(oldString, newString) {
- // Handle the identity case (this is due to unrolling editLength == 0
- if (newString === oldString) {
- return [{ value: newString }];
- }
- if (!newString) {
- return [{ value: oldString, removed: true }];
- }
- if (!oldString) {
- return [{ value: newString, added: true }];
- }
-
- newString = this.tokenize(newString);
- oldString = this.tokenize(oldString);
-
- var newLen = newString.length, oldLen = oldString.length;
- var maxEditLength = newLen + oldLen;
- var bestPath = [{ newPos: -1, components: [] }];
-
- // Seed editLength = 0
- var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
- if (bestPath[0].newPos+1 >= newLen && oldPos+1 >= oldLen) {
- return bestPath[0].components;
- }
-
- for (var editLength = 1; editLength <= maxEditLength; editLength++) {
- for (var diagonalPath = -1*editLength; diagonalPath <= editLength; diagonalPath+=2) {
- var basePath;
- var addPath = bestPath[diagonalPath-1],
- removePath = bestPath[diagonalPath+1];
- oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
- if (addPath) {
- // No one else is going to attempt to use this value, clear it
- bestPath[diagonalPath-1] = undefined;
- }
-
- var canAdd = addPath && addPath.newPos+1 < newLen;
- var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
- if (!canAdd && !canRemove) {
- bestPath[diagonalPath] = undefined;
- continue;
- }
-
- // Select the diagonal that we want to branch from. We select the prior
- // path whose position in the new string is the farthest from the origin
- // and does not pass the bounds of the diff graph
- if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
- basePath = clonePath(removePath);
- this.pushComponent(basePath.components, oldString[oldPos], undefined, true);
- } else {
- basePath = clonePath(addPath);
- basePath.newPos++;
- this.pushComponent(basePath.components, newString[basePath.newPos], true, undefined);
- }
-
- var oldPos = this.extractCommon(basePath, newString, oldString, diagonalPath);
-
- if (basePath.newPos+1 >= newLen && oldPos+1 >= oldLen) {
- return basePath.components;
- } else {
- bestPath[diagonalPath] = basePath;
- }
- }
- }
- },
-
- pushComponent: function(components, value, added, removed) {
- var last = components[components.length-1];
- if (last && last.added === added && last.removed === removed) {
- // We need to clone here as the component clone operation is just
- // as shallow array clone
- components[components.length-1] =
- {value: this.join(last.value, value), added: added, removed: removed };
- } else {
- components.push({value: value, added: added, removed: removed });
- }
- },
- extractCommon: function(basePath, newString, oldString, diagonalPath) {
- var newLen = newString.length,
- oldLen = oldString.length,
- newPos = basePath.newPos,
- oldPos = newPos - diagonalPath;
- while (newPos+1 < newLen && oldPos+1 < oldLen && this.equals(newString[newPos+1], oldString[oldPos+1])) {
- newPos++;
- oldPos++;
-
- this.pushComponent(basePath.components, newString[newPos], undefined, undefined);
- }
- basePath.newPos = newPos;
- return oldPos;
- },
-
- equals: function(left, right) {
- var reWhitespace = /\S/;
- if (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)) {
- return true;
- } else {
- return left === right;
- }
- },
- join: function(left, right) {
- return left + right;
- },
- tokenize: function(value) {
- return value;
- }
- };
-
- var CharDiff = new Diff();
-
- var WordDiff = new Diff(true);
- var WordWithSpaceDiff = new Diff();
- WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
- return removeEmpty(value.split(/(\s+|\b)/));
- };
-
- var CssDiff = new Diff(true);
- CssDiff.tokenize = function(value) {
- return removeEmpty(value.split(/([{}:;,]|\s+)/));
- };
-
- var LineDiff = new Diff();
- LineDiff.tokenize = function(value) {
- var retLines = [],
- lines = value.split(/^/m);
-
- for(var i = 0; i < lines.length; i++) {
- var line = lines[i],
- lastLine = lines[i - 1];
-
- // Merge lines that may contain windows new lines
- if (line == '\n' && lastLine && lastLine[lastLine.length - 1] === '\r') {
- retLines[retLines.length - 1] += '\n';
- } else if (line) {
- retLines.push(line);
- }
- }
-
- return retLines;
- };
-
- return {
- Diff: Diff,
-
- diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); },
- diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); },
- diffWordsWithSpace: function(oldStr, newStr) { return WordWithSpaceDiff.diff(oldStr, newStr); },
- diffLines: function(oldStr, newStr) { return LineDiff.diff(oldStr, newStr); },
-
- diffCss: function(oldStr, newStr) { return CssDiff.diff(oldStr, newStr); },
-
- createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) {
- var ret = [];
-
- ret.push('Index: ' + fileName);
- ret.push('===================================================================');
- ret.push('--- ' + fileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
- ret.push('+++ ' + fileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));
-
- var diff = LineDiff.diff(oldStr, newStr);
- if (!diff[diff.length-1].value) {
- diff.pop(); // Remove trailing newline add
- }
- diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier
-
- function contextLines(lines) {
- return lines.map(function(entry) { return ' ' + entry; });
- }
- function eofNL(curRange, i, current) {
- var last = diff[diff.length-2],
- isLast = i === diff.length-2,
- isLastOfType = i === diff.length-3 && (current.added !== last.added || current.removed !== last.removed);
-
- // Figure out if this is the last line for the given file and missing NL
- if (!/\n$/.test(current.value) && (isLast || isLastOfType)) {
- curRange.push('\\ No newline at end of file');
- }
- }
-
- var oldRangeStart = 0, newRangeStart = 0, curRange = [],
- oldLine = 1, newLine = 1;
- for (var i = 0; i < diff.length; i++) {
- var current = diff[i],
- lines = current.lines || current.value.replace(/\n$/, '').split('\n');
- current.lines = lines;
-
- if (current.added || current.removed) {
- if (!oldRangeStart) {
- var prev = diff[i-1];
- oldRangeStart = oldLine;
- newRangeStart = newLine;
-
- if (prev) {
- curRange = contextLines(prev.lines.slice(-4));
- oldRangeStart -= curRange.length;
- newRangeStart -= curRange.length;
- }
- }
- curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?'+':'-') + entry; }));
- eofNL(curRange, i, current);
-
- if (current.added) {
- newLine += lines.length;
- } else {
- oldLine += lines.length;
- }
- } else {
- if (oldRangeStart) {
- // Close out any changes that have been output (or join overlapping)
- if (lines.length <= 8 && i < diff.length-2) {
- // Overlapping
- curRange.push.apply(curRange, contextLines(lines));
- } else {
- // end the range and output
- var contextSize = Math.min(lines.length, 4);
- ret.push(
- '@@ -' + oldRangeStart + ',' + (oldLine-oldRangeStart+contextSize)
- + ' +' + newRangeStart + ',' + (newLine-newRangeStart+contextSize)
- + ' @@');
- ret.push.apply(ret, curRange);
- ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));
- if (lines.length <= 4) {
- eofNL(ret, i, current);
- }
-
- oldRangeStart = 0; newRangeStart = 0; curRange = [];
- }
- }
- oldLine += lines.length;
- newLine += lines.length;
- }
- }
-
- return ret.join('\n') + '\n';
- },
-
- applyPatch: function(oldStr, uniDiff) {
- var diffstr = uniDiff.split('\n');
- var diff = [];
- var remEOFNL = false,
- addEOFNL = false;
-
- for (var i = (diffstr[0][0]==='I'?4:0); i < diffstr.length; i++) {
- if(diffstr[i][0] === '@') {
- var meh = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
- diff.unshift({
- start:meh[3],
- oldlength:meh[2],
- oldlines:[],
- newlength:meh[4],
- newlines:[]
- });
- } else if(diffstr[i][0] === '+') {
- diff[0].newlines.push(diffstr[i].substr(1));
- } else if(diffstr[i][0] === '-') {
- diff[0].oldlines.push(diffstr[i].substr(1));
- } else if(diffstr[i][0] === ' ') {
- diff[0].newlines.push(diffstr[i].substr(1));
- diff[0].oldlines.push(diffstr[i].substr(1));
- } else if(diffstr[i][0] === '\\') {
- if (diffstr[i-1][0] === '+') {
- remEOFNL = true;
- } else if(diffstr[i-1][0] === '-') {
- addEOFNL = true;
- }
- }
- }
-
- var str = oldStr.split('\n');
- for (var i = diff.length - 1; i >= 0; i--) {
- var d = diff[i];
- for (var j = 0; j < d.oldlength; j++) {
- if(str[d.start-1+j] !== d.oldlines[j]) {
- return false;
- }
- }
- Array.prototype.splice.apply(str,[d.start-1,+d.oldlength].concat(d.newlines));
- }
-
- if (remEOFNL) {
- while (!str[str.length-1]) {
- str.pop();
- }
- } else if (addEOFNL) {
- str.push('');
- }
- return str.join('\n');
- },
-
- convertChangesToXML: function(changes){
- var ret = [];
- for ( var i = 0; i < changes.length; i++) {
- var change = changes[i];
- if (change.added) {
- ret.push('');
- } else if (change.removed) {
- ret.push('');
- }
-
- ret.push(escapeHTML(change.value));
-
- if (change.added) {
- ret.push(' ');
- } else if (change.removed) {
- ret.push('');
- }
- }
- return ret.join('');
- },
-
- // See: http://code.google.com/p/google-diff-match-patch/wiki/API
- convertChangesToDMP: function(changes){
- var ret = [], change;
- for ( var i = 0; i < changes.length; i++) {
- change = changes[i];
- ret.push([(change.added ? 1 : change.removed ? -1 : 0), change.value]);
- }
- return ret;
- }
- };
-})();
-
-if (typeof module !== 'undefined') {
- module.exports = JsDiff;
-}
-
-}); // module: browser/diff.js
-
-require.register("browser/escape-string-regexp.js", function(module, exports, require){
-'use strict';
-
-var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
-
-module.exports = function (str) {
- if (typeof str !== 'string') {
- throw new TypeError('Expected a string');
- }
-
- return str.replace(matchOperatorsRe, '\\$&');
-};
-
-}); // module: browser/escape-string-regexp.js
-
-require.register("browser/events.js", function(module, exports, require){
-/**
- * Module exports.
- */
-
-exports.EventEmitter = EventEmitter;
-
-/**
- * Check if `obj` is an array.
- */
-
-function isArray(obj) {
- return '[object Array]' == {}.toString.call(obj);
-}
-
-/**
- * Event emitter constructor.
- *
- * @api public
- */
-
-function EventEmitter(){};
-
-/**
- * Adds a listener.
- *
- * @api public
- */
-
-EventEmitter.prototype.on = function (name, fn) {
- if (!this.$events) {
- this.$events = {};
- }
-
- if (!this.$events[name]) {
- this.$events[name] = fn;
- } else if (isArray(this.$events[name])) {
- this.$events[name].push(fn);
- } else {
- this.$events[name] = [this.$events[name], fn];
- }
-
- return this;
-};
-
-EventEmitter.prototype.addListener = EventEmitter.prototype.on;
-
-/**
- * Adds a volatile listener.
- *
- * @api public
- */
-
-EventEmitter.prototype.once = function (name, fn) {
- var self = this;
-
- function on () {
- self.removeListener(name, on);
- fn.apply(this, arguments);
- };
-
- on.listener = fn;
- this.on(name, on);
-
- return this;
-};
-
-/**
- * Removes a listener.
- *
- * @api public
- */
-
-EventEmitter.prototype.removeListener = function (name, fn) {
- if (this.$events && this.$events[name]) {
- var list = this.$events[name];
-
- if (isArray(list)) {
- var pos = -1;
-
- for (var i = 0, l = list.length; i < l; i++) {
- if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
- pos = i;
- break;
- }
- }
-
- if (pos < 0) {
- return this;
- }
-
- list.splice(pos, 1);
-
- if (!list.length) {
- delete this.$events[name];
- }
- } else if (list === fn || (list.listener && list.listener === fn)) {
- delete this.$events[name];
- }
- }
-
- return this;
-};
-
-/**
- * Removes all listeners for an event.
- *
- * @api public
- */
-
-EventEmitter.prototype.removeAllListeners = function (name) {
- if (name === undefined) {
- this.$events = {};
- return this;
- }
-
- if (this.$events && this.$events[name]) {
- this.$events[name] = null;
- }
-
- return this;
-};
-
-/**
- * Gets all listeners for a certain event.
- *
- * @api public
- */
-
-EventEmitter.prototype.listeners = function (name) {
- if (!this.$events) {
- this.$events = {};
- }
-
- if (!this.$events[name]) {
- this.$events[name] = [];
- }
-
- if (!isArray(this.$events[name])) {
- this.$events[name] = [this.$events[name]];
- }
-
- return this.$events[name];
-};
-
-/**
- * Emits an event.
- *
- * @api public
- */
-
-EventEmitter.prototype.emit = function (name) {
- if (!this.$events) {
- return false;
- }
-
- var handler = this.$events[name];
-
- if (!handler) {
- return false;
- }
-
- var args = [].slice.call(arguments, 1);
-
- if ('function' == typeof handler) {
- handler.apply(this, args);
- } else if (isArray(handler)) {
- var listeners = handler.slice();
-
- for (var i = 0, l = listeners.length; i < l; i++) {
- listeners[i].apply(this, args);
- }
- } else {
- return false;
- }
-
- return true;
-};
-
-}); // module: browser/events.js
-
-require.register("browser/fs.js", function(module, exports, require){
-
-}); // module: browser/fs.js
-
-require.register("browser/glob.js", function(module, exports, require){
-
-}); // module: browser/glob.js
-
-require.register("browser/path.js", function(module, exports, require){
-
-}); // module: browser/path.js
-
-require.register("browser/progress.js", function(module, exports, require){
-/**
- * Expose `Progress`.
- */
-
-module.exports = Progress;
-
-/**
- * Initialize a new `Progress` indicator.
- */
-
-function Progress() {
- this.percent = 0;
- this.size(0);
- this.fontSize(11);
- this.font('helvetica, arial, sans-serif');
-}
-
-/**
- * Set progress size to `n`.
- *
- * @param {Number} n
- * @return {Progress} for chaining
- * @api public
- */
-
-Progress.prototype.size = function(n){
- this._size = n;
- return this;
-};
-
-/**
- * Set text to `str`.
- *
- * @param {String} str
- * @return {Progress} for chaining
- * @api public
- */
-
-Progress.prototype.text = function(str){
- this._text = str;
- return this;
-};
-
-/**
- * Set font size to `n`.
- *
- * @param {Number} n
- * @return {Progress} for chaining
- * @api public
- */
-
-Progress.prototype.fontSize = function(n){
- this._fontSize = n;
- return this;
-};
-
-/**
- * Set font `family`.
- *
- * @param {String} family
- * @return {Progress} for chaining
- */
-
-Progress.prototype.font = function(family){
- this._font = family;
- return this;
-};
-
-/**
- * Update percentage to `n`.
- *
- * @param {Number} n
- * @return {Progress} for chaining
- */
-
-Progress.prototype.update = function(n){
- this.percent = n;
- return this;
-};
-
-/**
- * Draw on `ctx`.
- *
- * @param {CanvasRenderingContext2d} ctx
- * @return {Progress} for chaining
- */
-
-Progress.prototype.draw = function(ctx){
- try {
- var percent = Math.min(this.percent, 100)
- , size = this._size
- , half = size / 2
- , x = half
- , y = half
- , rad = half - 1
- , fontSize = this._fontSize;
-
- ctx.font = fontSize + 'px ' + this._font;
-
- var angle = Math.PI * 2 * (percent / 100);
- ctx.clearRect(0, 0, size, size);
-
- // outer circle
- ctx.strokeStyle = '#9f9f9f';
- ctx.beginPath();
- ctx.arc(x, y, rad, 0, angle, false);
- ctx.stroke();
-
- // inner circle
- ctx.strokeStyle = '#eee';
- ctx.beginPath();
- ctx.arc(x, y, rad - 1, 0, angle, true);
- ctx.stroke();
-
- // text
- var text = this._text || (percent | 0) + '%'
- , w = ctx.measureText(text).width;
-
- ctx.fillText(
- text
- , x - w / 2 + 1
- , y + fontSize / 2 - 1);
- } catch (ex) {} //don't fail if we can't render progress
- return this;
-};
-
-}); // module: browser/progress.js
-
-require.register("browser/tty.js", function(module, exports, require){
-exports.isatty = function(){
- return true;
-};
-
-exports.getWindowSize = function(){
- if ('innerHeight' in global) {
- return [global.innerHeight, global.innerWidth];
- } else {
- // In a Web Worker, the DOM Window is not available.
- return [640, 480];
- }
-};
-
-}); // module: browser/tty.js
-
-require.register("context.js", function(module, exports, require){
-/**
- * Expose `Context`.
- */
-
-module.exports = Context;
-
-/**
- * Initialize a new `Context`.
- *
- * @api private
- */
-
-function Context(){}
-
-/**
- * Set or get the context `Runnable` to `runnable`.
- *
- * @param {Runnable} runnable
- * @return {Context}
- * @api private
- */
-
-Context.prototype.runnable = function(runnable){
- if (0 == arguments.length) return this._runnable;
- this.test = this._runnable = runnable;
- return this;
-};
-
-/**
- * Set test timeout `ms`.
- *
- * @param {Number} ms
- * @return {Context} self
- * @api private
- */
-
-Context.prototype.timeout = function(ms){
- if (arguments.length === 0) return this.runnable().timeout();
- this.runnable().timeout(ms);
- return this;
-};
-
-/**
- * Set test timeout `enabled`.
- *
- * @param {Boolean} enabled
- * @return {Context} self
- * @api private
- */
-
-Context.prototype.enableTimeouts = function (enabled) {
- this.runnable().enableTimeouts(enabled);
- return this;
-};
-
-
-/**
- * Set test slowness threshold `ms`.
- *
- * @param {Number} ms
- * @return {Context} self
- * @api private
- */
-
-Context.prototype.slow = function(ms){
- this.runnable().slow(ms);
- return this;
-};
-
-/**
- * Mark a test as skipped.
- *
- * @return {Context} self
- * @api private
- */
-
-Context.prototype.skip = function(){
- this.runnable().skip();
- return this;
-};
-
-/**
- * Inspect the context void of `._runnable`.
- *
- * @return {String}
- * @api private
- */
-
-Context.prototype.inspect = function(){
- return JSON.stringify(this, function(key, val){
- if ('_runnable' == key) return;
- if ('test' == key) return;
- return val;
- }, 2);
-};
-
-}); // module: context.js
-
-require.register("hook.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Runnable = require('./runnable');
-
-/**
- * Expose `Hook`.
- */
-
-module.exports = Hook;
-
-/**
- * Initialize a new `Hook` with the given `title` and callback `fn`.
- *
- * @param {String} title
- * @param {Function} fn
- * @api private
- */
-
-function Hook(title, fn) {
- Runnable.call(this, title, fn);
- this.type = 'hook';
-}
-
-/**
- * Inherit from `Runnable.prototype`.
- */
-
-function F(){};
-F.prototype = Runnable.prototype;
-Hook.prototype = new F;
-Hook.prototype.constructor = Hook;
-
-
-/**
- * Get or set the test `err`.
- *
- * @param {Error} err
- * @return {Error}
- * @api public
- */
-
-Hook.prototype.error = function(err){
- if (0 == arguments.length) {
- var err = this._error;
- this._error = null;
- return err;
- }
-
- this._error = err;
-};
-
-}); // module: hook.js
-
-require.register("interfaces/bdd.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Suite = require('../suite')
- , Test = require('../test')
- , utils = require('../utils')
- , escapeRe = require('browser/escape-string-regexp');
-
-/**
- * BDD-style interface:
- *
- * describe('Array', function(){
- * describe('#indexOf()', function(){
- * it('should return -1 when not present', function(){
- *
- * });
- *
- * it('should return the index when present', function(){
- *
- * });
- * });
- * });
- *
- */
-
-module.exports = function(suite){
- var suites = [suite];
-
- suite.on('pre-require', function(context, file, mocha){
-
- var common = require('./common')(suites, context);
-
- context.before = common.before;
- context.after = common.after;
- context.beforeEach = common.beforeEach;
- context.afterEach = common.afterEach;
- context.run = mocha.options.delay && common.runWithSuite(suite);
- /**
- * Describe a "suite" with the given `title`
- * and callback `fn` containing nested suites
- * and/or tests.
- */
-
- context.describe = context.context = function(title, fn){
- var suite = Suite.create(suites[0], title);
- suite.file = file;
- suites.unshift(suite);
- fn.call(suite);
- suites.shift();
- return suite;
- };
-
- /**
- * Pending describe.
- */
-
- context.xdescribe =
- context.xcontext =
- context.describe.skip = function(title, fn){
- var suite = Suite.create(suites[0], title);
- suite.pending = true;
- suites.unshift(suite);
- fn.call(suite);
- suites.shift();
- };
-
- /**
- * Exclusive suite.
- */
-
- context.describe.only = function(title, fn){
- var suite = context.describe(title, fn);
- mocha.grep(suite.fullTitle());
- return suite;
- };
-
- /**
- * Describe a specification or test-case
- * with the given `title` and callback `fn`
- * acting as a thunk.
- */
-
- context.it = context.specify = function(title, fn){
- var suite = suites[0];
- if (suite.pending) fn = null;
- var test = new Test(title, fn);
- test.file = file;
- suite.addTest(test);
- return test;
- };
-
- /**
- * Exclusive test-case.
- */
-
- context.it.only = function(title, fn){
- var test = context.it(title, fn);
- var reString = '^' + escapeRe(test.fullTitle()) + '$';
- mocha.grep(new RegExp(reString));
- return test;
- };
-
- /**
- * Pending test case.
- */
-
- context.xit =
- context.xspecify =
- context.it.skip = function(title){
- context.it(title);
- };
-
- });
-};
-
-}); // module: interfaces/bdd.js
-
-require.register("interfaces/common.js", function(module, exports, require){
-/**
- * Functions common to more than one interface
- * @module lib/interfaces/common
- */
-
-'use strict';
-
-module.exports = function (suites, context) {
-
- return {
- /**
- * This is only present if flag --delay is passed into Mocha. It triggers
- * root suite execution. Returns a function which runs the root suite.
- */
- runWithSuite: function runWithSuite(suite) {
- return function run() {
- suite.run();
- };
- },
-
- /**
- * Execute before running tests.
- */
- before: function (name, fn) {
- suites[0].beforeAll(name, fn);
- },
-
- /**
- * Execute after running tests.
- */
- after: function (name, fn) {
- suites[0].afterAll(name, fn);
- },
-
- /**
- * Execute before each test case.
- */
- beforeEach: function (name, fn) {
- suites[0].beforeEach(name, fn);
- },
-
- /**
- * Execute after each test case.
- */
- afterEach: function (name, fn) {
- suites[0].afterEach(name, fn);
- },
-
- test: {
- /**
- * Pending test case.
- */
- skip: function (title) {
- context.test(title);
- }
- }
- }
-};
-
-}); // module: interfaces/common.js
-
-require.register("interfaces/exports.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Suite = require('../suite')
- , Test = require('../test');
-
-/**
- * TDD-style interface:
- *
- * exports.Array = {
- * '#indexOf()': {
- * 'should return -1 when the value is not present': function(){
- *
- * },
- *
- * 'should return the correct index when the value is present': function(){
- *
- * }
- * }
- * };
- *
- */
-
-module.exports = function(suite){
- var suites = [suite];
-
- suite.on('require', visit);
-
- function visit(obj, file) {
- var suite;
- for (var key in obj) {
- if ('function' == typeof obj[key]) {
- var fn = obj[key];
- switch (key) {
- case 'before':
- suites[0].beforeAll(fn);
- break;
- case 'after':
- suites[0].afterAll(fn);
- break;
- case 'beforeEach':
- suites[0].beforeEach(fn);
- break;
- case 'afterEach':
- suites[0].afterEach(fn);
- break;
- default:
- var test = new Test(key, fn);
- test.file = file;
- suites[0].addTest(test);
- }
- } else {
- suite = Suite.create(suites[0], key);
- suites.unshift(suite);
- visit(obj[key]);
- suites.shift();
- }
- }
- }
-};
-
-}); // module: interfaces/exports.js
-
-require.register("interfaces/index.js", function(module, exports, require){
-exports.bdd = require('./bdd');
-exports.tdd = require('./tdd');
-exports.qunit = require('./qunit');
-exports.exports = require('./exports');
-
-}); // module: interfaces/index.js
-
-require.register("interfaces/qunit.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Suite = require('../suite')
- , Test = require('../test')
- , escapeRe = require('browser/escape-string-regexp')
- , utils = require('../utils');
-
-/**
- * QUnit-style interface:
- *
- * suite('Array');
- *
- * test('#length', function(){
- * var arr = [1,2,3];
- * ok(arr.length == 3);
- * });
- *
- * test('#indexOf()', function(){
- * var arr = [1,2,3];
- * ok(arr.indexOf(1) == 0);
- * ok(arr.indexOf(2) == 1);
- * ok(arr.indexOf(3) == 2);
- * });
- *
- * suite('String');
- *
- * test('#length', function(){
- * ok('foo'.length == 3);
- * });
- *
- */
-
-module.exports = function(suite){
- var suites = [suite];
-
- suite.on('pre-require', function(context, file, mocha){
-
- var common = require('./common')(suites, context);
-
- context.before = common.before;
- context.after = common.after;
- context.beforeEach = common.beforeEach;
- context.afterEach = common.afterEach;
- context.run = mocha.options.delay && common.runWithSuite(suite);
- /**
- * Describe a "suite" with the given `title`.
- */
-
- context.suite = function(title){
- if (suites.length > 1) suites.shift();
- var suite = Suite.create(suites[0], title);
- suite.file = file;
- suites.unshift(suite);
- return suite;
- };
-
- /**
- * Exclusive test-case.
- */
-
- context.suite.only = function(title, fn){
- var suite = context.suite(title, fn);
- mocha.grep(suite.fullTitle());
- };
-
- /**
- * Describe a specification or test-case
- * with the given `title` and callback `fn`
- * acting as a thunk.
- */
-
- context.test = function(title, fn){
- var test = new Test(title, fn);
- test.file = file;
- suites[0].addTest(test);
- return test;
- };
-
- /**
- * Exclusive test-case.
- */
-
- context.test.only = function(title, fn){
- var test = context.test(title, fn);
- var reString = '^' + escapeRe(test.fullTitle()) + '$';
- mocha.grep(new RegExp(reString));
- };
-
- context.test.skip = common.test.skip;
-
- });
-};
-
-}); // module: interfaces/qunit.js
-
-require.register("interfaces/tdd.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Suite = require('../suite')
- , Test = require('../test')
- , escapeRe = require('browser/escape-string-regexp')
- , utils = require('../utils');
-
-/**
- * TDD-style interface:
- *
- * suite('Array', function(){
- * suite('#indexOf()', function(){
- * suiteSetup(function(){
- *
- * });
- *
- * test('should return -1 when not present', function(){
- *
- * });
- *
- * test('should return the index when present', function(){
- *
- * });
- *
- * suiteTeardown(function(){
- *
- * });
- * });
- * });
- *
- */
-
-module.exports = function(suite){
- var suites = [suite];
-
- suite.on('pre-require', function(context, file, mocha){
-
- var common = require('./common')(suites, context);
-
- context.setup = common.beforeEach;
- context.teardown = common.afterEach;
- context.suiteSetup = common.before;
- context.suiteTeardown = common.after;
- context.run = mocha.options.delay && common.runWithSuite(suite);
- /**
- * Describe a "suite" with the given `title`
- * and callback `fn` containing nested suites
- * and/or tests.
- */
-
- context.suite = function(title, fn){
- var suite = Suite.create(suites[0], title);
- suite.file = file;
- suites.unshift(suite);
- fn.call(suite);
- suites.shift();
- return suite;
- };
-
- /**
- * Pending suite.
- */
- context.suite.skip = function(title, fn) {
- var suite = Suite.create(suites[0], title);
- suite.pending = true;
- suites.unshift(suite);
- fn.call(suite);
- suites.shift();
- };
-
- /**
- * Exclusive test-case.
- */
-
- context.suite.only = function(title, fn){
- var suite = context.suite(title, fn);
- mocha.grep(suite.fullTitle());
- };
-
- /**
- * Describe a specification or test-case
- * with the given `title` and callback `fn`
- * acting as a thunk.
- */
-
- context.test = function(title, fn){
- var suite = suites[0];
- if (suite.pending) fn = null;
- var test = new Test(title, fn);
- test.file = file;
- suite.addTest(test);
- return test;
- };
-
- /**
- * Exclusive test-case.
- */
-
- context.test.only = function(title, fn){
- var test = context.test(title, fn);
- var reString = '^' + escapeRe(test.fullTitle()) + '$';
- mocha.grep(new RegExp(reString));
- };
-
- context.test.skip = common.test.skip;
- });
-};
-
-}); // module: interfaces/tdd.js
-
-require.register("mocha.js", function(module, exports, require){
-/*!
- * mocha
- * Copyright(c) 2011 TJ Holowaychuk
- * MIT Licensed
- */
-
-/**
- * Module dependencies.
- */
-
-var path = require('browser/path')
- , escapeRe = require('browser/escape-string-regexp')
- , utils = require('./utils');
-
-/**
- * Expose `Mocha`.
- */
-
-exports = module.exports = Mocha;
-
-/**
- * To require local UIs and reporters when running in node.
- */
-
-if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
- var join = path.join
- , cwd = process.cwd();
- module.paths.push(cwd, join(cwd, 'node_modules'));
-}
-
-/**
- * Expose internals.
- */
-
-exports.utils = utils;
-exports.interfaces = require('./interfaces');
-exports.reporters = require('./reporters');
-exports.Runnable = require('./runnable');
-exports.Context = require('./context');
-exports.Runner = require('./runner');
-exports.Suite = require('./suite');
-exports.Hook = require('./hook');
-exports.Test = require('./test');
-
-/**
- * Return image `name` path.
- *
- * @param {String} name
- * @return {String}
- * @api private
- */
-
-function image(name) {
- return __dirname + '/../images/' + name + '.png';
-}
-
-/**
- * Setup mocha with `options`.
- *
- * Options:
- *
- * - `ui` name "bdd", "tdd", "exports" etc
- * - `reporter` reporter instance, defaults to `mocha.reporters.spec`
- * - `globals` array of accepted globals
- * - `timeout` timeout in milliseconds
- * - `bail` bail on the first test failure
- * - `slow` milliseconds to wait before considering a test slow
- * - `ignoreLeaks` ignore global leaks
- * - `fullTrace` display the full stack-trace on failing
- * - `grep` string or regexp to filter tests with
- *
- * @param {Object} options
- * @api public
- */
-
-function Mocha(options) {
- options = options || {};
- this.files = [];
- this.options = options;
- if (options.grep) this.grep(new RegExp(options.grep));
- if (options.fgrep) this.grep(options.fgrep);
- this.suite = new exports.Suite('', new exports.Context);
- this.ui(options.ui);
- this.bail(options.bail);
- this.reporter(options.reporter, options.reporterOptions);
- if (null != options.timeout) this.timeout(options.timeout);
- this.useColors(options.useColors);
- if (options.enableTimeouts !== null) this.enableTimeouts(options.enableTimeouts);
- if (options.slow) this.slow(options.slow);
-
- this.suite.on('pre-require', function (context) {
- exports.afterEach = context.afterEach || context.teardown;
- exports.after = context.after || context.suiteTeardown;
- exports.beforeEach = context.beforeEach || context.setup;
- exports.before = context.before || context.suiteSetup;
- exports.describe = context.describe || context.suite;
- exports.it = context.it || context.test;
- exports.setup = context.setup || context.beforeEach;
- exports.suiteSetup = context.suiteSetup || context.before;
- exports.suiteTeardown = context.suiteTeardown || context.after;
- exports.suite = context.suite || context.describe;
- exports.teardown = context.teardown || context.afterEach;
- exports.test = context.test || context.it;
- exports.run = context.run;
- });
-}
-
-/**
- * Enable or disable bailing on the first failure.
- *
- * @param {Boolean} [bail]
- * @api public
- */
-
-Mocha.prototype.bail = function(bail){
- if (0 == arguments.length) bail = true;
- this.suite.bail(bail);
- return this;
-};
-
-/**
- * Add test `file`.
- *
- * @param {String} file
- * @api public
- */
-
-Mocha.prototype.addFile = function(file){
- this.files.push(file);
- return this;
-};
-
-/**
- * Set reporter to `reporter`, defaults to "spec".
- *
- * @param {String|Function} reporter name or constructor
- * @param {Object} reporterOptions optional options
- * @api public
- */
-Mocha.prototype.reporter = function(reporter, reporterOptions){
- if ('function' == typeof reporter) {
- this._reporter = reporter;
- } else {
- reporter = reporter || 'spec';
- var _reporter;
- try { _reporter = require('./reporters/' + reporter); } catch (err) {}
- if (!_reporter) try { _reporter = require(reporter); } catch (err) {
- err.message.indexOf('Cannot find module') !== -1
- ? console.warn('"' + reporter + '" reporter not found')
- : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
- }
- if (!_reporter && reporter === 'teamcity')
- console.warn('The Teamcity reporter was moved to a package named ' +
- 'mocha-teamcity-reporter ' +
- '(https://npmjs.org/package/mocha-teamcity-reporter).');
- if (!_reporter) throw new Error('invalid reporter "' + reporter + '"');
- this._reporter = _reporter;
- }
- this.options.reporterOptions = reporterOptions;
- return this;
-};
-
-/**
- * Set test UI `name`, defaults to "bdd".
- *
- * @param {String} bdd
- * @api public
- */
-
-Mocha.prototype.ui = function(name){
- name = name || 'bdd';
- this._ui = exports.interfaces[name];
- if (!this._ui) try { this._ui = require(name); } catch (err) {}
- if (!this._ui) throw new Error('invalid interface "' + name + '"');
- this._ui = this._ui(this.suite);
- return this;
-};
-
-/**
- * Load registered files.
- *
- * @api private
- */
-
-Mocha.prototype.loadFiles = function(fn){
- var self = this;
- var suite = this.suite;
- var pending = this.files.length;
- this.files.forEach(function(file){
- file = path.resolve(file);
- suite.emit('pre-require', global, file, self);
- suite.emit('require', require(file), file, self);
- suite.emit('post-require', global, file, self);
- --pending || (fn && fn());
- });
-};
-
-/**
- * Enable growl support.
- *
- * @api private
- */
-
-Mocha.prototype._growl = function(runner, reporter) {
- var notify = require('growl');
-
- runner.on('end', function(){
- var stats = reporter.stats;
- if (stats.failures) {
- var msg = stats.failures + ' of ' + runner.total + ' tests failed';
- notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
- } else {
- notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
- name: 'mocha'
- , title: 'Passed'
- , image: image('ok')
- });
- }
- });
-};
-
-/**
- * Add regexp to grep, if `re` is a string it is escaped.
- *
- * @param {RegExp|String} re
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.grep = function(re){
- this.options.grep = 'string' == typeof re
- ? new RegExp(escapeRe(re))
- : re;
- return this;
-};
-
-/**
- * Invert `.grep()` matches.
- *
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.invert = function(){
- this.options.invert = true;
- return this;
-};
-
-/**
- * Ignore global leaks.
- *
- * @param {Boolean} ignore
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.ignoreLeaks = function(ignore){
- this.options.ignoreLeaks = !!ignore;
- return this;
-};
-
-/**
- * Enable global leak checking.
- *
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.checkLeaks = function(){
- this.options.ignoreLeaks = false;
- return this;
-};
-
-/**
- * Display long stack-trace on failing
- *
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.fullTrace = function() {
- this.options.fullStackTrace = true;
- return this;
-};
-
-/**
- * Enable growl support.
- *
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.growl = function(){
- this.options.growl = true;
- return this;
-};
-
-/**
- * Ignore `globals` array or string.
- *
- * @param {Array|String} globals
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.globals = function(globals){
- this.options.globals = (this.options.globals || []).concat(globals);
- return this;
-};
-
-/**
- * Emit color output.
- *
- * @param {Boolean} colors
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.useColors = function(colors){
- if (colors !== undefined) {
- this.options.useColors = colors;
- }
- return this;
-};
-
-/**
- * Use inline diffs rather than +/-.
- *
- * @param {Boolean} inlineDiffs
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
- this.options.useInlineDiffs = arguments.length && inlineDiffs != undefined
- ? inlineDiffs
- : false;
- return this;
-};
-
-/**
- * Set the timeout in milliseconds.
- *
- * @param {Number} timeout
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.timeout = function(timeout){
- this.suite.timeout(timeout);
- return this;
-};
-
-/**
- * Set slowness threshold in milliseconds.
- *
- * @param {Number} slow
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.slow = function(slow){
- this.suite.slow(slow);
- return this;
-};
-
-/**
- * Enable timeouts.
- *
- * @param {Boolean} enabled
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.enableTimeouts = function(enabled) {
- this.suite.enableTimeouts(arguments.length && enabled !== undefined
- ? enabled
- : true);
- return this
-};
-
-/**
- * Makes all tests async (accepting a callback)
- *
- * @return {Mocha}
- * @api public
- */
-
-Mocha.prototype.asyncOnly = function(){
- this.options.asyncOnly = true;
- return this;
-};
-
-/**
- * Disable syntax highlighting (in browser).
- * @returns {Mocha}
- * @api public
- */
-Mocha.prototype.noHighlighting = function() {
- this.options.noHighlighting = true;
- return this;
-};
-
-/**
- * Delay root suite execution.
- * @returns {Mocha}
- * @api public
- */
-Mocha.prototype.delay = function delay() {
- this.options.delay = true;
- return this;
-};
-
-/**
- * Run tests and invoke `fn()` when complete.
- *
- * @param {Function} fn
- * @return {Runner}
- * @api public
- */
-Mocha.prototype.run = function(fn){
- if (this.files.length) this.loadFiles();
- var suite = this.suite;
- var options = this.options;
- options.files = this.files;
- var runner = new exports.Runner(suite, options.delay);
- var reporter = new this._reporter(runner, options);
- runner.ignoreLeaks = false !== options.ignoreLeaks;
- runner.fullStackTrace = options.fullStackTrace;
- runner.asyncOnly = options.asyncOnly;
- if (options.grep) runner.grep(options.grep, options.invert);
- if (options.globals) runner.globals(options.globals);
- if (options.growl) this._growl(runner, reporter);
- if (options.useColors !== undefined) {
- exports.reporters.Base.useColors = options.useColors;
- }
- exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
-
- function done(failures) {
- if (reporter.done) {
- reporter.done(failures, fn);
- } else fn && fn(failures);
- }
-
- return runner.run(done);
-};
-
-}); // module: mocha.js
-
-require.register("ms.js", function(module, exports, require){
-/**
- * Helpers.
- */
-
-var s = 1000;
-var m = s * 60;
-var h = m * 60;
-var d = h * 24;
-var y = d * 365.25;
-
-/**
- * Parse or format the given `val`.
- *
- * Options:
- *
- * - `long` verbose formatting [false]
- *
- * @param {String|Number} val
- * @param {Object} options
- * @return {String|Number}
- * @api public
- */
-
-module.exports = function(val, options){
- options = options || {};
- if ('string' == typeof val) return parse(val);
- return options['long'] ? longFormat(val) : shortFormat(val);
-};
-
-/**
- * Parse the given `str` and return milliseconds.
- *
- * @param {String} str
- * @return {Number}
- * @api private
- */
-
-function parse(str) {
- var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str);
- if (!match) return;
- var n = parseFloat(match[1]);
- var type = (match[2] || 'ms').toLowerCase();
- switch (type) {
- case 'years':
- case 'year':
- case 'y':
- return n * y;
- case 'days':
- case 'day':
- case 'd':
- return n * d;
- case 'hours':
- case 'hour':
- case 'h':
- return n * h;
- case 'minutes':
- case 'minute':
- case 'm':
- return n * m;
- case 'seconds':
- case 'second':
- case 's':
- return n * s;
- case 'ms':
- return n;
- }
-}
-
-/**
- * Short format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
-
-function shortFormat(ms) {
- if (ms >= d) return Math.round(ms / d) + 'd';
- if (ms >= h) return Math.round(ms / h) + 'h';
- if (ms >= m) return Math.round(ms / m) + 'm';
- if (ms >= s) return Math.round(ms / s) + 's';
- return ms + 'ms';
-}
-
-/**
- * Long format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
-
-function longFormat(ms) {
- return plural(ms, d, 'day')
- || plural(ms, h, 'hour')
- || plural(ms, m, 'minute')
- || plural(ms, s, 'second')
- || ms + ' ms';
-}
-
-/**
- * Pluralization helper.
- */
-
-function plural(ms, n, name) {
- if (ms < n) return;
- if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
- return Math.ceil(ms / n) + ' ' + name + 's';
-}
-
-}); // module: ms.js
-
-require.register("pending.js", function(module, exports, require){
-
-/**
- * Expose `Pending`.
- */
-
-module.exports = Pending;
-
-/**
- * Initialize a new `Pending` error with the given message.
- *
- * @param {String} message
- */
-
-function Pending(message) {
- this.message = message;
-}
-
-}); // module: pending.js
-
-require.register("reporters/base.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var tty = require('browser/tty')
- , diff = require('browser/diff')
- , ms = require('../ms')
- , utils = require('../utils')
- , supportsColor = process.env ? require('supports-color') : null;
-
-/**
- * Save timer references to avoid Sinon interfering (see GH-237).
- */
-
-var Date = global.Date
- , setTimeout = global.setTimeout
- , setInterval = global.setInterval
- , clearTimeout = global.clearTimeout
- , clearInterval = global.clearInterval;
-
-/**
- * Check if both stdio streams are associated with a tty.
- */
-
-var isatty = tty.isatty(1) && tty.isatty(2);
-
-/**
- * Expose `Base`.
- */
-
-exports = module.exports = Base;
-
-/**
- * Enable coloring by default, except in the browser interface.
- */
-
-exports.useColors = process.env
- ? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
- : false;
-
-/**
- * Inline diffs instead of +/-
- */
-
-exports.inlineDiffs = false;
-
-/**
- * Default color map.
- */
-
-exports.colors = {
- 'pass': 90
- , 'fail': 31
- , 'bright pass': 92
- , 'bright fail': 91
- , 'bright yellow': 93
- , 'pending': 36
- , 'suite': 0
- , 'error title': 0
- , 'error message': 31
- , 'error stack': 90
- , 'checkmark': 32
- , 'fast': 90
- , 'medium': 33
- , 'slow': 31
- , 'green': 32
- , 'light': 90
- , 'diff gutter': 90
- , 'diff added': 42
- , 'diff removed': 41
-};
-
-/**
- * Default symbol map.
- */
-
-exports.symbols = {
- ok: '✓',
- err: '✖',
- dot: '․'
-};
-
-// With node.js on Windows: use symbols available in terminal default fonts
-if ('win32' == process.platform) {
- exports.symbols.ok = '\u221A';
- exports.symbols.err = '\u00D7';
- exports.symbols.dot = '.';
-}
-
-/**
- * Color `str` with the given `type`,
- * allowing colors to be disabled,
- * as well as user-defined color
- * schemes.
- *
- * @param {String} type
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-var color = exports.color = function(type, str) {
- if (!exports.useColors) return String(str);
- return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
-};
-
-/**
- * Expose term window size, with some
- * defaults for when stderr is not a tty.
- */
-
-exports.window = {
- width: isatty
- ? process.stdout.getWindowSize
- ? process.stdout.getWindowSize(1)[0]
- : tty.getWindowSize()[1]
- : 75
-};
-
-/**
- * Expose some basic cursor interactions
- * that are common among reporters.
- */
-
-exports.cursor = {
- hide: function(){
- isatty && process.stdout.write('\u001b[?25l');
- },
-
- show: function(){
- isatty && process.stdout.write('\u001b[?25h');
- },
-
- deleteLine: function(){
- isatty && process.stdout.write('\u001b[2K');
- },
-
- beginningOfLine: function(){
- isatty && process.stdout.write('\u001b[0G');
- },
-
- CR: function(){
- if (isatty) {
- exports.cursor.deleteLine();
- exports.cursor.beginningOfLine();
- } else {
- process.stdout.write('\r');
- }
- }
-};
-
-/**
- * Outut the given `failures` as a list.
- *
- * @param {Array} failures
- * @api public
- */
-
-exports.list = function(failures){
- console.log();
- failures.forEach(function(test, i){
- // format
- var fmt = color('error title', ' %s) %s:\n')
- + color('error message', ' %s')
- + color('error stack', '\n%s\n');
-
- // msg
- var err = test.err
- , message = err.message || ''
- , stack = err.stack || message
- , index = stack.indexOf(message)
- , actual = err.actual
- , expected = err.expected
- , escape = true;
- if (index === -1) {
- msg = message;
- } else {
- index += message.length;
- msg = stack.slice(0, index);
- // remove msg from stack
- stack = stack.slice(index + 1);
- }
-
- // uncaught
- if (err.uncaught) {
- msg = 'Uncaught ' + msg;
- }
- // explicitly show diff
- if (err.showDiff !== false && sameType(actual, expected)
- && expected !== undefined) {
-
- if ('string' !== typeof actual) {
- escape = false;
- err.actual = actual = utils.stringify(actual);
- err.expected = expected = utils.stringify(expected);
- }
-
- fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
- var match = message.match(/^([^:]+): expected/);
- msg = '\n ' + color('error message', match ? match[1] : msg);
-
- if (exports.inlineDiffs) {
- msg += inlineDiff(err, escape);
- } else {
- msg += unifiedDiff(err, escape);
- }
- }
-
- // indent stack trace
- stack = stack.replace(/^/gm, ' ');
-
- console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
- });
-};
-
-/**
- * Initialize a new `Base` reporter.
- *
- * All other reporters generally
- * inherit from this reporter, providing
- * stats such as test duration, number
- * of tests passed / failed etc.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Base(runner) {
- var self = this
- , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
- , failures = this.failures = [];
-
- if (!runner) return;
- this.runner = runner;
-
- runner.stats = stats;
-
- runner.on('start', function(){
- stats.start = new Date;
- });
-
- runner.on('suite', function(suite){
- stats.suites = stats.suites || 0;
- suite.root || stats.suites++;
- });
-
- runner.on('test end', function(test){
- stats.tests = stats.tests || 0;
- stats.tests++;
- });
-
- runner.on('pass', function(test){
- stats.passes = stats.passes || 0;
-
- var medium = test.slow() / 2;
- test.speed = test.duration > test.slow()
- ? 'slow'
- : test.duration > medium
- ? 'medium'
- : 'fast';
-
- stats.passes++;
- });
-
- runner.on('fail', function(test, err){
- stats.failures = stats.failures || 0;
- stats.failures++;
- test.err = err;
- failures.push(test);
- });
-
- runner.on('end', function(){
- stats.end = new Date;
- stats.duration = new Date - stats.start;
- });
-
- runner.on('pending', function(){
- stats.pending++;
- });
-}
-
-/**
- * Output common epilogue used by many of
- * the bundled reporters.
- *
- * @api public
- */
-
-Base.prototype.epilogue = function(){
- var stats = this.stats;
- var tests;
- var fmt;
-
- console.log();
-
- // passes
- fmt = color('bright pass', ' ')
- + color('green', ' %d passing')
- + color('light', ' (%s)');
-
- console.log(fmt,
- stats.passes || 0,
- ms(stats.duration));
-
- // pending
- if (stats.pending) {
- fmt = color('pending', ' ')
- + color('pending', ' %d pending');
-
- console.log(fmt, stats.pending);
- }
-
- // failures
- if (stats.failures) {
- fmt = color('fail', ' %d failing');
-
- console.log(fmt, stats.failures);
-
- Base.list(this.failures);
- console.log();
- }
-
- console.log();
-};
-
-/**
- * Pad the given `str` to `len`.
- *
- * @param {String} str
- * @param {String} len
- * @return {String}
- * @api private
- */
-
-function pad(str, len) {
- str = String(str);
- return Array(len - str.length + 1).join(' ') + str;
-}
-
-
-/**
- * Returns an inline diff between 2 strings with coloured ANSI output
- *
- * @param {Error} Error with actual/expected
- * @return {String} Diff
- * @api private
- */
-
-function inlineDiff(err, escape) {
- var msg = errorDiff(err, 'WordsWithSpace', escape);
-
- // linenos
- var lines = msg.split('\n');
- if (lines.length > 4) {
- var width = String(lines.length).length;
- msg = lines.map(function(str, i){
- return pad(++i, width) + ' |' + ' ' + str;
- }).join('\n');
- }
-
- // legend
- msg = '\n'
- + color('diff removed', 'actual')
- + ' '
- + color('diff added', 'expected')
- + '\n\n'
- + msg
- + '\n';
-
- // indent
- msg = msg.replace(/^/gm, ' ');
- return msg;
-}
-
-/**
- * Returns a unified diff between 2 strings
- *
- * @param {Error} Error with actual/expected
- * @return {String} Diff
- * @api private
- */
-
-function unifiedDiff(err, escape) {
- var indent = ' ';
- function cleanUp(line) {
- if (escape) {
- line = escapeInvisibles(line);
- }
- if (line[0] === '+') return indent + colorLines('diff added', line);
- if (line[0] === '-') return indent + colorLines('diff removed', line);
- if (line.match(/\@\@/)) return null;
- if (line.match(/\\ No newline/)) return null;
- else return indent + line;
- }
- function notBlank(line) {
- return line != null;
- }
- var msg = diff.createPatch('string', err.actual, err.expected);
- var lines = msg.split('\n').splice(4);
- return '\n '
- + colorLines('diff added', '+ expected') + ' '
- + colorLines('diff removed', '- actual')
- + '\n\n'
- + lines.map(cleanUp).filter(notBlank).join('\n');
-}
-
-/**
- * Return a character diff for `err`.
- *
- * @param {Error} err
- * @return {String}
- * @api private
- */
-
-function errorDiff(err, type, escape) {
- var actual = escape ? escapeInvisibles(err.actual) : err.actual;
- var expected = escape ? escapeInvisibles(err.expected) : err.expected;
- return diff['diff' + type](actual, expected).map(function(str){
- if (str.added) return colorLines('diff added', str.value);
- if (str.removed) return colorLines('diff removed', str.value);
- return str.value;
- }).join('');
-}
-
-/**
- * Returns a string with all invisible characters in plain text
- *
- * @param {String} line
- * @return {String}
- * @api private
- */
-function escapeInvisibles(line) {
- return line.replace(/\t/g, '')
- .replace(/\r/g, '')
- .replace(/\n/g, '\n');
-}
-
-/**
- * Color lines for `str`, using the color `name`.
- *
- * @param {String} name
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-function colorLines(name, str) {
- return str.split('\n').map(function(str){
- return color(name, str);
- }).join('\n');
-}
-
-/**
- * Check that a / b have the same type.
- *
- * @param {Object} a
- * @param {Object} b
- * @return {Boolean}
- * @api private
- */
-
-function sameType(a, b) {
- a = Object.prototype.toString.call(a);
- b = Object.prototype.toString.call(b);
- return a == b;
-}
-
-}); // module: reporters/base.js
-
-require.register("reporters/doc.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , utils = require('../utils');
-
-/**
- * Expose `Doc`.
- */
-
-exports = module.exports = Doc;
-
-/**
- * Initialize a new `Doc` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Doc(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , total = runner.total
- , indents = 2;
-
- function indent() {
- return Array(indents).join(' ');
- }
-
- runner.on('suite', function(suite){
- if (suite.root) return;
- ++indents;
- console.log('%s', indent());
- ++indents;
- console.log('%s%s ', indent(), utils.escape(suite.title));
- console.log('%s', indent());
- });
-
- runner.on('suite end', function(suite){
- if (suite.root) return;
- console.log('%s ', indent());
- --indents;
- console.log('%s ', indent());
- --indents;
- });
-
- runner.on('pass', function(test){
- console.log('%s %s ', indent(), utils.escape(test.title));
- var code = utils.escape(utils.clean(test.fn.toString()));
- console.log('%s %s
', indent(), code);
- });
-
- runner.on('fail', function(test, err){
- console.log('%s %s ', indent(), utils.escape(test.title));
- var code = utils.escape(utils.clean(test.fn.toString()));
- console.log('%s %s
', indent(), code);
- console.log('%s %s ', indent(), utils.escape(err));
- });
-}
-
-}); // module: reporters/doc.js
-
-require.register("reporters/dot.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , color = Base.color;
-
-/**
- * Expose `Dot`.
- */
-
-exports = module.exports = Dot;
-
-/**
- * Initialize a new `Dot` matrix test reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Dot(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , width = Base.window.width * .75 | 0
- , n = -1;
-
- runner.on('start', function(){
- process.stdout.write('\n');
- });
-
- runner.on('pending', function(test){
- if (++n % width == 0) process.stdout.write('\n ');
- process.stdout.write(color('pending', Base.symbols.dot));
- });
-
- runner.on('pass', function(test){
- if (++n % width == 0) process.stdout.write('\n ');
- if ('slow' == test.speed) {
- process.stdout.write(color('bright yellow', Base.symbols.dot));
- } else {
- process.stdout.write(color(test.speed, Base.symbols.dot));
- }
- });
-
- runner.on('fail', function(test, err){
- if (++n % width == 0) process.stdout.write('\n ');
- process.stdout.write(color('fail', Base.symbols.dot));
- });
-
- runner.on('end', function(){
- console.log();
- self.epilogue();
- });
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-Dot.prototype = new F;
-Dot.prototype.constructor = Dot;
-
-
-}); // module: reporters/dot.js
-
-require.register("reporters/html-cov.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var JSONCov = require('./json-cov')
- , fs = require('browser/fs');
-
-/**
- * Expose `HTMLCov`.
- */
-
-exports = module.exports = HTMLCov;
-
-/**
- * Initialize a new `JsCoverage` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function HTMLCov(runner) {
- var jade = require('jade')
- , file = __dirname + '/templates/coverage.jade'
- , str = fs.readFileSync(file, 'utf8')
- , fn = jade.compile(str, { filename: file })
- , self = this;
-
- JSONCov.call(this, runner, false);
-
- runner.on('end', function(){
- process.stdout.write(fn({
- cov: self.cov
- , coverageClass: coverageClass
- }));
- });
-}
-
-/**
- * Return coverage class for `n`.
- *
- * @return {String}
- * @api private
- */
-
-function coverageClass(n) {
- if (n >= 75) return 'high';
- if (n >= 50) return 'medium';
- if (n >= 25) return 'low';
- return 'terrible';
-}
-
-}); // module: reporters/html-cov.js
-
-require.register("reporters/html.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , utils = require('../utils')
- , Progress = require('../browser/progress')
- , escape = utils.escape;
-
-/**
- * Save timer references to avoid Sinon interfering (see GH-237).
- */
-
-var Date = global.Date
- , setTimeout = global.setTimeout
- , setInterval = global.setInterval
- , clearTimeout = global.clearTimeout
- , clearInterval = global.clearInterval;
-
-/**
- * Expose `HTML`.
- */
-
-exports = module.exports = HTML;
-
-/**
- * Stats template.
- */
-
-var statsTemplate = '';
-
-/**
- * Initialize a new `HTML` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function HTML(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , total = runner.total
- , stat = fragment(statsTemplate)
- , items = stat.getElementsByTagName('li')
- , passes = items[1].getElementsByTagName('em')[0]
- , passesLink = items[1].getElementsByTagName('a')[0]
- , failures = items[2].getElementsByTagName('em')[0]
- , failuresLink = items[2].getElementsByTagName('a')[0]
- , duration = items[3].getElementsByTagName('em')[0]
- , canvas = stat.getElementsByTagName('canvas')[0]
- , report = fragment('')
- , stack = [report]
- , progress
- , ctx
- , root = document.getElementById('mocha');
-
- if (canvas.getContext) {
- var ratio = window.devicePixelRatio || 1;
- canvas.style.width = canvas.width;
- canvas.style.height = canvas.height;
- canvas.width *= ratio;
- canvas.height *= ratio;
- ctx = canvas.getContext('2d');
- ctx.scale(ratio, ratio);
- progress = new Progress;
- }
-
- if (!root) return error('#mocha div missing, add it to your document');
-
- // pass toggle
- on(passesLink, 'click', function(){
- unhide();
- var name = /pass/.test(report.className) ? '' : ' pass';
- report.className = report.className.replace(/fail|pass/g, '') + name;
- if (report.className.trim()) hideSuitesWithout('test pass');
- });
-
- // failure toggle
- on(failuresLink, 'click', function(){
- unhide();
- var name = /fail/.test(report.className) ? '' : ' fail';
- report.className = report.className.replace(/fail|pass/g, '') + name;
- if (report.className.trim()) hideSuitesWithout('test fail');
- });
-
- root.appendChild(stat);
- root.appendChild(report);
-
- if (progress) progress.size(40);
-
- runner.on('suite', function(suite){
- if (suite.root) return;
-
- // suite
- var url = self.suiteURL(suite);
- var el = fragment(' ', url, escape(suite.title));
-
- // container
- stack[0].appendChild(el);
- stack.unshift(document.createElement('ul'));
- el.appendChild(stack[0]);
- });
-
- runner.on('suite end', function(suite){
- if (suite.root) return;
- stack.shift();
- });
-
- runner.on('fail', function(test, err){
- if ('hook' == test.type) runner.emit('test end', test);
- });
-
- runner.on('test end', function(test){
- // TODO: add to stats
- var percent = stats.tests / this.total * 100 | 0;
- if (progress) progress.update(percent).draw(ctx);
-
- // update stats
- var ms = new Date - stats.start;
- text(passes, stats.passes);
- text(failures, stats.failures);
- text(duration, (ms / 1000).toFixed(2));
-
- // test
- if ('passed' == test.state) {
- var url = self.testURL(test);
- var el = fragment('%e%ems ‣ ', test.speed, test.title, test.duration, url);
- } else if (test.pending) {
- var el = fragment('%e ', test.title);
- } else {
- var el = fragment(' ', test.title, self.testURL(test));
- var str = test.err.stack || test.err.toString();
-
- // FF / Opera do not add the message
- if (!~str.indexOf(test.err.message)) {
- str = test.err.message + '\n' + str;
- }
-
- // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
- // check for the result of the stringifying.
- if ('[object Error]' == str) str = test.err.message;
-
- // Safari doesn't give you a stack. Let's at least provide a source line.
- if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
- str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
- }
-
- el.appendChild(fragment('%e ', str));
- }
-
- // toggle code
- // TODO: defer
- if (!test.pending) {
- var h2 = el.getElementsByTagName('h2')[0];
-
- on(h2, 'click', function(){
- pre.style.display = 'none' == pre.style.display
- ? 'block'
- : 'none';
- });
-
- var pre = fragment('%e
', utils.clean(test.fn.toString()));
- el.appendChild(pre);
- pre.style.display = 'none';
- }
-
- // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
- if (stack[0]) stack[0].appendChild(el);
- });
-}
-
-/**
- * Makes a URL, preserving querystring ("search") parameters.
- * @param {string} s
- * @returns {string} your new URL
- */
-var makeUrl = function makeUrl(s) {
- var search = window.location.search;
-
- // Remove previous grep query parameter if present
- if (search) {
- search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
- }
-
- return window.location.pathname + (search ? search + '&' : '?' ) + 'grep=' + encodeURIComponent(s);
-};
-
-/**
- * Provide suite URL
- *
- * @param {Object} [suite]
- */
-HTML.prototype.suiteURL = function(suite){
- return makeUrl(suite.fullTitle());
-};
-
-/**
- * Provide test URL
- *
- * @param {Object} [test]
- */
-
-HTML.prototype.testURL = function(test){
- return makeUrl(test.fullTitle());
-};
-
-/**
- * Display error `msg`.
- */
-
-function error(msg) {
- document.body.appendChild(fragment('%s
', msg));
-}
-
-/**
- * Return a DOM fragment from `html`.
- */
-
-function fragment(html) {
- var args = arguments
- , div = document.createElement('div')
- , i = 1;
-
- div.innerHTML = html.replace(/%([se])/g, function(_, type){
- switch (type) {
- case 's': return String(args[i++]);
- case 'e': return escape(args[i++]);
- }
- });
-
- return div.firstChild;
-}
-
-/**
- * Check for suites that do not have elements
- * with `classname`, and hide them.
- */
-
-function hideSuitesWithout(classname) {
- var suites = document.getElementsByClassName('suite');
- for (var i = 0; i < suites.length; i++) {
- var els = suites[i].getElementsByClassName(classname);
- if (0 == els.length) suites[i].className += ' hidden';
- }
-}
-
-/**
- * Unhide .hidden suites.
- */
-
-function unhide() {
- var els = document.getElementsByClassName('suite hidden');
- for (var i = 0; i < els.length; ++i) {
- els[i].className = els[i].className.replace('suite hidden', 'suite');
- }
-}
-
-/**
- * Set `el` text to `str`.
- */
-
-function text(el, str) {
- if (el.textContent) {
- el.textContent = str;
- } else {
- el.innerText = str;
- }
-}
-
-/**
- * Listen on `event` with callback `fn`.
- */
-
-function on(el, event, fn) {
- if (el.addEventListener) {
- el.addEventListener(event, fn, false);
- } else {
- el.attachEvent('on' + event, fn);
- }
-}
-
-}); // module: reporters/html.js
-
-require.register("reporters/index.js", function(module, exports, require){
-exports.Base = require('./base');
-exports.Dot = require('./dot');
-exports.Doc = require('./doc');
-exports.TAP = require('./tap');
-exports.JSON = require('./json');
-exports.HTML = require('./html');
-exports.List = require('./list');
-exports.Min = require('./min');
-exports.Spec = require('./spec');
-exports.Nyan = require('./nyan');
-exports.XUnit = require('./xunit');
-exports.Markdown = require('./markdown');
-exports.Progress = require('./progress');
-exports.Landing = require('./landing');
-exports.JSONCov = require('./json-cov');
-exports.HTMLCov = require('./html-cov');
-exports.JSONStream = require('./json-stream');
-
-}); // module: reporters/index.js
-
-require.register("reporters/json-cov.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base');
-
-/**
- * Expose `JSONCov`.
- */
-
-exports = module.exports = JSONCov;
-
-/**
- * Initialize a new `JsCoverage` reporter.
- *
- * @param {Runner} runner
- * @param {Boolean} output
- * @api public
- */
-
-function JSONCov(runner, output) {
- var self = this
- , output = 1 == arguments.length ? true : output;
-
- Base.call(this, runner);
-
- var tests = []
- , failures = []
- , passes = [];
-
- runner.on('test end', function(test){
- tests.push(test);
- });
-
- runner.on('pass', function(test){
- passes.push(test);
- });
-
- runner.on('fail', function(test){
- failures.push(test);
- });
-
- runner.on('end', function(){
- var cov = global._$jscoverage || {};
- var result = self.cov = map(cov);
- result.stats = self.stats;
- result.tests = tests.map(clean);
- result.failures = failures.map(clean);
- result.passes = passes.map(clean);
- if (!output) return;
- process.stdout.write(JSON.stringify(result, null, 2 ));
- });
-}
-
-/**
- * Map jscoverage data to a JSON structure
- * suitable for reporting.
- *
- * @param {Object} cov
- * @return {Object}
- * @api private
- */
-
-function map(cov) {
- var ret = {
- instrumentation: 'node-jscoverage'
- , sloc: 0
- , hits: 0
- , misses: 0
- , coverage: 0
- , files: []
- };
-
- for (var filename in cov) {
- var data = coverage(filename, cov[filename]);
- ret.files.push(data);
- ret.hits += data.hits;
- ret.misses += data.misses;
- ret.sloc += data.sloc;
- }
-
- ret.files.sort(function(a, b) {
- return a.filename.localeCompare(b.filename);
- });
-
- if (ret.sloc > 0) {
- ret.coverage = (ret.hits / ret.sloc) * 100;
- }
-
- return ret;
-}
-
-/**
- * Map jscoverage data for a single source file
- * to a JSON structure suitable for reporting.
- *
- * @param {String} filename name of the source file
- * @param {Object} data jscoverage coverage data
- * @return {Object}
- * @api private
- */
-
-function coverage(filename, data) {
- var ret = {
- filename: filename,
- coverage: 0,
- hits: 0,
- misses: 0,
- sloc: 0,
- source: {}
- };
-
- data.source.forEach(function(line, num){
- num++;
-
- if (data[num] === 0) {
- ret.misses++;
- ret.sloc++;
- } else if (data[num] !== undefined) {
- ret.hits++;
- ret.sloc++;
- }
-
- ret.source[num] = {
- source: line
- , coverage: data[num] === undefined
- ? ''
- : data[num]
- };
- });
-
- ret.coverage = ret.hits / ret.sloc * 100;
-
- return ret;
-}
-
-/**
- * Return a plain-object representation of `test`
- * free of cyclic properties etc.
- *
- * @param {Object} test
- * @return {Object}
- * @api private
- */
-
-function clean(test) {
- return {
- title: test.title
- , fullTitle: test.fullTitle()
- , duration: test.duration
- }
-}
-
-}); // module: reporters/json-cov.js
-
-require.register("reporters/json-stream.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , color = Base.color;
-
-/**
- * Expose `List`.
- */
-
-exports = module.exports = List;
-
-/**
- * Initialize a new `List` test reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function List(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , total = runner.total;
-
- runner.on('start', function(){
- console.log(JSON.stringify(['start', { total: total }]));
- });
-
- runner.on('pass', function(test){
- console.log(JSON.stringify(['pass', clean(test)]));
- });
-
- runner.on('fail', function(test, err){
- test = clean(test);
- test.err = err.message;
- console.log(JSON.stringify(['fail', test]));
- });
-
- runner.on('end', function(){
- process.stdout.write(JSON.stringify(['end', self.stats]));
- });
-}
-
-/**
- * Return a plain-object representation of `test`
- * free of cyclic properties etc.
- *
- * @param {Object} test
- * @return {Object}
- * @api private
- */
-
-function clean(test) {
- return {
- title: test.title
- , fullTitle: test.fullTitle()
- , duration: test.duration
- }
-}
-
-}); // module: reporters/json-stream.js
-
-require.register("reporters/json.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `JSON`.
- */
-
-exports = module.exports = JSONReporter;
-
-/**
- * Initialize a new `JSON` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function JSONReporter(runner) {
- var self = this;
- Base.call(this, runner);
-
- var tests = []
- , pending = []
- , failures = []
- , passes = [];
-
- runner.on('test end', function(test){
- tests.push(test);
- });
-
- runner.on('pass', function(test){
- passes.push(test);
- });
-
- runner.on('fail', function(test){
- failures.push(test);
- });
-
- runner.on('pending', function(test){
- pending.push(test);
- });
-
- runner.on('end', function(){
- var obj = {
- stats: self.stats,
- tests: tests.map(clean),
- pending: pending.map(clean),
- failures: failures.map(clean),
- passes: passes.map(clean)
- };
-
- runner.testResults = obj;
-
- process.stdout.write(JSON.stringify(obj, null, 2));
- });
-}
-
-/**
- * Return a plain-object representation of `test`
- * free of cyclic properties etc.
- *
- * @param {Object} test
- * @return {Object}
- * @api private
- */
-
-function clean(test) {
- return {
- title: test.title,
- fullTitle: test.fullTitle(),
- duration: test.duration,
- err: errorJSON(test.err || {})
- }
-}
-
-/**
- * Transform `error` into a JSON object.
- * @param {Error} err
- * @return {Object}
- */
-
-function errorJSON(err) {
- var res = {};
- Object.getOwnPropertyNames(err).forEach(function(key) {
- res[key] = err[key];
- }, err);
- return res;
-}
-
-}); // module: reporters/json.js
-
-require.register("reporters/landing.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `Landing`.
- */
-
-exports = module.exports = Landing;
-
-/**
- * Airplane color.
- */
-
-Base.colors.plane = 0;
-
-/**
- * Airplane crash color.
- */
-
-Base.colors['plane crash'] = 31;
-
-/**
- * Runway color.
- */
-
-Base.colors.runway = 90;
-
-/**
- * Initialize a new `Landing` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Landing(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , width = Base.window.width * .75 | 0
- , total = runner.total
- , stream = process.stdout
- , plane = color('plane', '✈')
- , crashed = -1
- , n = 0;
-
- function runway() {
- var buf = Array(width).join('-');
- return ' ' + color('runway', buf);
- }
-
- runner.on('start', function(){
- stream.write('\n\n\n ');
- cursor.hide();
- });
-
- runner.on('test end', function(test){
- // check if the plane crashed
- var col = -1 == crashed
- ? width * ++n / total | 0
- : crashed;
-
- // show the crash
- if ('failed' == test.state) {
- plane = color('plane crash', '✈');
- crashed = col;
- }
-
- // render landing strip
- stream.write('\u001b['+(width+1)+'D\u001b[2A');
- stream.write(runway());
- stream.write('\n ');
- stream.write(color('runway', Array(col).join('â‹…')));
- stream.write(plane)
- stream.write(color('runway', Array(width - col).join('â‹…') + '\n'));
- stream.write(runway());
- stream.write('\u001b[0m');
- });
-
- runner.on('end', function(){
- cursor.show();
- console.log();
- self.epilogue();
- });
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-Landing.prototype = new F;
-Landing.prototype.constructor = Landing;
-
-
-}); // module: reporters/landing.js
-
-require.register("reporters/list.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `List`.
- */
-
-exports = module.exports = List;
-
-/**
- * Initialize a new `List` test reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function List(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , n = 0;
-
- runner.on('start', function(){
- console.log();
- });
-
- runner.on('test', function(test){
- process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
- });
-
- runner.on('pending', function(test){
- var fmt = color('checkmark', ' -')
- + color('pending', ' %s');
- console.log(fmt, test.fullTitle());
- });
-
- runner.on('pass', function(test){
- var fmt = color('checkmark', ' '+Base.symbols.dot)
- + color('pass', ' %s: ')
- + color(test.speed, '%dms');
- cursor.CR();
- console.log(fmt, test.fullTitle(), test.duration);
- });
-
- runner.on('fail', function(test, err){
- cursor.CR();
- console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
- });
-
- runner.on('end', self.epilogue.bind(self));
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-List.prototype = new F;
-List.prototype.constructor = List;
-
-
-}); // module: reporters/list.js
-
-require.register("reporters/markdown.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , utils = require('../utils');
-
-/**
- * Constants
- */
-
-var SUITE_PREFIX = '$';
-
-/**
- * Expose `Markdown`.
- */
-
-exports = module.exports = Markdown;
-
-/**
- * Initialize a new `Markdown` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Markdown(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , level = 0
- , buf = '';
-
- function title(str) {
- return Array(level).join('#') + ' ' + str;
- }
-
- function indent() {
- return Array(level).join(' ');
- }
-
- function mapTOC(suite, obj) {
- var ret = obj,
- key = SUITE_PREFIX + suite.title;
- obj = obj[key] = obj[key] || { suite: suite };
- suite.suites.forEach(function(suite){
- mapTOC(suite, obj);
- });
- return ret;
- }
-
- function stringifyTOC(obj, level) {
- ++level;
- var buf = '';
- var link;
- for (var key in obj) {
- if ('suite' == key) continue;
- if (key !== SUITE_PREFIX) {
- link = ' - [' + key.substring(1) + ']';
- link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
- buf += Array(level).join(' ') + link;
- }
- buf += stringifyTOC(obj[key], level);
- }
- return buf;
- }
-
- function generateTOC(suite) {
- var obj = mapTOC(suite, {});
- return stringifyTOC(obj, 0);
- }
-
- generateTOC(runner.suite);
-
- runner.on('suite', function(suite){
- ++level;
- var slug = utils.slug(suite.fullTitle());
- buf += ' ' + '\n';
- buf += title(suite.title) + '\n';
- });
-
- runner.on('suite end', function(suite){
- --level;
- });
-
- runner.on('pass', function(test){
- var code = utils.clean(test.fn.toString());
- buf += test.title + '.\n';
- buf += '\n```js\n';
- buf += code + '\n';
- buf += '```\n\n';
- });
-
- runner.on('end', function(){
- process.stdout.write('# TOC\n');
- process.stdout.write(generateTOC(runner.suite));
- process.stdout.write(buf);
- });
-}
-
-}); // module: reporters/markdown.js
-
-require.register("reporters/min.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base');
-
-/**
- * Expose `Min`.
- */
-
-exports = module.exports = Min;
-
-/**
- * Initialize a new `Min` minimal test reporter (best used with --watch).
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Min(runner) {
- Base.call(this, runner);
-
- runner.on('start', function(){
- // clear screen
- process.stdout.write('\u001b[2J');
- // set cursor position
- process.stdout.write('\u001b[1;3H');
- });
-
- runner.on('end', this.epilogue.bind(this));
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-Min.prototype = new F;
-Min.prototype.constructor = Min;
-
-
-}); // module: reporters/min.js
-
-require.register("reporters/nyan.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base');
-
-/**
- * Expose `Dot`.
- */
-
-exports = module.exports = NyanCat;
-
-/**
- * Initialize a new `Dot` matrix test reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function NyanCat(runner) {
- Base.call(this, runner);
- var self = this
- , stats = this.stats
- , width = Base.window.width * .75 | 0
- , rainbowColors = this.rainbowColors = self.generateColors()
- , colorIndex = this.colorIndex = 0
- , numerOfLines = this.numberOfLines = 4
- , trajectories = this.trajectories = [[], [], [], []]
- , nyanCatWidth = this.nyanCatWidth = 11
- , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
- , scoreboardWidth = this.scoreboardWidth = 5
- , tick = this.tick = 0
- , n = 0;
-
- runner.on('start', function(){
- Base.cursor.hide();
- self.draw();
- });
-
- runner.on('pending', function(test){
- self.draw();
- });
-
- runner.on('pass', function(test){
- self.draw();
- });
-
- runner.on('fail', function(test, err){
- self.draw();
- });
-
- runner.on('end', function(){
- Base.cursor.show();
- for (var i = 0; i < self.numberOfLines; i++) write('\n');
- self.epilogue();
- });
-}
-
-/**
- * Draw the nyan cat
- *
- * @api private
- */
-
-NyanCat.prototype.draw = function(){
- this.appendRainbow();
- this.drawScoreboard();
- this.drawRainbow();
- this.drawNyanCat();
- this.tick = !this.tick;
-};
-
-/**
- * Draw the "scoreboard" showing the number
- * of passes, failures and pending tests.
- *
- * @api private
- */
-
-NyanCat.prototype.drawScoreboard = function(){
- var stats = this.stats;
-
- function draw(type, n) {
- write(' ');
- write(Base.color(type, n));
- write('\n');
- }
-
- draw('green', stats.passes);
- draw('fail', stats.failures);
- draw('pending', stats.pending);
- write('\n');
-
- this.cursorUp(this.numberOfLines);
-};
-
-/**
- * Append the rainbow.
- *
- * @api private
- */
-
-NyanCat.prototype.appendRainbow = function(){
- var segment = this.tick ? '_' : '-';
- var rainbowified = this.rainbowify(segment);
-
- for (var index = 0; index < this.numberOfLines; index++) {
- var trajectory = this.trajectories[index];
- if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift();
- trajectory.push(rainbowified);
- }
-};
-
-/**
- * Draw the rainbow.
- *
- * @api private
- */
-
-NyanCat.prototype.drawRainbow = function(){
- var self = this;
-
- this.trajectories.forEach(function(line, index) {
- write('\u001b[' + self.scoreboardWidth + 'C');
- write(line.join(''));
- write('\n');
- });
-
- this.cursorUp(this.numberOfLines);
-};
-
-/**
- * Draw the nyan cat
- *
- * @api private
- */
-
-NyanCat.prototype.drawNyanCat = function() {
- var self = this;
- var startWidth = this.scoreboardWidth + this.trajectories[0].length;
- var dist = '\u001b[' + startWidth + 'C';
- var padding = '';
-
- write(dist);
- write('_,------,');
- write('\n');
-
- write(dist);
- padding = self.tick ? ' ' : ' ';
- write('_|' + padding + '/\\_/\\ ');
- write('\n');
-
- write(dist);
- padding = self.tick ? '_' : '__';
- var tail = self.tick ? '~' : '^';
- var face;
- write(tail + '|' + padding + this.face() + ' ');
- write('\n');
-
- write(dist);
- padding = self.tick ? ' ' : ' ';
- write(padding + '"" "" ');
- write('\n');
-
- this.cursorUp(this.numberOfLines);
-};
-
-/**
- * Draw nyan cat face.
- *
- * @return {String}
- * @api private
- */
-
-NyanCat.prototype.face = function() {
- var stats = this.stats;
- if (stats.failures) {
- return '( x .x)';
- } else if (stats.pending) {
- return '( o .o)';
- } else if(stats.passes) {
- return '( ^ .^)';
- } else {
- return '( - .-)';
- }
-};
-
-/**
- * Move cursor up `n`.
- *
- * @param {Number} n
- * @api private
- */
-
-NyanCat.prototype.cursorUp = function(n) {
- write('\u001b[' + n + 'A');
-};
-
-/**
- * Move cursor down `n`.
- *
- * @param {Number} n
- * @api private
- */
-
-NyanCat.prototype.cursorDown = function(n) {
- write('\u001b[' + n + 'B');
-};
-
-/**
- * Generate rainbow colors.
- *
- * @return {Array}
- * @api private
- */
-
-NyanCat.prototype.generateColors = function(){
- var colors = [];
-
- for (var i = 0; i < (6 * 7); i++) {
- var pi3 = Math.floor(Math.PI / 3);
- var n = (i * (1.0 / 6));
- var r = Math.floor(3 * Math.sin(n) + 3);
- var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
- var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
- colors.push(36 * r + 6 * g + b + 16);
- }
-
- return colors;
-};
-
-/**
- * Apply rainbow to the given `str`.
- *
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-NyanCat.prototype.rainbowify = function(str){
- if (!Base.useColors)
- return str;
- var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
- this.colorIndex += 1;
- return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
-};
-
-/**
- * Stdout helper.
- */
-
-function write(string) {
- process.stdout.write(string);
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-NyanCat.prototype = new F;
-NyanCat.prototype.constructor = NyanCat;
-
-
-}); // module: reporters/nyan.js
-
-require.register("reporters/progress.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `Progress`.
- */
-
-exports = module.exports = Progress;
-
-/**
- * General progress bar color.
- */
-
-Base.colors.progress = 90;
-
-/**
- * Initialize a new `Progress` bar test reporter.
- *
- * @param {Runner} runner
- * @param {Object} options
- * @api public
- */
-
-function Progress(runner, options) {
- Base.call(this, runner);
-
- var self = this
- , options = options || {}
- , stats = this.stats
- , width = Base.window.width * .50 | 0
- , total = runner.total
- , complete = 0
- , max = Math.max
- , lastN = -1;
-
- // default chars
- options.open = options.open || '[';
- options.complete = options.complete || 'â–¬';
- options.incomplete = options.incomplete || Base.symbols.dot;
- options.close = options.close || ']';
- options.verbose = false;
-
- // tests started
- runner.on('start', function(){
- console.log();
- cursor.hide();
- });
-
- // tests complete
- runner.on('test end', function(){
- complete++;
- var incomplete = total - complete
- , percent = complete / total
- , n = width * percent | 0
- , i = width - n;
-
- if (lastN === n && !options.verbose) {
- // Don't re-render the line if it hasn't changed
- return;
- }
- lastN = n;
-
- cursor.CR();
- process.stdout.write('\u001b[J');
- process.stdout.write(color('progress', ' ' + options.open));
- process.stdout.write(Array(n).join(options.complete));
- process.stdout.write(Array(i).join(options.incomplete));
- process.stdout.write(color('progress', options.close));
- if (options.verbose) {
- process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
- }
- });
-
- // tests are complete, output some stats
- // and the failures if any
- runner.on('end', function(){
- cursor.show();
- console.log();
- self.epilogue();
- });
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-Progress.prototype = new F;
-Progress.prototype.constructor = Progress;
-
-
-}); // module: reporters/progress.js
-
-require.register("reporters/spec.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `Spec`.
- */
-
-exports = module.exports = Spec;
-
-/**
- * Initialize a new `Spec` test reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function Spec(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , indents = 0
- , n = 0;
-
- function indent() {
- return Array(indents).join(' ')
- }
-
- runner.on('start', function(){
- console.log();
- });
-
- runner.on('suite', function(suite){
- ++indents;
- console.log(color('suite', '%s%s'), indent(), suite.title);
- });
-
- runner.on('suite end', function(suite){
- --indents;
- if (1 == indents) console.log();
- });
-
- runner.on('pending', function(test){
- var fmt = indent() + color('pending', ' - %s');
- console.log(fmt, test.title);
- });
-
- runner.on('pass', function(test){
- if ('fast' == test.speed) {
- var fmt = indent()
- + color('checkmark', ' ' + Base.symbols.ok)
- + color('pass', ' %s');
- cursor.CR();
- console.log(fmt, test.title);
- } else {
- var fmt = indent()
- + color('checkmark', ' ' + Base.symbols.ok)
- + color('pass', ' %s')
- + color(test.speed, ' (%dms)');
- cursor.CR();
- console.log(fmt, test.title, test.duration);
- }
- });
-
- runner.on('fail', function(test, err){
- cursor.CR();
- console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
- });
-
- runner.on('end', self.epilogue.bind(self));
-}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-Spec.prototype = new F;
-Spec.prototype.constructor = Spec;
-
-
-}); // module: reporters/spec.js
-
-require.register("reporters/tap.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , cursor = Base.cursor
- , color = Base.color;
-
-/**
- * Expose `TAP`.
- */
-
-exports = module.exports = TAP;
-
-/**
- * Initialize a new `TAP` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function TAP(runner) {
- Base.call(this, runner);
-
- var self = this
- , stats = this.stats
- , n = 1
- , passes = 0
- , failures = 0;
-
- runner.on('start', function(){
- var total = runner.grepTotal(runner.suite);
- console.log('%d..%d', 1, total);
- });
-
- runner.on('test end', function(){
- ++n;
- });
-
- runner.on('pending', function(test){
- console.log('ok %d %s # SKIP -', n, title(test));
- });
-
- runner.on('pass', function(test){
- passes++;
- console.log('ok %d %s', n, title(test));
- });
-
- runner.on('fail', function(test, err){
- failures++;
- console.log('not ok %d %s', n, title(test));
- if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
- });
-
- runner.on('end', function(){
- console.log('# tests ' + (passes + failures));
- console.log('# pass ' + passes);
- console.log('# fail ' + failures);
- });
-}
-
-/**
- * Return a TAP-safe title of `test`
- *
- * @param {Object} test
- * @return {String}
- * @api private
- */
-
-function title(test) {
- return test.fullTitle().replace(/#/g, '');
-}
-
-}); // module: reporters/tap.js
-
-require.register("reporters/xunit.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Base = require('./base')
- , utils = require('../utils')
- , fs = require('browser/fs')
- , escape = utils.escape;
-
-/**
- * Save timer references to avoid Sinon interfering (see GH-237).
- */
-
-var Date = global.Date
- , setTimeout = global.setTimeout
- , setInterval = global.setInterval
- , clearTimeout = global.clearTimeout
- , clearInterval = global.clearInterval;
-
-/**
- * Expose `XUnit`.
- */
-
-exports = module.exports = XUnit;
-
-/**
- * Initialize a new `XUnit` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
-
-function XUnit(runner, options) {
- Base.call(this, runner);
- var stats = this.stats
- , tests = []
- , self = this;
-
- if (options.reporterOptions && options.reporterOptions.output) {
- if (! fs.createWriteStream) {
- throw new Error('file output not supported in browser');
- }
- self.fileStream = fs.createWriteStream(options.reporterOptions.output);
- }
-
- runner.on('pending', function(test){
- tests.push(test);
- });
-
- runner.on('pass', function(test){
- tests.push(test);
- });
-
- runner.on('fail', function(test){
- tests.push(test);
- });
-
- runner.on('end', function(){
- self.write(tag('testsuite', {
- name: 'Mocha Tests'
- , tests: stats.tests
- , failures: stats.failures
- , errors: stats.failures
- , skipped: stats.tests - stats.failures - stats.passes
- , timestamp: (new Date).toUTCString()
- , time: (stats.duration / 1000) || 0
- }, false));
-
- tests.forEach(function(t) { self.test(t); });
- self.write('');
- });
-}
-
-/**
- * Override done to close the stream (if it's a file).
- */
-XUnit.prototype.done = function(failures, fn) {
- if (this.fileStream) {
- this.fileStream.end(function() {
- fn(failures);
- });
- } else {
- fn(failures);
- }
-};
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-function F(){};
-F.prototype = Base.prototype;
-XUnit.prototype = new F;
-XUnit.prototype.constructor = XUnit;
-
-
-/**
- * Write out the given line
- */
-XUnit.prototype.write = function(line) {
- if (this.fileStream) {
- this.fileStream.write(line + '\n');
- } else {
- console.log(line);
- }
-};
-
-/**
- * Output tag for the given `test.`
- */
-
-XUnit.prototype.test = function(test, ostream) {
- var attrs = {
- classname: test.parent.fullTitle()
- , name: test.title
- , time: (test.duration / 1000) || 0
- };
-
- if ('failed' == test.state) {
- var err = test.err;
- this.write(tag('testcase', attrs, false, tag('failure', {}, false, cdata(escape(err.message) + "\n" + err.stack))));
- } else if (test.pending) {
- this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
- } else {
- this.write(tag('testcase', attrs, true) );
- }
-};
-
-/**
- * HTML tag helper.
- */
-
-function tag(name, attrs, close, content) {
- var end = close ? '/>' : '>'
- , pairs = []
- , tag;
-
- for (var key in attrs) {
- pairs.push(key + '="' + escape(attrs[key]) + '"');
- }
-
- tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
- if (content) tag += content + '' + name + end;
- return tag;
-}
-
-/**
- * Return cdata escaped CDATA `str`.
- */
-
-function cdata(str) {
- return '';
-}
-
-}); // module: reporters/xunit.js
-
-require.register("runnable.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var EventEmitter = require('browser/events').EventEmitter
- , debug = require('browser/debug')('mocha:runnable')
- , Pending = require('./pending')
- , milliseconds = require('./ms')
- , utils = require('./utils');
-
-/**
- * Save timer references to avoid Sinon interfering (see GH-237).
- */
-
-var Date = global.Date
- , setTimeout = global.setTimeout
- , setInterval = global.setInterval
- , clearTimeout = global.clearTimeout
- , clearInterval = global.clearInterval;
-
-/**
- * Object#toString().
- */
-
-var toString = Object.prototype.toString;
-
-/**
- * Expose `Runnable`.
- */
-
-module.exports = Runnable;
-
-/**
- * Initialize a new `Runnable` with the given `title` and callback `fn`.
- *
- * @param {String} title
- * @param {Function} fn
- * @api private
- */
-
-function Runnable(title, fn) {
- this.title = title;
- this.fn = fn;
- this.async = fn && fn.length;
- this.sync = ! this.async;
- this._timeout = 2000;
- this._slow = 75;
- this._enableTimeouts = true;
- this.timedOut = false;
- this._trace = new Error('done() called multiple times')
-}
-
-/**
- * Inherit from `EventEmitter.prototype`.
- */
-
-function F(){};
-F.prototype = EventEmitter.prototype;
-Runnable.prototype = new F;
-Runnable.prototype.constructor = Runnable;
-
-
-/**
- * Set & get timeout `ms`.
- *
- * @param {Number|String} ms
- * @return {Runnable|Number} ms or self
- * @api private
- */
-
-Runnable.prototype.timeout = function(ms){
- if (0 == arguments.length) return this._timeout;
- if (ms === 0) this._enableTimeouts = false;
- if ('string' == typeof ms) ms = milliseconds(ms);
- debug('timeout %d', ms);
- this._timeout = ms;
- if (this.timer) this.resetTimeout();
- return this;
-};
-
-/**
- * Set & get slow `ms`.
- *
- * @param {Number|String} ms
- * @return {Runnable|Number} ms or self
- * @api private
- */
-
-Runnable.prototype.slow = function(ms){
- if (0 === arguments.length) return this._slow;
- if ('string' == typeof ms) ms = milliseconds(ms);
- debug('timeout %d', ms);
- this._slow = ms;
- return this;
-};
-
-/**
- * Set and & get timeout `enabled`.
- *
- * @param {Boolean} enabled
- * @return {Runnable|Boolean} enabled or self
- * @api private
- */
-
-Runnable.prototype.enableTimeouts = function(enabled){
- if (arguments.length === 0) return this._enableTimeouts;
- debug('enableTimeouts %s', enabled);
- this._enableTimeouts = enabled;
- return this;
-};
-
-/**
- * Halt and mark as pending.
- *
- * @api private
- */
-
-Runnable.prototype.skip = function(){
- throw new Pending();
-};
-
-/**
- * Return the full title generated by recursively
- * concatenating the parent's full title.
- *
- * @return {String}
- * @api public
- */
-
-Runnable.prototype.fullTitle = function(){
- return this.parent.fullTitle() + ' ' + this.title;
-};
-
-/**
- * Clear the timeout.
- *
- * @api private
- */
-
-Runnable.prototype.clearTimeout = function(){
- clearTimeout(this.timer);
-};
-
-/**
- * Inspect the runnable void of private properties.
- *
- * @return {String}
- * @api private
- */
-
-Runnable.prototype.inspect = function(){
- return JSON.stringify(this, function(key, val){
- if ('_' == key[0]) return;
- if ('parent' == key) return '#';
- if ('ctx' == key) return '#';
- return val;
- }, 2);
-};
-
-/**
- * Reset the timeout.
- *
- * @api private
- */
-
-Runnable.prototype.resetTimeout = function(){
- var self = this;
- var ms = this.timeout() || 1e9;
-
- if (!this._enableTimeouts) return;
- this.clearTimeout();
- this.timer = setTimeout(function(){
- if (!self._enableTimeouts) return;
- self.callback(new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.'));
- self.timedOut = true;
- }, ms);
-};
-
-/**
- * Whitelist these globals for this test run
- *
- * @api private
- */
-Runnable.prototype.globals = function(arr){
- var self = this;
- this._allowedGlobals = arr;
-};
-
-/**
- * Run the test and invoke `fn(err)`.
- *
- * @param {Function} fn
- * @api private
- */
-
-Runnable.prototype.run = function(fn){
- var self = this
- , start = new Date
- , ctx = this.ctx
- , finished
- , emitted;
-
- // Some times the ctx exists but it is not runnable
- if (ctx && ctx.runnable) ctx.runnable(this);
-
- // called multiple times
- function multiple(err) {
- if (emitted) return;
- emitted = true;
- self.emit('error', err || new Error('done() called multiple times; stacktrace may be inaccurate'));
- }
-
- // finished
- function done(err) {
- var ms = self.timeout();
- if (self.timedOut) return;
- if (finished) return multiple(err || self._trace);
-
- // Discard the resolution if this test has already failed asynchronously
- if (self.state) return;
-
- self.clearTimeout();
- self.duration = new Date - start;
- finished = true;
- if (!err && self.duration > ms && self._enableTimeouts) err = new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.');
- fn(err);
- }
-
- // for .resetTimeout()
- this.callback = done;
-
- // explicit async with `done` argument
- if (this.async) {
- this.resetTimeout();
-
- try {
- this.fn.call(ctx, function(err){
- if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);
- if (null != err) {
- if (Object.prototype.toString.call(err) === '[object Object]') {
- return done(new Error('done() invoked with non-Error: ' + JSON.stringify(err)));
- } else {
- return done(new Error('done() invoked with non-Error: ' + err));
- }
- }
- done();
- });
- } catch (err) {
- done(utils.getError(err));
- }
- return;
- }
-
- if (this.asyncOnly) {
- return done(new Error('--async-only option in use without declaring `done()`'));
- }
-
- // sync or promise-returning
- try {
- if (this.pending) {
- done();
- } else {
- callFn(this.fn);
- }
- } catch (err) {
- done(utils.getError(err));
- }
-
- function callFn(fn) {
- var result = fn.call(ctx);
- if (result && typeof result.then === 'function') {
- self.resetTimeout();
- result
- .then(function() {
- done()
- },
- function(reason) {
- done(reason || new Error('Promise rejected with no or falsy reason'))
- });
- } else {
- done();
- }
- }
-};
-
-}); // module: runnable.js
-
-require.register("runner.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var EventEmitter = require('browser/events').EventEmitter
- , debug = require('browser/debug')('mocha:runner')
- , Pending = require('./pending')
- , Test = require('./test')
- , utils = require('./utils')
- , filter = utils.filter
- , keys = utils.keys
- , type = utils.type
- , stringify = utils.stringify
- , stackFilter = utils.stackTraceFilter();
-
-/**
- * Non-enumerable globals.
- */
-
-var globals = [
- 'setTimeout',
- 'clearTimeout',
- 'setInterval',
- 'clearInterval',
- 'XMLHttpRequest',
- 'Date',
- 'setImmediate',
- 'clearImmediate'
-];
-
-/**
- * Expose `Runner`.
- */
-
-module.exports = Runner;
-
-/**
- * Initialize a `Runner` for the given `suite`.
- *
- * Events:
- *
- * - `start` execution started
- * - `end` execution complete
- * - `suite` (suite) test suite execution started
- * - `suite end` (suite) all tests (and sub-suites) have finished
- * - `test` (test) test execution started
- * - `test end` (test) test completed
- * - `hook` (hook) hook execution started
- * - `hook end` (hook) hook complete
- * - `pass` (test) test passed
- * - `fail` (test, err) test failed
- * - `pending` (test) test pending
- *
- * @param {Suite} suite Root suite
- * @param {boolean} [delay] Whether or not to delay execution of root suite
- * until ready.
- * @api public
- */
-
-function Runner(suite, delay) {
- var self = this;
- this._globals = [];
- this._abort = false;
- this._delay = delay;
- this.suite = suite;
- this.total = suite.total();
- this.failures = 0;
- this.on('test end', function(test){ self.checkGlobals(test); });
- this.on('hook end', function(hook){ self.checkGlobals(hook); });
- this.grep(/.*/);
- this.globals(this.globalProps().concat(extraGlobals()));
-}
-
-/**
- * Wrapper for setImmediate, process.nextTick, or browser polyfill.
- *
- * @param {Function} fn
- * @api private
- */
-
-Runner.immediately = global.setImmediate || process.nextTick;
-
-/**
- * Inherit from `EventEmitter.prototype`.
- */
-
-function F(){};
-F.prototype = EventEmitter.prototype;
-Runner.prototype = new F;
-Runner.prototype.constructor = Runner;
-
-
-/**
- * Run tests with full titles matching `re`. Updates runner.total
- * with number of tests matched.
- *
- * @param {RegExp} re
- * @param {Boolean} invert
- * @return {Runner} for chaining
- * @api public
- */
-
-Runner.prototype.grep = function(re, invert){
- debug('grep %s', re);
- this._grep = re;
- this._invert = invert;
- this.total = this.grepTotal(this.suite);
- return this;
-};
-
-/**
- * Returns the number of tests matching the grep search for the
- * given suite.
- *
- * @param {Suite} suite
- * @return {Number}
- * @api public
- */
-
-Runner.prototype.grepTotal = function(suite) {
- var self = this;
- var total = 0;
-
- suite.eachTest(function(test){
- var match = self._grep.test(test.fullTitle());
- if (self._invert) match = !match;
- if (match) total++;
- });
-
- return total;
-};
-
-/**
- * Return a list of global properties.
- *
- * @return {Array}
- * @api private
- */
-
-Runner.prototype.globalProps = function() {
- var props = utils.keys(global);
-
- // non-enumerables
- for (var i = 0; i < globals.length; ++i) {
- if (~utils.indexOf(props, globals[i])) continue;
- props.push(globals[i]);
- }
-
- return props;
-};
-
-/**
- * Allow the given `arr` of globals.
- *
- * @param {Array} arr
- * @return {Runner} for chaining
- * @api public
- */
-
-Runner.prototype.globals = function(arr){
- if (0 == arguments.length) return this._globals;
- debug('globals %j', arr);
- this._globals = this._globals.concat(arr);
- return this;
-};
-
-/**
- * Check for global variable leaks.
- *
- * @api private
- */
-
-Runner.prototype.checkGlobals = function(test){
- if (this.ignoreLeaks) return;
- var ok = this._globals;
-
- var globals = this.globalProps();
- var leaks;
-
- if (test) {
- ok = ok.concat(test._allowedGlobals || []);
- }
-
- if(this.prevGlobalsLength == globals.length) return;
- this.prevGlobalsLength = globals.length;
-
- leaks = filterLeaks(ok, globals);
- this._globals = this._globals.concat(leaks);
-
- if (leaks.length > 1) {
- this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
- } else if (leaks.length) {
- this.fail(test, new Error('global leak detected: ' + leaks[0]));
- }
-};
-
-/**
- * Fail the given `test`.
- *
- * @param {Test} test
- * @param {Error} err
- * @api private
- */
-
-Runner.prototype.fail = function(test, err) {
- ++this.failures;
- test.state = 'failed';
-
- if (!(err instanceof Error)) {
- err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
- }
-
- err.stack = (this.fullStackTrace || !err.stack)
- ? err.stack
- : stackFilter(err.stack);
-
- this.emit('fail', test, err);
-};
-
-/**
- * Fail the given `hook` with `err`.
- *
- * Hook failures work in the following pattern:
- * - If bail, then exit
- * - Failed `before` hook skips all tests in a suite and subsuites,
- * but jumps to corresponding `after` hook
- * - Failed `before each` hook skips remaining tests in a
- * suite and jumps to corresponding `after each` hook,
- * which is run only once
- * - Failed `after` hook does not alter
- * execution order
- * - Failed `after each` hook skips remaining tests in a
- * suite and subsuites, but executes other `after each`
- * hooks
- *
- * @param {Hook} hook
- * @param {Error} err
- * @api private
- */
-
-Runner.prototype.failHook = function(hook, err){
- this.fail(hook, err);
- if (this.suite.bail()) {
- this.emit('end');
- }
-};
-
-/**
- * Run hook `name` callbacks and then invoke `fn()`.
- *
- * @param {String} name
- * @param {Function} function
- * @api private
- */
-
-Runner.prototype.hook = function(name, fn){
- var suite = this.suite
- , hooks = suite['_' + name]
- , self = this
- , timer;
-
- function next(i) {
- var hook = hooks[i];
- if (!hook) return fn();
- self.currentRunnable = hook;
-
- hook.ctx.currentTest = self.test;
-
- self.emit('hook', hook);
-
- hook.on('error', function(err){
- self.failHook(hook, err);
- });
-
- hook.run(function(err){
- hook.removeAllListeners('error');
- var testError = hook.error();
- if (testError) self.fail(self.test, testError);
- if (err) {
- if (err instanceof Pending) {
- suite.pending = true;
- } else {
- self.failHook(hook, err);
-
- // stop executing hooks, notify callee of hook err
- return fn(err);
- }
- }
- self.emit('hook end', hook);
- delete hook.ctx.currentTest;
- next(++i);
- });
- }
-
- Runner.immediately(function(){
- next(0);
- });
-};
-
-/**
- * Run hook `name` for the given array of `suites`
- * in order, and callback `fn(err, errSuite)`.
- *
- * @param {String} name
- * @param {Array} suites
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.hooks = function(name, suites, fn){
- var self = this
- , orig = this.suite;
-
- function next(suite) {
- self.suite = suite;
-
- if (!suite) {
- self.suite = orig;
- return fn();
- }
-
- self.hook(name, function(err){
- if (err) {
- var errSuite = self.suite;
- self.suite = orig;
- return fn(err, errSuite);
- }
-
- next(suites.pop());
- });
- }
-
- next(suites.pop());
-};
-
-/**
- * Run hooks from the top level down.
- *
- * @param {String} name
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.hookUp = function(name, fn){
- var suites = [this.suite].concat(this.parents()).reverse();
- this.hooks(name, suites, fn);
-};
-
-/**
- * Run hooks from the bottom up.
- *
- * @param {String} name
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.hookDown = function(name, fn){
- var suites = [this.suite].concat(this.parents());
- this.hooks(name, suites, fn);
-};
-
-/**
- * Return an array of parent Suites from
- * closest to furthest.
- *
- * @return {Array}
- * @api private
- */
-
-Runner.prototype.parents = function(){
- var suite = this.suite
- , suites = [];
- while (suite = suite.parent) suites.push(suite);
- return suites;
-};
-
-/**
- * Run the current test and callback `fn(err)`.
- *
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.runTest = function(fn){
- var test = this.test
- , self = this;
-
- if (this.asyncOnly) test.asyncOnly = true;
-
- try {
- test.on('error', function(err){
- self.fail(test, err);
- });
- test.run(fn);
- } catch (err) {
- fn(err);
- }
-};
-
-/**
- * Run tests in the given `suite` and invoke
- * the callback `fn()` when complete.
- *
- * @param {Suite} suite
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.runTests = function(suite, fn){
- var self = this
- , tests = suite.tests.slice()
- , test;
-
-
- function hookErr(err, errSuite, after) {
- // before/after Each hook for errSuite failed:
- var orig = self.suite;
-
- // for failed 'after each' hook start from errSuite parent,
- // otherwise start from errSuite itself
- self.suite = after ? errSuite.parent : errSuite;
-
- if (self.suite) {
- // call hookUp afterEach
- self.hookUp('afterEach', function(err2, errSuite2) {
- self.suite = orig;
- // some hooks may fail even now
- if (err2) return hookErr(err2, errSuite2, true);
- // report error suite
- fn(errSuite);
- });
- } else {
- // there is no need calling other 'after each' hooks
- self.suite = orig;
- fn(errSuite);
- }
- }
-
- function next(err, errSuite) {
- // if we bail after first err
- if (self.failures && suite._bail) return fn();
-
- if (self._abort) return fn();
-
- if (err) return hookErr(err, errSuite, true);
-
- // next test
- test = tests.shift();
-
- // all done
- if (!test) return fn();
-
- // grep
- var match = self._grep.test(test.fullTitle());
- if (self._invert) match = !match;
- if (!match) return next();
-
- // pending
- if (test.pending) {
- self.emit('pending', test);
- self.emit('test end', test);
- return next();
- }
-
- // execute test and hook(s)
- self.emit('test', self.test = test);
- self.hookDown('beforeEach', function(err, errSuite){
-
- if (suite.pending) {
- self.emit('pending', test);
- self.emit('test end', test);
- return next();
- }
- if (err) return hookErr(err, errSuite, false);
-
- self.currentRunnable = self.test;
- self.runTest(function(err){
- test = self.test;
-
- if (err) {
- if (err instanceof Pending) {
- self.emit('pending', test);
- } else {
- self.fail(test, err);
- }
- self.emit('test end', test);
-
- if (err instanceof Pending) {
- return next();
- }
-
- return self.hookUp('afterEach', next);
- }
-
- test.state = 'passed';
- self.emit('pass', test);
- self.emit('test end', test);
- self.hookUp('afterEach', next);
- });
- });
- }
-
- this.next = next;
- next();
-};
-
-/**
- * Run the given `suite` and invoke the
- * callback `fn()` when complete.
- *
- * @param {Suite} suite
- * @param {Function} fn
- * @api private
- */
-
-Runner.prototype.runSuite = function(suite, fn){
- var total = this.grepTotal(suite)
- , self = this
- , i = 0;
-
- debug('run suite %s', suite.fullTitle());
-
- if (!total) return fn();
-
- this.emit('suite', this.suite = suite);
-
- function next(errSuite) {
- if (errSuite) {
- // current suite failed on a hook from errSuite
- if (errSuite == suite) {
- // if errSuite is current suite
- // continue to the next sibling suite
- return done();
- } else {
- // errSuite is among the parents of current suite
- // stop execution of errSuite and all sub-suites
- return done(errSuite);
- }
- }
-
- if (self._abort) return done();
-
- var curr = suite.suites[i++];
- if (!curr) return done();
- self.runSuite(curr, next);
- }
-
- function done(errSuite) {
- self.suite = suite;
- self.hook('afterAll', function(){
- self.emit('suite end', suite);
- fn(errSuite);
- });
- }
-
- this.hook('beforeAll', function(err){
- if (err) return done();
- self.runTests(suite, next);
- });
-};
-
-/**
- * Handle uncaught exceptions.
- *
- * @param {Error} err
- * @api private
- */
-
-Runner.prototype.uncaught = function(err){
- if (err) {
- debug('uncaught exception %s', err !== function () {
- return this;
- }.call(err) ? err : ( err.message || err ));
- } else {
- debug('uncaught undefined exception');
- err = utils.undefinedError();
- }
- err.uncaught = true;
-
- var runnable = this.currentRunnable;
- if (!runnable) return;
-
- runnable.clearTimeout();
-
- // Ignore errors if complete
- if (runnable.state) return;
- this.fail(runnable, err);
-
- // recover from test
- if ('test' == runnable.type) {
- this.emit('test end', runnable);
- this.hookUp('afterEach', this.next);
- return;
- }
-
- // bail on hooks
- this.emit('end');
-};
-
-/**
- * Run the root suite and invoke `fn(failures)`
- * on completion.
- *
- * @param {Function} fn
- * @return {Runner} for chaining
- * @api public
- */
-
-Runner.prototype.run = function(fn){
- var self = this,
- rootSuite = this.suite;
-
- fn = fn || function(){};
-
- function uncaught(err){
- self.uncaught(err);
- }
-
- function start() {
- self.emit('start');
- self.runSuite(rootSuite, function(){
- debug('finished running');
- self.emit('end');
- });
- }
-
- debug('start');
-
- // callback
- this.on('end', function(){
- debug('end');
- process.removeListener('uncaughtException', uncaught);
- fn(self.failures);
- });
-
- // uncaught exception
- process.on('uncaughtException', uncaught);
-
- if (this._delay) {
- // for reporters, I guess.
- // might be nice to debounce some dots while we wait.
- this.emit('waiting', rootSuite);
- rootSuite.once('run', start);
- }
- else {
- start();
- }
-
- return this;
-};
-
-/**
- * Cleanly abort execution
- *
- * @return {Runner} for chaining
- * @api public
- */
-Runner.prototype.abort = function(){
- debug('aborting');
- this._abort = true;
-};
-
-/**
- * Filter leaks with the given globals flagged as `ok`.
- *
- * @param {Array} ok
- * @param {Array} globals
- * @return {Array}
- * @api private
- */
-
-function filterLeaks(ok, globals) {
- return filter(globals, function(key){
- // Firefox and Chrome exposes iframes as index inside the window object
- if (/^d+/.test(key)) return false;
-
- // in firefox
- // if runner runs in an iframe, this iframe's window.getInterface method not init at first
- // it is assigned in some seconds
- if (global.navigator && /^getInterface/.test(key)) return false;
-
- // an iframe could be approached by window[iframeIndex]
- // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
- if (global.navigator && /^\d+/.test(key)) return false;
-
- // Opera and IE expose global variables for HTML element IDs (issue #243)
- if (/^mocha-/.test(key)) return false;
-
- var matched = filter(ok, function(ok){
- if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
- return key == ok;
- });
- return matched.length == 0 && (!global.navigator || 'onerror' !== key);
- });
-}
-
-/**
- * Array of globals dependent on the environment.
- *
- * @return {Array}
- * @api private
- */
-
-function extraGlobals() {
- if (typeof(process) === 'object' &&
- typeof(process.version) === 'string') {
-
- var nodeVersion = process.version.split('.').reduce(function(a, v) {
- return a << 8 | v;
- });
-
- // 'errno' was renamed to process._errno in v0.9.11.
-
- if (nodeVersion < 0x00090B) {
- return ['errno'];
- }
- }
-
- return [];
-}
-
-}); // module: runner.js
-
-require.register("suite.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var EventEmitter = require('browser/events').EventEmitter
- , debug = require('browser/debug')('mocha:suite')
- , milliseconds = require('./ms')
- , utils = require('./utils')
- , Hook = require('./hook');
-
-/**
- * Expose `Suite`.
- */
-
-exports = module.exports = Suite;
-
-/**
- * Create a new `Suite` with the given `title`
- * and parent `Suite`. When a suite with the
- * same title is already present, that suite
- * is returned to provide nicer reporter
- * and more flexible meta-testing.
- *
- * @param {Suite} parent
- * @param {String} title
- * @return {Suite}
- * @api public
- */
-
-exports.create = function(parent, title){
- var suite = new Suite(title, parent.ctx);
- suite.parent = parent;
- if (parent.pending) suite.pending = true;
- title = suite.fullTitle();
- parent.addSuite(suite);
- return suite;
-};
-
-/**
- * Initialize a new `Suite` with the given
- * `title` and `ctx`.
- *
- * @param {String} title
- * @param {Context} ctx
- * @api private
- */
-
-function Suite(title, parentContext) {
- this.title = title;
- var context = function() {};
- context.prototype = parentContext;
- this.ctx = new context();
- this.suites = [];
- this.tests = [];
- this.pending = false;
- this._beforeEach = [];
- this._beforeAll = [];
- this._afterEach = [];
- this._afterAll = [];
- this.root = !title;
- this._timeout = 2000;
- this._enableTimeouts = true;
- this._slow = 75;
- this._bail = false;
- this.delayed = false;
-}
-
-/**
- * Inherit from `EventEmitter.prototype`.
- */
-
-function F(){};
-F.prototype = EventEmitter.prototype;
-Suite.prototype = new F;
-Suite.prototype.constructor = Suite;
-
-
-/**
- * Return a clone of this `Suite`.
- *
- * @return {Suite}
- * @api private
- */
-
-Suite.prototype.clone = function(){
- var suite = new Suite(this.title);
- debug('clone');
- suite.ctx = this.ctx;
- suite.timeout(this.timeout());
- suite.enableTimeouts(this.enableTimeouts());
- suite.slow(this.slow());
- suite.bail(this.bail());
- return suite;
-};
-
-/**
- * Set timeout `ms` or short-hand such as "2s".
- *
- * @param {Number|String} ms
- * @return {Suite|Number} for chaining
- * @api private
- */
-
-Suite.prototype.timeout = function(ms){
- if (0 == arguments.length) return this._timeout;
- if (ms.toString() === '0') this._enableTimeouts = false;
- if ('string' == typeof ms) ms = milliseconds(ms);
- debug('timeout %d', ms);
- this._timeout = parseInt(ms, 10);
- return this;
-};
-
-/**
- * Set timeout `enabled`.
- *
- * @param {Boolean} enabled
- * @return {Suite|Boolean} self or enabled
- * @api private
- */
-
-Suite.prototype.enableTimeouts = function(enabled){
- if (arguments.length === 0) return this._enableTimeouts;
- debug('enableTimeouts %s', enabled);
- this._enableTimeouts = enabled;
- return this;
-};
-
-/**
- * Set slow `ms` or short-hand such as "2s".
- *
- * @param {Number|String} ms
- * @return {Suite|Number} for chaining
- * @api private
- */
-
-Suite.prototype.slow = function(ms){
- if (0 === arguments.length) return this._slow;
- if ('string' == typeof ms) ms = milliseconds(ms);
- debug('slow %d', ms);
- this._slow = ms;
- return this;
-};
-
-/**
- * Sets whether to bail after first error.
- *
- * @param {Boolean} bail
- * @return {Suite|Number} for chaining
- * @api private
- */
-
-Suite.prototype.bail = function(bail){
- if (0 == arguments.length) return this._bail;
- debug('bail %s', bail);
- this._bail = bail;
- return this;
-};
-
-/**
- * Run `fn(test[, done])` before running tests.
- *
- * @param {Function} fn
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.beforeAll = function(title, fn){
- if (this.pending) return this;
- if ('function' === typeof title) {
- fn = title;
- title = fn.name;
- }
- title = '"before all" hook' + (title ? ': ' + title : '');
-
- var hook = new Hook(title, fn);
- hook.parent = this;
- hook.timeout(this.timeout());
- hook.enableTimeouts(this.enableTimeouts());
- hook.slow(this.slow());
- hook.ctx = this.ctx;
- this._beforeAll.push(hook);
- this.emit('beforeAll', hook);
- return this;
-};
-
-/**
- * Run `fn(test[, done])` after running tests.
- *
- * @param {Function} fn
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.afterAll = function(title, fn){
- if (this.pending) return this;
- if ('function' === typeof title) {
- fn = title;
- title = fn.name;
- }
- title = '"after all" hook' + (title ? ': ' + title : '');
-
- var hook = new Hook(title, fn);
- hook.parent = this;
- hook.timeout(this.timeout());
- hook.enableTimeouts(this.enableTimeouts());
- hook.slow(this.slow());
- hook.ctx = this.ctx;
- this._afterAll.push(hook);
- this.emit('afterAll', hook);
- return this;
-};
-
-/**
- * Run `fn(test[, done])` before each test case.
- *
- * @param {Function} fn
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.beforeEach = function(title, fn){
- if (this.pending) return this;
- if ('function' === typeof title) {
- fn = title;
- title = fn.name;
- }
- title = '"before each" hook' + (title ? ': ' + title : '');
-
- var hook = new Hook(title, fn);
- hook.parent = this;
- hook.timeout(this.timeout());
- hook.enableTimeouts(this.enableTimeouts());
- hook.slow(this.slow());
- hook.ctx = this.ctx;
- this._beforeEach.push(hook);
- this.emit('beforeEach', hook);
- return this;
-};
-
-/**
- * Run `fn(test[, done])` after each test case.
- *
- * @param {Function} fn
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.afterEach = function(title, fn){
- if (this.pending) return this;
- if ('function' === typeof title) {
- fn = title;
- title = fn.name;
- }
- title = '"after each" hook' + (title ? ': ' + title : '');
-
- var hook = new Hook(title, fn);
- hook.parent = this;
- hook.timeout(this.timeout());
- hook.enableTimeouts(this.enableTimeouts());
- hook.slow(this.slow());
- hook.ctx = this.ctx;
- this._afterEach.push(hook);
- this.emit('afterEach', hook);
- return this;
-};
-
-/**
- * Add a test `suite`.
- *
- * @param {Suite} suite
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.addSuite = function(suite){
- suite.parent = this;
- suite.timeout(this.timeout());
- suite.enableTimeouts(this.enableTimeouts());
- suite.slow(this.slow());
- suite.bail(this.bail());
- this.suites.push(suite);
- this.emit('suite', suite);
- return this;
-};
-
-/**
- * Add a `test` to this suite.
- *
- * @param {Test} test
- * @return {Suite} for chaining
- * @api private
- */
-
-Suite.prototype.addTest = function(test){
- test.parent = this;
- test.timeout(this.timeout());
- test.enableTimeouts(this.enableTimeouts());
- test.slow(this.slow());
- test.ctx = this.ctx;
- this.tests.push(test);
- this.emit('test', test);
- return this;
-};
-
-/**
- * Return the full title generated by recursively
- * concatenating the parent's full title.
- *
- * @return {String}
- * @api public
- */
-
-Suite.prototype.fullTitle = function(){
- if (this.parent) {
- var full = this.parent.fullTitle();
- if (full) return full + ' ' + this.title;
- }
- return this.title;
-};
-
-/**
- * Return the total number of tests.
- *
- * @return {Number}
- * @api public
- */
-
-Suite.prototype.total = function(){
- return utils.reduce(this.suites, function(sum, suite){
- return sum + suite.total();
- }, 0) + this.tests.length;
-};
-
-/**
- * Iterates through each suite recursively to find
- * all tests. Applies a function in the format
- * `fn(test)`.
- *
- * @param {Function} fn
- * @return {Suite}
- * @api private
- */
-
-Suite.prototype.eachTest = function(fn){
- utils.forEach(this.tests, fn);
- utils.forEach(this.suites, function(suite){
- suite.eachTest(fn);
- });
- return this;
-};
-
-/**
- * This will run the root suite if we happen to be running in delayed mode.
- */
-Suite.prototype.run = function run() {
- if (this.root) {
- this.emit('run');
- }
-};
-
-}); // module: suite.js
-
-require.register("test.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var Runnable = require('./runnable');
-
-/**
- * Expose `Test`.
- */
-
-module.exports = Test;
-
-/**
- * Initialize a new `Test` with the given `title` and callback `fn`.
- *
- * @param {String} title
- * @param {Function} fn
- * @api private
- */
-
-function Test(title, fn) {
- Runnable.call(this, title, fn);
- this.pending = !fn;
- this.type = 'test';
-}
-
-/**
- * Inherit from `Runnable.prototype`.
- */
-
-function F(){};
-F.prototype = Runnable.prototype;
-Test.prototype = new F;
-Test.prototype.constructor = Test;
-
-
-}); // module: test.js
-
-require.register("utils.js", function(module, exports, require){
-/**
- * Module dependencies.
- */
-
-var fs = require('browser/fs')
- , path = require('browser/path')
- , basename = path.basename
- , exists = fs.existsSync || path.existsSync
- , glob = require('browser/glob')
- , join = path.join
- , debug = require('browser/debug')('mocha:watch');
-
-/**
- * Ignored directories.
- */
-
-var ignore = ['node_modules', '.git'];
-
-/**
- * Escape special characters in the given string of html.
- *
- * @param {String} html
- * @return {String}
- * @api private
- */
-
-exports.escape = function(html){
- return String(html)
- .replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(//g, '>');
-};
-
-/**
- * Array#forEach (<=IE8)
- *
- * @param {Array} array
- * @param {Function} fn
- * @param {Object} scope
- * @api private
- */
-
-exports.forEach = function(arr, fn, scope){
- for (var i = 0, l = arr.length; i < l; i++)
- fn.call(scope, arr[i], i);
-};
-
-/**
- * Array#map (<=IE8)
- *
- * @param {Array} array
- * @param {Function} fn
- * @param {Object} scope
- * @api private
- */
-
-exports.map = function(arr, fn, scope){
- var result = [];
- for (var i = 0, l = arr.length; i < l; i++)
- result.push(fn.call(scope, arr[i], i, arr));
- return result;
-};
-
-/**
- * Array#indexOf (<=IE8)
- *
- * @parma {Array} arr
- * @param {Object} obj to find index of
- * @param {Number} start
- * @api private
- */
-
-exports.indexOf = function(arr, obj, start){
- for (var i = start || 0, l = arr.length; i < l; i++) {
- if (arr[i] === obj)
- return i;
- }
- return -1;
-};
-
-/**
- * Array#reduce (<=IE8)
- *
- * @param {Array} array
- * @param {Function} fn
- * @param {Object} initial value
- * @api private
- */
-
-exports.reduce = function(arr, fn, val){
- var rval = val;
-
- for (var i = 0, l = arr.length; i < l; i++) {
- rval = fn(rval, arr[i], i, arr);
- }
-
- return rval;
-};
-
-/**
- * Array#filter (<=IE8)
- *
- * @param {Array} array
- * @param {Function} fn
- * @api private
- */
-
-exports.filter = function(arr, fn){
- var ret = [];
-
- for (var i = 0, l = arr.length; i < l; i++) {
- var val = arr[i];
- if (fn(val, i, arr)) ret.push(val);
- }
-
- return ret;
-};
-
-/**
- * Object.keys (<=IE8)
- *
- * @param {Object} obj
- * @return {Array} keys
- * @api private
- */
-
-exports.keys = Object.keys || function(obj) {
- var keys = []
- , has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
-
- for (var key in obj) {
- if (has.call(obj, key)) {
- keys.push(key);
- }
- }
-
- return keys;
-};
-
-/**
- * Watch the given `files` for changes
- * and invoke `fn(file)` on modification.
- *
- * @param {Array} files
- * @param {Function} fn
- * @api private
- */
-
-exports.watch = function(files, fn){
- var options = { interval: 100 };
- files.forEach(function(file){
- debug('file %s', file);
- fs.watchFile(file, options, function(curr, prev){
- if (prev.mtime < curr.mtime) fn(file);
- });
- });
-};
-
-/**
- * Array.isArray (<=IE8)
- *
- * @param {Object} obj
- * @return {Boolean}
- * @api private
- */
-var isArray = Array.isArray || function (obj) {
- return '[object Array]' == {}.toString.call(obj);
-};
-
-/**
- * @description
- * Buffer.prototype.toJSON polyfill
- * @type {Function}
- */
-if(typeof Buffer !== 'undefined' && Buffer.prototype) {
- Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
- return Array.prototype.slice.call(this, 0);
- };
-}
-
-/**
- * Ignored files.
- */
-
-function ignored(path){
- return !~ignore.indexOf(path);
-}
-
-/**
- * Lookup files in the given `dir`.
- *
- * @return {Array}
- * @api private
- */
-
-exports.files = function(dir, ext, ret){
- ret = ret || [];
- ext = ext || ['js'];
-
- var re = new RegExp('\\.(' + ext.join('|') + ')$');
-
- fs.readdirSync(dir)
- .filter(ignored)
- .forEach(function(path){
- path = join(dir, path);
- if (fs.statSync(path).isDirectory()) {
- exports.files(path, ext, ret);
- } else if (path.match(re)) {
- ret.push(path);
- }
- });
-
- return ret;
-};
-
-/**
- * Compute a slug from the given `str`.
- *
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-exports.slug = function(str){
- return str
- .toLowerCase()
- .replace(/ +/g, '-')
- .replace(/[^-\w]/g, '');
-};
-
-/**
- * Strip the function definition from `str`,
- * and re-indent for pre whitespace.
- */
-
-exports.clean = function(str) {
- str = str
- .replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
- .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
- .replace(/\s+\}$/, '');
-
- var spaces = str.match(/^\n?( *)/)[1].length
- , tabs = str.match(/^\n?(\t*)/)[1].length
- , re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
-
- str = str.replace(re, '');
-
- return exports.trim(str);
-};
-
-/**
- * Trim the given `str`.
- *
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-exports.trim = function(str){
- return str.replace(/^\s+|\s+$/g, '');
-};
-
-/**
- * Parse the given `qs`.
- *
- * @param {String} qs
- * @return {Object}
- * @api private
- */
-
-exports.parseQuery = function(qs){
- return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
- var i = pair.indexOf('=')
- , key = pair.slice(0, i)
- , val = pair.slice(++i);
-
- obj[key] = decodeURIComponent(val);
- return obj;
- }, {});
-};
-
-/**
- * Highlight the given string of `js`.
- *
- * @param {String} js
- * @return {String}
- * @api private
- */
-
-function highlight(js) {
- return js
- .replace(//g, '>')
- .replace(/\/\/(.*)/gm, '')
- .replace(/('.*?')/gm, '$1 ')
- .replace(/(\d+\.\d+)/gm, '$1 ')
- .replace(/(\d+)/gm, '$1 ')
- .replace(/\bnew[ \t]+(\w+)/gm, 'new $1 ')
- .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '$1 ')
-}
-
-/**
- * Highlight the contents of tag `name`.
- *
- * @param {String} name
- * @api private
- */
-
-exports.highlightTags = function(name) {
- var code = document.getElementById('mocha').getElementsByTagName(name);
- for (var i = 0, len = code.length; i < len; ++i) {
- code[i].innerHTML = highlight(code[i].innerHTML);
- }
-};
-
-/**
- * If a value could have properties, and has none, this function is called, which returns
- * a string representation of the empty value.
- *
- * Functions w/ no properties return `'[Function]'`
- * Arrays w/ length === 0 return `'[]'`
- * Objects w/ no properties return `'{}'`
- * All else: return result of `value.toString()`
- *
- * @param {*} value Value to inspect
- * @param {string} [type] The type of the value, if known.
- * @returns {string}
- */
-var emptyRepresentation = function emptyRepresentation(value, type) {
- type = type || exports.type(value);
-
- switch(type) {
- case 'function':
- return '[Function]';
- case 'object':
- return '{}';
- case 'array':
- return '[]';
- default:
- return value.toString();
- }
-};
-
-/**
- * Takes some variable and asks `{}.toString()` what it thinks it is.
- * @param {*} value Anything
- * @example
- * type({}) // 'object'
- * type([]) // 'array'
- * type(1) // 'number'
- * type(false) // 'boolean'
- * type(Infinity) // 'number'
- * type(null) // 'null'
- * type(new Date()) // 'date'
- * type(/foo/) // 'regexp'
- * type('type') // 'string'
- * type(global) // 'global'
- * @api private
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
- * @returns {string}
- */
-exports.type = function type(value) {
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
- return 'buffer';
- }
- return Object.prototype.toString.call(value)
- .replace(/^\[.+\s(.+?)\]$/, '$1')
- .toLowerCase();
-};
-
-/**
- * @summary Stringify `value`.
- * @description Different behavior depending on type of value.
- * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
- * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
- * - If `value` is an *empty* object, function, or array, return result of function
- * {@link emptyRepresentation}.
- * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
- * JSON.stringify().
- *
- * @see exports.type
- * @param {*} value
- * @return {string}
- * @api private
- */
-
-exports.stringify = function(value) {
- var type = exports.type(value);
-
- if (!~exports.indexOf(['object', 'array', 'function'], type)) {
- if(type != 'buffer') {
- return jsonStringify(value);
- }
- var json = value.toJSON();
- // Based on the toJSON result
- return jsonStringify(json.data && json.type ? json.data : json, 2)
- .replace(/,(\n|$)/g, '$1');
- }
-
- for (var prop in value) {
- if (Object.prototype.hasOwnProperty.call(value, prop)) {
- return jsonStringify(exports.canonicalize(value), 2).replace(/,(\n|$)/g, '$1');
- }
- }
-
- return emptyRepresentation(value, type);
-};
-
-/**
- * @description
- * like JSON.stringify but more sense.
- * @param {Object} object
- * @param {Number=} spaces
- * @param {number=} depth
- * @returns {*}
- * @private
- */
-function jsonStringify(object, spaces, depth) {
- if(typeof spaces == 'undefined') return _stringify(object); // primitive types
-
- depth = depth || 1;
- var space = spaces * depth
- , str = isArray(object) ? '[' : '{'
- , end = isArray(object) ? ']' : '}'
- , length = object.length || exports.keys(object).length
- , repeat = function(s, n) { return new Array(n).join(s); }; // `.repeat()` polyfill
-
- function _stringify(val) {
- switch (exports.type(val)) {
- case 'null':
- case 'undefined':
- val = '[' + val + ']';
- break;
- case 'array':
- case 'object':
- val = jsonStringify(val, spaces, depth + 1);
- break;
- case 'boolean':
- case 'regexp':
- case 'number':
- val = val === 0 && (1/val) === -Infinity // `-0`
- ? '-0'
- : val.toString();
- break;
- case 'date':
- val = '[Date: ' + val.toISOString() + ']';
- break;
- case 'buffer':
- var json = val.toJSON();
- // Based on the toJSON result
- json = json.data && json.type ? json.data : json;
- val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
- break;
- default:
- val = (val == '[Function]' || val == '[Circular]')
- ? val
- : '"' + val + '"'; //string
- }
- return val;
- }
-
- for(var i in object) {
- if(!object.hasOwnProperty(i)) continue; // not my business
- --length;
- str += '\n ' + repeat(' ', space)
- + (isArray(object) ? '' : '"' + i + '": ') // key
- + _stringify(object[i]) // value
- + (length ? ',' : ''); // comma
- }
-
- return str + (str.length != 1 // [], {}
- ? '\n' + repeat(' ', --space) + end
- : end);
-}
-
-/**
- * Return if obj is a Buffer
- * @param {Object} arg
- * @return {Boolean}
- * @api private
- */
-exports.isBuffer = function (arg) {
- return typeof Buffer !== 'undefined' && Buffer.isBuffer(arg);
-};
-
-/**
- * @summary Return a new Thing that has the keys in sorted order. Recursive.
- * @description If the Thing...
- * - has already been seen, return string `'[Circular]'`
- * - is `undefined`, return string `'[undefined]'`
- * - is `null`, return value `null`
- * - is some other primitive, return the value
- * - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
- * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
- * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
- *
- * @param {*} value Thing to inspect. May or may not have properties.
- * @param {Array} [stack=[]] Stack of seen values
- * @return {(Object|Array|Function|string|undefined)}
- * @see {@link exports.stringify}
- * @api private
- */
-
-exports.canonicalize = function(value, stack) {
- var canonicalizedObj,
- type = exports.type(value),
- prop,
- withStack = function withStack(value, fn) {
- stack.push(value);
- fn();
- stack.pop();
- };
-
- stack = stack || [];
-
- if (exports.indexOf(stack, value) !== -1) {
- return '[Circular]';
- }
-
- switch(type) {
- case 'undefined':
- case 'buffer':
- case 'null':
- canonicalizedObj = value;
- break;
- case 'array':
- withStack(value, function () {
- canonicalizedObj = exports.map(value, function (item) {
- return exports.canonicalize(item, stack);
- });
- });
- break;
- case 'function':
- for (prop in value) {
- canonicalizedObj = {};
- break;
- }
- if (!canonicalizedObj) {
- canonicalizedObj = emptyRepresentation(value, type);
- break;
- }
- /* falls through */
- case 'object':
- canonicalizedObj = canonicalizedObj || {};
- withStack(value, function () {
- exports.forEach(exports.keys(value).sort(), function (key) {
- canonicalizedObj[key] = exports.canonicalize(value[key], stack);
- });
- });
- break;
- case 'date':
- case 'number':
- case 'regexp':
- case 'boolean':
- canonicalizedObj = value;
- break;
- default:
- canonicalizedObj = value.toString();
- }
-
- return canonicalizedObj;
-};
-
-/**
- * Lookup file names at the given `path`.
- */
-exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
- var files = [];
- var re = new RegExp('\\.(' + extensions.join('|') + ')$');
-
- if (!exists(path)) {
- if (exists(path + '.js')) {
- path += '.js';
- } else {
- files = glob.sync(path);
- if (!files.length) throw new Error("cannot resolve path (or pattern) '" + path + "'");
- return files;
- }
- }
-
- try {
- var stat = fs.statSync(path);
- if (stat.isFile()) return path;
- }
- catch (ignored) {
- return;
- }
-
- fs.readdirSync(path).forEach(function(file) {
- file = join(path, file);
- try {
- var stat = fs.statSync(file);
- if (stat.isDirectory()) {
- if (recursive) {
- files = files.concat(lookupFiles(file, extensions, recursive));
- }
- return;
- }
- }
- catch (ignored) {
- return;
- }
- if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') return;
- files.push(file);
- });
-
- return files;
-};
-
-/**
- * Generate an undefined error with a message warning the user.
- *
- * @return {Error}
- */
-
-exports.undefinedError = function() {
- return new Error('Caught undefined error, did you throw without specifying what?');
-};
-
-/**
- * Generate an undefined error if `err` is not defined.
- *
- * @param {Error} err
- * @return {Error}
- */
-
-exports.getError = function(err) {
- return err || exports.undefinedError();
-};
-
-
-/**
- * @summary
- * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
- * @description
- * When invoking this function you get a filter function that get the Error.stack as an input,
- * and return a prettify output.
- * (i.e: strip Mocha, node_modules, bower and componentJS from stack trace).
- * @returns {Function}
- */
-
-exports.stackTraceFilter = function() {
- var slash = '/'
- , is = typeof document === 'undefined'
- ? { node: true }
- : { browser: true }
- , cwd = is.node
- ? process.cwd() + slash
- : location.href.replace(/\/[^\/]*$/, '/');
-
- function isNodeModule (line) {
- return (~line.indexOf('node_modules'));
- }
-
- function isMochaInternal (line) {
- return (~line.indexOf('node_modules' + slash + 'mocha')) ||
- (~line.indexOf('components' + slash + 'mochajs')) ||
- (~line.indexOf('components' + slash + 'mocha'));
- }
-
- // node_modules, bower, componentJS
- function isBrowserModule(line) {
- return (~line.indexOf('node_modules')) ||
- (~line.indexOf('components'));
- }
-
- function isNodeInternal (line) {
- return (~line.indexOf('(timers.js:')) ||
- (~line.indexOf('(events.js:')) ||
- (~line.indexOf('(node.js:')) ||
- (~line.indexOf('(module.js:')) ||
- (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
- false
- }
-
- return function(stack) {
- stack = stack.split('\n');
-
- stack = exports.reduce(stack, function(list, line) {
- if (is.node && (isNodeModule(line) ||
- isMochaInternal(line) ||
- isNodeInternal(line)))
- return list;
-
- if (is.browser && (isBrowserModule(line)))
- return list;
-
- // Clean up cwd(absolute)
- list.push(line.replace(cwd, ''));
- return list;
- }, []);
-
- return stack.join('\n');
- }
-};
-}); // module: utils.js
-// The global object is "self" in Web Workers.
-var global = (function() { return this; })();
-
-/**
- * Save timer references to avoid Sinon interfering (see GH-237).
- */
-
-var Date = global.Date;
-var setTimeout = global.setTimeout;
-var setInterval = global.setInterval;
-var clearTimeout = global.clearTimeout;
-var clearInterval = global.clearInterval;
-
-/**
- * Node shims.
- *
- * These are meant only to allow
- * mocha.js to run untouched, not
- * to allow running node code in
- * the browser.
- */
-
-var process = {};
-process.exit = function(status){};
-process.stdout = {};
-
-var uncaughtExceptionHandlers = [];
-
-var originalOnerrorHandler = global.onerror;
-
-/**
- * Remove uncaughtException listener.
- * Revert to original onerror handler if previously defined.
- */
-
-process.removeListener = function(e, fn){
- if ('uncaughtException' == e) {
- if (originalOnerrorHandler) {
- global.onerror = originalOnerrorHandler;
- } else {
- global.onerror = function() {};
- }
- var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
- if (i != -1) { uncaughtExceptionHandlers.splice(i, 1); }
- }
-};
-
-/**
- * Implements uncaughtException listener.
- */
-
-process.on = function(e, fn){
- if ('uncaughtException' == e) {
- global.onerror = function(err, url, line){
- fn(new Error(err + ' (' + url + ':' + line + ')'));
- return true;
- };
- uncaughtExceptionHandlers.push(fn);
- }
-};
-
-/**
- * Expose mocha.
- */
-
-var Mocha = global.Mocha = require('mocha'),
- mocha = global.mocha = new Mocha({ reporter: 'html' });
-
-// The BDD UI is registered by default, but no UI will be functional in the
-// browser without an explicit call to the overridden `mocha.ui` (see below).
-// Ensure that this default UI does not expose its methods to the global scope.
-mocha.suite.removeAllListeners('pre-require');
-
-var immediateQueue = []
- , immediateTimeout;
-
-function timeslice() {
- var immediateStart = new Date().getTime();
- while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
- immediateQueue.shift()();
- }
- if (immediateQueue.length) {
- immediateTimeout = setTimeout(timeslice, 0);
- } else {
- immediateTimeout = null;
- }
-}
-
-/**
- * High-performance override of Runner.immediately.
- */
-
-Mocha.Runner.immediately = function(callback) {
- immediateQueue.push(callback);
- if (!immediateTimeout) {
- immediateTimeout = setTimeout(timeslice, 0);
- }
-};
-
-/**
- * Function to allow assertion libraries to throw errors directly into mocha.
- * This is useful when running tests in a browser because window.onerror will
- * only receive the 'message' attribute of the Error.
- */
-mocha.throwError = function(err) {
- Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
- fn(err);
- });
- throw err;
-};
-
-/**
- * Override ui to ensure that the ui functions are initialized.
- * Normally this would happen in Mocha.prototype.loadFiles.
- */
-
-mocha.ui = function(ui){
- Mocha.prototype.ui.call(this, ui);
- this.suite.emit('pre-require', global, null, this);
- return this;
-};
-
-/**
- * Setup mocha with the given setting options.
- */
-
-mocha.setup = function(opts){
- if ('string' == typeof opts) opts = { ui: opts };
- for (var opt in opts) this[opt](opts[opt]);
- return this;
-};
-
-/**
- * Run mocha, returning the Runner.
- */
-
-mocha.run = function(fn){
- var options = mocha.options;
- mocha.globals('location');
-
- var query = Mocha.utils.parseQuery(global.location.search || '');
- if (query.grep) mocha.grep(new RegExp(query.grep));
- if (query.fgrep) mocha.grep(query.fgrep);
- if (query.invert) mocha.invert();
-
- return Mocha.prototype.run.call(mocha, function(err){
- // The DOM Document is not available in Web Workers.
- var document = global.document;
- if (document && document.getElementById('mocha') && options.noHighlighting !== true) {
- Mocha.utils.highlightTags('code');
- }
- if (fn) fn(err);
- });
-};
-
-/**
- * Expose the process shim.
- */
-
-Mocha.process = process;
-})();
diff --git a/test/vendor/sinon.js b/test/vendor/sinon.js
deleted file mode 100644
index 4ef8edf9..00000000
--- a/test/vendor/sinon.js
+++ /dev/null
@@ -1,6437 +0,0 @@
-/**
- * Sinon.JS 1.17.3, 2016/01/27
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
- *
- * (The BSD License)
- *
- * Copyright (c) 2010-2014, Christian Johansen, christian@cjohansen.no
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of Christian Johansen nor the names of his contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-(function (root, factory) {
- 'use strict';
- if (typeof define === 'function' && define.amd) {
- define('sinon', [], function () {
- return (root.sinon = factory());
- });
- } else if (typeof exports === 'object') {
- module.exports = factory();
- } else {
- root.sinon = factory();
- }
-}(this, function () {
- 'use strict';
- var samsam, formatio, lolex;
- (function () {
- function define(mod, deps, fn) {
- if (mod == "samsam") {
- samsam = deps();
- } else if (typeof deps === "function" && mod.length === 0) {
- lolex = deps();
- } else if (typeof fn === "function") {
- formatio = fn(samsam);
- }
- }
- define.amd = {};
-((typeof define === "function" && define.amd && function (m) { define("samsam", m); }) ||
- (typeof module === "object" &&
- function (m) { module.exports = m(); }) || // Node
- function (m) { this.samsam = m(); } // Browser globals
-)(function () {
- var o = Object.prototype;
- var div = typeof document !== "undefined" && document.createElement("div");
-
- function isNaN(value) {
- // Unlike global isNaN, this avoids type coercion
- // typeof check avoids IE host object issues, hat tip to
- // lodash
- var val = value; // JsLint thinks value !== value is "weird"
- return typeof value === "number" && value !== val;
- }
-
- function getClass(value) {
- // Returns the internal [[Class]] by calling Object.prototype.toString
- // with the provided value as this. Return value is a string, naming the
- // internal class, e.g. "Array"
- return o.toString.call(value).split(/[ \]]/)[1];
- }
-
- /**
- * @name samsam.isArguments
- * @param Object object
- *
- * Returns ``true`` if ``object`` is an ``arguments`` object,
- * ``false`` otherwise.
- */
- function isArguments(object) {
- if (getClass(object) === 'Arguments') { return true; }
- if (typeof object !== "object" || typeof object.length !== "number" ||
- getClass(object) === "Array") {
- return false;
- }
- if (typeof object.callee == "function") { return true; }
- try {
- object[object.length] = 6;
- delete object[object.length];
- } catch (e) {
- return true;
- }
- return false;
- }
-
- /**
- * @name samsam.isElement
- * @param Object object
- *
- * Returns ``true`` if ``object`` is a DOM element node. Unlike
- * Underscore.js/lodash, this function will return ``false`` if ``object``
- * is an *element-like* object, i.e. a regular object with a ``nodeType``
- * property that holds the value ``1``.
- */
- function isElement(object) {
- if (!object || object.nodeType !== 1 || !div) { return false; }
- try {
- object.appendChild(div);
- object.removeChild(div);
- } catch (e) {
- return false;
- }
- return true;
- }
-
- /**
- * @name samsam.keys
- * @param Object object
- *
- * Return an array of own property names.
- */
- function keys(object) {
- var ks = [], prop;
- for (prop in object) {
- if (o.hasOwnProperty.call(object, prop)) { ks.push(prop); }
- }
- return ks;
- }
-
- /**
- * @name samsam.isDate
- * @param Object value
- *
- * Returns true if the object is a ``Date``, or *date-like*. Duck typing
- * of date objects work by checking that the object has a ``getTime``
- * function whose return value equals the return value from the object's
- * ``valueOf``.
- */
- function isDate(value) {
- return typeof value.getTime == "function" &&
- value.getTime() == value.valueOf();
- }
-
- /**
- * @name samsam.isNegZero
- * @param Object value
- *
- * Returns ``true`` if ``value`` is ``-0``.
- */
- function isNegZero(value) {
- return value === 0 && 1 / value === -Infinity;
- }
-
- /**
- * @name samsam.equal
- * @param Object obj1
- * @param Object obj2
- *
- * Returns ``true`` if two objects are strictly equal. Compared to
- * ``===`` there are two exceptions:
- *
- * - NaN is considered equal to NaN
- * - -0 and +0 are not considered equal
- */
- function identical(obj1, obj2) {
- if (obj1 === obj2 || (isNaN(obj1) && isNaN(obj2))) {
- return obj1 !== 0 || isNegZero(obj1) === isNegZero(obj2);
- }
- }
-
-
- /**
- * @name samsam.deepEqual
- * @param Object obj1
- * @param Object obj2
- *
- * Deep equal comparison. Two values are "deep equal" if:
- *
- * - They are equal, according to samsam.identical
- * - They are both date objects representing the same time
- * - They are both arrays containing elements that are all deepEqual
- * - They are objects with the same set of properties, and each property
- * in ``obj1`` is deepEqual to the corresponding property in ``obj2``
- *
- * Supports cyclic objects.
- */
- function deepEqualCyclic(obj1, obj2) {
-
- // used for cyclic comparison
- // contain already visited objects
- var objects1 = [],
- objects2 = [],
- // contain pathes (position in the object structure)
- // of the already visited objects
- // indexes same as in objects arrays
- paths1 = [],
- paths2 = [],
- // contains combinations of already compared objects
- // in the manner: { "$1['ref']$2['ref']": true }
- compared = {};
-
- /**
- * used to check, if the value of a property is an object
- * (cyclic logic is only needed for objects)
- * only needed for cyclic logic
- */
- function isObject(value) {
-
- if (typeof value === 'object' && value !== null &&
- !(value instanceof Boolean) &&
- !(value instanceof Date) &&
- !(value instanceof Number) &&
- !(value instanceof RegExp) &&
- !(value instanceof String)) {
-
- return true;
- }
-
- return false;
- }
-
- /**
- * returns the index of the given object in the
- * given objects array, -1 if not contained
- * only needed for cyclic logic
- */
- function getIndex(objects, obj) {
-
- var i;
- for (i = 0; i < objects.length; i++) {
- if (objects[i] === obj) {
- return i;
- }
- }
-
- return -1;
- }
-
- // does the recursion for the deep equal check
- return (function deepEqual(obj1, obj2, path1, path2) {
- var type1 = typeof obj1;
- var type2 = typeof obj2;
-
- // == null also matches undefined
- if (obj1 === obj2 ||
- isNaN(obj1) || isNaN(obj2) ||
- obj1 == null || obj2 == null ||
- type1 !== "object" || type2 !== "object") {
-
- return identical(obj1, obj2);
- }
-
- // Elements are only equal if identical(expected, actual)
- if (isElement(obj1) || isElement(obj2)) { return false; }
-
- var isDate1 = isDate(obj1), isDate2 = isDate(obj2);
- if (isDate1 || isDate2) {
- if (!isDate1 || !isDate2 || obj1.getTime() !== obj2.getTime()) {
- return false;
- }
- }
-
- if (obj1 instanceof RegExp && obj2 instanceof RegExp) {
- if (obj1.toString() !== obj2.toString()) { return false; }
- }
-
- var class1 = getClass(obj1);
- var class2 = getClass(obj2);
- var keys1 = keys(obj1);
- var keys2 = keys(obj2);
-
- if (isArguments(obj1) || isArguments(obj2)) {
- if (obj1.length !== obj2.length) { return false; }
- } else {
- if (type1 !== type2 || class1 !== class2 ||
- keys1.length !== keys2.length) {
- return false;
- }
- }
-
- var key, i, l,
- // following vars are used for the cyclic logic
- value1, value2,
- isObject1, isObject2,
- index1, index2,
- newPath1, newPath2;
-
- for (i = 0, l = keys1.length; i < l; i++) {
- key = keys1[i];
- if (!o.hasOwnProperty.call(obj2, key)) {
- return false;
- }
-
- // Start of the cyclic logic
-
- value1 = obj1[key];
- value2 = obj2[key];
-
- isObject1 = isObject(value1);
- isObject2 = isObject(value2);
-
- // determine, if the objects were already visited
- // (it's faster to check for isObject first, than to
- // get -1 from getIndex for non objects)
- index1 = isObject1 ? getIndex(objects1, value1) : -1;
- index2 = isObject2 ? getIndex(objects2, value2) : -1;
-
- // determine the new pathes of the objects
- // - for non cyclic objects the current path will be extended
- // by current property name
- // - for cyclic objects the stored path is taken
- newPath1 = index1 !== -1
- ? paths1[index1]
- : path1 + '[' + JSON.stringify(key) + ']';
- newPath2 = index2 !== -1
- ? paths2[index2]
- : path2 + '[' + JSON.stringify(key) + ']';
-
- // stop recursion if current objects are already compared
- if (compared[newPath1 + newPath2]) {
- return true;
- }
-
- // remember the current objects and their pathes
- if (index1 === -1 && isObject1) {
- objects1.push(value1);
- paths1.push(newPath1);
- }
- if (index2 === -1 && isObject2) {
- objects2.push(value2);
- paths2.push(newPath2);
- }
-
- // remember that the current objects are already compared
- if (isObject1 && isObject2) {
- compared[newPath1 + newPath2] = true;
- }
-
- // End of cyclic logic
-
- // neither value1 nor value2 is a cycle
- // continue with next level
- if (!deepEqual(value1, value2, newPath1, newPath2)) {
- return false;
- }
- }
-
- return true;
-
- }(obj1, obj2, '$1', '$2'));
- }
-
- var match;
-
- function arrayContains(array, subset) {
- if (subset.length === 0) { return true; }
- var i, l, j, k;
- for (i = 0, l = array.length; i < l; ++i) {
- if (match(array[i], subset[0])) {
- for (j = 0, k = subset.length; j < k; ++j) {
- if (!match(array[i + j], subset[j])) { return false; }
- }
- return true;
- }
- }
- return false;
- }
-
- /**
- * @name samsam.match
- * @param Object object
- * @param Object matcher
- *
- * Compare arbitrary value ``object`` with matcher.
- */
- match = function match(object, matcher) {
- if (matcher && typeof matcher.test === "function") {
- return matcher.test(object);
- }
-
- if (typeof matcher === "function") {
- return matcher(object) === true;
- }
-
- if (typeof matcher === "string") {
- matcher = matcher.toLowerCase();
- var notNull = typeof object === "string" || !!object;
- return notNull &&
- (String(object)).toLowerCase().indexOf(matcher) >= 0;
- }
-
- if (typeof matcher === "number") {
- return matcher === object;
- }
-
- if (typeof matcher === "boolean") {
- return matcher === object;
- }
-
- if (typeof(matcher) === "undefined") {
- return typeof(object) === "undefined";
- }
-
- if (matcher === null) {
- return object === null;
- }
-
- if (getClass(object) === "Array" && getClass(matcher) === "Array") {
- return arrayContains(object, matcher);
- }
-
- if (matcher && typeof matcher === "object") {
- if (matcher === object) {
- return true;
- }
- var prop;
- for (prop in matcher) {
- var value = object[prop];
- if (typeof value === "undefined" &&
- typeof object.getAttribute === "function") {
- value = object.getAttribute(prop);
- }
- if (matcher[prop] === null || typeof matcher[prop] === 'undefined') {
- if (value !== matcher[prop]) {
- return false;
- }
- } else if (typeof value === "undefined" || !match(value, matcher[prop])) {
- return false;
- }
- }
- return true;
- }
-
- throw new Error("Matcher was not a string, a number, a " +
- "function, a boolean or an object");
- };
-
- return {
- isArguments: isArguments,
- isElement: isElement,
- isDate: isDate,
- isNegZero: isNegZero,
- identical: identical,
- deepEqual: deepEqualCyclic,
- match: match,
- keys: keys
- };
-});
-((typeof define === "function" && define.amd && function (m) {
- define("formatio", ["samsam"], m);
-}) || (typeof module === "object" && function (m) {
- module.exports = m(require("samsam"));
-}) || function (m) { this.formatio = m(this.samsam); }
-)(function (samsam) {
-
- var formatio = {
- excludeConstructors: ["Object", /^.$/],
- quoteStrings: true,
- limitChildrenCount: 0
- };
-
- var hasOwn = Object.prototype.hasOwnProperty;
-
- var specialObjects = [];
- if (typeof global !== "undefined") {
- specialObjects.push({ object: global, value: "[object global]" });
- }
- if (typeof document !== "undefined") {
- specialObjects.push({
- object: document,
- value: "[object HTMLDocument]"
- });
- }
- if (typeof window !== "undefined") {
- specialObjects.push({ object: window, value: "[object Window]" });
- }
-
- function functionName(func) {
- if (!func) { return ""; }
- if (func.displayName) { return func.displayName; }
- if (func.name) { return func.name; }
- var matches = func.toString().match(/function\s+([^\(]+)/m);
- return (matches && matches[1]) || "";
- }
-
- function constructorName(f, object) {
- var name = functionName(object && object.constructor);
- var excludes = f.excludeConstructors ||
- formatio.excludeConstructors || [];
-
- var i, l;
- for (i = 0, l = excludes.length; i < l; ++i) {
- if (typeof excludes[i] === "string" && excludes[i] === name) {
- return "";
- } else if (excludes[i].test && excludes[i].test(name)) {
- return "";
- }
- }
-
- return name;
- }
-
- function isCircular(object, objects) {
- if (typeof object !== "object") { return false; }
- var i, l;
- for (i = 0, l = objects.length; i < l; ++i) {
- if (objects[i] === object) { return true; }
- }
- return false;
- }
-
- function ascii(f, object, processed, indent) {
- if (typeof object === "string") {
- var qs = f.quoteStrings;
- var quote = typeof qs !== "boolean" || qs;
- return processed || quote ? '"' + object + '"' : object;
- }
-
- if (typeof object === "function" && !(object instanceof RegExp)) {
- return ascii.func(object);
- }
-
- processed = processed || [];
-
- if (isCircular(object, processed)) { return "[Circular]"; }
-
- if (Object.prototype.toString.call(object) === "[object Array]") {
- return ascii.array.call(f, object, processed);
- }
-
- if (!object) { return String((1/object) === -Infinity ? "-0" : object); }
- if (samsam.isElement(object)) { return ascii.element(object); }
-
- if (typeof object.toString === "function" &&
- object.toString !== Object.prototype.toString) {
- return object.toString();
- }
-
- var i, l;
- for (i = 0, l = specialObjects.length; i < l; i++) {
- if (object === specialObjects[i].object) {
- return specialObjects[i].value;
- }
- }
-
- return ascii.object.call(f, object, processed, indent);
- }
-
- ascii.func = function (func) {
- return "function " + functionName(func) + "() {}";
- };
-
- ascii.array = function (array, processed) {
- processed = processed || [];
- processed.push(array);
- var pieces = [];
- var i, l;
- l = (this.limitChildrenCount > 0) ?
- Math.min(this.limitChildrenCount, array.length) : array.length;
-
- for (i = 0; i < l; ++i) {
- pieces.push(ascii(this, array[i], processed));
- }
-
- if(l < array.length)
- pieces.push("[... " + (array.length - l) + " more elements]");
-
- return "[" + pieces.join(", ") + "]";
- };
-
- ascii.object = function (object, processed, indent) {
- processed = processed || [];
- processed.push(object);
- indent = indent || 0;
- var pieces = [], properties = samsam.keys(object).sort();
- var length = 3;
- var prop, str, obj, i, k, l;
- l = (this.limitChildrenCount > 0) ?
- Math.min(this.limitChildrenCount, properties.length) : properties.length;
-
- for (i = 0; i < l; ++i) {
- prop = properties[i];
- obj = object[prop];
-
- if (isCircular(obj, processed)) {
- str = "[Circular]";
- } else {
- str = ascii(this, obj, processed, indent + 2);
- }
-
- str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str;
- length += str.length;
- pieces.push(str);
- }
-
- var cons = constructorName(this, object);
- var prefix = cons ? "[" + cons + "] " : "";
- var is = "";
- for (i = 0, k = indent; i < k; ++i) { is += " "; }
-
- if(l < properties.length)
- pieces.push("[... " + (properties.length - l) + " more elements]");
-
- if (length + indent > 80) {
- return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" +
- is + "}";
- }
- return prefix + "{ " + pieces.join(", ") + " }";
- };
-
- ascii.element = function (element) {
- var tagName = element.tagName.toLowerCase();
- var attrs = element.attributes, attr, pairs = [], attrName, i, l, val;
-
- for (i = 0, l = attrs.length; i < l; ++i) {
- attr = attrs.item(i);
- attrName = attr.nodeName.toLowerCase().replace("html:", "");
- val = attr.nodeValue;
- if (attrName !== "contenteditable" || val !== "inherit") {
- if (!!val) { pairs.push(attrName + "=\"" + val + "\""); }
- }
- }
-
- var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
- var content = element.innerHTML;
-
- if (content.length > 20) {
- content = content.substr(0, 20) + "[...]";
- }
-
- var res = formatted + pairs.join(" ") + ">" + content +
- "" + tagName + ">";
-
- return res.replace(/ contentEditable="inherit"/, "");
- };
-
- function Formatio(options) {
- for (var opt in options) {
- this[opt] = options[opt];
- }
- }
-
- Formatio.prototype = {
- functionName: functionName,
-
- configure: function (options) {
- return new Formatio(options);
- },
-
- constructorName: function (object) {
- return constructorName(this, object);
- },
-
- ascii: function (object, processed, indent) {
- return ascii(this, object, processed, indent);
- }
- };
-
- return Formatio.prototype;
-});
-!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.lolex=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
- throw new Error("tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits");
- }
-
- while (i--) {
- parsed = parseInt(strings[i], 10);
-
- if (parsed >= 60) {
- throw new Error("Invalid time " + str);
- }
-
- ms += parsed * Math.pow(60, (l - i - 1));
- }
-
- return ms * 1000;
- }
-
- /**
- * Used to grok the `now` parameter to createClock.
- */
- function getEpoch(epoch) {
- if (!epoch) { return 0; }
- if (typeof epoch.getTime === "function") { return epoch.getTime(); }
- if (typeof epoch === "number") { return epoch; }
- throw new TypeError("now should be milliseconds since UNIX epoch");
- }
-
- function inRange(from, to, timer) {
- return timer && timer.callAt >= from && timer.callAt <= to;
- }
-
- function mirrorDateProperties(target, source) {
- var prop;
- for (prop in source) {
- if (source.hasOwnProperty(prop)) {
- target[prop] = source[prop];
- }
- }
-
- // set special now implementation
- if (source.now) {
- target.now = function now() {
- return target.clock.now;
- };
- } else {
- delete target.now;
- }
-
- // set special toSource implementation
- if (source.toSource) {
- target.toSource = function toSource() {
- return source.toSource();
- };
- } else {
- delete target.toSource;
- }
-
- // set special toString implementation
- target.toString = function toString() {
- return source.toString();
- };
-
- target.prototype = source.prototype;
- target.parse = source.parse;
- target.UTC = source.UTC;
- target.prototype.toUTCString = source.prototype.toUTCString;
-
- return target;
- }
-
- function createDate() {
- function ClockDate(year, month, date, hour, minute, second, ms) {
- // Defensive and verbose to avoid potential harm in passing
- // explicit undefined when user does not pass argument
- switch (arguments.length) {
- case 0:
- return new NativeDate(ClockDate.clock.now);
- case 1:
- return new NativeDate(year);
- case 2:
- return new NativeDate(year, month);
- case 3:
- return new NativeDate(year, month, date);
- case 4:
- return new NativeDate(year, month, date, hour);
- case 5:
- return new NativeDate(year, month, date, hour, minute);
- case 6:
- return new NativeDate(year, month, date, hour, minute, second);
- default:
- return new NativeDate(year, month, date, hour, minute, second, ms);
- }
- }
-
- return mirrorDateProperties(ClockDate, NativeDate);
- }
-
- function addTimer(clock, timer) {
- if (timer.func === undefined) {
- throw new Error("Callback must be provided to timer calls");
- }
-
- if (!clock.timers) {
- clock.timers = {};
- }
-
- timer.id = uniqueTimerId++;
- timer.createdAt = clock.now;
- timer.callAt = clock.now + (timer.delay || (clock.duringTick ? 1 : 0));
-
- clock.timers[timer.id] = timer;
-
- if (addTimerReturnsObject) {
- return {
- id: timer.id,
- ref: NOOP,
- unref: NOOP
- };
- }
-
- return timer.id;
- }
-
-
- function compareTimers(a, b) {
- // Sort first by absolute timing
- if (a.callAt < b.callAt) {
- return -1;
- }
- if (a.callAt > b.callAt) {
- return 1;
- }
-
- // Sort next by immediate, immediate timers take precedence
- if (a.immediate && !b.immediate) {
- return -1;
- }
- if (!a.immediate && b.immediate) {
- return 1;
- }
-
- // Sort next by creation time, earlier-created timers take precedence
- if (a.createdAt < b.createdAt) {
- return -1;
- }
- if (a.createdAt > b.createdAt) {
- return 1;
- }
-
- // Sort next by id, lower-id timers take precedence
- if (a.id < b.id) {
- return -1;
- }
- if (a.id > b.id) {
- return 1;
- }
-
- // As timer ids are unique, no fallback `0` is necessary
- }
-
- function firstTimerInRange(clock, from, to) {
- var timers = clock.timers,
- timer = null,
- id,
- isInRange;
-
- for (id in timers) {
- if (timers.hasOwnProperty(id)) {
- isInRange = inRange(from, to, timers[id]);
-
- if (isInRange && (!timer || compareTimers(timer, timers[id]) === 1)) {
- timer = timers[id];
- }
- }
- }
-
- return timer;
- }
-
- function firstTimer(clock) {
- var timers = clock.timers,
- timer = null,
- id;
-
- for (id in timers) {
- if (timers.hasOwnProperty(id)) {
- if (!timer || compareTimers(timer, timers[id]) === 1) {
- timer = timers[id];
- }
- }
- }
-
- return timer;
- }
-
- function callTimer(clock, timer) {
- var exception;
-
- if (typeof timer.interval === "number") {
- clock.timers[timer.id].callAt += timer.interval;
- } else {
- delete clock.timers[timer.id];
- }
-
- try {
- if (typeof timer.func === "function") {
- timer.func.apply(null, timer.args);
- } else {
- eval(timer.func);
- }
- } catch (e) {
- exception = e;
- }
-
- if (!clock.timers[timer.id]) {
- if (exception) {
- throw exception;
- }
- return;
- }
-
- if (exception) {
- throw exception;
- }
- }
-
- function timerType(timer) {
- if (timer.immediate) {
- return "Immediate";
- } else if (typeof timer.interval !== "undefined") {
- return "Interval";
- } else {
- return "Timeout";
- }
- }
-
- function clearTimer(clock, timerId, ttype) {
- if (!timerId) {
- // null appears to be allowed in most browsers, and appears to be
- // relied upon by some libraries, like Bootstrap carousel
- return;
- }
-
- if (!clock.timers) {
- clock.timers = [];
- }
-
- // in Node, timerId is an object with .ref()/.unref(), and
- // its .id field is the actual timer id.
- if (typeof timerId === "object") {
- timerId = timerId.id;
- }
-
- if (clock.timers.hasOwnProperty(timerId)) {
- // check that the ID matches a timer of the correct type
- var timer = clock.timers[timerId];
- if (timerType(timer) === ttype) {
- delete clock.timers[timerId];
- } else {
- throw new Error("Cannot clear timer: timer created with set" + ttype + "() but cleared with clear" + timerType(timer) + "()");
- }
- }
- }
-
- function uninstall(clock, target) {
- var method,
- i,
- l;
-
- for (i = 0, l = clock.methods.length; i < l; i++) {
- method = clock.methods[i];
-
- if (target[method].hadOwnProperty) {
- target[method] = clock["_" + method];
- } else {
- try {
- delete target[method];
- } catch (ignore) {}
- }
- }
-
- // Prevent multiple executions which will completely remove these props
- clock.methods = [];
- }
-
- function hijackMethod(target, method, clock) {
- var prop;
-
- clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(target, method);
- clock["_" + method] = target[method];
-
- if (method === "Date") {
- var date = mirrorDateProperties(clock[method], target[method]);
- target[method] = date;
- } else {
- target[method] = function () {
- return clock[method].apply(clock, arguments);
- };
-
- for (prop in clock[method]) {
- if (clock[method].hasOwnProperty(prop)) {
- target[method][prop] = clock[method][prop];
- }
- }
- }
-
- target[method].clock = clock;
- }
-
- var timers = {
- setTimeout: setTimeout,
- clearTimeout: clearTimeout,
- setImmediate: global.setImmediate,
- clearImmediate: global.clearImmediate,
- setInterval: setInterval,
- clearInterval: clearInterval,
- Date: Date
- };
-
- var keys = Object.keys || function (obj) {
- var ks = [],
- key;
-
- for (key in obj) {
- if (obj.hasOwnProperty(key)) {
- ks.push(key);
- }
- }
-
- return ks;
- };
-
- exports.timers = timers;
-
- function createClock(now) {
- var clock = {
- now: getEpoch(now),
- timeouts: {},
- Date: createDate()
- };
-
- clock.Date.clock = clock;
-
- clock.setTimeout = function setTimeout(func, timeout) {
- return addTimer(clock, {
- func: func,
- args: Array.prototype.slice.call(arguments, 2),
- delay: timeout
- });
- };
-
- clock.clearTimeout = function clearTimeout(timerId) {
- return clearTimer(clock, timerId, "Timeout");
- };
-
- clock.setInterval = function setInterval(func, timeout) {
- return addTimer(clock, {
- func: func,
- args: Array.prototype.slice.call(arguments, 2),
- delay: timeout,
- interval: timeout
- });
- };
-
- clock.clearInterval = function clearInterval(timerId) {
- return clearTimer(clock, timerId, "Interval");
- };
-
- clock.setImmediate = function setImmediate(func) {
- return addTimer(clock, {
- func: func,
- args: Array.prototype.slice.call(arguments, 1),
- immediate: true
- });
- };
-
- clock.clearImmediate = function clearImmediate(timerId) {
- return clearTimer(clock, timerId, "Immediate");
- };
-
- clock.tick = function tick(ms) {
- ms = typeof ms === "number" ? ms : parseTime(ms);
- var tickFrom = clock.now, tickTo = clock.now + ms, previous = clock.now;
- var timer = firstTimerInRange(clock, tickFrom, tickTo);
- var oldNow;
-
- clock.duringTick = true;
-
- var firstException;
- while (timer && tickFrom <= tickTo) {
- if (clock.timers[timer.id]) {
- tickFrom = clock.now = timer.callAt;
- try {
- oldNow = clock.now;
- callTimer(clock, timer);
- // compensate for any setSystemTime() call during timer callback
- if (oldNow !== clock.now) {
- tickFrom += clock.now - oldNow;
- tickTo += clock.now - oldNow;
- previous += clock.now - oldNow;
- }
- } catch (e) {
- firstException = firstException || e;
- }
- }
-
- timer = firstTimerInRange(clock, previous, tickTo);
- previous = tickFrom;
- }
-
- clock.duringTick = false;
- clock.now = tickTo;
-
- if (firstException) {
- throw firstException;
- }
-
- return clock.now;
- };
-
- clock.next = function next() {
- var timer = firstTimer(clock);
- if (!timer) {
- return clock.now;
- }
-
- clock.duringTick = true;
- try {
- clock.now = timer.callAt;
- callTimer(clock, timer);
- return clock.now;
- } finally {
- clock.duringTick = false;
- }
- };
-
- clock.reset = function reset() {
- clock.timers = {};
- };
-
- clock.setSystemTime = function setSystemTime(now) {
- // determine time difference
- var newNow = getEpoch(now);
- var difference = newNow - clock.now;
-
- // update 'system clock'
- clock.now = newNow;
-
- // update timers and intervals to keep them stable
- for (var id in clock.timers) {
- if (clock.timers.hasOwnProperty(id)) {
- var timer = clock.timers[id];
- timer.createdAt += difference;
- timer.callAt += difference;
- }
- }
- };
-
- return clock;
- }
- exports.createClock = createClock;
-
- exports.install = function install(target, now, toFake) {
- var i,
- l;
-
- if (typeof target === "number") {
- toFake = now;
- now = target;
- target = null;
- }
-
- if (!target) {
- target = global;
- }
-
- var clock = createClock(now);
-
- clock.uninstall = function () {
- uninstall(clock, target);
- };
-
- clock.methods = toFake || [];
-
- if (clock.methods.length === 0) {
- clock.methods = keys(timers);
- }
-
- for (i = 0, l = clock.methods.length; i < l; i++) {
- hijackMethod(target, clock.methods[i], clock);
- }
-
- return clock;
- };
-
-}(global || this));
-
-}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
-},{}]},{},[1])(1)
-});
- })();
- var define;
-/**
- * Sinon core utilities. For internal use only.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-var sinon = (function () {
-"use strict";
- // eslint-disable-line no-unused-vars
-
- var sinonModule;
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- sinonModule = module.exports = require("./sinon/util/core");
- require("./sinon/extend");
- require("./sinon/walk");
- require("./sinon/typeOf");
- require("./sinon/times_in_words");
- require("./sinon/spy");
- require("./sinon/call");
- require("./sinon/behavior");
- require("./sinon/stub");
- require("./sinon/mock");
- require("./sinon/collection");
- require("./sinon/assert");
- require("./sinon/sandbox");
- require("./sinon/test");
- require("./sinon/test_case");
- require("./sinon/match");
- require("./sinon/format");
- require("./sinon/log_error");
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require, module.exports, module);
- sinonModule = module.exports;
- } else {
- sinonModule = {};
- }
-
- return sinonModule;
-}());
-
-/**
- * @depend ../../sinon.js
- */
-/**
- * Sinon core utilities. For internal use only.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- var div = typeof document !== "undefined" && document.createElement("div");
- var hasOwn = Object.prototype.hasOwnProperty;
-
- function isDOMNode(obj) {
- var success = false;
-
- try {
- obj.appendChild(div);
- success = div.parentNode === obj;
- } catch (e) {
- return false;
- } finally {
- try {
- obj.removeChild(div);
- } catch (e) {
- // Remove failed, not much we can do about that
- }
- }
-
- return success;
- }
-
- function isElement(obj) {
- return div && obj && obj.nodeType === 1 && isDOMNode(obj);
- }
-
- function isFunction(obj) {
- return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply);
- }
-
- function isReallyNaN(val) {
- return typeof val === "number" && isNaN(val);
- }
-
- function mirrorProperties(target, source) {
- for (var prop in source) {
- if (!hasOwn.call(target, prop)) {
- target[prop] = source[prop];
- }
- }
- }
-
- function isRestorable(obj) {
- return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon;
- }
-
- // Cheap way to detect if we have ES5 support.
- var hasES5Support = "keys" in Object;
-
- function makeApi(sinon) {
- sinon.wrapMethod = function wrapMethod(object, property, method) {
- if (!object) {
- throw new TypeError("Should wrap property of object");
- }
-
- if (typeof method !== "function" && typeof method !== "object") {
- throw new TypeError("Method wrapper should be a function or a property descriptor");
- }
-
- function checkWrappedMethod(wrappedMethod) {
- var error;
-
- if (!isFunction(wrappedMethod)) {
- error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
- property + " as function");
- } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
- error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
- } else if (wrappedMethod.calledBefore) {
- var verb = wrappedMethod.returns ? "stubbed" : "spied on";
- error = new TypeError("Attempted to wrap " + property + " which is already " + verb);
- }
-
- if (error) {
- if (wrappedMethod && wrappedMethod.stackTrace) {
- error.stack += "\n--------------\n" + wrappedMethod.stackTrace;
- }
- throw error;
- }
- }
-
- var error, wrappedMethod, i;
-
- // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem
- // when using hasOwn.call on objects from other frames.
- var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property);
-
- if (hasES5Support) {
- var methodDesc = (typeof method === "function") ? {value: method} : method;
- var wrappedMethodDesc = sinon.getPropertyDescriptor(object, property);
-
- if (!wrappedMethodDesc) {
- error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
- property + " as function");
- } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) {
- error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
- }
- if (error) {
- if (wrappedMethodDesc && wrappedMethodDesc.stackTrace) {
- error.stack += "\n--------------\n" + wrappedMethodDesc.stackTrace;
- }
- throw error;
- }
-
- var types = sinon.objectKeys(methodDesc);
- for (i = 0; i < types.length; i++) {
- wrappedMethod = wrappedMethodDesc[types[i]];
- checkWrappedMethod(wrappedMethod);
- }
-
- mirrorProperties(methodDesc, wrappedMethodDesc);
- for (i = 0; i < types.length; i++) {
- mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]);
- }
- Object.defineProperty(object, property, methodDesc);
- } else {
- wrappedMethod = object[property];
- checkWrappedMethod(wrappedMethod);
- object[property] = method;
- method.displayName = property;
- }
-
- method.displayName = property;
-
- // Set up a stack trace which can be used later to find what line of
- // code the original method was created on.
- method.stackTrace = (new Error("Stack Trace for original")).stack;
-
- method.restore = function () {
- // For prototype properties try to reset by delete first.
- // If this fails (ex: localStorage on mobile safari) then force a reset
- // via direct assignment.
- if (!owned) {
- // In some cases `delete` may throw an error
- try {
- delete object[property];
- } catch (e) {} // eslint-disable-line no-empty
- // For native code functions `delete` fails without throwing an error
- // on Chrome < 43, PhantomJS, etc.
- } else if (hasES5Support) {
- Object.defineProperty(object, property, wrappedMethodDesc);
- }
-
- // Use strict equality comparison to check failures then force a reset
- // via direct assignment.
- if (object[property] === method) {
- object[property] = wrappedMethod;
- }
- };
-
- method.restore.sinon = true;
-
- if (!hasES5Support) {
- mirrorProperties(method, wrappedMethod);
- }
-
- return method;
- };
-
- sinon.create = function create(proto) {
- var F = function () {};
- F.prototype = proto;
- return new F();
- };
-
- sinon.deepEqual = function deepEqual(a, b) {
- if (sinon.match && sinon.match.isMatcher(a)) {
- return a.test(b);
- }
-
- if (typeof a !== "object" || typeof b !== "object") {
- return isReallyNaN(a) && isReallyNaN(b) || a === b;
- }
-
- if (isElement(a) || isElement(b)) {
- return a === b;
- }
-
- if (a === b) {
- return true;
- }
-
- if ((a === null && b !== null) || (a !== null && b === null)) {
- return false;
- }
-
- if (a instanceof RegExp && b instanceof RegExp) {
- return (a.source === b.source) && (a.global === b.global) &&
- (a.ignoreCase === b.ignoreCase) && (a.multiline === b.multiline);
- }
-
- var aString = Object.prototype.toString.call(a);
- if (aString !== Object.prototype.toString.call(b)) {
- return false;
- }
-
- if (aString === "[object Date]") {
- return a.valueOf() === b.valueOf();
- }
-
- var prop;
- var aLength = 0;
- var bLength = 0;
-
- if (aString === "[object Array]" && a.length !== b.length) {
- return false;
- }
-
- for (prop in a) {
- if (a.hasOwnProperty(prop)) {
- aLength += 1;
-
- if (!(prop in b)) {
- return false;
- }
-
- if (!deepEqual(a[prop], b[prop])) {
- return false;
- }
- }
- }
-
- for (prop in b) {
- if (b.hasOwnProperty(prop)) {
- bLength += 1;
- }
- }
-
- return aLength === bLength;
- };
-
- sinon.functionName = function functionName(func) {
- var name = func.displayName || func.name;
-
- // Use function decomposition as a last resort to get function
- // name. Does not rely on function decomposition to work - if it
- // doesn't debugging will be slightly less informative
- // (i.e. toString will say 'spy' rather than 'myFunc').
- if (!name) {
- var matches = func.toString().match(/function ([^\s\(]+)/);
- name = matches && matches[1];
- }
-
- return name;
- };
-
- sinon.functionToString = function toString() {
- if (this.getCall && this.callCount) {
- var thisValue,
- prop;
- var i = this.callCount;
-
- while (i--) {
- thisValue = this.getCall(i).thisValue;
-
- for (prop in thisValue) {
- if (thisValue[prop] === this) {
- return prop;
- }
- }
- }
- }
-
- return this.displayName || "sinon fake";
- };
-
- sinon.objectKeys = function objectKeys(obj) {
- if (obj !== Object(obj)) {
- throw new TypeError("sinon.objectKeys called on a non-object");
- }
-
- var keys = [];
- var key;
- for (key in obj) {
- if (hasOwn.call(obj, key)) {
- keys.push(key);
- }
- }
-
- return keys;
- };
-
- sinon.getPropertyDescriptor = function getPropertyDescriptor(object, property) {
- var proto = object;
- var descriptor;
-
- while (proto && !(descriptor = Object.getOwnPropertyDescriptor(proto, property))) {
- proto = Object.getPrototypeOf(proto);
- }
- return descriptor;
- };
-
- sinon.getConfig = function (custom) {
- var config = {};
- custom = custom || {};
- var defaults = sinon.defaultConfig;
-
- for (var prop in defaults) {
- if (defaults.hasOwnProperty(prop)) {
- config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop];
- }
- }
-
- return config;
- };
-
- sinon.defaultConfig = {
- injectIntoThis: true,
- injectInto: null,
- properties: ["spy", "stub", "mock", "clock", "server", "requests"],
- useFakeTimers: true,
- useFakeServer: true
- };
-
- sinon.timesInWords = function timesInWords(count) {
- return count === 1 && "once" ||
- count === 2 && "twice" ||
- count === 3 && "thrice" ||
- (count || 0) + " times";
- };
-
- sinon.calledInOrder = function (spies) {
- for (var i = 1, l = spies.length; i < l; i++) {
- if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) {
- return false;
- }
- }
-
- return true;
- };
-
- sinon.orderByFirstCall = function (spies) {
- return spies.sort(function (a, b) {
- // uuid, won't ever be equal
- var aCall = a.getCall(0);
- var bCall = b.getCall(0);
- var aId = aCall && aCall.callId || -1;
- var bId = bCall && bCall.callId || -1;
-
- return aId < bId ? -1 : 1;
- });
- };
-
- sinon.createStubInstance = function (constructor) {
- if (typeof constructor !== "function") {
- throw new TypeError("The constructor should be a function.");
- }
- return sinon.stub(sinon.create(constructor.prototype));
- };
-
- sinon.restore = function (object) {
- if (object !== null && typeof object === "object") {
- for (var prop in object) {
- if (isRestorable(object[prop])) {
- object[prop].restore();
- }
- }
- } else if (isRestorable(object)) {
- object.restore();
- }
- };
-
- return sinon;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports) {
- makeApi(exports);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
-
- // Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
- var hasDontEnumBug = (function () {
- var obj = {
- constructor: function () {
- return "0";
- },
- toString: function () {
- return "1";
- },
- valueOf: function () {
- return "2";
- },
- toLocaleString: function () {
- return "3";
- },
- prototype: function () {
- return "4";
- },
- isPrototypeOf: function () {
- return "5";
- },
- propertyIsEnumerable: function () {
- return "6";
- },
- hasOwnProperty: function () {
- return "7";
- },
- length: function () {
- return "8";
- },
- unique: function () {
- return "9";
- }
- };
-
- var result = [];
- for (var prop in obj) {
- if (obj.hasOwnProperty(prop)) {
- result.push(obj[prop]());
- }
- }
- return result.join("") !== "0123456789";
- })();
-
- /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
- * override properties in previous sources.
- *
- * target - The Object to extend
- * sources - Objects to copy properties from.
- *
- * Returns the extended target
- */
- function extend(target /*, sources */) {
- var sources = Array.prototype.slice.call(arguments, 1);
- var source, i, prop;
-
- for (i = 0; i < sources.length; i++) {
- source = sources[i];
-
- for (prop in source) {
- if (source.hasOwnProperty(prop)) {
- target[prop] = source[prop];
- }
- }
-
- // Make sure we copy (own) toString method even when in JScript with DontEnum bug
- // See https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
- if (hasDontEnumBug && source.hasOwnProperty("toString") && source.toString !== target.toString) {
- target.toString = source.toString;
- }
- }
-
- return target;
- }
-
- sinon.extend = extend;
- return sinon.extend;
- }
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- module.exports = makeApi(sinon);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
-
- function timesInWords(count) {
- switch (count) {
- case 1:
- return "once";
- case 2:
- return "twice";
- case 3:
- return "thrice";
- default:
- return (count || 0) + " times";
- }
- }
-
- sinon.timesInWords = timesInWords;
- return sinon.timesInWords;
- }
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- module.exports = makeApi(core);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- */
-/**
- * Format functions
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2014 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- function typeOf(value) {
- if (value === null) {
- return "null";
- } else if (value === undefined) {
- return "undefined";
- }
- var string = Object.prototype.toString.call(value);
- return string.substring(8, string.length - 1).toLowerCase();
- }
-
- sinon.typeOf = typeOf;
- return sinon.typeOf;
- }
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- module.exports = makeApi(core);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend typeOf.js
- */
-/*jslint eqeqeq: false, onevar: false, plusplus: false*/
-/*global module, require, sinon*/
-/**
- * Match functions
- *
- * @author Maximilian Antoni (mail@maxantoni.de)
- * @license BSD
- *
- * Copyright (c) 2012 Maximilian Antoni
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- function assertType(value, type, name) {
- var actual = sinon.typeOf(value);
- if (actual !== type) {
- throw new TypeError("Expected type of " + name + " to be " +
- type + ", but was " + actual);
- }
- }
-
- var matcher = {
- toString: function () {
- return this.message;
- }
- };
-
- function isMatcher(object) {
- return matcher.isPrototypeOf(object);
- }
-
- function matchObject(expectation, actual) {
- if (actual === null || actual === undefined) {
- return false;
- }
- for (var key in expectation) {
- if (expectation.hasOwnProperty(key)) {
- var exp = expectation[key];
- var act = actual[key];
- if (isMatcher(exp)) {
- if (!exp.test(act)) {
- return false;
- }
- } else if (sinon.typeOf(exp) === "object") {
- if (!matchObject(exp, act)) {
- return false;
- }
- } else if (!sinon.deepEqual(exp, act)) {
- return false;
- }
- }
- }
- return true;
- }
-
- function match(expectation, message) {
- var m = sinon.create(matcher);
- var type = sinon.typeOf(expectation);
- switch (type) {
- case "object":
- if (typeof expectation.test === "function") {
- m.test = function (actual) {
- return expectation.test(actual) === true;
- };
- m.message = "match(" + sinon.functionName(expectation.test) + ")";
- return m;
- }
- var str = [];
- for (var key in expectation) {
- if (expectation.hasOwnProperty(key)) {
- str.push(key + ": " + expectation[key]);
- }
- }
- m.test = function (actual) {
- return matchObject(expectation, actual);
- };
- m.message = "match(" + str.join(", ") + ")";
- break;
- case "number":
- m.test = function (actual) {
- // we need type coercion here
- return expectation == actual; // eslint-disable-line eqeqeq
- };
- break;
- case "string":
- m.test = function (actual) {
- if (typeof actual !== "string") {
- return false;
- }
- return actual.indexOf(expectation) !== -1;
- };
- m.message = "match(\"" + expectation + "\")";
- break;
- case "regexp":
- m.test = function (actual) {
- if (typeof actual !== "string") {
- return false;
- }
- return expectation.test(actual);
- };
- break;
- case "function":
- m.test = expectation;
- if (message) {
- m.message = message;
- } else {
- m.message = "match(" + sinon.functionName(expectation) + ")";
- }
- break;
- default:
- m.test = function (actual) {
- return sinon.deepEqual(expectation, actual);
- };
- }
- if (!m.message) {
- m.message = "match(" + expectation + ")";
- }
- return m;
- }
-
- matcher.or = function (m2) {
- if (!arguments.length) {
- throw new TypeError("Matcher expected");
- } else if (!isMatcher(m2)) {
- m2 = match(m2);
- }
- var m1 = this;
- var or = sinon.create(matcher);
- or.test = function (actual) {
- return m1.test(actual) || m2.test(actual);
- };
- or.message = m1.message + ".or(" + m2.message + ")";
- return or;
- };
-
- matcher.and = function (m2) {
- if (!arguments.length) {
- throw new TypeError("Matcher expected");
- } else if (!isMatcher(m2)) {
- m2 = match(m2);
- }
- var m1 = this;
- var and = sinon.create(matcher);
- and.test = function (actual) {
- return m1.test(actual) && m2.test(actual);
- };
- and.message = m1.message + ".and(" + m2.message + ")";
- return and;
- };
-
- match.isMatcher = isMatcher;
-
- match.any = match(function () {
- return true;
- }, "any");
-
- match.defined = match(function (actual) {
- return actual !== null && actual !== undefined;
- }, "defined");
-
- match.truthy = match(function (actual) {
- return !!actual;
- }, "truthy");
-
- match.falsy = match(function (actual) {
- return !actual;
- }, "falsy");
-
- match.same = function (expectation) {
- return match(function (actual) {
- return expectation === actual;
- }, "same(" + expectation + ")");
- };
-
- match.typeOf = function (type) {
- assertType(type, "string", "type");
- return match(function (actual) {
- return sinon.typeOf(actual) === type;
- }, "typeOf(\"" + type + "\")");
- };
-
- match.instanceOf = function (type) {
- assertType(type, "function", "type");
- return match(function (actual) {
- return actual instanceof type;
- }, "instanceOf(" + sinon.functionName(type) + ")");
- };
-
- function createPropertyMatcher(propertyTest, messagePrefix) {
- return function (property, value) {
- assertType(property, "string", "property");
- var onlyProperty = arguments.length === 1;
- var message = messagePrefix + "(\"" + property + "\"";
- if (!onlyProperty) {
- message += ", " + value;
- }
- message += ")";
- return match(function (actual) {
- if (actual === undefined || actual === null ||
- !propertyTest(actual, property)) {
- return false;
- }
- return onlyProperty || sinon.deepEqual(value, actual[property]);
- }, message);
- };
- }
-
- match.has = createPropertyMatcher(function (actual, property) {
- if (typeof actual === "object") {
- return property in actual;
- }
- return actual[property] !== undefined;
- }, "has");
-
- match.hasOwn = createPropertyMatcher(function (actual, property) {
- return actual.hasOwnProperty(property);
- }, "hasOwn");
-
- match.bool = match.typeOf("boolean");
- match.number = match.typeOf("number");
- match.string = match.typeOf("string");
- match.object = match.typeOf("object");
- match.func = match.typeOf("function");
- match.array = match.typeOf("array");
- match.regexp = match.typeOf("regexp");
- match.date = match.typeOf("date");
-
- sinon.match = match;
- return match;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./typeOf");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- */
-/**
- * Format functions
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2014 Christian Johansen
- */
-(function (sinonGlobal, formatio) {
-
- function makeApi(sinon) {
- function valueFormatter(value) {
- return "" + value;
- }
-
- function getFormatioFormatter() {
- var formatter = formatio.configure({
- quoteStrings: false,
- limitChildrenCount: 250
- });
-
- function format() {
- return formatter.ascii.apply(formatter, arguments);
- }
-
- return format;
- }
-
- function getNodeFormatter() {
- try {
- var util = require("util");
- } catch (e) {
- /* Node, but no util module - would be very old, but better safe than sorry */
- }
-
- function format(v) {
- var isObjectWithNativeToString = typeof v === "object" && v.toString === Object.prototype.toString;
- return isObjectWithNativeToString ? util.inspect(v) : v;
- }
-
- return util ? format : valueFormatter;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var formatter;
-
- if (isNode) {
- try {
- formatio = require("formatio");
- }
- catch (e) {} // eslint-disable-line no-empty
- }
-
- if (formatio) {
- formatter = getFormatioFormatter();
- } else if (isNode) {
- formatter = getNodeFormatter();
- } else {
- formatter = valueFormatter;
- }
-
- sinon.format = formatter;
- return sinon.format;
- }
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- module.exports = makeApi(sinon);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon, // eslint-disable-line no-undef
- typeof formatio === "object" && formatio // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend match.js
- * @depend format.js
- */
-/**
- * Spy calls
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @author Maximilian Antoni (mail@maxantoni.de)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- * Copyright (c) 2013 Maximilian Antoni
- */
-(function (sinonGlobal) {
-
- var slice = Array.prototype.slice;
-
- function makeApi(sinon) {
- function throwYieldError(proxy, text, args) {
- var msg = sinon.functionName(proxy) + text;
- if (args.length) {
- msg += " Received [" + slice.call(args).join(", ") + "]";
- }
- throw new Error(msg);
- }
-
- var callProto = {
- calledOn: function calledOn(thisValue) {
- if (sinon.match && sinon.match.isMatcher(thisValue)) {
- return thisValue.test(this.thisValue);
- }
- return this.thisValue === thisValue;
- },
-
- calledWith: function calledWith() {
- var l = arguments.length;
- if (l > this.args.length) {
- return false;
- }
- for (var i = 0; i < l; i += 1) {
- if (!sinon.deepEqual(arguments[i], this.args[i])) {
- return false;
- }
- }
-
- return true;
- },
-
- calledWithMatch: function calledWithMatch() {
- var l = arguments.length;
- if (l > this.args.length) {
- return false;
- }
- for (var i = 0; i < l; i += 1) {
- var actual = this.args[i];
- var expectation = arguments[i];
- if (!sinon.match || !sinon.match(expectation).test(actual)) {
- return false;
- }
- }
- return true;
- },
-
- calledWithExactly: function calledWithExactly() {
- return arguments.length === this.args.length &&
- this.calledWith.apply(this, arguments);
- },
-
- notCalledWith: function notCalledWith() {
- return !this.calledWith.apply(this, arguments);
- },
-
- notCalledWithMatch: function notCalledWithMatch() {
- return !this.calledWithMatch.apply(this, arguments);
- },
-
- returned: function returned(value) {
- return sinon.deepEqual(value, this.returnValue);
- },
-
- threw: function threw(error) {
- if (typeof error === "undefined" || !this.exception) {
- return !!this.exception;
- }
-
- return this.exception === error || this.exception.name === error;
- },
-
- calledWithNew: function calledWithNew() {
- return this.proxy.prototype && this.thisValue instanceof this.proxy;
- },
-
- calledBefore: function (other) {
- return this.callId < other.callId;
- },
-
- calledAfter: function (other) {
- return this.callId > other.callId;
- },
-
- callArg: function (pos) {
- this.args[pos]();
- },
-
- callArgOn: function (pos, thisValue) {
- this.args[pos].apply(thisValue);
- },
-
- callArgWith: function (pos) {
- this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1)));
- },
-
- callArgOnWith: function (pos, thisValue) {
- var args = slice.call(arguments, 2);
- this.args[pos].apply(thisValue, args);
- },
-
- "yield": function () {
- this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0)));
- },
-
- yieldOn: function (thisValue) {
- var args = this.args;
- for (var i = 0, l = args.length; i < l; ++i) {
- if (typeof args[i] === "function") {
- args[i].apply(thisValue, slice.call(arguments, 1));
- return;
- }
- }
- throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
- },
-
- yieldTo: function (prop) {
- this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1)));
- },
-
- yieldToOn: function (prop, thisValue) {
- var args = this.args;
- for (var i = 0, l = args.length; i < l; ++i) {
- if (args[i] && typeof args[i][prop] === "function") {
- args[i][prop].apply(thisValue, slice.call(arguments, 2));
- return;
- }
- }
- throwYieldError(this.proxy, " cannot yield to '" + prop +
- "' since no callback was passed.", args);
- },
-
- getStackFrames: function () {
- // Omit the error message and the two top stack frames in sinon itself:
- return this.stack && this.stack.split("\n").slice(3);
- },
-
- toString: function () {
- var callStr = this.proxy ? this.proxy.toString() + "(" : "";
- var args = [];
-
- if (!this.args) {
- return ":(";
- }
-
- for (var i = 0, l = this.args.length; i < l; ++i) {
- args.push(sinon.format(this.args[i]));
- }
-
- callStr = callStr + args.join(", ") + ")";
-
- if (typeof this.returnValue !== "undefined") {
- callStr += " => " + sinon.format(this.returnValue);
- }
-
- if (this.exception) {
- callStr += " !" + this.exception.name;
-
- if (this.exception.message) {
- callStr += "(" + this.exception.message + ")";
- }
- }
- if (this.stack) {
- callStr += this.getStackFrames()[0].replace(/^\s*(?:at\s+|@)?/, " at ");
-
- }
-
- return callStr;
- }
- };
-
- callProto.invokeCallback = callProto.yield;
-
- function createSpyCall(spy, thisValue, args, returnValue, exception, id, stack) {
- if (typeof id !== "number") {
- throw new TypeError("Call id is not a number");
- }
- var proxyCall = sinon.create(callProto);
- proxyCall.proxy = spy;
- proxyCall.thisValue = thisValue;
- proxyCall.args = args;
- proxyCall.returnValue = returnValue;
- proxyCall.exception = exception;
- proxyCall.callId = id;
- proxyCall.stack = stack;
-
- return proxyCall;
- }
- createSpyCall.toString = callProto.toString; // used by mocks
-
- sinon.spyCall = createSpyCall;
- return createSpyCall;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./match");
- require("./format");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend times_in_words.js
- * @depend util/core.js
- * @depend extend.js
- * @depend call.js
- * @depend format.js
- */
-/**
- * Spy functions
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- var push = Array.prototype.push;
- var slice = Array.prototype.slice;
- var callId = 0;
-
- function spy(object, property, types) {
- if (!property && typeof object === "function") {
- return spy.create(object);
- }
-
- if (!object && !property) {
- return spy.create(function () { });
- }
-
- if (types) {
- var methodDesc = sinon.getPropertyDescriptor(object, property);
- for (var i = 0; i < types.length; i++) {
- methodDesc[types[i]] = spy.create(methodDesc[types[i]]);
- }
- return sinon.wrapMethod(object, property, methodDesc);
- }
-
- return sinon.wrapMethod(object, property, spy.create(object[property]));
- }
-
- function matchingFake(fakes, args, strict) {
- if (!fakes) {
- return undefined;
- }
-
- for (var i = 0, l = fakes.length; i < l; i++) {
- if (fakes[i].matches(args, strict)) {
- return fakes[i];
- }
- }
- }
-
- function incrementCallCount() {
- this.called = true;
- this.callCount += 1;
- this.notCalled = false;
- this.calledOnce = this.callCount === 1;
- this.calledTwice = this.callCount === 2;
- this.calledThrice = this.callCount === 3;
- }
-
- function createCallProperties() {
- this.firstCall = this.getCall(0);
- this.secondCall = this.getCall(1);
- this.thirdCall = this.getCall(2);
- this.lastCall = this.getCall(this.callCount - 1);
- }
-
- var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
- function createProxy(func, proxyLength) {
- // Retain the function length:
- var p;
- if (proxyLength) {
- eval("p = (function proxy(" + vars.substring(0, proxyLength * 2 - 1) + // eslint-disable-line no-eval
- ") { return p.invoke(func, this, slice.call(arguments)); });");
- } else {
- p = function proxy() {
- return p.invoke(func, this, slice.call(arguments));
- };
- }
- p.isSinonProxy = true;
- return p;
- }
-
- var uuid = 0;
-
- // Public API
- var spyApi = {
- reset: function () {
- if (this.invoking) {
- var err = new Error("Cannot reset Sinon function while invoking it. " +
- "Move the call to .reset outside of the callback.");
- err.name = "InvalidResetException";
- throw err;
- }
-
- this.called = false;
- this.notCalled = true;
- this.calledOnce = false;
- this.calledTwice = false;
- this.calledThrice = false;
- this.callCount = 0;
- this.firstCall = null;
- this.secondCall = null;
- this.thirdCall = null;
- this.lastCall = null;
- this.args = [];
- this.returnValues = [];
- this.thisValues = [];
- this.exceptions = [];
- this.callIds = [];
- this.stacks = [];
- if (this.fakes) {
- for (var i = 0; i < this.fakes.length; i++) {
- this.fakes[i].reset();
- }
- }
-
- return this;
- },
-
- create: function create(func, spyLength) {
- var name;
-
- if (typeof func !== "function") {
- func = function () { };
- } else {
- name = sinon.functionName(func);
- }
-
- if (!spyLength) {
- spyLength = func.length;
- }
-
- var proxy = createProxy(func, spyLength);
-
- sinon.extend(proxy, spy);
- delete proxy.create;
- sinon.extend(proxy, func);
-
- proxy.reset();
- proxy.prototype = func.prototype;
- proxy.displayName = name || "spy";
- proxy.toString = sinon.functionToString;
- proxy.instantiateFake = sinon.spy.create;
- proxy.id = "spy#" + uuid++;
-
- return proxy;
- },
-
- invoke: function invoke(func, thisValue, args) {
- var matching = matchingFake(this.fakes, args);
- var exception, returnValue;
-
- incrementCallCount.call(this);
- push.call(this.thisValues, thisValue);
- push.call(this.args, args);
- push.call(this.callIds, callId++);
-
- // Make call properties available from within the spied function:
- createCallProperties.call(this);
-
- try {
- this.invoking = true;
-
- if (matching) {
- returnValue = matching.invoke(func, thisValue, args);
- } else {
- returnValue = (this.func || func).apply(thisValue, args);
- }
-
- var thisCall = this.getCall(this.callCount - 1);
- if (thisCall.calledWithNew() && typeof returnValue !== "object") {
- returnValue = thisValue;
- }
- } catch (e) {
- exception = e;
- } finally {
- delete this.invoking;
- }
-
- push.call(this.exceptions, exception);
- push.call(this.returnValues, returnValue);
- push.call(this.stacks, new Error().stack);
-
- // Make return value and exception available in the calls:
- createCallProperties.call(this);
-
- if (exception !== undefined) {
- throw exception;
- }
-
- return returnValue;
- },
-
- named: function named(name) {
- this.displayName = name;
- return this;
- },
-
- getCall: function getCall(i) {
- if (i < 0 || i >= this.callCount) {
- return null;
- }
-
- return sinon.spyCall(this, this.thisValues[i], this.args[i],
- this.returnValues[i], this.exceptions[i],
- this.callIds[i], this.stacks[i]);
- },
-
- getCalls: function () {
- var calls = [];
- var i;
-
- for (i = 0; i < this.callCount; i++) {
- calls.push(this.getCall(i));
- }
-
- return calls;
- },
-
- calledBefore: function calledBefore(spyFn) {
- if (!this.called) {
- return false;
- }
-
- if (!spyFn.called) {
- return true;
- }
-
- return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
- },
-
- calledAfter: function calledAfter(spyFn) {
- if (!this.called || !spyFn.called) {
- return false;
- }
-
- return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1];
- },
-
- withArgs: function () {
- var args = slice.call(arguments);
-
- if (this.fakes) {
- var match = matchingFake(this.fakes, args, true);
-
- if (match) {
- return match;
- }
- } else {
- this.fakes = [];
- }
-
- var original = this;
- var fake = this.instantiateFake();
- fake.matchingAguments = args;
- fake.parent = this;
- push.call(this.fakes, fake);
-
- fake.withArgs = function () {
- return original.withArgs.apply(original, arguments);
- };
-
- for (var i = 0; i < this.args.length; i++) {
- if (fake.matches(this.args[i])) {
- incrementCallCount.call(fake);
- push.call(fake.thisValues, this.thisValues[i]);
- push.call(fake.args, this.args[i]);
- push.call(fake.returnValues, this.returnValues[i]);
- push.call(fake.exceptions, this.exceptions[i]);
- push.call(fake.callIds, this.callIds[i]);
- }
- }
- createCallProperties.call(fake);
-
- return fake;
- },
-
- matches: function (args, strict) {
- var margs = this.matchingAguments;
-
- if (margs.length <= args.length &&
- sinon.deepEqual(margs, args.slice(0, margs.length))) {
- return !strict || margs.length === args.length;
- }
- },
-
- printf: function (format) {
- var spyInstance = this;
- var args = slice.call(arguments, 1);
- var formatter;
-
- return (format || "").replace(/%(.)/g, function (match, specifyer) {
- formatter = spyApi.formatters[specifyer];
-
- if (typeof formatter === "function") {
- return formatter.call(null, spyInstance, args);
- } else if (!isNaN(parseInt(specifyer, 10))) {
- return sinon.format(args[specifyer - 1]);
- }
-
- return "%" + specifyer;
- });
- }
- };
-
- function delegateToCalls(method, matchAny, actual, notCalled) {
- spyApi[method] = function () {
- if (!this.called) {
- if (notCalled) {
- return notCalled.apply(this, arguments);
- }
- return false;
- }
-
- var currentCall;
- var matches = 0;
-
- for (var i = 0, l = this.callCount; i < l; i += 1) {
- currentCall = this.getCall(i);
-
- if (currentCall[actual || method].apply(currentCall, arguments)) {
- matches += 1;
-
- if (matchAny) {
- return true;
- }
- }
- }
-
- return matches === this.callCount;
- };
- }
-
- delegateToCalls("calledOn", true);
- delegateToCalls("alwaysCalledOn", false, "calledOn");
- delegateToCalls("calledWith", true);
- delegateToCalls("calledWithMatch", true);
- delegateToCalls("alwaysCalledWith", false, "calledWith");
- delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch");
- delegateToCalls("calledWithExactly", true);
- delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly");
- delegateToCalls("neverCalledWith", false, "notCalledWith", function () {
- return true;
- });
- delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", function () {
- return true;
- });
- delegateToCalls("threw", true);
- delegateToCalls("alwaysThrew", false, "threw");
- delegateToCalls("returned", true);
- delegateToCalls("alwaysReturned", false, "returned");
- delegateToCalls("calledWithNew", true);
- delegateToCalls("alwaysCalledWithNew", false, "calledWithNew");
- delegateToCalls("callArg", false, "callArgWith", function () {
- throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
- });
- spyApi.callArgWith = spyApi.callArg;
- delegateToCalls("callArgOn", false, "callArgOnWith", function () {
- throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
- });
- spyApi.callArgOnWith = spyApi.callArgOn;
- delegateToCalls("yield", false, "yield", function () {
- throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
- });
- // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
- spyApi.invokeCallback = spyApi.yield;
- delegateToCalls("yieldOn", false, "yieldOn", function () {
- throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
- });
- delegateToCalls("yieldTo", false, "yieldTo", function (property) {
- throw new Error(this.toString() + " cannot yield to '" + property +
- "' since it was not yet invoked.");
- });
- delegateToCalls("yieldToOn", false, "yieldToOn", function (property) {
- throw new Error(this.toString() + " cannot yield to '" + property +
- "' since it was not yet invoked.");
- });
-
- spyApi.formatters = {
- c: function (spyInstance) {
- return sinon.timesInWords(spyInstance.callCount);
- },
-
- n: function (spyInstance) {
- return spyInstance.toString();
- },
-
- C: function (spyInstance) {
- var calls = [];
-
- for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
- var stringifiedCall = " " + spyInstance.getCall(i).toString();
- if (/\n/.test(calls[i - 1])) {
- stringifiedCall = "\n" + stringifiedCall;
- }
- push.call(calls, stringifiedCall);
- }
-
- return calls.length > 0 ? "\n" + calls.join("\n") : "";
- },
-
- t: function (spyInstance) {
- var objects = [];
-
- for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
- push.call(objects, sinon.format(spyInstance.thisValues[i]));
- }
-
- return objects.join(", ");
- },
-
- "*": function (spyInstance, args) {
- var formatted = [];
-
- for (var i = 0, l = args.length; i < l; ++i) {
- push.call(formatted, sinon.format(args[i]));
- }
-
- return formatted.join(", ");
- }
- };
-
- sinon.extend(spy, spyApi);
-
- spy.spyCall = sinon.spyCall;
- sinon.spy = spy;
-
- return spy;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- require("./call");
- require("./extend");
- require("./times_in_words");
- require("./format");
- module.exports = makeApi(core);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend extend.js
- */
-/**
- * Stub behavior
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @author Tim Fischbach (mail@timfischbach.de)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- var slice = Array.prototype.slice;
- var join = Array.prototype.join;
- var useLeftMostCallback = -1;
- var useRightMostCallback = -2;
-
- var nextTick = (function () {
- if (typeof process === "object" && typeof process.nextTick === "function") {
- return process.nextTick;
- }
-
- if (typeof setImmediate === "function") {
- return setImmediate;
- }
-
- return function (callback) {
- setTimeout(callback, 0);
- };
- })();
-
- function throwsException(error, message) {
- if (typeof error === "string") {
- this.exception = new Error(message || "");
- this.exception.name = error;
- } else if (!error) {
- this.exception = new Error("Error");
- } else {
- this.exception = error;
- }
-
- return this;
- }
-
- function getCallback(behavior, args) {
- var callArgAt = behavior.callArgAt;
-
- if (callArgAt >= 0) {
- return args[callArgAt];
- }
-
- var argumentList;
-
- if (callArgAt === useLeftMostCallback) {
- argumentList = args;
- }
-
- if (callArgAt === useRightMostCallback) {
- argumentList = slice.call(args).reverse();
- }
-
- var callArgProp = behavior.callArgProp;
-
- for (var i = 0, l = argumentList.length; i < l; ++i) {
- if (!callArgProp && typeof argumentList[i] === "function") {
- return argumentList[i];
- }
-
- if (callArgProp && argumentList[i] &&
- typeof argumentList[i][callArgProp] === "function") {
- return argumentList[i][callArgProp];
- }
- }
-
- return null;
- }
-
- function makeApi(sinon) {
- function getCallbackError(behavior, func, args) {
- if (behavior.callArgAt < 0) {
- var msg;
-
- if (behavior.callArgProp) {
- msg = sinon.functionName(behavior.stub) +
- " expected to yield to '" + behavior.callArgProp +
- "', but no object with such a property was passed.";
- } else {
- msg = sinon.functionName(behavior.stub) +
- " expected to yield, but no callback was passed.";
- }
-
- if (args.length > 0) {
- msg += " Received [" + join.call(args, ", ") + "]";
- }
-
- return msg;
- }
-
- return "argument at index " + behavior.callArgAt + " is not a function: " + func;
- }
-
- function callCallback(behavior, args) {
- if (typeof behavior.callArgAt === "number") {
- var func = getCallback(behavior, args);
-
- if (typeof func !== "function") {
- throw new TypeError(getCallbackError(behavior, func, args));
- }
-
- if (behavior.callbackAsync) {
- nextTick(function () {
- func.apply(behavior.callbackContext, behavior.callbackArguments);
- });
- } else {
- func.apply(behavior.callbackContext, behavior.callbackArguments);
- }
- }
- }
-
- var proto = {
- create: function create(stub) {
- var behavior = sinon.extend({}, sinon.behavior);
- delete behavior.create;
- behavior.stub = stub;
-
- return behavior;
- },
-
- isPresent: function isPresent() {
- return (typeof this.callArgAt === "number" ||
- this.exception ||
- typeof this.returnArgAt === "number" ||
- this.returnThis ||
- this.returnValueDefined);
- },
-
- invoke: function invoke(context, args) {
- callCallback(this, args);
-
- if (this.exception) {
- throw this.exception;
- } else if (typeof this.returnArgAt === "number") {
- return args[this.returnArgAt];
- } else if (this.returnThis) {
- return context;
- }
-
- return this.returnValue;
- },
-
- onCall: function onCall(index) {
- return this.stub.onCall(index);
- },
-
- onFirstCall: function onFirstCall() {
- return this.stub.onFirstCall();
- },
-
- onSecondCall: function onSecondCall() {
- return this.stub.onSecondCall();
- },
-
- onThirdCall: function onThirdCall() {
- return this.stub.onThirdCall();
- },
-
- withArgs: function withArgs(/* arguments */) {
- throw new Error(
- "Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " +
- "is not supported. Use \"stub.withArgs(...).onCall(...)\" " +
- "to define sequential behavior for calls with certain arguments."
- );
- },
-
- callsArg: function callsArg(pos) {
- if (typeof pos !== "number") {
- throw new TypeError("argument index is not number");
- }
-
- this.callArgAt = pos;
- this.callbackArguments = [];
- this.callbackContext = undefined;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- callsArgOn: function callsArgOn(pos, context) {
- if (typeof pos !== "number") {
- throw new TypeError("argument index is not number");
- }
- if (typeof context !== "object") {
- throw new TypeError("argument context is not an object");
- }
-
- this.callArgAt = pos;
- this.callbackArguments = [];
- this.callbackContext = context;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- callsArgWith: function callsArgWith(pos) {
- if (typeof pos !== "number") {
- throw new TypeError("argument index is not number");
- }
-
- this.callArgAt = pos;
- this.callbackArguments = slice.call(arguments, 1);
- this.callbackContext = undefined;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- callsArgOnWith: function callsArgWith(pos, context) {
- if (typeof pos !== "number") {
- throw new TypeError("argument index is not number");
- }
- if (typeof context !== "object") {
- throw new TypeError("argument context is not an object");
- }
-
- this.callArgAt = pos;
- this.callbackArguments = slice.call(arguments, 2);
- this.callbackContext = context;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- yields: function () {
- this.callArgAt = useLeftMostCallback;
- this.callbackArguments = slice.call(arguments, 0);
- this.callbackContext = undefined;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- yieldsRight: function () {
- this.callArgAt = useRightMostCallback;
- this.callbackArguments = slice.call(arguments, 0);
- this.callbackContext = undefined;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- yieldsOn: function (context) {
- if (typeof context !== "object") {
- throw new TypeError("argument context is not an object");
- }
-
- this.callArgAt = useLeftMostCallback;
- this.callbackArguments = slice.call(arguments, 1);
- this.callbackContext = context;
- this.callArgProp = undefined;
- this.callbackAsync = false;
-
- return this;
- },
-
- yieldsTo: function (prop) {
- this.callArgAt = useLeftMostCallback;
- this.callbackArguments = slice.call(arguments, 1);
- this.callbackContext = undefined;
- this.callArgProp = prop;
- this.callbackAsync = false;
-
- return this;
- },
-
- yieldsToOn: function (prop, context) {
- if (typeof context !== "object") {
- throw new TypeError("argument context is not an object");
- }
-
- this.callArgAt = useLeftMostCallback;
- this.callbackArguments = slice.call(arguments, 2);
- this.callbackContext = context;
- this.callArgProp = prop;
- this.callbackAsync = false;
-
- return this;
- },
-
- throws: throwsException,
- throwsException: throwsException,
-
- returns: function returns(value) {
- this.returnValue = value;
- this.returnValueDefined = true;
- this.exception = undefined;
-
- return this;
- },
-
- returnsArg: function returnsArg(pos) {
- if (typeof pos !== "number") {
- throw new TypeError("argument index is not number");
- }
-
- this.returnArgAt = pos;
-
- return this;
- },
-
- returnsThis: function returnsThis() {
- this.returnThis = true;
-
- return this;
- }
- };
-
- function createAsyncVersion(syncFnName) {
- return function () {
- var result = this[syncFnName].apply(this, arguments);
- this.callbackAsync = true;
- return result;
- };
- }
-
- // create asynchronous versions of callsArg* and yields* methods
- for (var method in proto) {
- // need to avoid creating anotherasync versions of the newly added async methods
- if (proto.hasOwnProperty(method) && method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
- proto[method + "Async"] = createAsyncVersion(method);
- }
- }
-
- sinon.behavior = proto;
- return proto;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./extend");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- function walkInternal(obj, iterator, context, originalObj, seen) {
- var proto, prop;
-
- if (typeof Object.getOwnPropertyNames !== "function") {
- // We explicitly want to enumerate through all of the prototype's properties
- // in this case, therefore we deliberately leave out an own property check.
- /* eslint-disable guard-for-in */
- for (prop in obj) {
- iterator.call(context, obj[prop], prop, obj);
- }
- /* eslint-enable guard-for-in */
-
- return;
- }
-
- Object.getOwnPropertyNames(obj).forEach(function (k) {
- if (!seen[k]) {
- seen[k] = true;
- var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ?
- originalObj : obj;
- iterator.call(context, target[k], k, target);
- }
- });
-
- proto = Object.getPrototypeOf(obj);
- if (proto) {
- walkInternal(proto, iterator, context, originalObj, seen);
- }
- }
-
- /* Public: walks the prototype chain of an object and iterates over every own property
- * name encountered. The iterator is called in the same fashion that Array.prototype.forEach
- * works, where it is passed the value, key, and own object as the 1st, 2nd, and 3rd positional
- * argument, respectively. In cases where Object.getOwnPropertyNames is not available, walk will
- * default to using a simple for..in loop.
- *
- * obj - The object to walk the prototype chain for.
- * iterator - The function to be called on each pass of the walk.
- * context - (Optional) When given, the iterator will be called with this object as the receiver.
- */
- function walk(obj, iterator, context) {
- return walkInternal(obj, iterator, context, obj, {});
- }
-
- sinon.walk = walk;
- return sinon.walk;
- }
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- module.exports = makeApi(sinon);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend extend.js
- * @depend spy.js
- * @depend behavior.js
- * @depend walk.js
- */
-/**
- * Stub functions
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- function stub(object, property, func) {
- if (!!func && typeof func !== "function" && typeof func !== "object") {
- throw new TypeError("Custom stub should be a function or a property descriptor");
- }
-
- var wrapper;
-
- if (func) {
- if (typeof func === "function") {
- wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func;
- } else {
- wrapper = func;
- if (sinon.spy && sinon.spy.create) {
- var types = sinon.objectKeys(wrapper);
- for (var i = 0; i < types.length; i++) {
- wrapper[types[i]] = sinon.spy.create(wrapper[types[i]]);
- }
- }
- }
- } else {
- var stubLength = 0;
- if (typeof object === "object" && typeof object[property] === "function") {
- stubLength = object[property].length;
- }
- wrapper = stub.create(stubLength);
- }
-
- if (!object && typeof property === "undefined") {
- return sinon.stub.create();
- }
-
- if (typeof property === "undefined" && typeof object === "object") {
- sinon.walk(object || {}, function (value, prop, propOwner) {
- // we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object
- // is not Object.prototype
- if (
- propOwner !== Object.prototype &&
- prop !== "constructor" &&
- typeof sinon.getPropertyDescriptor(propOwner, prop).value === "function"
- ) {
- stub(object, prop);
- }
- });
-
- return object;
- }
-
- return sinon.wrapMethod(object, property, wrapper);
- }
-
-
- /*eslint-disable no-use-before-define*/
- function getParentBehaviour(stubInstance) {
- return (stubInstance.parent && getCurrentBehavior(stubInstance.parent));
- }
-
- function getDefaultBehavior(stubInstance) {
- return stubInstance.defaultBehavior ||
- getParentBehaviour(stubInstance) ||
- sinon.behavior.create(stubInstance);
- }
-
- function getCurrentBehavior(stubInstance) {
- var behavior = stubInstance.behaviors[stubInstance.callCount - 1];
- return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stubInstance);
- }
- /*eslint-enable no-use-before-define*/
-
- var uuid = 0;
-
- var proto = {
- create: function create(stubLength) {
- var functionStub = function () {
- return getCurrentBehavior(functionStub).invoke(this, arguments);
- };
-
- functionStub.id = "stub#" + uuid++;
- var orig = functionStub;
- functionStub = sinon.spy.create(functionStub, stubLength);
- functionStub.func = orig;
-
- sinon.extend(functionStub, stub);
- functionStub.instantiateFake = sinon.stub.create;
- functionStub.displayName = "stub";
- functionStub.toString = sinon.functionToString;
-
- functionStub.defaultBehavior = null;
- functionStub.behaviors = [];
-
- return functionStub;
- },
-
- resetBehavior: function () {
- var i;
-
- this.defaultBehavior = null;
- this.behaviors = [];
-
- delete this.returnValue;
- delete this.returnArgAt;
- this.returnThis = false;
-
- if (this.fakes) {
- for (i = 0; i < this.fakes.length; i++) {
- this.fakes[i].resetBehavior();
- }
- }
- },
-
- onCall: function onCall(index) {
- if (!this.behaviors[index]) {
- this.behaviors[index] = sinon.behavior.create(this);
- }
-
- return this.behaviors[index];
- },
-
- onFirstCall: function onFirstCall() {
- return this.onCall(0);
- },
-
- onSecondCall: function onSecondCall() {
- return this.onCall(1);
- },
-
- onThirdCall: function onThirdCall() {
- return this.onCall(2);
- }
- };
-
- function createBehavior(behaviorMethod) {
- return function () {
- this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this);
- this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
- return this;
- };
- }
-
- for (var method in sinon.behavior) {
- if (sinon.behavior.hasOwnProperty(method) &&
- !proto.hasOwnProperty(method) &&
- method !== "create" &&
- method !== "withArgs" &&
- method !== "invoke") {
- proto[method] = createBehavior(method);
- }
- }
-
- sinon.extend(stub, proto);
- sinon.stub = stub;
-
- return stub;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- require("./behavior");
- require("./spy");
- require("./extend");
- module.exports = makeApi(core);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend times_in_words.js
- * @depend util/core.js
- * @depend call.js
- * @depend extend.js
- * @depend match.js
- * @depend spy.js
- * @depend stub.js
- * @depend format.js
- */
-/**
- * Mock functions.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- var push = [].push;
- var match = sinon.match;
-
- function mock(object) {
- // if (typeof console !== undefined && console.warn) {
- // console.warn("mock will be removed from Sinon.JS v2.0");
- // }
-
- if (!object) {
- return sinon.expectation.create("Anonymous mock");
- }
-
- return mock.create(object);
- }
-
- function each(collection, callback) {
- if (!collection) {
- return;
- }
-
- for (var i = 0, l = collection.length; i < l; i += 1) {
- callback(collection[i]);
- }
- }
-
- function arrayEquals(arr1, arr2, compareLength) {
- if (compareLength && (arr1.length !== arr2.length)) {
- return false;
- }
-
- for (var i = 0, l = arr1.length; i < l; i++) {
- if (!sinon.deepEqual(arr1[i], arr2[i])) {
- return false;
- }
- }
- return true;
- }
-
- sinon.extend(mock, {
- create: function create(object) {
- if (!object) {
- throw new TypeError("object is null");
- }
-
- var mockObject = sinon.extend({}, mock);
- mockObject.object = object;
- delete mockObject.create;
-
- return mockObject;
- },
-
- expects: function expects(method) {
- if (!method) {
- throw new TypeError("method is falsy");
- }
-
- if (!this.expectations) {
- this.expectations = {};
- this.proxies = [];
- }
-
- if (!this.expectations[method]) {
- this.expectations[method] = [];
- var mockObject = this;
-
- sinon.wrapMethod(this.object, method, function () {
- return mockObject.invokeMethod(method, this, arguments);
- });
-
- push.call(this.proxies, method);
- }
-
- var expectation = sinon.expectation.create(method);
- push.call(this.expectations[method], expectation);
-
- return expectation;
- },
-
- restore: function restore() {
- var object = this.object;
-
- each(this.proxies, function (proxy) {
- if (typeof object[proxy].restore === "function") {
- object[proxy].restore();
- }
- });
- },
-
- verify: function verify() {
- var expectations = this.expectations || {};
- var messages = [];
- var met = [];
-
- each(this.proxies, function (proxy) {
- each(expectations[proxy], function (expectation) {
- if (!expectation.met()) {
- push.call(messages, expectation.toString());
- } else {
- push.call(met, expectation.toString());
- }
- });
- });
-
- this.restore();
-
- if (messages.length > 0) {
- sinon.expectation.fail(messages.concat(met).join("\n"));
- } else if (met.length > 0) {
- sinon.expectation.pass(messages.concat(met).join("\n"));
- }
-
- return true;
- },
-
- invokeMethod: function invokeMethod(method, thisValue, args) {
- var expectations = this.expectations && this.expectations[method] ? this.expectations[method] : [];
- var expectationsWithMatchingArgs = [];
- var currentArgs = args || [];
- var i, available;
-
- for (i = 0; i < expectations.length; i += 1) {
- var expectedArgs = expectations[i].expectedArguments || [];
- if (arrayEquals(expectedArgs, currentArgs, expectations[i].expectsExactArgCount)) {
- expectationsWithMatchingArgs.push(expectations[i]);
- }
- }
-
- for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) {
- if (!expectationsWithMatchingArgs[i].met() &&
- expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) {
- return expectationsWithMatchingArgs[i].apply(thisValue, args);
- }
- }
-
- var messages = [];
- var exhausted = 0;
-
- for (i = 0; i < expectationsWithMatchingArgs.length; i += 1) {
- if (expectationsWithMatchingArgs[i].allowsCall(thisValue, args)) {
- available = available || expectationsWithMatchingArgs[i];
- } else {
- exhausted += 1;
- }
- }
-
- if (available && exhausted === 0) {
- return available.apply(thisValue, args);
- }
-
- for (i = 0; i < expectations.length; i += 1) {
- push.call(messages, " " + expectations[i].toString());
- }
-
- messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({
- proxy: method,
- args: args
- }));
-
- sinon.expectation.fail(messages.join("\n"));
- }
- });
-
- var times = sinon.timesInWords;
- var slice = Array.prototype.slice;
-
- function callCountInWords(callCount) {
- if (callCount === 0) {
- return "never called";
- }
-
- return "called " + times(callCount);
- }
-
- function expectedCallCountInWords(expectation) {
- var min = expectation.minCalls;
- var max = expectation.maxCalls;
-
- if (typeof min === "number" && typeof max === "number") {
- var str = times(min);
-
- if (min !== max) {
- str = "at least " + str + " and at most " + times(max);
- }
-
- return str;
- }
-
- if (typeof min === "number") {
- return "at least " + times(min);
- }
-
- return "at most " + times(max);
- }
-
- function receivedMinCalls(expectation) {
- var hasMinLimit = typeof expectation.minCalls === "number";
- return !hasMinLimit || expectation.callCount >= expectation.minCalls;
- }
-
- function receivedMaxCalls(expectation) {
- if (typeof expectation.maxCalls !== "number") {
- return false;
- }
-
- return expectation.callCount === expectation.maxCalls;
- }
-
- function verifyMatcher(possibleMatcher, arg) {
- var isMatcher = match && match.isMatcher(possibleMatcher);
-
- return isMatcher && possibleMatcher.test(arg) || true;
- }
-
- sinon.expectation = {
- minCalls: 1,
- maxCalls: 1,
-
- create: function create(methodName) {
- var expectation = sinon.extend(sinon.stub.create(), sinon.expectation);
- delete expectation.create;
- expectation.method = methodName;
-
- return expectation;
- },
-
- invoke: function invoke(func, thisValue, args) {
- this.verifyCallAllowed(thisValue, args);
-
- return sinon.spy.invoke.apply(this, arguments);
- },
-
- atLeast: function atLeast(num) {
- if (typeof num !== "number") {
- throw new TypeError("'" + num + "' is not number");
- }
-
- if (!this.limitsSet) {
- this.maxCalls = null;
- this.limitsSet = true;
- }
-
- this.minCalls = num;
-
- return this;
- },
-
- atMost: function atMost(num) {
- if (typeof num !== "number") {
- throw new TypeError("'" + num + "' is not number");
- }
-
- if (!this.limitsSet) {
- this.minCalls = null;
- this.limitsSet = true;
- }
-
- this.maxCalls = num;
-
- return this;
- },
-
- never: function never() {
- return this.exactly(0);
- },
-
- once: function once() {
- return this.exactly(1);
- },
-
- twice: function twice() {
- return this.exactly(2);
- },
-
- thrice: function thrice() {
- return this.exactly(3);
- },
-
- exactly: function exactly(num) {
- if (typeof num !== "number") {
- throw new TypeError("'" + num + "' is not a number");
- }
-
- this.atLeast(num);
- return this.atMost(num);
- },
-
- met: function met() {
- return !this.failed && receivedMinCalls(this);
- },
-
- verifyCallAllowed: function verifyCallAllowed(thisValue, args) {
- if (receivedMaxCalls(this)) {
- this.failed = true;
- sinon.expectation.fail(this.method + " already called " + times(this.maxCalls));
- }
-
- if ("expectedThis" in this && this.expectedThis !== thisValue) {
- sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " +
- this.expectedThis);
- }
-
- if (!("expectedArguments" in this)) {
- return;
- }
-
- if (!args) {
- sinon.expectation.fail(this.method + " received no arguments, expected " +
- sinon.format(this.expectedArguments));
- }
-
- if (args.length < this.expectedArguments.length) {
- sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) +
- "), expected " + sinon.format(this.expectedArguments));
- }
-
- if (this.expectsExactArgCount &&
- args.length !== this.expectedArguments.length) {
- sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) +
- "), expected " + sinon.format(this.expectedArguments));
- }
-
- for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
-
- if (!verifyMatcher(this.expectedArguments[i], args[i])) {
- sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +
- ", didn't match " + this.expectedArguments.toString());
- }
-
- if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
- sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +
- ", expected " + sinon.format(this.expectedArguments));
- }
- }
- },
-
- allowsCall: function allowsCall(thisValue, args) {
- if (this.met() && receivedMaxCalls(this)) {
- return false;
- }
-
- if ("expectedThis" in this && this.expectedThis !== thisValue) {
- return false;
- }
-
- if (!("expectedArguments" in this)) {
- return true;
- }
-
- args = args || [];
-
- if (args.length < this.expectedArguments.length) {
- return false;
- }
-
- if (this.expectsExactArgCount &&
- args.length !== this.expectedArguments.length) {
- return false;
- }
-
- for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
- if (!verifyMatcher(this.expectedArguments[i], args[i])) {
- return false;
- }
-
- if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
- return false;
- }
- }
-
- return true;
- },
-
- withArgs: function withArgs() {
- this.expectedArguments = slice.call(arguments);
- return this;
- },
-
- withExactArgs: function withExactArgs() {
- this.withArgs.apply(this, arguments);
- this.expectsExactArgCount = true;
- return this;
- },
-
- on: function on(thisValue) {
- this.expectedThis = thisValue;
- return this;
- },
-
- toString: function () {
- var args = (this.expectedArguments || []).slice();
-
- if (!this.expectsExactArgCount) {
- push.call(args, "[...]");
- }
-
- var callStr = sinon.spyCall.toString.call({
- proxy: this.method || "anonymous mock expectation",
- args: args
- });
-
- var message = callStr.replace(", [...", "[, ...") + " " +
- expectedCallCountInWords(this);
-
- if (this.met()) {
- return "Expectation met: " + message;
- }
-
- return "Expected " + message + " (" +
- callCountInWords(this.callCount) + ")";
- },
-
- verify: function verify() {
- if (!this.met()) {
- sinon.expectation.fail(this.toString());
- } else {
- sinon.expectation.pass(this.toString());
- }
-
- return true;
- },
-
- pass: function pass(message) {
- sinon.assert.pass(message);
- },
-
- fail: function fail(message) {
- var exception = new Error(message);
- exception.name = "ExpectationError";
-
- throw exception;
- }
- };
-
- sinon.mock = mock;
- return mock;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./times_in_words");
- require("./call");
- require("./extend");
- require("./match");
- require("./spy");
- require("./stub");
- require("./format");
-
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend spy.js
- * @depend stub.js
- * @depend mock.js
- */
-/**
- * Collections of stubs, spies and mocks.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- var push = [].push;
- var hasOwnProperty = Object.prototype.hasOwnProperty;
-
- function getFakes(fakeCollection) {
- if (!fakeCollection.fakes) {
- fakeCollection.fakes = [];
- }
-
- return fakeCollection.fakes;
- }
-
- function each(fakeCollection, method) {
- var fakes = getFakes(fakeCollection);
-
- for (var i = 0, l = fakes.length; i < l; i += 1) {
- if (typeof fakes[i][method] === "function") {
- fakes[i][method]();
- }
- }
- }
-
- function compact(fakeCollection) {
- var fakes = getFakes(fakeCollection);
- var i = 0;
- while (i < fakes.length) {
- fakes.splice(i, 1);
- }
- }
-
- function makeApi(sinon) {
- var collection = {
- verify: function resolve() {
- each(this, "verify");
- },
-
- restore: function restore() {
- each(this, "restore");
- compact(this);
- },
-
- reset: function restore() {
- each(this, "reset");
- },
-
- verifyAndRestore: function verifyAndRestore() {
- var exception;
-
- try {
- this.verify();
- } catch (e) {
- exception = e;
- }
-
- this.restore();
-
- if (exception) {
- throw exception;
- }
- },
-
- add: function add(fake) {
- push.call(getFakes(this), fake);
- return fake;
- },
-
- spy: function spy() {
- return this.add(sinon.spy.apply(sinon, arguments));
- },
-
- stub: function stub(object, property, value) {
- if (property) {
- var original = object[property];
-
- if (typeof original !== "function") {
- if (!hasOwnProperty.call(object, property)) {
- throw new TypeError("Cannot stub non-existent own property " + property);
- }
-
- object[property] = value;
-
- return this.add({
- restore: function () {
- object[property] = original;
- }
- });
- }
- }
- if (!property && !!object && typeof object === "object") {
- var stubbedObj = sinon.stub.apply(sinon, arguments);
-
- for (var prop in stubbedObj) {
- if (typeof stubbedObj[prop] === "function") {
- this.add(stubbedObj[prop]);
- }
- }
-
- return stubbedObj;
- }
-
- return this.add(sinon.stub.apply(sinon, arguments));
- },
-
- mock: function mock() {
- return this.add(sinon.mock.apply(sinon, arguments));
- },
-
- inject: function inject(obj) {
- var col = this;
-
- obj.spy = function () {
- return col.spy.apply(col, arguments);
- };
-
- obj.stub = function () {
- return col.stub.apply(col, arguments);
- };
-
- obj.mock = function () {
- return col.mock.apply(col, arguments);
- };
-
- return obj;
- }
- };
-
- sinon.collection = collection;
- return collection;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./mock");
- require("./spy");
- require("./stub");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * Fake timer API
- * setTimeout
- * setInterval
- * clearTimeout
- * clearInterval
- * tick
- * reset
- * Date
- *
- * Inspired by jsUnitMockTimeOut from JsUnit
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function () {
-
- function makeApi(s, lol) {
- /*global lolex */
- var llx = typeof lolex !== "undefined" ? lolex : lol;
-
- s.useFakeTimers = function () {
- var now;
- var methods = Array.prototype.slice.call(arguments);
-
- if (typeof methods[0] === "string") {
- now = 0;
- } else {
- now = methods.shift();
- }
-
- var clock = llx.install(now || 0, methods);
- clock.restore = clock.uninstall;
- return clock;
- };
-
- s.clock = {
- create: function (now) {
- return llx.createClock(now);
- }
- };
-
- s.timers = {
- setTimeout: setTimeout,
- clearTimeout: clearTimeout,
- setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined),
- clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined),
- setInterval: setInterval,
- clearInterval: clearInterval,
- Date: Date
- };
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, epxorts, module, lolex) {
- var core = require("./core");
- makeApi(core, lolex);
- module.exports = core;
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require, module.exports, module, require("lolex"));
- } else {
- makeApi(sinon); // eslint-disable-line no-undef
- }
-}());
-
-/**
- * Minimal Event interface implementation
- *
- * Original implementation by Sven Fuchs: https://gist.github.com/995028
- * Modifications and tests by Christian Johansen.
- *
- * @author Sven Fuchs (svenfuchs@artweb-design.de)
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2011 Sven Fuchs, Christian Johansen
- */
-if (typeof sinon === "undefined") {
- this.sinon = {};
-}
-
-(function () {
-
- var push = [].push;
-
- function makeApi(sinon) {
- sinon.Event = function Event(type, bubbles, cancelable, target) {
- this.initEvent(type, bubbles, cancelable, target);
- };
-
- sinon.Event.prototype = {
- initEvent: function (type, bubbles, cancelable, target) {
- this.type = type;
- this.bubbles = bubbles;
- this.cancelable = cancelable;
- this.target = target;
- },
-
- stopPropagation: function () {},
-
- preventDefault: function () {
- this.defaultPrevented = true;
- }
- };
-
- sinon.ProgressEvent = function ProgressEvent(type, progressEventRaw, target) {
- this.initEvent(type, false, false, target);
- this.loaded = progressEventRaw.loaded || null;
- this.total = progressEventRaw.total || null;
- this.lengthComputable = !!progressEventRaw.total;
- };
-
- sinon.ProgressEvent.prototype = new sinon.Event();
-
- sinon.ProgressEvent.prototype.constructor = sinon.ProgressEvent;
-
- sinon.CustomEvent = function CustomEvent(type, customData, target) {
- this.initEvent(type, false, false, target);
- this.detail = customData.detail || null;
- };
-
- sinon.CustomEvent.prototype = new sinon.Event();
-
- sinon.CustomEvent.prototype.constructor = sinon.CustomEvent;
-
- sinon.EventTarget = {
- addEventListener: function addEventListener(event, listener) {
- this.eventListeners = this.eventListeners || {};
- this.eventListeners[event] = this.eventListeners[event] || [];
- push.call(this.eventListeners[event], listener);
- },
-
- removeEventListener: function removeEventListener(event, listener) {
- var listeners = this.eventListeners && this.eventListeners[event] || [];
-
- for (var i = 0, l = listeners.length; i < l; ++i) {
- if (listeners[i] === listener) {
- return listeners.splice(i, 1);
- }
- }
- },
-
- dispatchEvent: function dispatchEvent(event) {
- var type = event.type;
- var listeners = this.eventListeners && this.eventListeners[type] || [];
-
- for (var i = 0; i < listeners.length; i++) {
- if (typeof listeners[i] === "function") {
- listeners[i].call(this, event);
- } else {
- listeners[i].handleEvent(event);
- }
- }
-
- return !!event.defaultPrevented;
- }
- };
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require) {
- var sinon = require("./core");
- makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require);
- } else {
- makeApi(sinon); // eslint-disable-line no-undef
- }
-}());
-
-/**
- * @depend util/core.js
- */
-/**
- * Logs errors
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2014 Christian Johansen
- */
-(function (sinonGlobal) {
-
- // cache a reference to setTimeout, so that our reference won't be stubbed out
- // when using fake timers and errors will still get logged
- // https://github.com/cjohansen/Sinon.JS/issues/381
- var realSetTimeout = setTimeout;
-
- function makeApi(sinon) {
-
- function log() {}
-
- function logError(label, err) {
- var msg = label + " threw exception: ";
-
- function throwLoggedError() {
- err.message = msg + err.message;
- throw err;
- }
-
- sinon.log(msg + "[" + err.name + "] " + err.message);
-
- if (err.stack) {
- sinon.log(err.stack);
- }
-
- if (logError.useImmediateExceptions) {
- throwLoggedError();
- } else {
- logError.setTimeout(throwLoggedError, 0);
- }
- }
-
- // When set to true, any errors logged will be thrown immediately;
- // If set to false, the errors will be thrown in separate execution frame.
- logError.useImmediateExceptions = false;
-
- // wrap realSetTimeout with something we can stub in tests
- logError.setTimeout = function (func, timeout) {
- realSetTimeout(func, timeout);
- };
-
- var exports = {};
- exports.log = sinon.log = log;
- exports.logError = sinon.logError = logError;
-
- return exports;
- }
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- module.exports = makeApi(sinon);
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend core.js
- * @depend ../extend.js
- * @depend event.js
- * @depend ../log_error.js
- */
-/**
- * Fake XDomainRequest object
- */
-
-/**
- * Returns the global to prevent assigning values to 'this' when this is undefined.
- * This can occur when files are interpreted by node in strict mode.
- * @private
- */
-function getGlobal() {
-
- return typeof window !== "undefined" ? window : global;
-}
-
-if (typeof sinon === "undefined") {
- if (typeof this === "undefined") {
- getGlobal().sinon = {};
- } else {
- this.sinon = {};
- }
-}
-
-// wrapper for global
-(function (global) {
-
- var xdr = { XDomainRequest: global.XDomainRequest };
- xdr.GlobalXDomainRequest = global.XDomainRequest;
- xdr.supportsXDR = typeof xdr.GlobalXDomainRequest !== "undefined";
- xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false;
-
- function makeApi(sinon) {
- sinon.xdr = xdr;
-
- function FakeXDomainRequest() {
- this.readyState = FakeXDomainRequest.UNSENT;
- this.requestBody = null;
- this.requestHeaders = {};
- this.status = 0;
- this.timeout = null;
-
- if (typeof FakeXDomainRequest.onCreate === "function") {
- FakeXDomainRequest.onCreate(this);
- }
- }
-
- function verifyState(x) {
- if (x.readyState !== FakeXDomainRequest.OPENED) {
- throw new Error("INVALID_STATE_ERR");
- }
-
- if (x.sendFlag) {
- throw new Error("INVALID_STATE_ERR");
- }
- }
-
- function verifyRequestSent(x) {
- if (x.readyState === FakeXDomainRequest.UNSENT) {
- throw new Error("Request not sent");
- }
- if (x.readyState === FakeXDomainRequest.DONE) {
- throw new Error("Request done");
- }
- }
-
- function verifyResponseBodyType(body) {
- if (typeof body !== "string") {
- var error = new Error("Attempted to respond to fake XDomainRequest with " +
- body + ", which is not a string.");
- error.name = "InvalidBodyException";
- throw error;
- }
- }
-
- sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, {
- open: function open(method, url) {
- this.method = method;
- this.url = url;
-
- this.responseText = null;
- this.sendFlag = false;
-
- this.readyStateChange(FakeXDomainRequest.OPENED);
- },
-
- readyStateChange: function readyStateChange(state) {
- this.readyState = state;
- var eventName = "";
- switch (this.readyState) {
- case FakeXDomainRequest.UNSENT:
- break;
- case FakeXDomainRequest.OPENED:
- break;
- case FakeXDomainRequest.LOADING:
- if (this.sendFlag) {
- //raise the progress event
- eventName = "onprogress";
- }
- break;
- case FakeXDomainRequest.DONE:
- if (this.isTimeout) {
- eventName = "ontimeout";
- } else if (this.errorFlag || (this.status < 200 || this.status > 299)) {
- eventName = "onerror";
- } else {
- eventName = "onload";
- }
- break;
- }
-
- // raising event (if defined)
- if (eventName) {
- if (typeof this[eventName] === "function") {
- try {
- this[eventName]();
- } catch (e) {
- sinon.logError("Fake XHR " + eventName + " handler", e);
- }
- }
- }
- },
-
- send: function send(data) {
- verifyState(this);
-
- if (!/^(get|head)$/i.test(this.method)) {
- this.requestBody = data;
- }
- this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
-
- this.errorFlag = false;
- this.sendFlag = true;
- this.readyStateChange(FakeXDomainRequest.OPENED);
-
- if (typeof this.onSend === "function") {
- this.onSend(this);
- }
- },
-
- abort: function abort() {
- this.aborted = true;
- this.responseText = null;
- this.errorFlag = true;
-
- if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) {
- this.readyStateChange(sinon.FakeXDomainRequest.DONE);
- this.sendFlag = false;
- }
- },
-
- setResponseBody: function setResponseBody(body) {
- verifyRequestSent(this);
- verifyResponseBodyType(body);
-
- var chunkSize = this.chunkSize || 10;
- var index = 0;
- this.responseText = "";
-
- do {
- this.readyStateChange(FakeXDomainRequest.LOADING);
- this.responseText += body.substring(index, index + chunkSize);
- index += chunkSize;
- } while (index < body.length);
-
- this.readyStateChange(FakeXDomainRequest.DONE);
- },
-
- respond: function respond(status, contentType, body) {
- // content-type ignored, since XDomainRequest does not carry this
- // we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease
- // test integration across browsers
- this.status = typeof status === "number" ? status : 200;
- this.setResponseBody(body || "");
- },
-
- simulatetimeout: function simulatetimeout() {
- this.status = 0;
- this.isTimeout = true;
- // Access to this should actually throw an error
- this.responseText = undefined;
- this.readyStateChange(FakeXDomainRequest.DONE);
- }
- });
-
- sinon.extend(FakeXDomainRequest, {
- UNSENT: 0,
- OPENED: 1,
- LOADING: 3,
- DONE: 4
- });
-
- sinon.useFakeXDomainRequest = function useFakeXDomainRequest() {
- sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) {
- if (xdr.supportsXDR) {
- global.XDomainRequest = xdr.GlobalXDomainRequest;
- }
-
- delete sinon.FakeXDomainRequest.restore;
-
- if (keepOnCreate !== true) {
- delete sinon.FakeXDomainRequest.onCreate;
- }
- };
- if (xdr.supportsXDR) {
- global.XDomainRequest = sinon.FakeXDomainRequest;
- }
- return sinon.FakeXDomainRequest;
- };
-
- sinon.FakeXDomainRequest = FakeXDomainRequest;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./core");
- require("../extend");
- require("./event");
- require("../log_error");
- makeApi(sinon);
- module.exports = sinon;
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require, module.exports, module);
- } else {
- makeApi(sinon); // eslint-disable-line no-undef
- }
-})(typeof global !== "undefined" ? global : self);
-
-/**
- * @depend core.js
- * @depend ../extend.js
- * @depend event.js
- * @depend ../log_error.js
- */
-/**
- * Fake XMLHttpRequest object
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal, global) {
-
- function getWorkingXHR(globalScope) {
- var supportsXHR = typeof globalScope.XMLHttpRequest !== "undefined";
- if (supportsXHR) {
- return globalScope.XMLHttpRequest;
- }
-
- var supportsActiveX = typeof globalScope.ActiveXObject !== "undefined";
- if (supportsActiveX) {
- return function () {
- return new globalScope.ActiveXObject("MSXML2.XMLHTTP.3.0");
- };
- }
-
- return false;
- }
-
- var supportsProgress = typeof ProgressEvent !== "undefined";
- var supportsCustomEvent = typeof CustomEvent !== "undefined";
- var supportsFormData = typeof FormData !== "undefined";
- var supportsArrayBuffer = typeof ArrayBuffer !== "undefined";
- var supportsBlob = typeof Blob === "function";
- var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest };
- sinonXhr.GlobalXMLHttpRequest = global.XMLHttpRequest;
- sinonXhr.GlobalActiveXObject = global.ActiveXObject;
- sinonXhr.supportsActiveX = typeof sinonXhr.GlobalActiveXObject !== "undefined";
- sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest !== "undefined";
- sinonXhr.workingXHR = getWorkingXHR(global);
- sinonXhr.supportsCORS = sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest());
-
- var unsafeHeaders = {
- "Accept-Charset": true,
- "Accept-Encoding": true,
- Connection: true,
- "Content-Length": true,
- Cookie: true,
- Cookie2: true,
- "Content-Transfer-Encoding": true,
- Date: true,
- Expect: true,
- Host: true,
- "Keep-Alive": true,
- Referer: true,
- TE: true,
- Trailer: true,
- "Transfer-Encoding": true,
- Upgrade: true,
- "User-Agent": true,
- Via: true
- };
-
- // An upload object is created for each
- // FakeXMLHttpRequest and allows upload
- // events to be simulated using uploadProgress
- // and uploadError.
- function UploadProgress() {
- this.eventListeners = {
- progress: [],
- load: [],
- abort: [],
- error: []
- };
- }
-
- UploadProgress.prototype.addEventListener = function addEventListener(event, listener) {
- this.eventListeners[event].push(listener);
- };
-
- UploadProgress.prototype.removeEventListener = function removeEventListener(event, listener) {
- var listeners = this.eventListeners[event] || [];
-
- for (var i = 0, l = listeners.length; i < l; ++i) {
- if (listeners[i] === listener) {
- return listeners.splice(i, 1);
- }
- }
- };
-
- UploadProgress.prototype.dispatchEvent = function dispatchEvent(event) {
- var listeners = this.eventListeners[event.type] || [];
-
- for (var i = 0, listener; (listener = listeners[i]) != null; i++) {
- listener(event);
- }
- };
-
- // Note that for FakeXMLHttpRequest to work pre ES5
- // we lose some of the alignment with the spec.
- // To ensure as close a match as possible,
- // set responseType before calling open, send or respond;
- function FakeXMLHttpRequest() {
- this.readyState = FakeXMLHttpRequest.UNSENT;
- this.requestHeaders = {};
- this.requestBody = null;
- this.status = 0;
- this.statusText = "";
- this.upload = new UploadProgress();
- this.responseType = "";
- this.response = "";
- if (sinonXhr.supportsCORS) {
- this.withCredentials = false;
- }
-
- var xhr = this;
- var events = ["loadstart", "load", "abort", "loadend"];
-
- function addEventListener(eventName) {
- xhr.addEventListener(eventName, function (event) {
- var listener = xhr["on" + eventName];
-
- if (listener && typeof listener === "function") {
- listener.call(this, event);
- }
- });
- }
-
- for (var i = events.length - 1; i >= 0; i--) {
- addEventListener(events[i]);
- }
-
- if (typeof FakeXMLHttpRequest.onCreate === "function") {
- FakeXMLHttpRequest.onCreate(this);
- }
- }
-
- function verifyState(xhr) {
- if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
- throw new Error("INVALID_STATE_ERR");
- }
-
- if (xhr.sendFlag) {
- throw new Error("INVALID_STATE_ERR");
- }
- }
-
- function getHeader(headers, header) {
- header = header.toLowerCase();
-
- for (var h in headers) {
- if (h.toLowerCase() === header) {
- return h;
- }
- }
-
- return null;
- }
-
- // filtering to enable a white-list version of Sinon FakeXhr,
- // where whitelisted requests are passed through to real XHR
- function each(collection, callback) {
- if (!collection) {
- return;
- }
-
- for (var i = 0, l = collection.length; i < l; i += 1) {
- callback(collection[i]);
- }
- }
- function some(collection, callback) {
- for (var index = 0; index < collection.length; index++) {
- if (callback(collection[index]) === true) {
- return true;
- }
- }
- return false;
- }
- // largest arity in XHR is 5 - XHR#open
- var apply = function (obj, method, args) {
- switch (args.length) {
- case 0: return obj[method]();
- case 1: return obj[method](args[0]);
- case 2: return obj[method](args[0], args[1]);
- case 3: return obj[method](args[0], args[1], args[2]);
- case 4: return obj[method](args[0], args[1], args[2], args[3]);
- case 5: return obj[method](args[0], args[1], args[2], args[3], args[4]);
- }
- };
-
- FakeXMLHttpRequest.filters = [];
- FakeXMLHttpRequest.addFilter = function addFilter(fn) {
- this.filters.push(fn);
- };
- var IE6Re = /MSIE 6/;
- FakeXMLHttpRequest.defake = function defake(fakeXhr, xhrArgs) {
- var xhr = new sinonXhr.workingXHR(); // eslint-disable-line new-cap
-
- each([
- "open",
- "setRequestHeader",
- "send",
- "abort",
- "getResponseHeader",
- "getAllResponseHeaders",
- "addEventListener",
- "overrideMimeType",
- "removeEventListener"
- ], function (method) {
- fakeXhr[method] = function () {
- return apply(xhr, method, arguments);
- };
- });
-
- var copyAttrs = function (args) {
- each(args, function (attr) {
- try {
- fakeXhr[attr] = xhr[attr];
- } catch (e) {
- if (!IE6Re.test(navigator.userAgent)) {
- throw e;
- }
- }
- });
- };
-
- var stateChange = function stateChange() {
- fakeXhr.readyState = xhr.readyState;
- if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) {
- copyAttrs(["status", "statusText"]);
- }
- if (xhr.readyState >= FakeXMLHttpRequest.LOADING) {
- copyAttrs(["responseText", "response"]);
- }
- if (xhr.readyState === FakeXMLHttpRequest.DONE) {
- copyAttrs(["responseXML"]);
- }
- if (fakeXhr.onreadystatechange) {
- fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr });
- }
- };
-
- if (xhr.addEventListener) {
- for (var event in fakeXhr.eventListeners) {
- if (fakeXhr.eventListeners.hasOwnProperty(event)) {
-
- /*eslint-disable no-loop-func*/
- each(fakeXhr.eventListeners[event], function (handler) {
- xhr.addEventListener(event, handler);
- });
- /*eslint-enable no-loop-func*/
- }
- }
- xhr.addEventListener("readystatechange", stateChange);
- } else {
- xhr.onreadystatechange = stateChange;
- }
- apply(xhr, "open", xhrArgs);
- };
- FakeXMLHttpRequest.useFilters = false;
-
- function verifyRequestOpened(xhr) {
- if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
- throw new Error("INVALID_STATE_ERR - " + xhr.readyState);
- }
- }
-
- function verifyRequestSent(xhr) {
- if (xhr.readyState === FakeXMLHttpRequest.DONE) {
- throw new Error("Request done");
- }
- }
-
- function verifyHeadersReceived(xhr) {
- if (xhr.async && xhr.readyState !== FakeXMLHttpRequest.HEADERS_RECEIVED) {
- throw new Error("No headers received");
- }
- }
-
- function verifyResponseBodyType(body) {
- if (typeof body !== "string") {
- var error = new Error("Attempted to respond to fake XMLHttpRequest with " +
- body + ", which is not a string.");
- error.name = "InvalidBodyException";
- throw error;
- }
- }
-
- function convertToArrayBuffer(body) {
- var buffer = new ArrayBuffer(body.length);
- var view = new Uint8Array(buffer);
- for (var i = 0; i < body.length; i++) {
- var charCode = body.charCodeAt(i);
- if (charCode >= 256) {
- throw new TypeError("arraybuffer or blob responseTypes require binary string, " +
- "invalid character " + body[i] + " found.");
- }
- view[i] = charCode;
- }
- return buffer;
- }
-
- function isXmlContentType(contentType) {
- return !contentType || /(text\/xml)|(application\/xml)|(\+xml)/.test(contentType);
- }
-
- function convertResponseBody(responseType, contentType, body) {
- if (responseType === "" || responseType === "text") {
- return body;
- } else if (supportsArrayBuffer && responseType === "arraybuffer") {
- return convertToArrayBuffer(body);
- } else if (responseType === "json") {
- try {
- return JSON.parse(body);
- } catch (e) {
- // Return parsing failure as null
- return null;
- }
- } else if (supportsBlob && responseType === "blob") {
- var blobOptions = {};
- if (contentType) {
- blobOptions.type = contentType;
- }
- return new Blob([convertToArrayBuffer(body)], blobOptions);
- } else if (responseType === "document") {
- if (isXmlContentType(contentType)) {
- return FakeXMLHttpRequest.parseXML(body);
- }
- return null;
- }
- throw new Error("Invalid responseType " + responseType);
- }
-
- function clearResponse(xhr) {
- if (xhr.responseType === "" || xhr.responseType === "text") {
- xhr.response = xhr.responseText = "";
- } else {
- xhr.response = xhr.responseText = null;
- }
- xhr.responseXML = null;
- }
-
- FakeXMLHttpRequest.parseXML = function parseXML(text) {
- // Treat empty string as parsing failure
- if (text !== "") {
- try {
- if (typeof DOMParser !== "undefined") {
- var parser = new DOMParser();
- return parser.parseFromString(text, "text/xml");
- }
- var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async = "false";
- xmlDoc.loadXML(text);
- return xmlDoc;
- } catch (e) {
- // Unable to parse XML - no biggie
- }
- }
-
- return null;
- };
-
- FakeXMLHttpRequest.statusCodes = {
- 100: "Continue",
- 101: "Switching Protocols",
- 200: "OK",
- 201: "Created",
- 202: "Accepted",
- 203: "Non-Authoritative Information",
- 204: "No Content",
- 205: "Reset Content",
- 206: "Partial Content",
- 207: "Multi-Status",
- 300: "Multiple Choice",
- 301: "Moved Permanently",
- 302: "Found",
- 303: "See Other",
- 304: "Not Modified",
- 305: "Use Proxy",
- 307: "Temporary Redirect",
- 400: "Bad Request",
- 401: "Unauthorized",
- 402: "Payment Required",
- 403: "Forbidden",
- 404: "Not Found",
- 405: "Method Not Allowed",
- 406: "Not Acceptable",
- 407: "Proxy Authentication Required",
- 408: "Request Timeout",
- 409: "Conflict",
- 410: "Gone",
- 411: "Length Required",
- 412: "Precondition Failed",
- 413: "Request Entity Too Large",
- 414: "Request-URI Too Long",
- 415: "Unsupported Media Type",
- 416: "Requested Range Not Satisfiable",
- 417: "Expectation Failed",
- 422: "Unprocessable Entity",
- 500: "Internal Server Error",
- 501: "Not Implemented",
- 502: "Bad Gateway",
- 503: "Service Unavailable",
- 504: "Gateway Timeout",
- 505: "HTTP Version Not Supported"
- };
-
- function makeApi(sinon) {
- sinon.xhr = sinonXhr;
-
- sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, {
- async: true,
-
- open: function open(method, url, async, username, password) {
- this.method = method;
- this.url = url;
- this.async = typeof async === "boolean" ? async : true;
- this.username = username;
- this.password = password;
- clearResponse(this);
- this.requestHeaders = {};
- this.sendFlag = false;
-
- if (FakeXMLHttpRequest.useFilters === true) {
- var xhrArgs = arguments;
- var defake = some(FakeXMLHttpRequest.filters, function (filter) {
- return filter.apply(this, xhrArgs);
- });
- if (defake) {
- return FakeXMLHttpRequest.defake(this, arguments);
- }
- }
- this.readyStateChange(FakeXMLHttpRequest.OPENED);
- },
-
- readyStateChange: function readyStateChange(state) {
- this.readyState = state;
-
- var readyStateChangeEvent = new sinon.Event("readystatechange", false, false, this);
-
- if (typeof this.onreadystatechange === "function") {
- try {
- this.onreadystatechange(readyStateChangeEvent);
- } catch (e) {
- sinon.logError("Fake XHR onreadystatechange handler", e);
- }
- }
-
- switch (this.readyState) {
- case FakeXMLHttpRequest.DONE:
- if (supportsProgress) {
- this.upload.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
- this.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
- }
- this.upload.dispatchEvent(new sinon.Event("load", false, false, this));
- this.dispatchEvent(new sinon.Event("load", false, false, this));
- this.dispatchEvent(new sinon.Event("loadend", false, false, this));
- break;
- }
-
- this.dispatchEvent(readyStateChangeEvent);
- },
-
- setRequestHeader: function setRequestHeader(header, value) {
- verifyState(this);
-
- if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) {
- throw new Error("Refused to set unsafe header \"" + header + "\"");
- }
-
- if (this.requestHeaders[header]) {
- this.requestHeaders[header] += "," + value;
- } else {
- this.requestHeaders[header] = value;
- }
- },
-
- // Helps testing
- setResponseHeaders: function setResponseHeaders(headers) {
- verifyRequestOpened(this);
- this.responseHeaders = {};
-
- for (var header in headers) {
- if (headers.hasOwnProperty(header)) {
- this.responseHeaders[header] = headers[header];
- }
- }
-
- if (this.async) {
- this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED);
- } else {
- this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED;
- }
- },
-
- // Currently treats ALL data as a DOMString (i.e. no Document)
- send: function send(data) {
- verifyState(this);
-
- if (!/^(get|head)$/i.test(this.method)) {
- var contentType = getHeader(this.requestHeaders, "Content-Type");
- if (this.requestHeaders[contentType]) {
- var value = this.requestHeaders[contentType].split(";");
- this.requestHeaders[contentType] = value[0] + ";charset=utf-8";
- } else if (supportsFormData && !(data instanceof FormData)) {
- this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
- }
-
- this.requestBody = data;
- }
-
- this.errorFlag = false;
- this.sendFlag = this.async;
- clearResponse(this);
- this.readyStateChange(FakeXMLHttpRequest.OPENED);
-
- if (typeof this.onSend === "function") {
- this.onSend(this);
- }
-
- this.dispatchEvent(new sinon.Event("loadstart", false, false, this));
- },
-
- abort: function abort() {
- this.aborted = true;
- clearResponse(this);
- this.errorFlag = true;
- this.requestHeaders = {};
- this.responseHeaders = {};
-
- if (this.readyState > FakeXMLHttpRequest.UNSENT && this.sendFlag) {
- this.readyStateChange(FakeXMLHttpRequest.DONE);
- this.sendFlag = false;
- }
-
- this.readyState = FakeXMLHttpRequest.UNSENT;
-
- this.dispatchEvent(new sinon.Event("abort", false, false, this));
-
- this.upload.dispatchEvent(new sinon.Event("abort", false, false, this));
-
- if (typeof this.onerror === "function") {
- this.onerror();
- }
- },
-
- getResponseHeader: function getResponseHeader(header) {
- if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
- return null;
- }
-
- if (/^Set-Cookie2?$/i.test(header)) {
- return null;
- }
-
- header = getHeader(this.responseHeaders, header);
-
- return this.responseHeaders[header] || null;
- },
-
- getAllResponseHeaders: function getAllResponseHeaders() {
- if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
- return "";
- }
-
- var headers = "";
-
- for (var header in this.responseHeaders) {
- if (this.responseHeaders.hasOwnProperty(header) &&
- !/^Set-Cookie2?$/i.test(header)) {
- headers += header + ": " + this.responseHeaders[header] + "\r\n";
- }
- }
-
- return headers;
- },
-
- setResponseBody: function setResponseBody(body) {
- verifyRequestSent(this);
- verifyHeadersReceived(this);
- verifyResponseBodyType(body);
- var contentType = this.getResponseHeader("Content-Type");
-
- var isTextResponse = this.responseType === "" || this.responseType === "text";
- clearResponse(this);
- if (this.async) {
- var chunkSize = this.chunkSize || 10;
- var index = 0;
-
- do {
- this.readyStateChange(FakeXMLHttpRequest.LOADING);
-
- if (isTextResponse) {
- this.responseText = this.response += body.substring(index, index + chunkSize);
- }
- index += chunkSize;
- } while (index < body.length);
- }
-
- this.response = convertResponseBody(this.responseType, contentType, body);
- if (isTextResponse) {
- this.responseText = this.response;
- }
-
- if (this.responseType === "document") {
- this.responseXML = this.response;
- } else if (this.responseType === "" && isXmlContentType(contentType)) {
- this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText);
- }
- this.readyStateChange(FakeXMLHttpRequest.DONE);
- },
-
- respond: function respond(status, headers, body) {
- this.status = typeof status === "number" ? status : 200;
- this.statusText = FakeXMLHttpRequest.statusCodes[this.status];
- this.setResponseHeaders(headers || {});
- this.setResponseBody(body || "");
- },
-
- uploadProgress: function uploadProgress(progressEventRaw) {
- if (supportsProgress) {
- this.upload.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw));
- }
- },
-
- downloadProgress: function downloadProgress(progressEventRaw) {
- if (supportsProgress) {
- this.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw));
- }
- },
-
- uploadError: function uploadError(error) {
- if (supportsCustomEvent) {
- this.upload.dispatchEvent(new sinon.CustomEvent("error", {detail: error}));
- }
- }
- });
-
- sinon.extend(FakeXMLHttpRequest, {
- UNSENT: 0,
- OPENED: 1,
- HEADERS_RECEIVED: 2,
- LOADING: 3,
- DONE: 4
- });
-
- sinon.useFakeXMLHttpRequest = function () {
- FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
- if (sinonXhr.supportsXHR) {
- global.XMLHttpRequest = sinonXhr.GlobalXMLHttpRequest;
- }
-
- if (sinonXhr.supportsActiveX) {
- global.ActiveXObject = sinonXhr.GlobalActiveXObject;
- }
-
- delete FakeXMLHttpRequest.restore;
-
- if (keepOnCreate !== true) {
- delete FakeXMLHttpRequest.onCreate;
- }
- };
- if (sinonXhr.supportsXHR) {
- global.XMLHttpRequest = FakeXMLHttpRequest;
- }
-
- if (sinonXhr.supportsActiveX) {
- global.ActiveXObject = function ActiveXObject(objId) {
- if (objId === "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) {
-
- return new FakeXMLHttpRequest();
- }
-
- return new sinonXhr.GlobalActiveXObject(objId);
- };
- }
-
- return FakeXMLHttpRequest;
- };
-
- sinon.FakeXMLHttpRequest = FakeXMLHttpRequest;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./core");
- require("../extend");
- require("./event");
- require("../log_error");
- makeApi(sinon);
- module.exports = sinon;
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon, // eslint-disable-line no-undef
- typeof global !== "undefined" ? global : self
-));
-
-/**
- * @depend fake_xdomain_request.js
- * @depend fake_xml_http_request.js
- * @depend ../format.js
- * @depend ../log_error.js
- */
-/**
- * The Sinon "server" mimics a web server that receives requests from
- * sinon.FakeXMLHttpRequest and provides an API to respond to those requests,
- * both synchronously and asynchronously. To respond synchronuously, canned
- * answers have to be provided upfront.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function () {
-
- var push = [].push;
-
- function responseArray(handler) {
- var response = handler;
-
- if (Object.prototype.toString.call(handler) !== "[object Array]") {
- response = [200, {}, handler];
- }
-
- if (typeof response[2] !== "string") {
- throw new TypeError("Fake server response body should be string, but was " +
- typeof response[2]);
- }
-
- return response;
- }
-
- var wloc = typeof window !== "undefined" ? window.location : {};
- var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host);
-
- function matchOne(response, reqMethod, reqUrl) {
- var rmeth = response.method;
- var matchMethod = !rmeth || rmeth.toLowerCase() === reqMethod.toLowerCase();
- var url = response.url;
- var matchUrl = !url || url === reqUrl || (typeof url.test === "function" && url.test(reqUrl));
-
- return matchMethod && matchUrl;
- }
-
- function match(response, request) {
- var requestUrl = request.url;
-
- if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) {
- requestUrl = requestUrl.replace(rCurrLoc, "");
- }
-
- if (matchOne(response, this.getHTTPMethod(request), requestUrl)) {
- if (typeof response.response === "function") {
- var ru = response.url;
- var args = [request].concat(ru && typeof ru.exec === "function" ? ru.exec(requestUrl).slice(1) : []);
- return response.response.apply(response, args);
- }
-
- return true;
- }
-
- return false;
- }
-
- function makeApi(sinon) {
- sinon.fakeServer = {
- create: function (config) {
- var server = sinon.create(this);
- server.configure(config);
- if (!sinon.xhr.supportsCORS) {
- this.xhr = sinon.useFakeXDomainRequest();
- } else {
- this.xhr = sinon.useFakeXMLHttpRequest();
- }
- server.requests = [];
-
- this.xhr.onCreate = function (xhrObj) {
- server.addRequest(xhrObj);
- };
-
- return server;
- },
- configure: function (config) {
- var whitelist = {
- "autoRespond": true,
- "autoRespondAfter": true,
- "respondImmediately": true,
- "fakeHTTPMethods": true
- };
- var setting;
-
- config = config || {};
- for (setting in config) {
- if (whitelist.hasOwnProperty(setting) && config.hasOwnProperty(setting)) {
- this[setting] = config[setting];
- }
- }
- },
- addRequest: function addRequest(xhrObj) {
- var server = this;
- push.call(this.requests, xhrObj);
-
- xhrObj.onSend = function () {
- server.handleRequest(this);
-
- if (server.respondImmediately) {
- server.respond();
- } else if (server.autoRespond && !server.responding) {
- setTimeout(function () {
- server.responding = false;
- server.respond();
- }, server.autoRespondAfter || 10);
-
- server.responding = true;
- }
- };
- },
-
- getHTTPMethod: function getHTTPMethod(request) {
- if (this.fakeHTTPMethods && /post/i.test(request.method)) {
- var matches = (request.requestBody || "").match(/_method=([^\b;]+)/);
- return matches ? matches[1] : request.method;
- }
-
- return request.method;
- },
-
- handleRequest: function handleRequest(xhr) {
- if (xhr.async) {
- if (!this.queue) {
- this.queue = [];
- }
-
- push.call(this.queue, xhr);
- } else {
- this.processRequest(xhr);
- }
- },
-
- log: function log(response, request) {
- var str;
-
- str = "Request:\n" + sinon.format(request) + "\n\n";
- str += "Response:\n" + sinon.format(response) + "\n\n";
-
- sinon.log(str);
- },
-
- respondWith: function respondWith(method, url, body) {
- if (arguments.length === 1 && typeof method !== "function") {
- this.response = responseArray(method);
- return;
- }
-
- if (!this.responses) {
- this.responses = [];
- }
-
- if (arguments.length === 1) {
- body = method;
- url = method = null;
- }
-
- if (arguments.length === 2) {
- body = url;
- url = method;
- method = null;
- }
-
- push.call(this.responses, {
- method: method,
- url: url,
- response: typeof body === "function" ? body : responseArray(body)
- });
- },
-
- respond: function respond() {
- if (arguments.length > 0) {
- this.respondWith.apply(this, arguments);
- }
-
- var queue = this.queue || [];
- var requests = queue.splice(0, queue.length);
-
- for (var i = 0; i < requests.length; i++) {
- this.processRequest(requests[i]);
- }
- },
-
- processRequest: function processRequest(request) {
- try {
- if (request.aborted) {
- return;
- }
-
- var response = this.response || [404, {}, ""];
-
- if (this.responses) {
- for (var l = this.responses.length, i = l - 1; i >= 0; i--) {
- if (match.call(this, this.responses[i], request)) {
- response = this.responses[i].response;
- break;
- }
- }
- }
-
- if (request.readyState !== 4) {
- this.log(response, request);
-
- request.respond(response[0], response[1], response[2]);
- }
- } catch (e) {
- sinon.logError("Fake server request processing", e);
- }
- },
-
- restore: function restore() {
- return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments);
- }
- };
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./core");
- require("./fake_xdomain_request");
- require("./fake_xml_http_request");
- require("../format");
- makeApi(sinon);
- module.exports = sinon;
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require, module.exports, module);
- } else {
- makeApi(sinon); // eslint-disable-line no-undef
- }
-}());
-
-/**
- * @depend fake_server.js
- * @depend fake_timers.js
- */
-/**
- * Add-on for sinon.fakeServer that automatically handles a fake timer along with
- * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery
- * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead,
- * it polls the object for completion with setInterval. Dispite the direct
- * motivation, there is nothing jQuery-specific in this file, so it can be used
- * in any environment where the ajax implementation depends on setInterval or
- * setTimeout.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function () {
-
- function makeApi(sinon) {
- function Server() {}
- Server.prototype = sinon.fakeServer;
-
- sinon.fakeServerWithClock = new Server();
-
- sinon.fakeServerWithClock.addRequest = function addRequest(xhr) {
- if (xhr.async) {
- if (typeof setTimeout.clock === "object") {
- this.clock = setTimeout.clock;
- } else {
- this.clock = sinon.useFakeTimers();
- this.resetClock = true;
- }
-
- if (!this.longestTimeout) {
- var clockSetTimeout = this.clock.setTimeout;
- var clockSetInterval = this.clock.setInterval;
- var server = this;
-
- this.clock.setTimeout = function (fn, timeout) {
- server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
-
- return clockSetTimeout.apply(this, arguments);
- };
-
- this.clock.setInterval = function (fn, timeout) {
- server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
-
- return clockSetInterval.apply(this, arguments);
- };
- }
- }
-
- return sinon.fakeServer.addRequest.call(this, xhr);
- };
-
- sinon.fakeServerWithClock.respond = function respond() {
- var returnVal = sinon.fakeServer.respond.apply(this, arguments);
-
- if (this.clock) {
- this.clock.tick(this.longestTimeout || 0);
- this.longestTimeout = 0;
-
- if (this.resetClock) {
- this.clock.restore();
- this.resetClock = false;
- }
- }
-
- return returnVal;
- };
-
- sinon.fakeServerWithClock.restore = function restore() {
- if (this.clock) {
- this.clock.restore();
- }
-
- return sinon.fakeServer.restore.apply(this, arguments);
- };
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require) {
- var sinon = require("./core");
- require("./fake_server");
- require("./fake_timers");
- makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require);
- } else {
- makeApi(sinon); // eslint-disable-line no-undef
- }
-}());
-
-/**
- * @depend util/core.js
- * @depend extend.js
- * @depend collection.js
- * @depend util/fake_timers.js
- * @depend util/fake_server_with_clock.js
- */
-/**
- * Manages fake collections as well as fake utilities such as Sinon's
- * timers and fake XHR implementation in one convenient object.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- var push = [].push;
-
- function exposeValue(sandbox, config, key, value) {
- if (!value) {
- return;
- }
-
- if (config.injectInto && !(key in config.injectInto)) {
- config.injectInto[key] = value;
- sandbox.injectedKeys.push(key);
- } else {
- push.call(sandbox.args, value);
- }
- }
-
- function prepareSandboxFromConfig(config) {
- var sandbox = sinon.create(sinon.sandbox);
-
- if (config.useFakeServer) {
- if (typeof config.useFakeServer === "object") {
- sandbox.serverPrototype = config.useFakeServer;
- }
-
- sandbox.useFakeServer();
- }
-
- if (config.useFakeTimers) {
- if (typeof config.useFakeTimers === "object") {
- sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers);
- } else {
- sandbox.useFakeTimers();
- }
- }
-
- return sandbox;
- }
-
- sinon.sandbox = sinon.extend(sinon.create(sinon.collection), {
- useFakeTimers: function useFakeTimers() {
- this.clock = sinon.useFakeTimers.apply(sinon, arguments);
-
- return this.add(this.clock);
- },
-
- serverPrototype: sinon.fakeServer,
-
- useFakeServer: function useFakeServer() {
- var proto = this.serverPrototype || sinon.fakeServer;
-
- if (!proto || !proto.create) {
- return null;
- }
-
- this.server = proto.create();
- return this.add(this.server);
- },
-
- inject: function (obj) {
- sinon.collection.inject.call(this, obj);
-
- if (this.clock) {
- obj.clock = this.clock;
- }
-
- if (this.server) {
- obj.server = this.server;
- obj.requests = this.server.requests;
- }
-
- obj.match = sinon.match;
-
- return obj;
- },
-
- restore: function () {
- sinon.collection.restore.apply(this, arguments);
- this.restoreContext();
- },
-
- restoreContext: function () {
- if (this.injectedKeys) {
- for (var i = 0, j = this.injectedKeys.length; i < j; i++) {
- delete this.injectInto[this.injectedKeys[i]];
- }
- this.injectedKeys = [];
- }
- },
-
- create: function (config) {
- if (!config) {
- return sinon.create(sinon.sandbox);
- }
-
- var sandbox = prepareSandboxFromConfig(config);
- sandbox.args = sandbox.args || [];
- sandbox.injectedKeys = [];
- sandbox.injectInto = config.injectInto;
- var prop,
- value;
- var exposed = sandbox.inject({});
-
- if (config.properties) {
- for (var i = 0, l = config.properties.length; i < l; i++) {
- prop = config.properties[i];
- value = exposed[prop] || prop === "sandbox" && sandbox;
- exposeValue(sandbox, config, prop, value);
- }
- } else {
- exposeValue(sandbox, config, "sandbox", value);
- }
-
- return sandbox;
- },
-
- match: sinon.match
- });
-
- sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer;
-
- return sinon.sandbox;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./extend");
- require("./util/fake_server_with_clock");
- require("./util/fake_timers");
- require("./collection");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend util/core.js
- * @depend sandbox.js
- */
-/**
- * Test function, sandboxes fakes
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function makeApi(sinon) {
- var slice = Array.prototype.slice;
-
- function test(callback) {
- var type = typeof callback;
-
- if (type !== "function") {
- throw new TypeError("sinon.test needs to wrap a test function, got " + type);
- }
-
- function sinonSandboxedTest() {
- var config = sinon.getConfig(sinon.config);
- config.injectInto = config.injectIntoThis && this || config.injectInto;
- var sandbox = sinon.sandbox.create(config);
- var args = slice.call(arguments);
- var oldDone = args.length && args[args.length - 1];
- var exception, result;
-
- if (typeof oldDone === "function") {
- args[args.length - 1] = function sinonDone(res) {
- if (res) {
- sandbox.restore();
- } else {
- sandbox.verifyAndRestore();
- }
- oldDone(res);
- };
- }
-
- try {
- result = callback.apply(this, args.concat(sandbox.args));
- } catch (e) {
- exception = e;
- }
-
- if (typeof oldDone !== "function") {
- if (typeof exception !== "undefined") {
- sandbox.restore();
- throw exception;
- } else {
- sandbox.verifyAndRestore();
- }
- }
-
- return result;
- }
-
- if (callback.length) {
- return function sinonAsyncSandboxedTest(done) { // eslint-disable-line no-unused-vars
- return sinonSandboxedTest.apply(this, arguments);
- };
- }
-
- return sinonSandboxedTest;
- }
-
- test.config = {
- injectIntoThis: true,
- injectInto: null,
- properties: ["spy", "stub", "mock", "clock", "server", "requests"],
- useFakeTimers: true,
- useFakeServer: true
- };
-
- sinon.test = test;
- return test;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- require("./sandbox");
- module.exports = makeApi(core);
- }
-
- if (isAMD) {
- define(loadDependencies);
- } else if (isNode) {
- loadDependencies(require, module.exports, module);
- } else if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(typeof sinon === "object" && sinon || null)); // eslint-disable-line no-undef
-
-/**
- * @depend util/core.js
- * @depend test.js
- */
-/**
- * Test case, sandboxes all test functions
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal) {
-
- function createTest(property, setUp, tearDown) {
- return function () {
- if (setUp) {
- setUp.apply(this, arguments);
- }
-
- var exception, result;
-
- try {
- result = property.apply(this, arguments);
- } catch (e) {
- exception = e;
- }
-
- if (tearDown) {
- tearDown.apply(this, arguments);
- }
-
- if (exception) {
- throw exception;
- }
-
- return result;
- };
- }
-
- function makeApi(sinon) {
- function testCase(tests, prefix) {
- if (!tests || typeof tests !== "object") {
- throw new TypeError("sinon.testCase needs an object with test functions");
- }
-
- prefix = prefix || "test";
- var rPrefix = new RegExp("^" + prefix);
- var methods = {};
- var setUp = tests.setUp;
- var tearDown = tests.tearDown;
- var testName,
- property,
- method;
-
- for (testName in tests) {
- if (tests.hasOwnProperty(testName) && !/^(setUp|tearDown)$/.test(testName)) {
- property = tests[testName];
-
- if (typeof property === "function" && rPrefix.test(testName)) {
- method = property;
-
- if (setUp || tearDown) {
- method = createTest(property, setUp, tearDown);
- }
-
- methods[testName] = sinon.test(method);
- } else {
- methods[testName] = tests[testName];
- }
- }
- }
-
- return methods;
- }
-
- sinon.testCase = testCase;
- return testCase;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var core = require("./util/core");
- require("./test");
- module.exports = makeApi(core);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon // eslint-disable-line no-undef
-));
-
-/**
- * @depend times_in_words.js
- * @depend util/core.js
- * @depend match.js
- * @depend format.js
- */
-/**
- * Assertions matching the test spy retrieval interface.
- *
- * @author Christian Johansen (christian@cjohansen.no)
- * @license BSD
- *
- * Copyright (c) 2010-2013 Christian Johansen
- */
-(function (sinonGlobal, global) {
-
- var slice = Array.prototype.slice;
-
- function makeApi(sinon) {
- var assert;
-
- function verifyIsStub() {
- var method;
-
- for (var i = 0, l = arguments.length; i < l; ++i) {
- method = arguments[i];
-
- if (!method) {
- assert.fail("fake is not a spy");
- }
-
- if (method.proxy && method.proxy.isSinonProxy) {
- verifyIsStub(method.proxy);
- } else {
- if (typeof method !== "function") {
- assert.fail(method + " is not a function");
- }
-
- if (typeof method.getCall !== "function") {
- assert.fail(method + " is not stubbed");
- }
- }
-
- }
- }
-
- function failAssertion(object, msg) {
- object = object || global;
- var failMethod = object.fail || assert.fail;
- failMethod.call(object, msg);
- }
-
- function mirrorPropAsAssertion(name, method, message) {
- if (arguments.length === 2) {
- message = method;
- method = name;
- }
-
- assert[name] = function (fake) {
- verifyIsStub(fake);
-
- var args = slice.call(arguments, 1);
- var failed = false;
-
- if (typeof method === "function") {
- failed = !method(fake);
- } else {
- failed = typeof fake[method] === "function" ?
- !fake[method].apply(fake, args) : !fake[method];
- }
-
- if (failed) {
- failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args)));
- } else {
- assert.pass(name);
- }
- };
- }
-
- function exposedName(prefix, prop) {
- return !prefix || /^fail/.test(prop) ? prop :
- prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1);
- }
-
- assert = {
- failException: "AssertError",
-
- fail: function fail(message) {
- var error = new Error(message);
- error.name = this.failException || assert.failException;
-
- throw error;
- },
-
- pass: function pass() {},
-
- callOrder: function assertCallOrder() {
- verifyIsStub.apply(null, arguments);
- var expected = "";
- var actual = "";
-
- if (!sinon.calledInOrder(arguments)) {
- try {
- expected = [].join.call(arguments, ", ");
- var calls = slice.call(arguments);
- var i = calls.length;
- while (i) {
- if (!calls[--i].called) {
- calls.splice(i, 1);
- }
- }
- actual = sinon.orderByFirstCall(calls).join(", ");
- } catch (e) {
- // If this fails, we'll just fall back to the blank string
- }
-
- failAssertion(this, "expected " + expected + " to be " +
- "called in order but were called as " + actual);
- } else {
- assert.pass("callOrder");
- }
- },
-
- callCount: function assertCallCount(method, count) {
- verifyIsStub(method);
-
- if (method.callCount !== count) {
- var msg = "expected %n to be called " + sinon.timesInWords(count) +
- " but was called %c%C";
- failAssertion(this, method.printf(msg));
- } else {
- assert.pass("callCount");
- }
- },
-
- expose: function expose(target, options) {
- if (!target) {
- throw new TypeError("target is null or undefined");
- }
-
- var o = options || {};
- var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix;
- var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail;
-
- for (var method in this) {
- if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) {
- target[exposedName(prefix, method)] = this[method];
- }
- }
-
- return target;
- },
-
- match: function match(actual, expectation) {
- var matcher = sinon.match(expectation);
- if (matcher.test(actual)) {
- assert.pass("match");
- } else {
- var formatted = [
- "expected value to match",
- " expected = " + sinon.format(expectation),
- " actual = " + sinon.format(actual)
- ];
-
- failAssertion(this, formatted.join("\n"));
- }
- }
- };
-
- mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
- mirrorPropAsAssertion("notCalled", function (spy) {
- return !spy.called;
- }, "expected %n to not have been called but was called %c%C");
- mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
- mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
- mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
- mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
- mirrorPropAsAssertion(
- "alwaysCalledOn",
- "expected %n to always be called with %1 as this but was called with %t"
- );
- mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
- mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
- mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C");
- mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C");
- mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C");
- mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C");
- mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C");
- mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C");
- mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C");
- mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C");
- mirrorPropAsAssertion("threw", "%n did not throw exception%C");
- mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
-
- sinon.assert = assert;
- return assert;
- }
-
- var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
- var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
-
- function loadDependencies(require, exports, module) {
- var sinon = require("./util/core");
- require("./match");
- require("./format");
- module.exports = makeApi(sinon);
- }
-
- if (isAMD) {
- define(loadDependencies);
- return;
- }
-
- if (isNode) {
- loadDependencies(require, module.exports, module);
- return;
- }
-
- if (sinonGlobal) {
- makeApi(sinonGlobal);
- }
-}(
- typeof sinon === "object" && sinon, // eslint-disable-line no-undef
- typeof global !== "undefined" ? global : self
-));
-
- return sinon;
-}));
diff --git a/test/vendor/uniq.js b/test/vendor/uniq.js
deleted file mode 100644
index 44eb1c10..00000000
--- a/test/vendor/uniq.js
+++ /dev/null
@@ -1,46 +0,0 @@
-/* uniq 0.4.0 - http://larsjung.de/uniq/ */
-(function (root, factory) {
-'use strict';
-
-// istanbul ignore else
-if (typeof exports === 'object') {
- module.exports = factory();
-} else {
- root.uniq = factory();
-}
-
-}(this, function () {
- 'use strict';
-
- var PREFIX = 'UNIQ-';
- var SUFFIX = '-ID';
- var LENGTH = 4;
- var ZERO_PAD = new Array(LENGTH + 1).join('0');
- var RE_ID = new RegExp('^' + PREFIX + '\\d{' + LENGTH + '}' + SUFFIX + '$');
-
- var counter = 0;
-
- function id() {
- counter += 1;
- return PREFIX + (ZERO_PAD + counter).substr(-LENGTH) + SUFFIX;
- }
-
- function isId(sequence) {
- return RE_ID.test(sequence);
- }
-
- function obj() {
- return {_uniq_id: id()};
- }
-
- function path(suffix) {
- return '/_uniq_path/' + id() + (suffix ? suffix : '');
- }
-
- return {
- id: id,
- isId: isId,
- obj: obj,
- path: path
- };
-}));