Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
webpagetest = require "webpagetest"
gulp.task 'test-perf', ->
wpt = new webpagetest('www.webpagetest.org', 'APIKEY')
parameters =
disableHTTPHeaders: true
private: true
video: true
location: 'Dulles:Chrome'
login: 'admin'
password: 'password'
testSpecs =
runs:
1:
firstView:
SpeedIndex: 1500
median:
firstView:
bytesIn: 1000000
visualComplete: 4000
wpt.runTest 'http://someurl.com', parameters, (err, data) ->
testID = data.data.testId
checkStatus = ->
wpt.getTestStatus testID, (err, data) ->
console.log "Status for #{testID}: #{data.data.statusText}"
unless data.data.completeTime
setTimeout checkStatus, 5000
else
wpt.getTestResults testID, specs: testSpecs, (err, data) ->
console.log "http://www.webpagetest.org/result/#{testID}/"
process.exit 1 if err > 0
checkStatus()
var webpagetest;
webpagetest = require("webpagetest");
gulp.task('test-perf', function() {
var parameters, testSpecs, wpt;
wpt = new webpagetest('www.webpagetest.org', 'APIKEY');
parameters = {
disableHTTPHeaders: true,
"private": true,
video: true,
location: 'Dulles:Chrome',
login: 'admin',
password: 'password'
};
testSpecs = {
runs: {
1: {
firstView: {
SpeedIndex: 1500
}
}
},
median: {
firstView: {
bytesIn: 1000000,
visualComplete: 4000
}
}
};
return wpt.runTest('http://someurl.com', parameters, function(err, data) {
var checkStatus, testID;
testID = data.data.testId;
checkStatus = function() {
return wpt.getTestStatus(testID, function(err, data) {
console.log("Status for " + testID + ": " + data.data.statusText);
if (!data.data.completeTime) {
return setTimeout(checkStatus, 5000);
} else {
return wpt.getTestResults(testID, {
specs: testSpecs
}, function(err, data) {
console.log("http://www.webpagetest.org/result/" + testID + "/");
if (err > 0) {
return process.exit(1);
}
});
}
});
};
return checkStatus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.