Fix test failures — closes #132

This commit is contained in:
Rich Harris
2018-03-03 14:33:47 -05:00
committed by GitHub
parent d9cb572271
commit a96fb93bfb
5 changed files with 1591 additions and 559 deletions

View File

@@ -5,26 +5,33 @@ import serve from 'serve-static';
import sapper from '../../../middleware';
import { routes } from './manifest/server.js';
let count;
let pending;
let ended;
process.on('message', message => {
if (message.action === 'start') {
count = 0;
if (pending) {
throw new Error(`Already capturing`);
}
pending = new Set();
ended = false;
process.send({ type: 'ready' });
}
if (message.action === 'end') {
ended = true;
if (count === 0) process.send({ type: 'done' });
if (pending.size === 0) {
process.send({ type: 'done' });
pending = null;
}
}
});
const app = express();
app.use((req, res, next) => {
count += 1;
if (pending) pending.add(req.url);
const { write, end } = res;
const chunks = [];
@@ -38,7 +45,7 @@ app.use((req, res, next) => {
if (chunk) chunks.push(new Buffer(chunk));
end.apply(res, arguments);
count -= 1;
if (pending) pending.delete(req.url);
process.send({
method: req.method,
@@ -48,7 +55,7 @@ app.use((req, res, next) => {
body: Buffer.concat(chunks).toString()
});
if (count === 0 && ended) {
if (pending && pending.size === 0 && ended) {
process.send({ type: 'done' });
}
};

View File

@@ -1,4 +1,4 @@
<!doctype>
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>