Skip to content

Commit 45d4e82

Browse files
committed
feat: remove polyfill for user timing api, add unit tests
1 parent 6d6877b commit 45d4e82

8 files changed

Lines changed: 41 additions & 1189 deletions

File tree

dist/statful.js

Lines changed: 1 addition & 579 deletions
Large diffs are not rendered by default.

dist/statful.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/statful.umd.js

Lines changed: 1 addition & 579 deletions
Large diffs are not rendered by default.

dist/statful.umd.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "statful-client-javascript",
3-
"version": "2.0.4",
3+
"version": "2.1.0",
44
"description": "Statful client for Javascript applications",
55
"banner": "/**\n* <%= pkg.name %> <%= pkg.version %>\n* Copyright 2017 Statful <https://www.statful.com/>\n*/\n",
66
"scripts": {
@@ -26,7 +26,7 @@
2626
"babel-plugin-external-helpers": "^6.22.0",
2727
"babel-polyfill": "^6.26.0",
2828
"babel-preset-env": "^1.6.1",
29-
"eslint": "^4.9.0",
29+
"eslint": "^4.11.0",
3030
"jasmine-ajax": "^3.3.1",
3131
"jasmine-core": "^2.8.0",
3232
"karma": "^1.7.1",

src/statful.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'usertiming';
21
import StatfulLogger from './logger';
32
import StatfulUtil from './statful-util';
43
import Metric from './metric.model';
@@ -111,17 +110,6 @@ export default class Statful {
111110
}
112111
}
113112

114-
/**
115-
* Clear resources
116-
*/
117-
static clearResources() {
118-
try {
119-
window.performance.clearResourceTimings();
120-
} catch (ex) {
121-
this.logger.error(ex);
122-
}
123-
}
124-
125113
/**
126114
* Clear measures
127115
* @param {Array} measures - list of measures to clear (optional)

tests/statful-util.tests.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ describe('Statful Util Unit testing', () => {
1212
});
1313
});
1414

15-
it('should to send POST request', () => {
15+
it('should not send POST request - Dry Run', () => {
16+
statfulUtil = new StatfulUtil({
17+
dryrun: true
18+
});
19+
jasmine.Ajax.install();
20+
21+
statfulUtil.sendData({
22+
id: 1
23+
});
24+
25+
const request = jasmine.Ajax.requests.mostRecent();
26+
expect(request).toEqual(undefined);
27+
28+
jasmine.Ajax.uninstall();
29+
});
30+
31+
it('should send POST request', () => {
1632
jasmine.Ajax.install();
1733

1834
statfulUtil.sendData({

tests/statful.tests.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,16 @@ describe('Statful Client Unit testing', () => {
186186
it('should clear all performance marks when calling clearMarks without arguments', () => {
187187
statful.initialize();
188188

189-
statful.registerMark('start_test');
190-
191189
spyOn(window.performance, 'clearMarks');
192190

193191
statful.clearMarks();
194192

195-
expect(window.performance.clearMarks).toHaveBeenCalled();
193+
expect(window.performance.clearMarks).toHaveBeenCalledWith();
196194
});
197195

198196
it('should clear performance marks when calling clearMarks with an Array of marks', () => {
199197
statful.initialize();
200198

201-
statful.registerMark('start_test');
202-
203199
spyOn(window.performance, 'clearMarks');
204200

205201
statful.clearMarks(['start_test']);
@@ -214,19 +210,17 @@ describe('Statful Client Unit testing', () => {
214210

215211
statful.clearMeasures();
216212

217-
expect(window.performance.clearMeasures).toHaveBeenCalled();
213+
expect(window.performance.clearMeasures).toHaveBeenCalledWith();
218214
});
219215

220-
it('should clear performance measures when calling clearMeasures with an Array of measures', () => {
216+
it('should clear performance measures when calling clearMeasures with an Array of marks', () => {
221217
statful.initialize();
222218

223-
statful.registerMeasure('measure', 'metric');
224-
225-
spyOn(window.performance, 'clearMarks');
219+
spyOn(window.performance, 'clearMeasures');
226220

227-
statful.clearMarks(['measure']);
221+
statful.clearMeasures(['start_test']);
228222

229-
expect(window.performance.clearMarks).toHaveBeenCalledWith('measure');
223+
expect(window.performance.clearMeasures).toHaveBeenCalledWith('start_test');
230224
});
231225

232226
it('should add a performance mark when calling registerMark', () => {
@@ -239,6 +233,16 @@ describe('Statful Client Unit testing', () => {
239233
expect(window.performance.mark).toHaveBeenCalledWith('mark_test');
240234
});
241235

236+
it('should not add a performance mark when calling registerMark', () => {
237+
statful.initialize();
238+
239+
spyOn(window.performance, 'mark');
240+
241+
statful.registerMark();
242+
243+
expect(window.performance.mark).not.toHaveBeenCalled();
244+
});
245+
242246
it('should add a performance measure when calling registerMeasure', () => {
243247
statful.initialize();
244248

0 commit comments

Comments
 (0)