Demo for query storing
Change-Id: I947bcac841992c3f6cfd01ab337c265b0d01cb70
diff --git a/node_modules/tiny-lr/test/client.js b/node_modules/tiny-lr/test/client.js
new file mode 100644
index 0000000..2fa664a
--- /dev/null
+++ b/node_modules/tiny-lr/test/client.js
@@ -0,0 +1,46 @@
+
+import request from 'supertest';
+import assert from 'assert';
+import {parse} from 'url';
+import listen from './helpers/listen';
+import {Client as WebSocket} from 'faye-websocket';
+
+describe('tiny-lr', () => {
+ before(listen());
+ it('accepts ws clients', function (done) {
+ const url = parse(this.request.url);
+ const server = this.app;
+
+ const ws = this.ws = new WebSocket('ws://' + url.host + '/livereload');
+
+ ws.onopen = event => {
+ const hello = {
+ command: 'hello',
+ protocols: ['http://livereload.com/protocols/official-7']
+ };
+
+ ws.send(JSON.stringify(hello));
+ };
+
+ ws.onmessage = event => {
+ assert.deepEqual(event.data, JSON.stringify({
+ command: 'hello',
+ protocols: ['http://livereload.com/protocols/official-7'],
+ serverName: 'tiny-lr'
+ }));
+
+ assert.ok(Object.keys(server.clients).length);
+ done();
+ };
+ });
+
+ it('properly cleans up established connection on exit', function (done) {
+ const ws = this.ws;
+
+ ws.onclose = done.bind(null, null);
+
+ request(this.server)
+ .get('/kill')
+ .expect(200, () => {});
+ });
+});
diff --git a/node_modules/tiny-lr/test/helpers/listen.js b/node_modules/tiny-lr/test/helpers/listen.js
new file mode 100644
index 0000000..cf0f136
--- /dev/null
+++ b/node_modules/tiny-lr/test/helpers/listen.js
@@ -0,0 +1,19 @@
+
+import {Server} from '../..';
+import request from 'supertest';
+
+export default function listen (opts) {
+ opts = opts || {};
+
+ return function _listen (done) {
+ this.app = new Server(opts);
+ const srv = this.server = this.app.server;
+ const ctx = this;
+ this.server.listen(err => {
+ if (err) return done(err);
+ ctx.request = request(srv)
+ .get(this.app.rootPath)
+ .expect(200, done);
+ });
+ };
+};
diff --git a/node_modules/tiny-lr/test/http.js b/node_modules/tiny-lr/test/http.js
new file mode 100644
index 0000000..cc9d83f
--- /dev/null
+++ b/node_modules/tiny-lr/test/http.js
@@ -0,0 +1,14 @@
+import app from '../examples/express/app';
+import request from 'supertest';
+
+describe('mocha spec examples', () => {
+ describe('tinylr', () => {
+ it('GET /', done => {
+ request(app)
+ .get('/')
+ .expect('Content-Type', /text\/html/)
+ .expect(/Testing/)
+ .expect(200, done);
+ });
+ });
+});
diff --git a/node_modules/tiny-lr/test/middleware.js b/node_modules/tiny-lr/test/middleware.js
new file mode 100644
index 0000000..39a9b9a
--- /dev/null
+++ b/node_modules/tiny-lr/test/middleware.js
@@ -0,0 +1,123 @@
+
+var http = require('http');
+var express = require('express');
+var request = require('supertest');
+var debug = require('debug')('tinylr:test');
+var Server = require('..').Server;
+
+var port = parseInt(process.env.npm_package_config_test_port || 0, 10);
+
+describe('Express Middleware', () => {
+ before(function () {
+ this.app = express();
+ this.lr = new Server();
+
+ this.app.use(this.lr.handler.bind(this.lr));
+
+ this.server = http.createServer(this.app);
+ debug('Start %s suite, listen on %d', 'Express', port);
+ this.server.listen(port);
+ });
+
+ after(function (done) {
+ this.server.close(done);
+ });
+
+ describe('GET /', function () {
+ it('respond with nothing, but respond', function (done) {
+ request(this.server)
+ .get('/')
+ .expect('Content-Type', /json/)
+ .expect(/\{"tinylr":"Welcome","version":"[\d].[\d].[\d]+"\}/)
+ .expect(200, done);
+ });
+
+ it('unknown route are noop with middlewares, next-ing', function (done) {
+ request(this.server)
+ .get('/whatev')
+ .expect('Content-Type', /text\/html/)
+ .expect(/Cannot GET \/whatev/)
+ .expect(404, done);
+ });
+ });
+
+ describe('GET /changed', function () {
+ it('with no clients, no files', function (done) {
+ request(this.server)
+ .get('/changed')
+ .expect('Content-Type', /json/)
+ .expect(/"clients":\[\]/)
+ .expect(/"files":\[\]/)
+ .expect(200, done);
+ });
+
+ it('with no clients, some files', function (done) {
+ request(this.server)
+ .get('/changed?files=gonna.css,test.css,it.css')
+ .expect('Content-Type', /json/)
+ .expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}')
+ .expect(200, done);
+ });
+ });
+
+ describe('POST /changed', function () {
+ it('with no clients, no files', function (done) {
+ request(this.server)
+ .post('/changed')
+ .expect('Content-Type', /json/)
+ .expect(/"clients":\[\]/)
+ .expect(/"files":\[\]/)
+ .expect(200, done);
+ });
+
+ it('with no clients, some files', function (done) {
+ var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
+ request(this.server)
+ .post('/changed')
+ .send({ files: data.files })
+ .expect('Content-Type', /json/)
+ // .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+ });
+
+ describe('POST /alert', function () {
+ it('with no clients, no message', function (done) {
+ var data = { clients: [] };
+ request(this.server)
+ .post('/alert')
+ .expect('Content-Type', /json/)
+ .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+
+ it('with no clients, some message', function (done) {
+ var message = 'Hello Client!';
+ var data = { clients: [], message: message };
+ request(this.server)
+ .post('/alert')
+ .send({ message: message })
+ .expect('Content-Type', /json/)
+ .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+ });
+
+ describe('GET /livereload.js', function () {
+ it('respond with livereload script', function (done) {
+ request(this.server)
+ .get('/livereload.js')
+ .expect(/LiveReload/)
+ .expect(200, done);
+ });
+ });
+
+ describe('GET /kill', function () {
+ it('shutdown the server', function (done) {
+ var server = this.server;
+ request(server)
+ .get('/kill')
+ .expect(200, done);
+ });
+ });
+});
diff --git a/node_modules/tiny-lr/test/server.js b/node_modules/tiny-lr/test/server.js
new file mode 100644
index 0000000..0927c80
--- /dev/null
+++ b/node_modules/tiny-lr/test/server.js
@@ -0,0 +1,127 @@
+import request from 'supertest';
+import assert from 'assert';
+import listen from './helpers/listen';
+
+function testRoutes ({ prefix = '' } = {}) {
+ const buildUrl = url => prefix ? `/${prefix}${url}` : url;
+
+ describe('GET /', function () {
+ it('respond with nothing, but respond', function (done) {
+ request(this.server)
+ .get(buildUrl('/'))
+ .expect('Content-Type', /json/)
+ .expect(/\{"tinylr":"Welcome","version":"[\d].[\d].[\d]+"\}/)
+ .expect(200, done);
+ });
+
+ it('unknown route respond with proper 404 and error message', function (done) {
+ request(this.server)
+ .get(buildUrl('/whatev'))
+ .expect('Content-Type', /json/)
+ .expect('{"error":"not_found","reason":"no such route"}')
+ .expect(404, done);
+ });
+ });
+
+ describe('GET /changed', function () {
+ it('with no clients, no files', function (done) {
+ request(this.server)
+ .get(buildUrl('/changed'))
+ .expect('Content-Type', /json/)
+ .expect(/"clients":\[\]/)
+ .expect(/"files":\[\]/)
+ .expect(200, done);
+ });
+
+ it('with no clients, some files', function (done) {
+ request(this.server)
+ .get(buildUrl('/changed?files=gonna.css,test.css,it.css'))
+ .expect('Content-Type', /json/)
+ .expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}')
+ .expect(200, done);
+ });
+ });
+
+ describe('POST /changed', function () {
+ it('with no clients, no files', function (done) {
+ request(this.server)
+ .post(buildUrl('/changed'))
+ .expect('Content-Type', /json/)
+ .expect(/"clients":\[\]/)
+ .expect(/"files":\[\]/)
+ .expect(200, done);
+ });
+
+ it('with no clients, some files', function (done) {
+ const data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
+
+ request(this.server)
+ .post(buildUrl('/changed'))
+ // .type('json')
+ .send({ files: data.files })
+ .expect('Content-Type', /json/)
+ .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+ });
+
+ describe('POST /alert', function () {
+ it('with no clients, no message', function (done) {
+ const data = { clients: [] };
+ request(this.server)
+ .post(buildUrl('/alert'))
+ .expect('Content-Type', /json/)
+ .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+
+ it('with no clients, some message', function (done) {
+ const message = 'Hello Client!';
+ const data = { clients: [], message: message };
+ request(this.server)
+ .post(buildUrl('/alert'))
+ .send({ message: message })
+ .expect('Content-Type', /json/)
+ .expect(JSON.stringify(data))
+ .expect(200, done);
+ });
+ });
+
+ describe('GET /livereload.js', function () {
+ it('respond with livereload script', function (done) {
+ request(this.server)
+ .get(buildUrl('/livereload.js'))
+ .expect(/LiveReload/)
+ .expect(200, done);
+ });
+ });
+
+ describe('GET /kill', function () {
+ it('shutdown the server', function (done) {
+ const srv = this.server;
+ request(srv)
+ .get(buildUrl('/kill'))
+ .expect(200, err => {
+ if (err) return done(err);
+ assert.ok(!srv._handle);
+ done();
+ });
+ });
+ });
+}
+
+describe('Server', () => {
+ context('with no options', function () {
+ before(listen());
+ testRoutes();
+ });
+
+ context('with prefix option', function () {
+ const options = {
+ prefix: 'tiny-lr'
+ };
+
+ before(listen(options));
+ testRoutes(options);
+ });
+});