<commit_before>'use strict';

var mongoDBStoreCachedFactory = require('../../lib/index.js');

var express = require('express');
var session = require('express-session');
var MongoDBStoreCached = mongoDBStoreCachedFactory(session);
var request = require('request');

var sinon = require('sinon');

describe('MongoDBStoreCached', function () {

    var server, store,
        getMethod, destroyMethod, setMethod,
        cacheGetMethod, cacheRemoveMethod, cacheSetMethod;

    describe('with default options', function () {

        before(function (done) {

            store = new MongoDBStoreCached({
                collection: 'connect-mongodb-session-cached'
            });

            getMethod = sinon.spy(store, 'get');
            destroyMethod = sinon.spy(store, 'destroy');
            setMethod = sinon.spy(store, 'set');

            cacheGetMethod = sinon.spy(store._cache, 'get');
            cacheRemoveMethod = sinon.spy(store._cache, 'remove');
            cacheSetMethod = sinon.spy(store._cache, 'set');

            request = request.defaults({ jar: request.jar() });

            var app = express();

            app.use(session({
                store: store,
                secret: 'sssh!',
                saveUninitialized: true,
                resave: true,
                unset: 'destroy'
            }));

            app.get('/destroy', function (req, res) {
                delete req.session;
                res.send('Destroyed!');
            });

            app.get('*', function (req, res) {
                res.send('Hello World!');
            });

            server = app.listen(3030, function () {
                done();
            });

        });

        after(function (done) {

            server.close();
            store.db.close();
            store._cache.destroy();
            done();

        });

        it('should set the session entry', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(0);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(2);

                expect(cacheGetMethod.callCount).to.eql(0);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(2);

                done();

            });

        });

        it('should get the session from cache', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(1);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(3);

                expect(cacheGetMethod.callCount).to.eql(1);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(3);

                done();

            });

        });

        it('should get the session from db if cache empty', function (done) {

            store._cache.remove(cacheSetMethod.lastCall.args[0]);

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(2);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(4);

                expect(cacheGetMethod.callCount).to.eql(2);
                expect(cacheRemoveMethod.callCount).to.eql(1);
                expect(cacheSetMethod.callCount).to.eql(4);

                expect(cacheGetMethod.threw('Error')).to.eql(true);

                done();

            });

        });

        it('should destroy the session entry', function (done) {

            request('http://localhost:3030/destroy', function (err, response, body) {

                expect(body).to.eql('Destroyed!');

                expect(getMethod.callCount).to.eql(3);
                expect(destroyMethod.callCount).to.eql(1);
                expect(setMethod.callCount).to.eql(4);

                expect(cacheGetMethod.callCount).to.eql(3);
                expect(cacheRemoveMethod.callCount).to.eql(2);
                expect(cacheSetMethod.callCount).to.eql(4);

                done();

            });

        });

    });

    describe('with option for short cache expiry', function () {

        before(function (done) {

            store = new MongoDBStoreCached({
                collection: 'connect-mongodb-session-cached',
                expireCacheAfter: 10
            });

            getMethod = sinon.spy(store, 'get');
            destroyMethod = sinon.spy(store, 'destroy');
            setMethod = sinon.spy(store, 'set');

            cacheGetMethod = sinon.spy(store._cache, 'get');
            cacheRemoveMethod = sinon.spy(store._cache, 'remove');
            cacheSetMethod = sinon.spy(store._cache, 'set');

            request = request.defaults({ jar: request.jar() });

            var app = express();

            app.use(session({
                store: store,
                secret: 'sssh!',
                saveUninitialized: true,
                resave: true,
                unset: 'destroy'
            }));

            app.get('/destroy', function (req, res) {
                delete req.session;
                res.send('Destroyed!');
            });

            app.get('*', function (req, res) {
                res.send('Hello World!');
            });

            server = app.listen(3030, function () {
                done();
            });

        });

        after(function (done) {

            server.close();
            store.db.close();
            store._cache.destroy();
            done();

        });

        it('should load the session from db after cache expired', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(0);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(2);

                expect(cacheGetMethod.callCount).to.eql(0);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(2);

                setTimeout(function () {

                    request('http://localhost:3030', function (err, response, body) {

                        expect(body).to.eql('Hello World!');

                        expect(getMethod.callCount).to.eql(1);
                        expect(destroyMethod.callCount).to.eql(0);
                        expect(setMethod.callCount).to.eql(3);

                        expect(cacheGetMethod.callCount).to.eql(1);
                        expect(cacheRemoveMethod.callCount).to.eql(0);
                        expect(cacheSetMethod.callCount).to.eql(3);

                        expect(cacheGetMethod.threw('Error')).to.eql(true);

                        done();

                    });

                }, 20);

            });

        });

    });

});
<commit_msg>test: compatible with connect-mongodb-session v1.2.0<commit_after>'use strict';

var mongoDBStoreCachedFactory = require('../../lib/index.js');

var express = require('express');
var session = require('express-session');
var MongoDBStoreCached = mongoDBStoreCachedFactory(session);
var request = require('request');

var sinon = require('sinon');

describe('MongoDBStoreCached', function () {

    var server, store,
        getMethod, destroyMethod, setMethod,
        cacheGetMethod, cacheRemoveMethod, cacheSetMethod;

    describe('with default options', function () {

        before(function (done) {

            store = new MongoDBStoreCached({
                collection: 'connect-mongodb-session-cached'
            });

            getMethod = sinon.spy(store, 'get');
            destroyMethod = sinon.spy(store, 'destroy');
            setMethod = sinon.spy(store, 'set');

            cacheGetMethod = sinon.spy(store._cache, 'get');
            cacheRemoveMethod = sinon.spy(store._cache, 'remove');
            cacheSetMethod = sinon.spy(store._cache, 'set');

            request = request.defaults({ jar: request.jar() });

            var app = express();

            app.use(session({
                store: store,
                secret: 'sssh!',
                saveUninitialized: true,
                resave: true,
                unset: 'destroy'
            }));

            app.get('/destroy', function (req, res) {
                delete req.session;
                res.send('Destroyed!');
            });

            app.get('*', function (req, res) {
                res.send('Hello World!');
            });

            server = app.listen(3030, function () {
                done();
            });

        });

        after(function (done) {

            server.close();
            store.db.close();
            store._cache.destroy();
            done();

        });

        it('should set the session entry', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(0);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(1);

                expect(cacheGetMethod.callCount).to.eql(0);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(1);

                done();

            });

        });

        it('should get the session from cache', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(1);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(2);

                expect(cacheGetMethod.callCount).to.eql(1);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(2);

                done();

            });

        });

        it('should get the session from db if cache empty', function (done) {

            store._cache.remove(cacheSetMethod.lastCall.args[0]);

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(2);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(3);

                expect(cacheGetMethod.callCount).to.eql(2);
                expect(cacheRemoveMethod.callCount).to.eql(1);
                expect(cacheSetMethod.callCount).to.eql(3);

                expect(cacheGetMethod.threw('Error')).to.eql(true);

                done();

            });

        });

        it('should destroy the session entry', function (done) {

            request('http://localhost:3030/destroy', function (err, response, body) {

                expect(body).to.eql('Destroyed!');

                expect(getMethod.callCount).to.eql(3);
                expect(destroyMethod.callCount).to.eql(1);
                expect(setMethod.callCount).to.eql(3);

                expect(cacheGetMethod.callCount).to.eql(3);
                expect(cacheRemoveMethod.callCount).to.eql(2);
                expect(cacheSetMethod.callCount).to.eql(3);

                done();

            });

        });

    });

    describe('with option for short cache expiry', function () {

        before(function (done) {

            store = new MongoDBStoreCached({
                collection: 'connect-mongodb-session-cached',
                expireCacheAfter: 10
            });

            getMethod = sinon.spy(store, 'get');
            destroyMethod = sinon.spy(store, 'destroy');
            setMethod = sinon.spy(store, 'set');

            cacheGetMethod = sinon.spy(store._cache, 'get');
            cacheRemoveMethod = sinon.spy(store._cache, 'remove');
            cacheSetMethod = sinon.spy(store._cache, 'set');

            request = request.defaults({ jar: request.jar() });

            var app = express();

            app.use(session({
                store: store,
                secret: 'sssh!',
                saveUninitialized: true,
                resave: true,
                unset: 'destroy'
            }));

            app.get('/destroy', function (req, res) {
                delete req.session;
                res.send('Destroyed!');
            });

            app.get('*', function (req, res) {
                res.send('Hello World!');
            });

            server = app.listen(3030, function () {
                done();
            });

        });

        after(function (done) {

            server.close();
            store.db.close();
            store._cache.destroy();
            done();

        });

        it('should load the session from db after cache expired', function (done) {

            request('http://localhost:3030', function (err, response, body) {

                expect(body).to.eql('Hello World!');

                expect(getMethod.callCount).to.eql(0);
                expect(destroyMethod.callCount).to.eql(0);
                expect(setMethod.callCount).to.eql(1);

                expect(cacheGetMethod.callCount).to.eql(0);
                expect(cacheRemoveMethod.callCount).to.eql(0);
                expect(cacheSetMethod.callCount).to.eql(1);

                setTimeout(function () {

                    request('http://localhost:3030', function (err, response, body) {

                        expect(body).to.eql('Hello World!');

                        expect(getMethod.callCount).to.eql(1);
                        expect(destroyMethod.callCount).to.eql(0);
                        expect(setMethod.callCount).to.eql(2);

                        expect(cacheGetMethod.callCount).to.eql(1);
                        expect(cacheRemoveMethod.callCount).to.eql(0);
                        expect(cacheSetMethod.callCount).to.eql(2);

                        expect(cacheGetMethod.threw('Error')).to.eql(true);

                        done();

                    });

                }, 20);

            });

        });

    });

});
<|endoftext|>


<commit_before>module.exports = {
  'vue-devtools e2e tests': function (browser) {
    browser
    .url('http://localhost:' + (process.env.PORT || 8081))
      .waitForElementVisible('.message', 1000)
      .assert.containsText('.message', 'Ready. Detected Vue')
      .assert.elementPresent('.instance')
      .assert.containsText('.instance', 'Root')

      // select instance
      .click('.instance .self')
      .assert.cssClassPresent('.instance', 'selected')
      .assert.visible('.tree')
      .assert.containsText('.component-name', 'Root')
      .assert.elementPresent('.data-field')
      .assert.containsText('.data-field', 'obj: Object')

      // should expand root by default
      .assert.count('.instance', 5)

      // select child instance
      .click('.instance .instance:nth-child(1) .self')
      .assert.containsText('.component-name', 'Counter')
      .assert.containsText('.data-field', 'count: 0 computed')
      .assert.containsText('.data-field:nth-child(2)', 'hello: undefined')
      .assert.containsText('.data-field:nth-child(3)', 'test: 1 computed')

      // expand child instance
      .click('.instance .instance:nth-child(2) .arrow-wrapper')
      .assert.count('.instance', 7)

      // add/remove component from app side
      .frame('target')
        .click('.add')
        .frame(null)
      .assert.count('.instance', 10)
      .frame('target')
        .click('.remove')
        .frame(null)
      .assert.count('.instance', 9)

      // filter components
      .setValue('.search input', 'counter')
      .assert.count('.instance', 1)
      .clearValue('.search input')
      .setValue('.search input', 'target')
      .assert.count('.instance', 5)

      // vuex
      .frame('target')
        .click('.increment')
        .click('.increment')
        .click('.decrement')
        .assert.containsText('#counter p', '1')
        .frame(null)
      .click('.button.vuex')
      .assert.count('.history .entry', 4)
      .assert.containsText('.vuex-state-inspector', 'type: "DECREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count: 1')
      .assert.cssClassPresent('.history .entry:nth-child(4)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(4)', 'active')

      // filtering
      .setValue('.search input', 'inc')
      .assert.count('.history .entry', 3)
      .assert.count('.history .entry.inspected', 0)
      .assert.count('.history .entry.active', 0)
      .clearValue('.search input')

      .setValue('.search input', '/dec/i')
      .assert.count('.history .entry', 2)
      .assert.count('.history .entry.inspected.active', 1)
      .clearValue('.search input')

      .setValue('.search input', '/dec)/i')
      .assert.count('.history .entry', 4)
      .assert.count('.history .entry.inspected.active', 1)
      .clearValue('.search input')

      // inspecting
      .click('.history .entry:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'active')
      .assert.containsText('.vuex-state-inspector', 'type: "INCREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count: 2')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)
      // time-travel
      .click('.history .entry:nth-child(3) .entry-actions .action:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      .click('.history .entry:nth-child(2)')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(2)', 'active')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .assert.containsText('.vuex-state-inspector', 'type: "INCREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count: 1')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)
      .click('.history .entry:nth-child(2) .entry-actions .action:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'active')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)

      // base state
      .click('.history .entry:nth-child(1)')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(1)', 'active')
      .assert.containsText('.vuex-state-inspector', 'count: 0')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)
      .click('.history .entry:nth-child(1) .entry-actions .action:nth-child(1)')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '0')
        .frame(null)

      // revert
      .click('.history .entry:nth-child(4)')
      .click('.history .entry:nth-child(4) .action:nth-child(2)')
      .assert.count('.history .entry', 3)
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.containsText('.vuex-state-inspector', 'count: 2')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      // commit
      .click('.history .entry:nth-child(3) .action')
      .assert.count('.history .entry', 1)
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'active')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.containsText('.vuex-state-inspector', 'count: 2')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      // copy vuex state
      .click('.export')
      .waitFor(100)
      .assert.containsText('.export .message', '(Copied to clipboard!)')
      .waitForElementNotVisible('.export .message', 3000)

      // import vuex state
      .click('.import')
      .assert.elementPresent('.import-state')
      .setValue('.import-state textarea', '{invalid: json}')
      .waitForElementVisible('.message.invalid-json', 100)
      .clearValue('.import-state textarea')
      .setValue('.import-state textarea', '{"valid": "json"}')
      .waitForElementNotVisible('.message.invalid-json', 1000)
      .assert.containsText('.vuex-state-inspector', 'valid: "json"')
      .click('.import')
      .waitForElementNotPresent('.import-state', 2000)

      // done
      .end()
  }
}
<commit_msg>fix tests after whitespace change<commit_after>module.exports = {
  'vue-devtools e2e tests': function (browser) {
    browser
    .url('http://localhost:' + (process.env.PORT || 8081))
      .waitForElementVisible('.message', 1000)
      .assert.containsText('.message', 'Ready. Detected Vue')
      .assert.elementPresent('.instance')
      .assert.containsText('.instance', 'Root')

      // select instance
      .click('.instance .self')
      .assert.cssClassPresent('.instance', 'selected')
      .assert.visible('.tree')
      .assert.containsText('.component-name', 'Root')
      .assert.elementPresent('.data-field')
      .assert.containsText('.data-field', 'obj:Object')

      // should expand root by default
      .assert.count('.instance', 5)

      // select child instance
      .click('.instance .instance:nth-child(1) .self')
      .assert.containsText('.component-name', 'Counter')
      .assert.containsText('.data-field', 'count:0 computed')
      .assert.containsText('.data-field:nth-child(2)', 'hello:undefined')
      .assert.containsText('.data-field:nth-child(3)', 'test:1 computed')

      // expand child instance
      .click('.instance .instance:nth-child(2) .arrow-wrapper')
      .assert.count('.instance', 7)

      // add/remove component from app side
      .frame('target')
        .click('.add')
        .frame(null)
      .assert.count('.instance', 10)
      .frame('target')
        .click('.remove')
        .frame(null)
      .assert.count('.instance', 9)

      // filter components
      .setValue('.search input', 'counter')
      .assert.count('.instance', 1)
      .clearValue('.search input')
      .setValue('.search input', 'target')
      .assert.count('.instance', 5)

      // vuex
      .frame('target')
        .click('.increment')
        .click('.increment')
        .click('.decrement')
        .assert.containsText('#counter p', '1')
        .frame(null)
      .click('.button.vuex')
      .assert.count('.history .entry', 4)
      .assert.containsText('.vuex-state-inspector', 'type:"DECREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count:1')
      .assert.cssClassPresent('.history .entry:nth-child(4)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(4)', 'active')

      // filtering
      .setValue('.search input', 'inc')
      .assert.count('.history .entry', 3)
      .assert.count('.history .entry.inspected', 0)
      .assert.count('.history .entry.active', 0)
      .clearValue('.search input')

      .setValue('.search input', '/dec/i')
      .assert.count('.history .entry', 2)
      .assert.count('.history .entry.inspected.active', 1)
      .clearValue('.search input')

      .setValue('.search input', '/dec)/i')
      .assert.count('.history .entry', 4)
      .assert.count('.history .entry.inspected.active', 1)
      .clearValue('.search input')

      // inspecting
      .click('.history .entry:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'active')
      .assert.containsText('.vuex-state-inspector', 'type:"INCREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count:2')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)
      // time-travel
      .click('.history .entry:nth-child(3) .entry-actions .action:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      .click('.history .entry:nth-child(2)')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(2)', 'active')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .assert.containsText('.vuex-state-inspector', 'type:"INCREMENT"')
      .assert.containsText('.vuex-state-inspector', 'count:1')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)
      .click('.history .entry:nth-child(2) .entry-actions .action:nth-child(3)')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(2)', 'active')
      .assert.cssClassNotPresent('.history .entry:nth-child(3)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)

      // base state
      .click('.history .entry:nth-child(1)')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.cssClassNotPresent('.history .entry:nth-child(1)', 'active')
      .assert.containsText('.vuex-state-inspector', 'count:0')
      .frame('target')
        .assert.containsText('#counter p', '1')
        .frame(null)
      .click('.history .entry:nth-child(1) .entry-actions .action:nth-child(1)')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'active')
      .frame('target')
        .assert.containsText('#counter p', '0')
        .frame(null)

      // revert
      .click('.history .entry:nth-child(4)')
      .click('.history .entry:nth-child(4) .action:nth-child(2)')
      .assert.count('.history .entry', 3)
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'active')
      .assert.cssClassPresent('.history .entry:nth-child(3)', 'inspected')
      .assert.containsText('.vuex-state-inspector', 'count:2')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      // commit
      .click('.history .entry:nth-child(3) .action')
      .assert.count('.history .entry', 1)
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'active')
      .assert.cssClassPresent('.history .entry:nth-child(1)', 'inspected')
      .assert.containsText('.vuex-state-inspector', 'count:2')
      .frame('target')
        .assert.containsText('#counter p', '2')
        .frame(null)

      // copy vuex state
      .click('.export')
      .waitFor(100)
      .assert.containsText('.export .message', '(Copied to clipboard!)')
      .waitForElementNotVisible('.export .message', 3000)

      // import vuex state
      .click('.import')
      .assert.elementPresent('.import-state')
      .setValue('.import-state textarea', '{invalid: json}')
      .waitForElementVisible('.message.invalid-json', 100)
      .clearValue('.import-state textarea')
      .setValue('.import-state textarea', '{"valid": "json"}')
      .waitForElementNotVisible('.message.invalid-json', 1000)
      .assert.containsText('.vuex-state-inspector', 'valid:"json"')
      .click('.import')
      .waitForElementNotPresent('.import-state', 2000)

      // done
      .end()
  }
}
<|endoftext|>


<commit_before>
var path = require('path'),
    through = require('through2'),
    settings = require('pelias-config').generate(),
    pbf = require('../../stream/pbf'),
    features = require('../../config/features');

module.exports.tests = {};

// Test exports
module.exports.tests.interface = function(test, common) {
  test('interface: config', function(t) {
    t.equal(typeof pbf.config, 'function', 'config function');
    t.end();
  });
  test('interface: parser', function(t) {
    t.equal(typeof pbf.parser, 'function', 'stream factory');
    t.end();
  });
};

// Configuration can be configured, if options are not explicitly
// specified then the defaults are used from your pelias/config
module.exports.tests.config = function(test, common) {
  test('config: load defaults', function(t) {
    var defaults = pbf.config();
    var expected = {
      file: settings.imports.openstreetmap.datapath + '/' + settings.imports.openstreetmap.import[0].filename,
      leveldb: settings.imports.openstreetmap.leveldbpath,
      tags: features
    };
    t.equal(defaults.file, expected.file, 'load from settings');
    t.equal(defaults.leveldb, expected.leveldb, 'load from settings');
    t.deepEqual(defaults.tags, expected.tags, 'load from settings');
    t.end();
  });
  test('config: override pbf path', function(t) {
    var conf = pbf.config({ file: '/tmp/foo' });
    t.equal(conf.file, '/tmp/foo', 'override defaults');
    t.end();
  });
  test('config: override leveldb path', function(t) {
    var conf = pbf.config({ leveldb: '/tmp/foo' });
    t.equal(conf.leveldb, '/tmp/foo', 'override defaults');
    t.end();
  });
  test('config: override tags', function(t) {
    var conf = pbf.config({ tags: ['foo+bar'] });
    t.deepEqual(conf.tags, ['foo+bar'], 'override defaults');
    t.end();
  });
};

// Validate configuration options
module.exports.tests.validate = function(test, common) {
  test('validate: pbf path', function(t) {
    var conf = pbf.config({ file: '/tmp/noexist.pbf' });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
  test('validate: leveldb path', function(t) {
    var conf = pbf.config({ leveldb: '/tmp/noexist.pbf' });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
  test('validate: tags', function(t) {
    var conf = pbf.config({ tags: [] });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
};

// Create a new streaming pbf parser based on your config
module.exports.tests.parser = function(test, common) {
  test('parser: create parser', function(t) {
    var config = { file: path.resolve(__dirname + '/../vancouver_canada.osm.pbf') };
    var stream = pbf.parser(config);
    t.equal(typeof stream, 'object', 'valid stream');
    t.equal(typeof stream._read, 'function', 'valid readable');
    t.equal(typeof stream._write, 'function', 'valid writeable');
    stream.kill();
    t.end();
  });
};

module.exports.all = function (tape, common) {

  function test(name, testFunction) {
    return tape('pbf: ' + name, testFunction);
  }

  for( var testCase in module.exports.tests ){
    module.exports.tests[testCase](test, common);
  }
};
<commit_msg>use one var per require in test<commit_after>var path = require('path');
var through = require('through2');
var settings = require('pelias-config').generate();
var pbf = require('../../stream/pbf');
var features = require('../../config/features');

module.exports.tests = {};

// Test exports
module.exports.tests.interface = function(test, common) {
  test('interface: config', function(t) {
    t.equal(typeof pbf.config, 'function', 'config function');
    t.end();
  });
  test('interface: parser', function(t) {
    t.equal(typeof pbf.parser, 'function', 'stream factory');
    t.end();
  });
};

// Configuration can be configured, if options are not explicitly
// specified then the defaults are used from your pelias/config
module.exports.tests.config = function(test, common) {
  test('config: load defaults', function(t) {
    var defaults = pbf.config();
    var expected = {
      file: settings.imports.openstreetmap.datapath + '/' + settings.imports.openstreetmap.import[0].filename,
      leveldb: settings.imports.openstreetmap.leveldbpath,
      tags: features
    };
    t.equal(defaults.file, expected.file, 'load from settings');
    t.equal(defaults.leveldb, expected.leveldb, 'load from settings');
    t.deepEqual(defaults.tags, expected.tags, 'load from settings');
    t.end();
  });
  test('config: override pbf path', function(t) {
    var conf = pbf.config({ file: '/tmp/foo' });
    t.equal(conf.file, '/tmp/foo', 'override defaults');
    t.end();
  });
  test('config: override leveldb path', function(t) {
    var conf = pbf.config({ leveldb: '/tmp/foo' });
    t.equal(conf.leveldb, '/tmp/foo', 'override defaults');
    t.end();
  });
  test('config: override tags', function(t) {
    var conf = pbf.config({ tags: ['foo+bar'] });
    t.deepEqual(conf.tags, ['foo+bar'], 'override defaults');
    t.end();
  });
};

// Validate configuration options
module.exports.tests.validate = function(test, common) {
  test('validate: pbf path', function(t) {
    var conf = pbf.config({ file: '/tmp/noexist.pbf' });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
  test('validate: leveldb path', function(t) {
    var conf = pbf.config({ leveldb: '/tmp/noexist.pbf' });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
  test('validate: tags', function(t) {
    var conf = pbf.config({ tags: [] });
    t.throws(function(){
      var stream = pbf.parser(conf);
      stream.kill();
    });
    t.end();
  });
};

// Create a new streaming pbf parser based on your config
module.exports.tests.parser = function(test, common) {
  test('parser: create parser', function(t) {
    var config = { file: path.resolve(__dirname + '/../vancouver_canada.osm.pbf') };
    var stream = pbf.parser(config);
    t.equal(typeof stream, 'object', 'valid stream');
    t.equal(typeof stream._read, 'function', 'valid readable');
    t.equal(typeof stream._write, 'function', 'valid writeable');
    stream.kill();
    t.end();
  });
};

module.exports.all = function (tape, common) {

  function test(name, testFunction) {
    return tape('pbf: ' + name, testFunction);
  }

  for( var testCase in module.exports.tests ){
    module.exports.tests[testCase](test, common);
  }
};
<|endoftext|>


<commit_before>'use strict';

exports.loadAngularMocks = function () {
    browser.clearMockModules();
    browser.addMockModule('swiftBrowserE2E', function () {
        var ngMocks = document.createElement('script');
        ngMocks.src = 'bower_components/angular-mocks/angular-mocks.js';
        document.body.appendChild(ngMocks);

        var swiftSim = document.createElement('script');
        swiftSim.src = 'js/test/swift-simulator.js';
        document.body.appendChild(swiftSim);
    });
    browser.addMockModule('swiftBrowserE2E', function() {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.reset();
        });
    });
};

exports.addContainer = function(name) {
    browser.addMockModule('swiftBrowserE2E', function(name) {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.addContainer(name);
        });
    }, name);
};

exports.setObjects = function(container, objects) {
    browser.addMockModule('swiftBrowserE2E', function(container, jsonObjects) {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.setObjects(container, JSON.parse(jsonObjects));
        });
    }, container, JSON.stringify(objects));
};
<commit_msg>swift-mock: refactor script loading<commit_after>'use strict';

exports.loadAngularMocks = function () {
    browser.clearMockModules();
    browser.addMockModule('swiftBrowserE2E', function () {
        var srcs = [
            'bower_components/angular-mocks/angular-mocks.js',
            'js/test/swift-simulator.js'
        ];
        srcs.forEach(function (src) {
            var script = document.createElement('script');
            script.src = src;
            document.body.appendChild(script);
        });
    });
    browser.addMockModule('swiftBrowserE2E', function() {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.reset();
        });
    });
};

exports.addContainer = function(name) {
    browser.addMockModule('swiftBrowserE2E', function(name) {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.addContainer(name);
        });
    }, name);
};

exports.setObjects = function(container, objects) {
    browser.addMockModule('swiftBrowserE2E', function(container, jsonObjects) {
        angular.module('swiftBrowserE2E').run(function(swiftSim) {
            swiftSim.setObjects(container, JSON.parse(jsonObjects));
        });
    }, container, JSON.stringify(objects));
};
<|endoftext|>


<commit_before>
var venacava = require('../venacava.js')
, Core = venacava.Core
, Model = venacava.Model
, assert = require('assert')
, EventEmitter = require('events').EventEmitter
;

var randomId = function () {
    return 'test' + Math.floor(Math.random() * 1000000);
};

describe('Model', function () {

    var redis
    , newModel = function (options) {
	return new Model(options);
    }
    ;

    it('should be constructable', function () {
	assert(newModel({}), 'unable to create a new model');
    });

    describe('#methods', function () {
	it('should exist', function () {
	    assert(newModel({}).methods, 'model did not have a proto property.');
	});

	it('should have the functions from the construction argument', function () {
	    assert(newModel({
		method: function () {}
	    }).methods.method, 'model proto did not have the argument\'s method');
	});
    });

    describe('#create', function () {

	it('should exist and create a new instance', function () {
	    assert(newModel({}).create({}));
	});

	describe('-> instance', function () {

	    it('should should have a core', function () {
		var instance = newModel({}).create({});
		assert(instance.hasOwnProperty('core'), 'new instance did not have a core.');
		assert.equal(typeof instance.core, 'object', 'new instance core was not an object');
	    });

	    it('should have a core with the desired channel prefix', function () {
		var prefix = 'prefix/'
		, instance = newModel({
		    prefix: 'prefix/'
		}).create({});
		assert.equal(0, instance.core.channel.indexOf(prefix));
	    })

	    it('should have initial values equal to the creation arguments', function () {
		var attrs = {x: 1}
		, instance = newModel({}).create(attrs)
		;
		assert.deepEqual(instance.core.toJSON(), attrs, 'initial core did not have provided attributes.');
	    });

	    describe(':defaults', function () {
		it('should have default values from instance creation', function () {
		    var attrs = {x: 1}
		    , instance = newModel({
			defaults: attrs
		    }).create({})
		    ;
		    assert.deepEqual(instance.core.toJSON(), attrs, 'initial core did not have default attributes.');
		});

		it ('should override defaults with creation parameter', function () {
		    var attrs = {x: 2}
		    , instance = newModel({
			defaults: {
			    x: 1
			    , y: 1
			}
		    }).create(attrs)
		    ;
		    assert.deepEqual(instance.core.toJSON(), {
			x: 2
			, y: 1
		    }, 'initial core defaults were not overriden by creation argument.');
		    assert.deepEqual(attrs, {x: 2}, 'creation argument was mutated');
		});
	    });

	    describe(':initialize', function () {

		it('should be called on creation', function (done) {
		    newModel({
			initialize: function () {
			    return done();
			}
		    }).create({});
		});

		it('should be called with an initialized core', function (done) {
		    var attrs = {x: 1};
		    newModel({
			defaults: attrs
			, initialize: function () {
			    assert.equal(typeof this.core, 'object', 'initialze called with a core which was not an object');
			    assert.deepEqual(this.core.toJSON(), attrs, 'core was not properly initialized before initialize method was called');
			    return done();
			}
		    }).create({});
		});

		it('should be called synchronously', function () {
		    var instance = newModel({
			initialize: function () {
			    this.initialized = true;
			}
		    }).create({});
		    assert(instance.initialized, 'create callback called before initialize');
		});
	    });

	    describe(':methods', function () {
		it('should exist on created instances', function () {
		    var instance = newModel({
			methods: {
			    method: function (arg) {
				assert(this.core, 'method was not called with a context containing the core.');
				assert.equal(arg, 1, 'method was not called with arguments');
			    }
			}
		    }).create({});
		    assert(instance.method, 'instance was not created with the defined method');
		    assert.equal(typeof instance.method, 'function', 'instance was not created with the defined method as a function');
		    instance.method(1)
		});
	    });

	});

    // 	describe(':async', function () {
    // 	    it('should be provided', function (done) {
    // 		newModel({}).create({}, done);
    // 	    });

    // 	    it('should be called after the core has been stored', function (done) {
    // 		var attrs = {x: 1};
    // 		newModel({}).create(attrs, function (err, instance) {
    // 		    assert.ifError(err);
    // 		    var dupCore = new Core(instance.core.channel, redis);
    // 		    dupCore.fetch(function (err) {
    // 			assert.ifError(err);
    // 			assert.deepEqual(dupCore.toJSON(), attrs);
    // 			return done();
    // 		    });
    // 		});
    // 	    });

    // 	    it('should be called after initialization', function (done) {
    // 		var instance = newModel({
    // 		    initialize: function () {
    // 			this.initialized = true;
    // 		    }
    // 		}).create({}, function () {
    // 		    assert(this.initialized, 'create callback called before initialize');
    // 		});
    // 	    });
    // 	});

    });

    describe('#get', function () {
	it('should retrieve an object with a core of the same channel', function () {
	    var model = newModel({});
	    model.create({}, function (err, instance) {
		assert.ifError(err);
		var dup = model.get(instance.core.channel);
		assert.equal(dup.core.channel, instance.core.channel, 'fetched channel was not correct.');
	    });
	});
    });

    describe(':initialize', function () {
	it('should not be called by fetch', function () {
	    var model = newModel({
		initialize: function () {
		    this.initialized = true;
		}
	    });
	    model.create({}, function (err, instance) {
		var dup = model.get(instance.core.channel);
		assert(!dup.initialized);
	    });
	});
    });

    describe(':methods', function () {
	it('should exist on gotten instances', function () {
	    var model = newModel({
		methods: {
		    method: function (arg) {
			assert(this.core, 'method was not called with a context containing the core.');
			assert.equal(arg, 1, 'method was not called with arguments');
		    }
		}
	    });

	    var instance = model.create({})
	    , dup = model.get(instance.core.channel)
	    ;
	    assert(dup.method, 'instance was not gotten with the defined method');
	    assert.equal(typeof dup.method, 'function', 'instance was not gotten with the defined method as a function');
	    dup.method(1)
	});
    });
});
<commit_msg>Fix model tests.<commit_after>
var venacava = require('../venacava.js')
, Core = venacava.Core
, Model = venacava.Model
, assert = require('assert')
, EventEmitter = require('events').EventEmitter
;

var randomId = function () {
    return 'test' + Math.floor(Math.random() * 1000000);
};

describe('Model', function () {

    var redis
    , newModel = function (options) {
	return new Model(options);
    }
    ;

    it('should be constructable', function () {
	assert(newModel({}), 'unable to create a new model');
    });

    describe('#methods', function () {
	it('should exist', function () {
	    assert(newModel({}).methods, 'model did not have a proto property.');
	});

	it('should have the functions from the construction argument', function () {
	    assert(newModel({
		methods: {
		    method: function () {}
		}
	    }).methods.method, 'model proto did not have the argument\'s method');
	});
    });

    describe('#create', function () {

	it('should exist and create a new instance', function () {
	    assert(newModel({}).create({}));
	});

	describe('-> instance', function () {

	    it('should should have a core', function () {
		var instance = newModel({}).create({});
		assert(instance.hasOwnProperty('core'), 'new instance did not have a core.');
		assert.equal(typeof instance.core, 'object', 'new instance core was not an object');
	    });

	    it('should have a core with the desired channel prefix', function () {
		var root = 'prefix/'
		, instance = newModel({
		    channelRoot: 'prefix/'
		}).create({});
		assert.equal(0, instance.core.channel.indexOf(root));
	    })

	    it('should have initial values equal to the creation arguments', function () {
		var attrs = {x: 1}
		, instance = newModel({}).create(attrs)
		;
		assert.deepEqual(instance.core.toJSON(), attrs, 'initial core did not have provided attributes.');
	    });

	    describe(':defaults', function () {
		it('should have default values from instance creation', function () {
		    var attrs = {x: 1}
		    , instance = newModel({
			defaults: attrs
		    }).create({})
		    ;
		    assert.deepEqual(instance.core.toJSON(), attrs, 'initial core did not have default attributes.');
		});

		it ('should override defaults with creation parameter', function () {
		    var attrs = {x: 2}
		    , instance = newModel({
			defaults: {
			    x: 1
			    , y: 1
			}
		    }).create(attrs)
		    ;
		    assert.deepEqual(instance.core.toJSON(), {
			x: 2
			, y: 1
		    }, 'initial core defaults were not overriden by creation argument.');
		    assert.deepEqual(attrs, {x: 2}, 'creation argument was mutated');
		});
	    });

	    describe(':initialize', function () {

		it('should be called on creation', function (done) {
		    newModel({
			initialize: function () {
			    return done();
			}
		    }).create({});
		});

		it('should be called with an initialized core', function (done) {
		    var attrs = {x: 1};
		    newModel({
			defaults: attrs
			, initialize: function () {
			    assert.equal(typeof this.core, 'object', 'initialze called with a core which was not an object');
			    assert.deepEqual(this.core.toJSON(), attrs, 'core was not properly initialized before initialize method was called');
			    return done();
			}
		    }).create({});
		});

		it('should be called synchronously', function () {
		    var instance = newModel({
			initialize: function () {
			    this.initialized = true;
			}
		    }).create({});
		    assert(instance.initialized, 'create callback did not invoke initialized on the instance');
		});
	    });

	    describe(':methods', function () {
		it('should exist on created instances', function () {
		    var instance = newModel({
			methods: {
			    method: function (arg) {
				assert(this.core, 'method was not called with a context containing the core.');
				assert.equal(arg, 1, 'method was not called with arguments');
			    }
			}
		    }).create({});
		    assert(instance.method, 'instance was not created with the defined method');
		    assert.equal(typeof instance.method, 'function', 'instance was not created with the defined method as a function');
		    instance.method(1)
		});
	    });

	});

    // 	describe(':async', function () {
    // 	    it('should be provided', function (done) {
    // 		newModel({}).create({}, done);
    // 	    });

    // 	    it('should be called after the core has been stored', function (done) {
    // 		var attrs = {x: 1};
    // 		newModel({}).create(attrs, function (err, instance) {
    // 		    assert.ifError(err);
    // 		    var dupCore = new Core(instance.core.channel, redis);
    // 		    dupCore.fetch(function (err) {
    // 			assert.ifError(err);
    // 			assert.deepEqual(dupCore.toJSON(), attrs);
    // 			return done();
    // 		    });
    // 		});
    // 	    });

    // 	    it('should be called after initialization', function (done) {
    // 		var instance = newModel({
    // 		    initialize: function () {
    // 			this.initialized = true;
    // 		    }
    // 		}).create({}, function () {
    // 		    assert(this.initialized, 'create callback called before initialize');
    // 		});
    // 	    });
    // 	});

    });

    describe('#get', function () {
	it('should retrieve an object with a core of the same channel', function () {
	    var model = newModel({});
	    model.create({}, function (err, instance) {
		assert.ifError(err);
		var dup = model.get(instance.core.channel);
		assert.equal(dup.core.channel, instance.core.channel, 'fetched channel was not correct.');
	    });
	});
    });

    describe(':initialize', function () {
	it('should not be called by fetch', function () {
	    var model = newModel({
		initialize: function () {
		    this.initialized = true;
		}
	    });
	    model.create({}, function (err, instance) {
		var dup = model.get(instance.core.channel);
		assert(!dup.initialized);
	    });
	});
    });

    describe(':methods', function () {
	it('should exist on gotten instances', function () {
	    var model = newModel({
		methods: {
		    method: function (arg) {
			assert(this.core, 'method was not called with a context containing the core.');
			assert.equal(arg, 1, 'method was not called with arguments');
		    }
		}
	    });

	    var instance = model.create({})
	    , dup = model.get(instance.core.channel)
	    ;
	    assert(dup.method, 'instance was not gotten with the defined method');
	    assert.equal(typeof dup.method, 'function', 'instance was not gotten with the defined method as a function');
	    dup.method(1)
	});
    });
});
<|endoftext|>


<commit_before>'use strict';

require('should');
var fs = require('fs');
var assert = require('assert');

var moduleon = require('../index');

describe('Global usage', function() {

	it('should create a template function from a sql string', function (done) {

		var tplFunc = moduleon('SELECT * FROM table');

		(tplFunc).should.be.a.Function();

		done();
	});

	it('should be able to handle messy sql strings', function(done){

		var sql = fs.readFileSync(__dirname + '/in.sql').toString();

		console.log('---------SQL before------->');
		console.log(sql);

		//get the templating function corresponding to your sql file
		var tplFunc = moduleon( sql );
		(tplFunc).should.be.a.Function();
		var sqlObj = tplFunc({ id : 2 });

		console.log('---------SQL after------->');
		console.log(sqlObj.sql);

		done();

  });

  it('should be able to handle complete file', function() {
    this.timeout(10000);
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    var tplFunc = moduleon(sql);
    var query = tplFunc({
      ids: [1,2,3,4],
      col1: 'test1',
      col3: 5,
    });
    console.log(query.sql);
    assert.equal(query.values[0], 1)
    assert.equal(query.values[1], 2)
    assert.equal(query.values[2], 3)
    assert.equal(query.values[3], 4)
    assert.equal(query.values[4], 'test1')
    assert.equal(query.values[5], 5)
    assert.equal(query.values[6], 5)
  });

  // 2679ms for 100 000 runs
  it('should measure performances : build', function() {
    this.timeout(10000);
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    benchmark(100000, function(){
      moduleon(sql);
    });
  });

  // 19ms for 100 000 runs
  it('should measure performances : execute', function() {
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    var tpl = moduleon(sql);
    var values = {
      ids: [1,2,3,4],
      col1: 'test1',
      col2: 'test2',
      col3: 5,
    };
    benchmark(100000, function(){
      tpl(values);
    });
  });

});

function benchmark(nbRuns, testFunction){
  var startTime = Date.now();
  for (var i=0; i<nbRuns; i++) {
    testFunction();
  }
  var endTime = Date.now();
  var diffTime = endTime - startTime;
  var log = `total ${diffTime}ms, avg ${diffTime/nbRuns}ms`;
  console.log(log);
}
<commit_msg>es5 tests<commit_after>'use strict';

require('should');
var fs = require('fs');
var assert = require('assert');

var moduleon = require('../index');

describe('Global usage', function() {

	it('should create a template function from a sql string', function (done) {

		var tplFunc = moduleon('SELECT * FROM table');

		(tplFunc).should.be.a.Function();

		done();
	});

	it('should be able to handle messy sql strings', function(done){

		var sql = fs.readFileSync(__dirname + '/in.sql').toString();

		console.log('---------SQL before------->');
		console.log(sql);

		//get the templating function corresponding to your sql file
		var tplFunc = moduleon( sql );
		(tplFunc).should.be.a.Function();
		var sqlObj = tplFunc({ id : 2 });

		console.log('---------SQL after------->');
		console.log(sqlObj.sql);

		done();

  });

  it('should be able to handle complete file', function() {
    this.timeout(10000);
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    var tplFunc = moduleon(sql);
    var query = tplFunc({
      ids: [1,2,3,4],
      col1: 'test1',
      col3: 5,
    });
    console.log(query.sql);
    assert.equal(query.values[0], 1);
    assert.equal(query.values[1], 2);
    assert.equal(query.values[2], 3);
    assert.equal(query.values[3], 4);
    assert.equal(query.values[4], 'test1');
    assert.equal(query.values[5], 5);
    assert.equal(query.values[6], 5);
  });

  // 2679ms for 100 000 runs
  it('should measure performances : build', function() {
    this.timeout(10000);
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    benchmark(100000, function(){
      moduleon(sql);
    });
  });

  // 19ms for 100 000 runs
  it('should measure performances : execute', function() {
    var sql = fs.readFileSync(__dirname + '/complete.sql').toString();
    var tpl = moduleon(sql);
    var values = {
      ids: [1,2,3,4],
      col1: 'test1',
      col2: 'test2',
      col3: 5,
    };
    benchmark(100000, function(){
      tpl(values);
    });
  });

});

function benchmark(nbRuns, testFunction){
  var startTime = Date.now();
  for (var i=0; i<nbRuns; i++) {
    testFunction();
  }
  var endTime = Date.now();
  var diffTime = endTime - startTime;
  var log = 'total ' + diffTime + 'ms, avg '+diffTime/nbRuns+'ms';
  console.log(log);
}
<|endoftext|>


<commit_before>define(['$',
        'expect'],
function($,
        expect){

    var a = $.Id('a'),
        b = $.Id('b'),
        c = $.Id('c'),
        d = $.Id('d'),
        create = $.Member($.Id('Object'), $.Id('create'));

    return {
        'module': "Object",
        'tests': [
            ["Simple Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.Assign(a,
                            $.Object({
                                 'kind': 'init',
                                 'key': $.String('ab'),
                                 'value': $.Number(1)
                             })))))

                    .test($.Expression($.Member(a, $.Id('ab'))))
                        .type('number', 1)

                    .test($.Expression($.ComputedMember(a, $.Add($.String('a'), $.String('b')))))
                        .type('number', 1);
            }],
            ["Non Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a, $.Object()))))

                    .test($.Expression($.Member(a, b)))
                        .type('undefined', undefined);
            }],
            ["Multiple Properties Member Object Literal",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(2)
                                 })))))

                    .test($.Expression(
                        $.Add(
                            $.Member(a, b),
                            $.Member(a, c))))
                        .type('number', 3);
            }],
            ["Multiple Duplicate Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(2)
                                 })))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 2);
            }],
            ["Getter Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return($.Number(1))))
                                 })))))

                     .test($.Expression($.Member(a, b)))
                         .type('number', 1);
            }],
            ["Getter This Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return(
                                                $.Member($.This(), c))))
                                 })))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 1);
            }],
            ["Set value for Getter only Property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return(
                                                $.Member($.This(), c))))
                                 }))),
                         $.Expression(
                             $.Assign(
                                 $.Member(a, b),
                                 $.Number(100)))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 1);
            }],

            ["Objects passed by reference",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 })),
                                 $.Declarator(b, a)),
                         $.Expression(
                             $.Assign(
                                 $.Member(a, c),
                                 $.Number(2)))))

                    .test($.Expression($.Member(b, c)))
                        .type('number', 2);
            }],

            ["setter yields set value",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.Assign(a, $.Object({
                            'kind': 'set',
                            'key': $.String('b'),
                            'value': $.FunctionExpression(null, [c],
                                 $.Block(
                                    $.Expression($.Assign($.Member($.This(), d), $.Number(23))),
                                    $.Return($.Number(13))))
                        })))))

                    .test($.Expression(
                        $.Add(
                            $.Assign($.Member(a, b), $.Number(100)),
                            $.Member(a, d))))
                        .type('number', 123);
            }],

            ["Delete property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }))),
                         $.Expression(
                             $.Delete($.Member(a, b)))))

                     .testResult()
                         .type('boolean', true)

                     .test($.Expression($.Member(a, b)))
                         .type('undefined', undefined);
            }],
            ["Delete undefined property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object())),
                         $.Expression(
                             $.Delete($.Member(a, b)))))

                      .testResult()
                         .type('boolean', true)

                     .test($.Expression($.Member(a, b)))
                         .type('undefined', undefined);
            }],

            ["Access member on literal",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Number(1)))))

                      .test(
                          $.Expression(
                              $.Equals(
                                  $.Member(a, $.Id('toString')),
                                  $.Member($.Member($.Id('Number'), $.Id('prototype')), $.Id('toString')))))
                         .type('boolean', true);
            }],

            ["Setting non writable property in non strict",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('writable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Assign(
                                $.Member(a, $.Id('x')),
                                $.Number(100)))))

                      .testResult()
                          .type('number', 100)

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],
            ["Setting non writable property in strict errors",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.String('use strict')),
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('writable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Assign(
                                $.Member(a, $.Id('x')),
                                $.Number(100)))))

                      .isError()

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],
        ]
    };
});
<commit_msg>Added test for delete property<commit_after>define(['$',
        'expect'],
function($,
        expect){

    var a = $.Id('a'),
        b = $.Id('b'),
        c = $.Id('c'),
        d = $.Id('d'),
        create = $.Member($.Id('Object'), $.Id('create'));

    return {
        'module': "Object",
        'tests': [
            ["Simple Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.Assign(a,
                            $.Object({
                                 'kind': 'init',
                                 'key': $.String('ab'),
                                 'value': $.Number(1)
                             })))))

                    .test($.Expression($.Member(a, $.Id('ab'))))
                        .type('number', 1)

                    .test($.Expression($.ComputedMember(a, $.Add($.String('a'), $.String('b')))))
                        .type('number', 1);
            }],
            ["Non Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a, $.Object()))))

                    .test($.Expression($.Member(a, b)))
                        .type('undefined', undefined);
            }],
            ["Multiple Properties Member Object Literal",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(2)
                                 })))))

                    .test($.Expression(
                        $.Add(
                            $.Member(a, b),
                            $.Member(a, c))))
                        .type('number', 3);
            }],
            ["Multiple Duplicate Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(2)
                                 })))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 2);
            }],
            ["Getter Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return($.Number(1))))
                                 })))))

                     .test($.Expression($.Member(a, b)))
                         .type('number', 1);
            }],
            ["Getter This Property Member Object Expression",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return(
                                                $.Member($.This(), c))))
                                 })))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 1);
            }],
            ["Set value for Getter only Property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 }, {
                                     'kind': 'get',
                                     'key': $.String('b'),
                                     'value': $.FunctionExpression(null, [],
                                         $.Block(
                                            $.Return(
                                                $.Member($.This(), c))))
                                 }))),
                         $.Expression(
                             $.Assign(
                                 $.Member(a, b),
                                 $.Number(100)))))

                    .test($.Expression($.Member(a, b)))
                        .type('number', 1);
            }],

            ["Objects passed by reference",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('c'),
                                     'value': $.Number(1)
                                 })),
                                 $.Declarator(b, a)),
                         $.Expression(
                             $.Assign(
                                 $.Member(a, c),
                                 $.Number(2)))))

                    .test($.Expression($.Member(b, c)))
                        .type('number', 2);
            }],

            ["setter yields set value",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.Assign(a, $.Object({
                            'kind': 'set',
                            'key': $.String('b'),
                            'value': $.FunctionExpression(null, [c],
                                 $.Block(
                                    $.Expression($.Assign($.Member($.This(), d), $.Number(23))),
                                    $.Return($.Number(13))))
                        })))))

                    .test($.Expression(
                        $.Add(
                            $.Assign($.Member(a, b), $.Number(100)),
                            $.Member(a, d))))
                        .type('number', 123);
            }],

            ["Delete property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object({
                                     'kind': 'init',
                                     'key': $.String('b'),
                                     'value': $.Number(1)
                                 }))),
                         $.Expression(
                             $.Delete($.Member(a, b)))))

                     .testResult()
                         .type('boolean', true)

                     .test($.Expression($.Member(a, b)))
                         .type('undefined', undefined);
            }],
            ["Delete undefined property",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Object())),
                         $.Expression(
                             $.Delete($.Member(a, b)))))

                      .testResult()
                         .type('boolean', true)

                     .test($.Expression($.Member(a, b)))
                         .type('undefined', undefined);
            }],
            ["Delete non configurable property in non strict",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('configurable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Delete(
                                $.Member(a, $.Id('x'))))))

                      .testResult()
                          .type('boolean', false)

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],
            ["Delete non configurable property in strict",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.String('use strict')),
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('configurable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Delete(
                                $.Member(a, $.Id('x'))))))

                      .isError()

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],

            ["Access member on literal",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Number(1)))))

                      .test(
                          $.Expression(
                              $.Equals(
                                  $.Member(a, $.Id('toString')),
                                  $.Member($.Member($.Id('Number'), $.Id('prototype')), $.Id('toString')))))
                         .type('boolean', true);
            }],

            ["Setting non writable property in non strict",
            function(){
                expect.run(
                    $.Program(
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('writable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Assign(
                                $.Member(a, $.Id('x')),
                                $.Number(100)))))

                      .testResult()
                          .type('number', 100)

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],
            ["Setting non writable property in strict errors",
            function(){
                expect.run(
                    $.Program(
                        $.Expression($.String('use strict')),
                        $.Var(
                            $.Declarator(a,
                                $.Call(create, [
                                    $.Null(),
                                    $.Object({
                                        'kind': 'init',
                                        'key': $.String('x'),
                                        'value': $.Object({
                                            'kind': 'init',
                                            'key': $.String('value'),
                                            'value': $.Number(3)
                                        }, {
                                            'kind': 'init',
                                            'key': $.String('writable'),
                                            'value': $.Boolean(false)
                                        })
                                    })]))),
                        $.Expression(
                            $.Assign(
                                $.Member(a, $.Id('x')),
                                $.Number(100)))))

                      .isError()

                      .test($.Expression($.Member(a, $.Id('x'))))
                         .type('number', 3);
            }],
        ]
    };
});
<|endoftext|>