mirror of
https://github.com/LukeHagar/relay.git
synced 2025-12-07 20:57:45 +00:00
Saving inital relay POC
This commit is contained in:
53
client/node_modules/xmlhttprequest-ssl/tests/test-sync-response.js
generated
vendored
Normal file
53
client/node_modules/xmlhttprequest-ssl/tests/test-sync-response.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
var assert = require("assert")
|
||||
, spawn = require('child_process').spawn
|
||||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
|
||||
, serverProcess;
|
||||
|
||||
// Running a sync XHR and a webserver within the same process will cause a deadlock
|
||||
serverProcess = spawn(process.argv[0], [__dirname + "/server.js"], { stdio: 'inherit' });
|
||||
|
||||
setTimeout(function () {
|
||||
try {
|
||||
runTest()
|
||||
} catch (e) {
|
||||
throw e
|
||||
} finally {
|
||||
serverProcess.kill('SIGINT');
|
||||
}
|
||||
}, 100);
|
||||
|
||||
function runTest() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var isSync = false;
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
assert.equal(xhr.responseText, "Hello world!");
|
||||
assert.equal(xhr.getResponseHeader('content-type'), 'text/plain')
|
||||
isSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
xhr.open("GET", "http://localhost:8888/text", false);
|
||||
xhr.send();
|
||||
|
||||
assert(isSync, "XMLHttpRequest was not synchronous");
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
isSync = false;
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
assert.equal(xhr.response.toString(), 'Hello world!');
|
||||
assert.equal(xhr.getResponseHeader('content-type'), 'application/octet-stream')
|
||||
isSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
xhr.open("GET", "http://localhost:8888/binary", false);
|
||||
xhr.send();
|
||||
|
||||
assert(isSync, "XMLHttpRequest was not synchronous");
|
||||
|
||||
console.log("done");
|
||||
}
|
||||
Reference in New Issue
Block a user