<commit_before>var assert = require("assert");
var middleware = require('..');
var express = require('express');
var should = require('should');
var request = require('supertest');

describe('middleware initialize', function () {

    it('check bigpipe expose', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            res.should.have.property('bigpipe');

            res.once('finish', function () {
                should(res.bigpipe).not.be.ok;
            });

            res.end(responseText);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);

                done();
            });
    });

    it('check bigpipe options', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware({
            key: 'test'
        }));

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            bigpipe.options.should.have.property('key', 'test');

            res.end(responseText);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });
});

describe('bigpipe quickling filter', function () {

    it('single pagelet', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelet=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('signle pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('multi pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets[]=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('more pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');
            bigpipe.quicklings.should.have.property(1, 'pageletB');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets[]=pageletA&pagelets[]=pageletB')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });
});

describe('render', function () {

    it('single render', function (done) {
        var app = express();

        app.use(middleware());

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    varA: 'value A'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, '<script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletA","html":"the result is value A","js":[],"css":[],"styles":[],"scripts":[]});</script>');
                done();
            });
    });

    it('multi render', function (done) {
        var app = express();

        app.use(middleware());

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    varA: 'value A'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                locals: {
                    varA: 'value B'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, '<script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletA","html":"the result is value A","js":[],"css":[],"styles":[],"scripts":[]});</script><script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletB","html":"the result is value B","js":[],"css":[],"styles":[],"scripts":[]});</script>');
                done();
            });
    });
});

describe('render template', function () {

    it('template', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletApageletB');
                done();
            });
    });
});


describe('render event', function () {

    it('template', function (done) {
        var app = express();
        var expected = 2;
        var actually = 0;

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    key: '123'
                },
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.on('pagelet:render:before', function (pagelet, locals) {
                assert.equal(pagelet.id, 'pageletA');
                assert.equal(locals.key, '123');
                locals.key2 = '456';
                actually++;
            });

            bigpipe.on('pagelet:render:after', function (pagelet, locals) {
                assert.equal(pagelet.id, 'pageletA');
                assert.equal(locals.key, '123');
                assert.equal(locals.key2, '456');
                actually++;
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletA');
                assert.equal(actually, expected);
                done();
            });
    });
});

describe('render order', function () {

    it('async', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            // 50 ms later
            bigpipe.bind('pageletA', function (next) {
                setTimeout(function () {
                    next();
                }, 50);
            });

            // 10 ms later
            bigpipe.bind('pageletB', function (next) {
                setTimeout(function () {
                    next();
                }, 10);
            });


            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletBpageletA');
                done();
            });
    });

    it('pipeline', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'pipeline',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'pipeline',
                compiled: function () {
                    return 'whatever';
                }
            });

            // 50 ms later
            bigpipe.bind('pageletA', function (next) {
                setTimeout(function () {
                    next();
                }, 50);
            });

            // 10 ms later
            bigpipe.bind('pageletB', function (next) {
                setTimeout(function () {
                    next();
                }, 10);
            });


            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletApageletB');
                done();
            });
    });
});

describe('render quickling', function () {

    it('quickling 1', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'quickling',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/?pagelet=pageletB')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletB');
                done();
            });
    });


    it('quickling 2', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'quickling',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/?pagelet=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletA');
                done();
            });
    });
});

describe('Provider', function () {

    it('bigpipe.bind', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {
                    return locals.content;
                }
            });

            bigpipe.bind('pageletA', function (next) {
                next(null, {
                    content: 'test123'
                });
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'test123');
                done();
            });
    });

    it('bigpipe.bind all', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {
                    return locals.content;
                }
            });

            bigpipe.bind('all', function (id, next) {
                assert.equal(id, 'pageletA');
                next(null, {
                    content: 'test123'
                });
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'test123');
                done();
            });
    });


    it('prepare:source', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {<commit_msg>disable prepare:source and all in testcase<commit_after>var assert = require("assert");
var middleware = require('..');
var express = require('express');
var should = require('should');
var request = require('supertest');

describe('middleware initialize', function () {

    it('check bigpipe expose', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            res.should.have.property('bigpipe');

            res.once('finish', function () {
                should(res.bigpipe).not.be.ok;
            });

            res.end(responseText);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);

                done();
            });
    });

    it('check bigpipe options', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware({
            key: 'test'
        }));

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            bigpipe.options.should.have.property('key', 'test');

            res.end(responseText);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });
});

describe('bigpipe quickling filter', function () {

    it('single pagelet', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelet=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('signle pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('multi pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets[]=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });

    it('more pagelets', function (done) {
        var app = express();
        var responseText = 'hello world';

        app.use(middleware());

        app.use(function (req, res, next) {
            var bigpipe = res.bigpipe;

            assert.ok(bigpipe.isQuicklingMode());
            assert.ok(res.locals.isQuicklingMode);

            bigpipe.quicklings.should.have.property(0, 'pageletA');
            bigpipe.quicklings.should.have.property(1, 'pageletB');

            res.end(responseText);
        });

        request(app.listen())
            .get('/?pagelets[]=pageletA&pagelets[]=pageletB')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, responseText);
                done();
            });
    });
});

describe('render', function () {

    it('single render', function (done) {
        var app = express();

        app.use(middleware());

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    varA: 'value A'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, '<script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletA","html":"the result is value A","js":[],"css":[],"styles":[],"scripts":[]});</script>');
                done();
            });
    });

    it('multi render', function (done) {
        var app = express();

        app.use(middleware());

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    varA: 'value A'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                locals: {
                    varA: 'value B'
                },
                compiled: function (locals) {
                    return 'the result is ' + locals.varA;
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, '<script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletA","html":"the result is value A","js":[],"css":[],"styles":[],"scripts":[]});</script><script type="text/javascript">BigPipe.onPageletArrive({"container":"","reqID":null,"id":"pageletB","html":"the result is value B","js":[],"css":[],"styles":[],"scripts":[]});</script>');
                done();
            });
    });
});

describe('render template', function () {

    it('template', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletApageletB');
                done();
            });
    });
});


describe('render event', function () {

    it('template', function (done) {
        var app = express();
        var expected = 2;
        var actually = 0;

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                locals: {
                    key: '123'
                },
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.on('pagelet:render:before', function (pagelet, locals) {
                assert.equal(pagelet.id, 'pageletA');
                assert.equal(locals.key, '123');
                locals.key2 = '456';
                actually++;
            });

            bigpipe.on('pagelet:render:after', function (pagelet, locals) {
                assert.equal(pagelet.id, 'pageletA');
                assert.equal(locals.key, '123');
                assert.equal(locals.key2, '456');
                actually++;
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletA');
                assert.equal(actually, expected);
                done();
            });
    });
});

describe('render order', function () {

    it('async', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            // 50 ms later
            bigpipe.bind('pageletA', function (next) {
                setTimeout(function () {
                    next();
                }, 50);
            });

            // 10 ms later
            bigpipe.bind('pageletB', function (next) {
                setTimeout(function () {
                    next();
                }, 10);
            });


            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletBpageletA');
                done();
            });
    });

    it('pipeline', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'pipeline',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'pipeline',
                compiled: function () {
                    return 'whatever';
                }
            });

            // 50 ms later
            bigpipe.bind('pageletA', function (next) {
                setTimeout(function () {
                    next();
                }, 50);
            });

            // 10 ms later
            bigpipe.bind('pageletB', function (next) {
                setTimeout(function () {
                    next();
                }, 10);
            });


            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletApageletB');
                done();
            });
    });
});

describe('render quickling', function () {

    it('quickling 1', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'quickling',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/?pagelet=pageletB')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletB');
                done();
            });
    });


    it('quickling 2', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.id %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.addPagelet({
                id: 'pageletB',
                mode: 'quickling',
                compiled: function () {
                    return 'whatever';
                }
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/?pagelet=pageletA')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'pageletA');
                done();
            });
    });
});

describe('Provider', function () {

    it('bigpipe.bind', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {
                    return locals.content;
                }
            });

            bigpipe.bind('pageletA', function (next) {
                next(null, {
                    content: 'test123'
                });
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'test123');
                done();
            });
    });

    // disabled for sync render
    it.skip('bigpipe.bind all', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {
                    return locals.content;
                }
            });

            bigpipe.bind('all', function (id, next) {
                assert.equal(id, 'pageletA');
                next(null, {
                    content: 'test123'
                });
            });

            bigpipe.pipe(res);
        });

        request(app.listen())
            .get('/')
            .end(function (err, res) {
                if (err) return done(err);

                assert.equal(res.text, 'test123');
                done();
            });
    });

    // disabled for sync render
    it.skip('prepare:source', function (done) {
        var app = express();

        app.use(middleware({
            tpl: {
                _default: '<%= this.html %>'
            }
        }));

        app.use(function (req, res) {
            var bigpipe = res.bigpipe;

            bigpipe.addPagelet({
                id: 'pageletA',
                mode: 'async',
                compiled: function (locals) {
{'fraction_non_alphanumeric': 0.14486794717887155, 'fraction_numerical': 0.003241296518607443, 'mean_word_length': 1.1978101708330584, 'pattern_counts': {'":': 48, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2702783', 'n_tokens_mistral': 9368, 'n_tokens_neox': 8636, 'n_words': 1687}