зеркало из https://github.com/Azure/ms-rest-js.git
Enable browser tests with npm test (#108)
* Enable browser tests with npm test * Add chrome-unit script * Add sudo: true to .travis.yml to support chrome testing * Add back a safe amount of parallelism * Fix bug in testserver * Run node tests in script * chrome-unit -> unit
This commit is contained in:
Родитель
cbf8dad4b4
Коммит
ce09bc0435
|
@ -0,0 +1,64 @@
|
|||
const { major } = require("semver");
|
||||
const { spawn, exec } = require("child_process");
|
||||
const { join } = require("path");
|
||||
|
||||
const webpackDevServer = spawn(join(__dirname, "../node_modules/.bin/ts-node"), [join(__dirname, "../testserver")], { shell: true })
|
||||
function cleanupDevServer() {
|
||||
webpackDevServer.stderr.destroy();
|
||||
webpackDevServer.stdout.destroy();
|
||||
webpackDevServer.kill();
|
||||
};
|
||||
|
||||
let mochaRunning = false
|
||||
const webpackDevServerHandler = (data) => {
|
||||
if (!mochaRunning) {
|
||||
mochaRunning = true
|
||||
|
||||
const mochaChromePromise = new Promise((resolve, reject) => {
|
||||
if (major(process.version) < 8) {
|
||||
// Skip browser tests in pre-node 8
|
||||
resolve();
|
||||
} else {
|
||||
const mochaChromeExecutable = join(__dirname, "../node_modules/.bin/mocha-chrome");
|
||||
exec(`${mochaChromeExecutable} http://localhost:3001`, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
console.log(stdout);
|
||||
console.error(stderr);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const mochaPromise = new Promise((resolve, reject) => {
|
||||
const mochaExecutable = join(__dirname, "../node_modules/.bin/_mocha");
|
||||
const mocha = exec(mochaExecutable, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
console.log(stdout);
|
||||
console.error(stderr);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([mochaPromise, mochaChromePromise]).then(res => {
|
||||
cleanupDevServer();
|
||||
process.exit(0);
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
cleanupDevServer();
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
webpackDevServer.stderr.on('data', data => {
|
||||
console.error("webpack dev server error:", data.toString());
|
||||
});
|
||||
|
||||
webpackDevServer.stdout.on('data', webpackDevServerHandler);
|
||||
webpackDevServer.on('exit', webpackDevServerHandler);
|
|
@ -1,5 +1,7 @@
|
|||
language: node_js
|
||||
sudo: false
|
||||
sudo: true
|
||||
addons:
|
||||
chrome: stable
|
||||
node_js:
|
||||
- "6"
|
||||
- "8"
|
11
package.json
11
package.json
|
@ -55,6 +55,7 @@
|
|||
"mocha": "^5.1.1",
|
||||
"mocha-chrome": "^1.1.0",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"semver": "^5.5.0",
|
||||
"should": "5.2.0",
|
||||
"shx": "^0.2.2",
|
||||
"ts-loader": "^4.2.0",
|
||||
|
@ -81,16 +82,14 @@
|
|||
"build:browser": "webpack && node node_modules/uglify-es/bin/uglifyjs --source-map -c -m -o msRestBundle.min.js msRestBundle.js",
|
||||
"watch:node": "tsc -w",
|
||||
"watch:browser": "webpack -w",
|
||||
"test": "run-p test:tslint test:nodejs-unit",
|
||||
"test:server": "ts-node testserver",
|
||||
"test": "run-p test:tslint test:unit",
|
||||
"test:tslint": "tslint -p . -c tslint.json --exclude \"./test/**/*.ts\"",
|
||||
"test:nodejs-unit": "mocha",
|
||||
"test:mocha-chrome": "sleep 0.5 && mocha-chrome http://localhost:3001",
|
||||
"test:chrome-unit": "run-p -r test:server test:mocha-chrome",
|
||||
"test:unit": "node ./.scripts/unit",
|
||||
"test:server": "ts-node testserver",
|
||||
"prepare": "npm run build",
|
||||
"publish-preview": "npm test && shx rm -rf dist/test && node ./.scripts/publish",
|
||||
"local": "node ./.scripts/local.js",
|
||||
"preview": "node ./.scripts/preview.js",
|
||||
"latest": "node ./.scripts/latest.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,19 +97,11 @@ describe("axiosHttpClient", () => {
|
|||
});
|
||||
|
||||
it("should allow canceling requests", async function() {
|
||||
// ensure that a large upload is actually cancelled
|
||||
this.timeout(2000);
|
||||
|
||||
const controller = getAbortController();
|
||||
const request = new WebResource(`${baseURL}/fileupload`, "POST", new Uint8Array(1024*1024*100), undefined, undefined, true, controller.signal);
|
||||
const request = new WebResource(`${baseURL}/fileupload`, "POST", new Uint8Array(1024*1024*10), undefined, undefined, true, controller.signal);
|
||||
const client = new AxiosHttpClient();
|
||||
const promise = client.sendRequest(request);
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
controller.abort();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
controller.abort();
|
||||
try {
|
||||
await promise;
|
||||
assert.fail('');
|
||||
|
@ -139,23 +131,15 @@ describe("axiosHttpClient", () => {
|
|||
});
|
||||
|
||||
it("should allow canceling multiple requests with one token", async function () {
|
||||
// ensure that a large upload is actually cancelled
|
||||
this.timeout(4000);
|
||||
|
||||
const controller = getAbortController();
|
||||
const buf = new Uint8Array(1024*1024*100);
|
||||
const buf = new Uint8Array(1024*1024*1);
|
||||
const requests = [
|
||||
new WebResource(`${baseURL}/fileupload`, "POST", buf, undefined, undefined, true, controller.signal),
|
||||
new WebResource(`${baseURL}/fileupload`, "POST", buf, undefined, undefined, true, controller.signal)
|
||||
];
|
||||
const client = new AxiosHttpClient();
|
||||
const promises = requests.map(r => client.sendRequest(r));
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
controller.abort();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
controller.abort();
|
||||
// Ensure each promise is individually rejected
|
||||
for (const promise of promises) {
|
||||
try {
|
||||
|
|
|
@ -17,18 +17,17 @@ app.use(express.static(path.join(__dirname, "../")));
|
|||
app.use(express.static(path.join(__dirname, "../test/resources/")));
|
||||
|
||||
app.post("/fileupload", function(req, res) {
|
||||
res.status(200);
|
||||
req.pipe(res);
|
||||
});
|
||||
|
||||
app.get("/set-cookie", function(req, res) {
|
||||
res.setHeader("Set-Cookie", "data=123456");
|
||||
res.end(200);
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.get("/cookie", function(req, res) {
|
||||
res.setHeader("Cookie", req.header("Cookie"));
|
||||
res.end(200);
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.listen(port, function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче