-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Partially working test setup in phantom
- Loading branch information
Jan Krems
committed
Apr 15, 2016
1 parent
b2f3553
commit 05f88e8
Showing
8 changed files
with
81 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../test/.eslintrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../test/gofer.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
var execFile = require('child_process').execFile; | ||
|
||
require('./mock-service'); | ||
|
||
describe('in a browser', function () { | ||
xit('works (almost) just the same', function (done) { | ||
var mochifyBin = require.resolve('.bin/mochify'); | ||
this.timeout(60 * 1000); | ||
var child = execFile(mochifyBin, [ | ||
'--reporter', 'spec', | ||
'./node_modules/promise/polyfill', | ||
'./node_modules/whatwg-fetch', | ||
'./test-browser/**/*.test.js', | ||
], done); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stderr); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
var MOCK_SERVICE_PORT = 3066; | ||
|
||
var options = { | ||
baseUrl: 'http://127.0.0.1:' + MOCK_SERVICE_PORT, | ||
}; | ||
module.exports = options; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,57 @@ | ||
'use strict'; | ||
var http = require('http'); | ||
var parseUrl = require('url').parse; | ||
|
||
function withMockService() { | ||
var http = require('http'); | ||
var parseUrl = require('url').parse; | ||
var options = require('./mock-service.browser'); | ||
|
||
var options = {}; | ||
var server; | ||
var MOCK_SERVICE_PORT = +(options.baseUrl.match(/:(\d+)/)[1]); | ||
|
||
function sendEcho(req, res) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify({ | ||
method: req.method, | ||
url: req.url, | ||
headers: req.headers, | ||
})); | ||
} | ||
var server; | ||
|
||
function send404(req, res) { | ||
res.statusCode = 404; | ||
sendEcho(req, res); | ||
} | ||
function sendEcho(req, res) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify({ | ||
method: req.method, | ||
url: req.url, | ||
headers: req.headers, | ||
})); | ||
} | ||
|
||
function handleRequest(req, res) { | ||
var pathname = parseUrl(req.url).pathname; | ||
switch (pathname) { | ||
case '/echo': | ||
return sendEcho(req, res); | ||
function send404(req, res) { | ||
res.statusCode = 404; | ||
sendEcho(req, res); | ||
} | ||
|
||
case '/json/404': | ||
return send404(req, res); | ||
function handleRequest(req, res) { | ||
var pathname = parseUrl(req.url).pathname; | ||
switch (pathname) { | ||
case '/echo': | ||
return sendEcho(req, res); | ||
|
||
default: | ||
return res.end('ok'); | ||
} | ||
case '/json/404': | ||
return send404(req, res); | ||
|
||
default: | ||
return res.end('ok'); | ||
} | ||
} | ||
|
||
before(function (done) { | ||
server = http.createServer(handleRequest); | ||
server.on('error', done); | ||
server.listen(function () { | ||
options.baseUrl = 'http://127.0.0.1:' + server.address().port; | ||
done(); | ||
}); | ||
before(function (done) { | ||
server = http.createServer(handleRequest); | ||
server.on('error', done); | ||
server.listen(MOCK_SERVICE_PORT, function () { | ||
done(); | ||
}); | ||
|
||
after(function () { | ||
if (server) { | ||
try { | ||
server.close(); | ||
} catch (e) { | ||
// Ignore cleanup error | ||
} | ||
}); | ||
|
||
after(function () { | ||
if (server) { | ||
try { | ||
server.close(); | ||
} catch (e) { | ||
// Ignore cleanup error | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
return options; | ||
} | ||
module.exports = withMockService; | ||
module.exports = options; |