mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-14 12:04:39 +00:00
Fix test failures — closes #132
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!doctype>
|
||||
<!doctype html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
|
||||
Reference in New Issue
Block a user