|
| 1 | +/** |
| 2 | + * Copyright (c) 2013, Twitter Inc. |
| 3 | + * Copyright (c) 2014, Google Inc. |
| 4 | + * Copyright (c) 2014, Marcel Duran and other contributors |
| 5 | + * Released under the MIT License |
| 6 | + */ |
| 7 | + |
| 8 | +var assert = require('assert'), |
| 9 | + http = require('http'), |
| 10 | + url = require('url'), |
| 11 | + WebPageTest = require('../lib/webpagetest'), |
| 12 | + wpt = new WebPageTest(); |
| 13 | + |
| 14 | +// proxy for test on 5432 port |
| 15 | +http.createServer(function(req, res) { |
| 16 | + var requestUrl = url.parse(req.url); |
| 17 | + var body = []; |
| 18 | + |
| 19 | + req.on('data', function(data) { |
| 20 | + body.push(data); |
| 21 | + }); |
| 22 | + req.on('end', function() { |
| 23 | + var orgreq = http.request({ |
| 24 | + host: req.headers.host, |
| 25 | + port: requestUrl.port || 80, |
| 26 | + path: requestUrl.path, |
| 27 | + method: req.method, |
| 28 | + headers: req.headers |
| 29 | + }, |
| 30 | + function(orgres) { |
| 31 | + res.writeHead(orgres.statusCode, orgres.headers); |
| 32 | + orgres.on('data', function(chunk) { |
| 33 | + res.write(chunk); |
| 34 | + }); |
| 35 | + orgres.on('end', function() { |
| 36 | + res.end(); |
| 37 | + }); |
| 38 | + }); |
| 39 | + if(body.length > 0) { |
| 40 | + orgreq.write(body.join('')); |
| 41 | + } |
| 42 | + orgreq.end(); |
| 43 | + }); |
| 44 | +}).listen(5432); |
| 45 | + |
| 46 | +describe('Run via proxy', function() { |
| 47 | + describe('An Example WebPageTest Server', function() { |
| 48 | + |
| 49 | + it('gets a test status request', function(done) { |
| 50 | + wpt.getTestStatus('120816_V2_2', { |
| 51 | + proxy: 'localhost:5432' |
| 52 | + }, function (err, data) { |
| 53 | + if (err) return done(err); |
| 54 | + assert.equal(data.data.id, '120816_V2_2'); |
| 55 | + done(); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments