Skip to content

Commit

Permalink
#257 - move whitelist code to filter.js
Browse files Browse the repository at this point in the history
  • Loading branch information
beenanner committed Jan 25, 2017
1 parent ac55eae commit 87edfc8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/core/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Promise = require('bluebird'),
connectivity = require('../support/connectivity'),
path = require('path'),
util = require('../support/util'),
filter = require('../support/filters'),
moment = require('moment'),
get = require('lodash.get'),
xvfb = require('../support/video/xvfb');
Expand Down Expand Up @@ -233,15 +234,7 @@ class Engine {
})
.then((result) => {
if(options.userTimingWhitelist) {
const userTimingWhitelistRegex = new RegExp(options.userTimingWhitelist);
let userTimingMarks = result.timings.userTimings.marks;
result.timings.userTimings.marks = userTimingMarks.filter((mark) => {
return userTimingWhitelistRegex.exec(mark.name) !== null;
}, {});
let userTimingMeasurements = result.timings.userTimings.measures;
result.timings.userTimings.measures = userTimingMeasurements.filter((measure) => {
return userTimingWhitelistRegex.exec(measure.name) !== null;
}, {});
result = filter.userTimingWhitelist(result, options.userTimingWhitelist);
}
return {
browserScripts: result,
Expand Down
13 changes: 13 additions & 0 deletions lib/support/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ module.exports = {
onlyDirectories: function(filepath) {
return fs.statAsync(filepath)
.then((stat) => stat.isDirectory());
},
userTimingWhitelist: function(result, whitelistRegex) {
const userTimingWhitelistRegex = new RegExp(whitelistRegex);
let userTimingMarks = result.timings.userTimings.marks;
result.timings.userTimings.marks = userTimingMarks.filter((mark) => {
return userTimingWhitelistRegex.exec(mark.name) !== null;
}, {});
let userTimingMeasurements = result.timings.userTimings.measures;
result.timings.userTimings.measures = userTimingMeasurements.filter((measure) => {
return userTimingWhitelistRegex.exec(measure.name) !== null;
}, {});

return result;
}
};

0 comments on commit 87edfc8

Please sign in to comment.