bv-ui-core 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +40 -0
- package/.travis.yml +5 -0
- package/CONTRIBUTING.md +98 -0
- package/LICENSE.md +13 -0
- package/OWNERS +2 -0
- package/README.md +63 -0
- package/catalog-info.yaml +30 -0
- package/karma.conf.js +130 -0
- package/lib/README.md +61 -0
- package/lib/api/.babelrc +3 -0
- package/lib/api/.eslintrc +9 -0
- package/lib/api/README.md +134 -0
- package/lib/api/index.js +15 -0
- package/lib/api/statistics.js +148 -0
- package/lib/application/README.md +96 -0
- package/lib/application/index.js +171 -0
- package/lib/body/README.md +13 -0
- package/lib/body/index.js +19 -0
- package/lib/bvFetch/README.md +101 -0
- package/lib/bvFetch/index.js +383 -0
- package/lib/checkHighContrast/README.md +26 -0
- package/lib/checkHighContrast/index.js +36 -0
- package/lib/cookie/README.md +29 -0
- package/lib/cookie/index.js +111 -0
- package/lib/cookieConsent/README.md +41 -0
- package/lib/cookieConsent/index.js +227 -0
- package/lib/cssLoadChecker/README.md +19 -0
- package/lib/cssLoadChecker/index.js +72 -0
- package/lib/date.now/README.md +11 -0
- package/lib/date.now/index.js +40 -0
- package/lib/domainPolice/README.md +66 -0
- package/lib/domainPolice/index.js +95 -0
- package/lib/evented/README.md +42 -0
- package/lib/evented/index.js +135 -0
- package/lib/getOriginalConstructor/README.md +16 -0
- package/lib/getOriginalConstructor/index.js +52 -0
- package/lib/global/README.md +10 -0
- package/lib/global/index.js +48 -0
- package/lib/ie/README.md +13 -0
- package/lib/ie/index.js +25 -0
- package/lib/loader/README.md +73 -0
- package/lib/loader/index.js +358 -0
- package/lib/logger/README.md +82 -0
- package/lib/logger/index.js +180 -0
- package/lib/messageFormat/README.md +10 -0
- package/lib/messageFormat/index.js +42 -0
- package/lib/namespacer/README.md +57 -0
- package/lib/namespacer/index.js +98 -0
- package/lib/performance/README.md +35 -0
- package/lib/performance/entries.js +5 -0
- package/lib/performance/getEntries.js +42 -0
- package/lib/performance/getEntriesByName.js +61 -0
- package/lib/performance/getEntriesByType.js +55 -0
- package/lib/performance/index.js +11 -0
- package/lib/performance/mark.js +97 -0
- package/lib/performance/measure.js +106 -0
- package/lib/performance/now.js +63 -0
- package/lib/pixelsDisplayed/README.md +19 -0
- package/lib/pixelsDisplayed/index.js +113 -0
- package/lib/polyfills/README.md +39 -0
- package/lib/polyfills/fetch/Headers.js +3 -0
- package/lib/polyfills/fetch/Request.js +3 -0
- package/lib/polyfills/fetch/Response.js +3 -0
- package/lib/polyfills/fetch/fetch.js +3 -0
- package/lib/polyfills/fetch/index.js +57 -0
- package/lib/polyfills/promise.js +265 -0
- package/lib/queryShadowDom/README.md +50 -0
- package/lib/queryShadowDom/index.js +93 -0
- package/lib/region/README.md +64 -0
- package/lib/region/europe/index.js +94 -0
- package/lib/region/europe/territories.js +40 -0
- package/lib/region/index.js +123 -0
- package/lib/staticAssetLoader/README.md +116 -0
- package/lib/staticAssetLoader/index.js +248 -0
- package/lib/waitForBody/README.md +21 -0
- package/lib/waitForBody/index.js +36 -0
- package/mkdocs.yaml +5 -0
- package/package.json +55 -0
- package/test/.eslintrc +5 -0
- package/test/fixtures/lib.loader.document-is-wrong-in-ie8.js +5 -0
- package/test/fixtures/lib.loader.loadscript-attribute.js +3 -0
- package/test/fixtures/lib.loader.loadscript.js +3 -0
- package/test/fixtures/lib.loader.loadstylesheet.css +3 -0
- package/test/unit/api/.eslintrc +6 -0
- package/test/unit/api/index.spec.js +37 -0
- package/test/unit/api/response.json +67 -0
- package/test/unit/api/statistics.spec.js +218 -0
- package/test/unit/application/index.spec.js +313 -0
- package/test/unit/body/index.spec.js +15 -0
- package/test/unit/bvFetch/index.spec.js +246 -0
- package/test/unit/checkHighContrast/index.spec.js +16 -0
- package/test/unit/cookie/index.spec.js +191 -0
- package/test/unit/cookieConsent/index.spec.js +119 -0
- package/test/unit/cssLoadChecker/index.spec.js +75 -0
- package/test/unit/date.now/index.spec.js +21 -0
- package/test/unit/domainPolice/index.spec.js +141 -0
- package/test/unit/evented/index.spec.js +59 -0
- package/test/unit/getOriginalConstructor/index.spec.js +60 -0
- package/test/unit/global/index.spec.js +84 -0
- package/test/unit/ie/index.spec.js +14 -0
- package/test/unit/loader/index.spec.js +644 -0
- package/test/unit/logger/index.spec.js +141 -0
- package/test/unit/messageFormat/index.spec.js +31 -0
- package/test/unit/mochaInit.js +8 -0
- package/test/unit/namespacer/index.spec.js +100 -0
- package/test/unit/performance/getEntries.spec.js +30 -0
- package/test/unit/performance/getEntriesByName.spec.js +88 -0
- package/test/unit/performance/getEntriesByType.spec.js +48 -0
- package/test/unit/performance/index.spec.js +35 -0
- package/test/unit/performance/mark.spec.js +40 -0
- package/test/unit/performance/measure.spec.js +50 -0
- package/test/unit/performance/now.spec.js +21 -0
- package/test/unit/pixelsDisplayed/index.spec.js +271 -0
- package/test/unit/polyfills/fetch/Headers.js +12 -0
- package/test/unit/polyfills/fetch/Request.js +12 -0
- package/test/unit/polyfills/fetch/Response.js +12 -0
- package/test/unit/polyfills/fetch/fetch.js +12 -0
- package/test/unit/polyfills/fetch/index.js +61 -0
- package/test/unit/polyfills/promise.spec.js +48 -0
- package/test/unit/region/europe/index.spec.js +70 -0
- package/test/unit/region/index.spec.js +113 -0
- package/test/unit/staticAssetLoader/index.spec.js +215 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the logger module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var Logger = require('../../../lib/logger');
|
|
7
|
+
var global = require('../../../lib/global');
|
|
8
|
+
|
|
9
|
+
describe('lib/logger', function () {
|
|
10
|
+
var sandbox;
|
|
11
|
+
var debugStub;
|
|
12
|
+
var logStub;
|
|
13
|
+
var infoStub;
|
|
14
|
+
var groupStub;
|
|
15
|
+
var groupEndStub;
|
|
16
|
+
|
|
17
|
+
beforeEach(function () {
|
|
18
|
+
sandbox = sinon.sandbox.create();
|
|
19
|
+
|
|
20
|
+
debugStub = sandbox.stub(global.console, 'debug');
|
|
21
|
+
logStub = sandbox.stub(global.console, 'log');
|
|
22
|
+
infoStub = sandbox.stub(global.console, 'info');
|
|
23
|
+
groupStub = sandbox.stub(global.console, 'group');
|
|
24
|
+
groupEndStub = sandbox.stub(global.console, 'groupEnd');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(function () {
|
|
28
|
+
// reset the log level to the default
|
|
29
|
+
Logger.setLogLevel(Logger.INFO);
|
|
30
|
+
sandbox.restore();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('works', function () {
|
|
34
|
+
Logger.info('Hello');
|
|
35
|
+
sinon.assert.notCalled(infoStub);
|
|
36
|
+
Logger.setLogLevel(Logger.INFO, true);
|
|
37
|
+
Logger.info('World');
|
|
38
|
+
sinon.assert.calledWith(infoStub, 'World');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('does not log anything if off', function () {
|
|
42
|
+
Logger.setLogLevel(Logger.OFF);
|
|
43
|
+
Logger.debug('foo');
|
|
44
|
+
sinon.assert.notCalled(debugStub);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('does not log if there is no console', function () {
|
|
48
|
+
var tempConsole = global.console;
|
|
49
|
+
global.console = false;
|
|
50
|
+
|
|
51
|
+
Logger.info('foo');
|
|
52
|
+
global.console = tempConsole;
|
|
53
|
+
|
|
54
|
+
sinon.assert.notCalled(infoStub);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it.skip('defaults to `log` in internet explorer', function () {
|
|
58
|
+
// TODO - fake IE
|
|
59
|
+
Logger.info('foo');
|
|
60
|
+
expect(logStub).to.have.been.calledWith('foo');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('logs the result of a passed function', function () {
|
|
64
|
+
var funcToLog = function () {
|
|
65
|
+
return ['foo'];
|
|
66
|
+
};
|
|
67
|
+
Logger.info(funcToLog);
|
|
68
|
+
expect(infoStub).to.have.been.calledWith('foo');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('#setLogLevel', function () {
|
|
72
|
+
it('defaults to 0', function () {
|
|
73
|
+
Logger.setLogLevel();
|
|
74
|
+
expect(Logger.getLogLevel()).to.equal(Logger.LOG);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('sets log level', function () {
|
|
78
|
+
Logger.setLogLevel(Logger.OFF)
|
|
79
|
+
expect(Logger.getLogLevel()).to.equal(Logger.OFF);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('#assert', function () {
|
|
84
|
+
it('does not do anything if Logger.OFF', function () {
|
|
85
|
+
Logger.setLogLevel(Logger.OFF);
|
|
86
|
+
expect(function () {
|
|
87
|
+
Logger.assert(false);
|
|
88
|
+
}).to.not.throw(Error, /Assertion failed/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('evaluates a function', function () {
|
|
92
|
+
var funcToAssert = function () {
|
|
93
|
+
// According to #assert, return an array
|
|
94
|
+
return [false];
|
|
95
|
+
};
|
|
96
|
+
expect(function () {
|
|
97
|
+
Logger.assert(funcToAssert);
|
|
98
|
+
}).to.throw(Error, /Assertion failed/);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('throws if the assertion failed', function () {
|
|
102
|
+
expect(function () {
|
|
103
|
+
Logger.assert(false)
|
|
104
|
+
}).to.throw(Error, /Assertion failed/);
|
|
105
|
+
});
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('#group', function () {
|
|
109
|
+
it('calls console.group if maxLevel is < the current log level', function () {
|
|
110
|
+
Logger.group(Logger.INFO);
|
|
111
|
+
expect(groupStub).to.have.been.called;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('does not call console.group if maxLevel is < the current log level', function () {
|
|
115
|
+
Logger.group(Logger.DEBUG);
|
|
116
|
+
expect(groupStub).to.not.have.been.called;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('passes arguments on to console.group', function () {
|
|
120
|
+
Logger.group(Logger.INFO, 'Test Group');
|
|
121
|
+
expect(groupStub).to.have.been.calledWith('Test Group');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('#groupEnd', function () {
|
|
126
|
+
it('calls console.groupEnd if maxLevel is < the current log level', function () {
|
|
127
|
+
Logger.groupEnd(Logger.INFO);
|
|
128
|
+
expect(groupEndStub).to.have.been.called;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('does not call console.groupEnd if maxLevel is < the current log level', function () {
|
|
132
|
+
Logger.groupEnd(Logger.DEBUG);
|
|
133
|
+
expect(groupEndStub).to.not.have.been.called;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('passes arguments on to console.groupEnd', function () {
|
|
137
|
+
Logger.groupEnd(Logger.INFO, 'Test GroupEnd');
|
|
138
|
+
expect(groupEndStub).to.have.been.calledWith('Test GroupEnd');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the messageFormat module
|
|
4
|
+
*/
|
|
5
|
+
var messageFormat = require('../../../lib/messageFormat');
|
|
6
|
+
|
|
7
|
+
describe('lib/messageFormat', function () {
|
|
8
|
+
it('messageFormat.generateCountryFromLocale', function () {
|
|
9
|
+
function test1 () {
|
|
10
|
+
return messageFormat.generateCountryFromLocale('en_US');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
expect(test1()).to.be.equal('United States');
|
|
14
|
+
|
|
15
|
+
function test2 () {
|
|
16
|
+
return messageFormat.generateCountryFromLocale('en_DE');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(test2()).to.be.equal('Germany')
|
|
20
|
+
|
|
21
|
+
function test3 () {
|
|
22
|
+
return messageFormat.generateCountryFromLocale('de_DE');
|
|
23
|
+
}
|
|
24
|
+
expect(test3()).to.be.equal('Deutschland')
|
|
25
|
+
|
|
26
|
+
function test4 () {
|
|
27
|
+
return messageFormat.generateCountryFromLocale()
|
|
28
|
+
}
|
|
29
|
+
expect(test4()).to.be.empty
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Tests for the namespacer module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var global = require('../../../lib/global');
|
|
7
|
+
var namespacer = require('../../../lib/namespacer');
|
|
8
|
+
|
|
9
|
+
describe('lib/namespacer', function () {
|
|
10
|
+
var nameA = 'nameA';
|
|
11
|
+
var nameB = 'nameB';
|
|
12
|
+
|
|
13
|
+
function hasNamespaceProperties (name, obj) {
|
|
14
|
+
expect(obj.name).to.equal(name);
|
|
15
|
+
expect(obj.registerProperty).to.be.a('function');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
beforeEach(function () {
|
|
19
|
+
global[nameA] = undefined;
|
|
20
|
+
global[nameB] = undefined;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('creates a namespace', function () {
|
|
24
|
+
var namespace = namespacer.namespace(nameA);
|
|
25
|
+
expect(namespace).to.be.an('object');
|
|
26
|
+
expect(global[nameA]).to.equal(namespace);
|
|
27
|
+
hasNamespaceProperties(nameA, namespace);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('adds the namespace to the global object', function () {
|
|
31
|
+
var namespace = namespacer.namespace(nameA);
|
|
32
|
+
expect(global[nameA]).to.equal(namespace);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('returns the same namespace instance on second invocation', function () {
|
|
36
|
+
var namespace1 = namespacer.namespace(nameA);
|
|
37
|
+
var namespace2 = namespacer.namespace(nameA);
|
|
38
|
+
expect(namespace1).to.equal(namespace2);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('creates distinct namespace instances', function () {
|
|
42
|
+
var namespaceA = namespacer.namespace(nameA);
|
|
43
|
+
var namespaceB = namespacer.namespace(nameB);
|
|
44
|
+
expect(namespaceA).to.not.equal(namespaceB);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('throws when non-object property is already assigned to global', function () {
|
|
48
|
+
expect(function () {
|
|
49
|
+
global[nameA] = false;
|
|
50
|
+
namespacer.namespace(nameA);
|
|
51
|
+
}).to.throw(Error);
|
|
52
|
+
|
|
53
|
+
expect(function () {
|
|
54
|
+
global[nameA] = null;
|
|
55
|
+
namespacer.namespace(nameA);
|
|
56
|
+
}).to.throw(Error);
|
|
57
|
+
|
|
58
|
+
expect(function () {
|
|
59
|
+
global[nameA] = '';
|
|
60
|
+
namespacer.namespace(nameA);
|
|
61
|
+
}).to.throw(Error);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('decorates existing object property assigned to global', function () {
|
|
65
|
+
global[nameA] = {};
|
|
66
|
+
namespacer.namespace(nameA);
|
|
67
|
+
hasNamespaceProperties(nameA, global[nameA]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('namespace', function () {
|
|
71
|
+
var propA = 'propA';
|
|
72
|
+
var propB = 'propB';
|
|
73
|
+
var valueA = {};
|
|
74
|
+
var valueB = {};
|
|
75
|
+
var namespace;
|
|
76
|
+
|
|
77
|
+
beforeEach(function () {
|
|
78
|
+
namespace = namespacer.namespace(nameA);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('registerProperty', function () {
|
|
82
|
+
|
|
83
|
+
it('registers properties', function () {
|
|
84
|
+
namespace.registerProperty(propA, valueA);
|
|
85
|
+
namespace.registerProperty(propB, valueB);
|
|
86
|
+
|
|
87
|
+
expect(namespace[propA]).to.equal(valueA);
|
|
88
|
+
expect(namespace[propB]).to.equal(valueB);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('throws on reregistering a property', function () {
|
|
92
|
+
expect(function () {
|
|
93
|
+
namespace.registerProperty(propA, valueA);
|
|
94
|
+
namespace.registerProperty(propA, valueA);
|
|
95
|
+
}).to.throw(Error);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/getEntries.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfGetEntries = require('../../../lib/performance/getEntries.js');
|
|
8
|
+
var perfMark = require('../../../lib/performance/mark.js');
|
|
9
|
+
|
|
10
|
+
describe('lib/performance/getEntries', function () {
|
|
11
|
+
before(function () {
|
|
12
|
+
perfMark.mark('test1');
|
|
13
|
+
perfMark.mark('test2');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('returns an array of all performance marks', function () {
|
|
17
|
+
var result = perfGetEntries.getEntries();
|
|
18
|
+
|
|
19
|
+
// Test 1: it returns an array.
|
|
20
|
+
expect(result).to.be.an('array');
|
|
21
|
+
|
|
22
|
+
// Test 2: the array contains the relevant performance marks themselves.
|
|
23
|
+
// In order to make sure we're only checking marks created
|
|
24
|
+
// in *this* test, we use the *last* 2 marks, rather than
|
|
25
|
+
// hardcoding indexes 0 and 1, in case other tests make marks.
|
|
26
|
+
expect(result[result.length-2].name).to.equal('test1');
|
|
27
|
+
expect(result[result.length-1].name).to.equal('test2');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/getEntriesByName.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfGetEntriesByName = require('../../../lib/performance/getEntriesByName.js');
|
|
8
|
+
var perfMark = require('../../../lib/performance/mark.js');
|
|
9
|
+
|
|
10
|
+
describe('lib/performance/getEntriesByName', function () {
|
|
11
|
+
before(function () {
|
|
12
|
+
perfMark.mark('test-by-name1');
|
|
13
|
+
perfMark.mark('test-by-name2');
|
|
14
|
+
perfMark.mark('test-by-name2');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('returns an array of all matching performance marks by name', function () {
|
|
18
|
+
var result1 = perfGetEntriesByName.getEntriesByName('test-by-name1');
|
|
19
|
+
var result2 = perfGetEntriesByName.getEntriesByName('test-by-name2');
|
|
20
|
+
|
|
21
|
+
// Test 1: it returns an array.
|
|
22
|
+
expect(result1).to.be.an('array');
|
|
23
|
+
expect(result2).to.be.an('array');
|
|
24
|
+
|
|
25
|
+
// Test 2: the arrays contain the relevant number of performance marks.
|
|
26
|
+
expect(result1.length).to.equal(1);
|
|
27
|
+
expect(result2.length).to.equal(2);
|
|
28
|
+
|
|
29
|
+
// Test 3: the arrays contain the relevant performance marks themselves.
|
|
30
|
+
// In order to make sure we're only checking marks created
|
|
31
|
+
// in *this* test, we use the *last* 2 marks, rather than
|
|
32
|
+
// hardcoding indexes 0 and 1, in case other tests make marks.
|
|
33
|
+
expect(result1[result1.length-1].name).to.equal('test-by-name1');
|
|
34
|
+
expect(result2[result2.length-2].name).to.equal('test-by-name2');
|
|
35
|
+
expect(result2[result2.length-1].name).to.equal('test-by-name2');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns an array of all matching performance marks by name and entryType', function () {
|
|
39
|
+
var result1 = perfGetEntriesByName.getEntriesByName('test-by-name1', 'mark');
|
|
40
|
+
var result2 = perfGetEntriesByName.getEntriesByName('test-by-name2', 'mark');
|
|
41
|
+
|
|
42
|
+
// Test 1: it returns an array.
|
|
43
|
+
expect(result1).to.be.an('array');
|
|
44
|
+
expect(result2).to.be.an('array');
|
|
45
|
+
|
|
46
|
+
// Test 2: the arrays contain the relevant number of performance marks.
|
|
47
|
+
expect(result1.length).to.equal(1);
|
|
48
|
+
expect(result2.length).to.equal(2);
|
|
49
|
+
|
|
50
|
+
// Test 3: the arrays contain the relevant performance marks themselves.
|
|
51
|
+
// In order to make sure we're only checking marks created
|
|
52
|
+
// in *this* test, we use the *last* 2 marks, rather than
|
|
53
|
+
// hardcoding indexes 0 and 1, in case other tests make marks.
|
|
54
|
+
expect(result1[result1.length-1].name).to.equal('test-by-name1');
|
|
55
|
+
expect(result2[result2.length-2].name).to.equal('test-by-name2');
|
|
56
|
+
expect(result2[result2.length-1].name).to.equal('test-by-name2');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('returns an empty array if no name match is found', function () {
|
|
60
|
+
var result = perfGetEntriesByName.getEntriesByName('test-by-name3');
|
|
61
|
+
|
|
62
|
+
// Test 1: it returns an array.
|
|
63
|
+
expect(result).to.be.an('array');
|
|
64
|
+
|
|
65
|
+
// Test 2: the array contains no performance marks.
|
|
66
|
+
expect(result.length).to.equal(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('returns an empty array if no entryType match is found', function () {
|
|
70
|
+
var result = perfGetEntriesByName.getEntriesByName('test-by-name1', 'paint');
|
|
71
|
+
|
|
72
|
+
// Test 1: it returns an array.
|
|
73
|
+
expect(result).to.be.an('array');
|
|
74
|
+
|
|
75
|
+
// Test 2: the array contains no performance marks.
|
|
76
|
+
expect(result.length).to.equal(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
it('throws an error if no arguments are passed', function () {
|
|
81
|
+
//name is passed to the nativeImplementation which is undefined and returns an empty array
|
|
82
|
+
function test () {
|
|
83
|
+
return perfGetEntriesByName.getEntriesByName()
|
|
84
|
+
}
|
|
85
|
+
expect(test()).to.be.empty;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/getEntriesByType.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfGetEntriesByType = require('../../../lib/performance/getEntriesByType.js');
|
|
8
|
+
var perfMark = require('../../../lib/performance/mark.js');
|
|
9
|
+
|
|
10
|
+
describe('lib/performance/getEntriesByType', function () {
|
|
11
|
+
before(function () {
|
|
12
|
+
//Clearing all the marks as marks from other tests were being added
|
|
13
|
+
performance.clearMarks()
|
|
14
|
+
perfMark.mark('test-by-name1');
|
|
15
|
+
perfMark.mark('test-by-name2');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns an array of all matching performance marks by type', function () {
|
|
19
|
+
var result = perfGetEntriesByType.getEntriesByType('mark');
|
|
20
|
+
// Test 1: it returns an array.
|
|
21
|
+
expect(result).to.be.an('array');
|
|
22
|
+
|
|
23
|
+
// Test 2: the array contains the relevant number of performance marks.
|
|
24
|
+
expect(result.length).to.equal(2);
|
|
25
|
+
|
|
26
|
+
// Test 3: the arrays contain the relevant performance marks themselves.
|
|
27
|
+
// In order to make sure we're only checking marks created
|
|
28
|
+
// in *this* test, we use the *last* 2 marks, rather than
|
|
29
|
+
// hardcoding indexes 0 and 1, in case other tests make marks.
|
|
30
|
+
expect(result[result.length-2].name).to.equal('test-by-name1');
|
|
31
|
+
expect(result[result.length-1].name).to.equal('test-by-name2');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('returns an empty array if no entryType match is found', function () {
|
|
35
|
+
var result = perfGetEntriesByType.getEntriesByType('unknown-type');
|
|
36
|
+
|
|
37
|
+
// Test 1: it returns an array.
|
|
38
|
+
expect(result).to.be.an('array');
|
|
39
|
+
|
|
40
|
+
// Test 2: the array contains no performance marks.
|
|
41
|
+
expect(result.length).to.equal(0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('throws an error if no arguments are passed', function () {
|
|
45
|
+
expect(perfGetEntriesByType.getEntriesByType()).to.be.empty;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/index.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfModule = require('../../../lib/performance');
|
|
8
|
+
|
|
9
|
+
describe('lib/performance', function () {
|
|
10
|
+
|
|
11
|
+
it('exposes a getEntries function', function () {
|
|
12
|
+
expect(perfModule.getEntries).to.be.a('function');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('exposes a getEntriesByName function', function () {
|
|
16
|
+
expect(perfModule.getEntriesByName).to.be.a('function');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('exposes a getEntriesByType function', function () {
|
|
20
|
+
expect(perfModule.getEntriesByType).to.be.a('function');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('exposes a now function', function () {
|
|
24
|
+
expect(perfModule.now).to.be.a('function');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('exposes a mark function', function () {
|
|
28
|
+
expect(perfModule.mark).to.be.a('function');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('exposes a measure function', function () {
|
|
32
|
+
expect(perfModule.measure).to.be.a('function');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/mark.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfMark = require('../../../lib/performance/mark.js');
|
|
8
|
+
|
|
9
|
+
describe('lib/performance/mark', function () {
|
|
10
|
+
|
|
11
|
+
it('can create a mark', function () {
|
|
12
|
+
var markName = 'test-mark';
|
|
13
|
+
|
|
14
|
+
expect(function () { perfMark.mark(markName); }).to.not.throw(Error);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('can create multiple marks', function () {
|
|
18
|
+
var markName1 = 'test-mark-1';
|
|
19
|
+
var markName2 = 'test-mark-2';
|
|
20
|
+
|
|
21
|
+
expect(function () { perfMark.mark(markName1); }).to.not.throw(Error);
|
|
22
|
+
expect(function () { perfMark.mark(markName2); }).to.not.throw(Error);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('can create multiple marks of the same name', function () {
|
|
26
|
+
var markName = 'test-mark';
|
|
27
|
+
|
|
28
|
+
expect(function () { perfMark.mark(markName); }).to.not.throw(Error);
|
|
29
|
+
expect(function () { perfMark.mark(markName); }).to.not.throw(Error);
|
|
30
|
+
expect(function () { perfMark.mark(markName); }).to.not.throw(Error);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('throws an error if the mark name is a reserved name', function () {
|
|
34
|
+
// 'navigationStart' is part of the PerformanceTiming interface.
|
|
35
|
+
var markName = 'navigationStart';
|
|
36
|
+
|
|
37
|
+
expect(function () { perfMark.mark(markName); }).to.throw(Error);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/measure.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfMark = require('../../../lib/performance/mark.js');
|
|
8
|
+
var perfMeasure = require('../../../lib/performance/measure.js');
|
|
9
|
+
|
|
10
|
+
describe('lib/performance/measure', function () {
|
|
11
|
+
|
|
12
|
+
it('can create a measure', function () {
|
|
13
|
+
var measureName = 'test-measure';
|
|
14
|
+
|
|
15
|
+
expect(function () { perfMeasure.measure(measureName); }).to.not.throw(Error);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('can create multiple measures', function () {
|
|
19
|
+
var measureName1 = 'test-measure-1';
|
|
20
|
+
var measureName2 = 'test-measure-2';
|
|
21
|
+
|
|
22
|
+
expect(function () { perfMeasure.measure(measureName1); }).to.not.throw(Error);
|
|
23
|
+
expect(function () { perfMeasure.measure(measureName2); }).to.not.throw(Error);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('can create multiple measures of the same name', function () {
|
|
27
|
+
var measureName = 'test-measure';
|
|
28
|
+
|
|
29
|
+
expect(function () { perfMeasure.measure(measureName); }).to.not.throw(Error);
|
|
30
|
+
expect(function () { perfMeasure.measure(measureName); }).to.not.throw(Error);
|
|
31
|
+
expect(function () { perfMeasure.measure(measureName); }).to.not.throw(Error);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('throws an error if the measure name is omitted', function () {
|
|
35
|
+
expect(perfMeasure.measure()).to.be.empty;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('throws an error if the startMark or endMark name is supplied, but is invalid', function () {
|
|
39
|
+
var measureName = 'test-measure';
|
|
40
|
+
var invalidMark = 'lskdjflskdjflskjdflskdjflsdkjflskdjflskfjlskdfjslkdfj';
|
|
41
|
+
|
|
42
|
+
expect(function () { perfMeasure.measure(measureName, invalidMark); }).to.throw(Error);
|
|
43
|
+
|
|
44
|
+
var validMark = 'valid-mark-name';
|
|
45
|
+
perfMark.mark(validMark)
|
|
46
|
+
|
|
47
|
+
expect(function () { perfMeasure.measure(measureName, validMark, invalidMark); }).to.throw(Error);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Unit tests for the performance/now.js module.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Imports.
|
|
7
|
+
var perfNow = require('../../../lib/performance/now.js');
|
|
8
|
+
|
|
9
|
+
describe('lib/performance/now', function () {
|
|
10
|
+
|
|
11
|
+
it('returns a non-negative number', function () {
|
|
12
|
+
var result = perfNow.now();
|
|
13
|
+
|
|
14
|
+
// Test 1: it returns a number.
|
|
15
|
+
expect(result).to.be.a('number');
|
|
16
|
+
|
|
17
|
+
// Test 2: the number is non-negative.
|
|
18
|
+
expect(result).to.be.above(0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
});
|