2 var http = require('http');
3 var assert = require('assert');
4 var connect = require('connect');
5 var express = require('express');
6 var request = require('supertest');
7 var debug = require('debug')('tinylr:test');
8 var Server = require('..').Server;
10 var npmenv = process.env;
12 var port = parseInt(process.env.npm_package_config_test_port || 0, 10);
14 // describe('Connect Middleware', suite('Connect Middleware', connect()));
15 describe('Express Middleware', suite('Express Middleware', express()));
17 // XXX cover up the ws connection done in client.js / server.js tests:w
18 function suite(name, app) {return function() {
22 this.lr = new Server();
25 .use(this.lr.handler.bind(this.lr));
27 this.server = http.createServer(this.app);
28 debug('Start %s suite, listen on %d', name, port);
29 this.server.listen(port);
33 after(function(done) {
34 this.server.close(done);
37 describe('GET /', function() {
38 it('respond with nothing, but respond', function(done){
41 .expect('Content-Type', /json/)
42 .expect(/\{"tinylr":"Welcome","version":"[\d].[\d].[\d]+"\}/)
46 it('unknown route are noop with middlewares, next-ing', function(done){
49 .expect('Content-Type', /text\/html/)
50 .expect(/Cannot GET \/whatev/)
56 describe('GET /changed', function() {
57 it('with no clients, no files', function(done) {
60 .expect('Content-Type', /json/)
61 .expect(/"clients":\[\]/)
62 .expect(/"files":\[\]/)
66 it('with no clients, some files', function(done) {
68 .get('/changed?files=gonna.css,test.css,it.css')
69 .expect('Content-Type', /json/)
70 .expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}')
75 describe('POST /changed', function() {
76 it('with no clients, no files', function(done) {
79 .expect('Content-Type', /json/)
80 .expect(/"clients":\[\]/)
81 .expect(/"files":\[\]/)
85 it('with no clients, some files', function(done) {
86 var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
88 var r = request(this.server)
90 .send({ files: data.files })
91 .expect('Content-Type', /json/)
92 // .expect(JSON.stringify(data))
97 describe('GET /livereload.js', function() {
98 it('respond with livereload script', function(done) {
100 .get('/livereload.js')
101 .expect(/LiveReload/)
106 describe('GET /kill', function() {
107 it('shutdown the server', function(done) {
108 var server = this.server;