Skip to content

Commit

Permalink
test(reload): unload watcher when client unloads
Browse files Browse the repository at this point in the history
  • Loading branch information
thepian committed Jun 14, 2015
1 parent 37da79e commit e494c68
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function setDefaultOptions(options) {
// Determine if assets should be (re)packed on startup
var packAssets = process.env['SS_PACK'];

//TODO packAssets vs packedAssets
options.packedAssets = packAssets || false;

options.liveReload = ['code', 'css', 'static', 'templates', 'views'];
Expand Down Expand Up @@ -68,7 +67,8 @@ module.exports = function(ss, router) {

// Require sub modules
var templateEngine = require('./template_engine')(ss,options),
formatters = require('./formatters')(ss,options);
formatters = require('./formatters')(ss,options),
liveReload = require('./live_reload');

// extend http response API
require('./http')(ss, clients, options);
Expand Down Expand Up @@ -260,15 +260,15 @@ module.exports = function(ss, router) {
// Else serve files and watch for changes to files in development
require('./serve/dev')(ss, router, options);
if (options.liveReload) {
require('./live_reload')(ss, options);
liveReload(ss, options);
}
}
// Listen out for requests to async load new assets
require('./serve/ondemand')(ss, router, options);
},

unload: function() {

liveReload.unload();
ss.client.formatters = {};
ss.client.templateEngines = {};
ss.bundler.unload();
Expand Down
11 changes: 9 additions & 2 deletions lib/client/live_reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var pathlib = require('path'),
var lastRun = {
updateCSS: {at:Date.now()},
reload: {at:Date.now()}
};
}, watcher;

var cssExtensions = ['.css', '.styl', '.stylus', '.less'];

Expand All @@ -39,7 +39,7 @@ module.exports = function(ss, options) {
return _results;
})();

var watcher = chokidar.watch(watchDirs, {
watcher = chokidar.watch(watchDirs, {
ignored: /(\/\.|~$)/
});
watcher.on('add', function(path) {
Expand Down Expand Up @@ -97,3 +97,10 @@ module.exports = function(ss, options) {
return onChange;
};

module.exports.unload = function() {
if (watcher) {
watcher.close();
watcher = null;
}
};

1 change: 1 addition & 0 deletions test/unit/client/bundler/custom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('custom bundler', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/client/bundler/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('default bundler:', function () {
ss.root = ss.api.root = fixtures.project;
//ss.api.bundler = require('../../../../lib/client/bundler/index')(ss.api,options);

options.liveReload = false;

describe('client with standard css+code', function() {

var client;

beforeEach(function() {
ss.client.set({liveReload:false});

client = ss.client.define('main', {
css: 'main',
code: 'main/demo.coffee',
Expand Down
5 changes: 3 additions & 2 deletions test/unit/client/bundler/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ describe('bundler', function () {

ss.root = ss.api.root = fixtures.project;

options.liveReload = false;

describe('API',function() {

beforeEach(function() {
ss.client.set({liveReload:false});
});
afterEach(function() {
ss.client.forget();
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/constants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('constants',function() {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/formatters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var ss = require( '../../../lib/socketstream'),
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/formatters/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('css formatter', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/formatters/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('html formatter', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/formatters/javascript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('js formatter', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('client asset manager index', function () {
if (ss.client.assets.assets.constants.abc) {
delete ss.client.assets.assets.constants.abc;
}
ss.client.set({liveReload:false});
});

afterEach(function() {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/client/pack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ describe('pack',function() {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});
});

afterEach(function(done) {
ss.client.forget();
fixtures.cleanup(done);
});

var newEngine = function newEngine(api,config,options) {
function newEngine(api,config,options) {
api.should.equal(ss.api);
options.should.equal(ss.client.options);
return {
Expand All @@ -35,7 +36,7 @@ describe('pack',function() {
return '<script id="new-' + id + '" type="text/x-tmpl">' + template + JSON.stringify(opts.constants) + '</script>';
}
}
};
}

it('should make blank css and minimal js bundles when nothing is defined', function() {

Expand Down
1 change: 1 addition & 0 deletions test/unit/client/template_engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Template engine', function() {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});

ss.client.formatters.add('html');
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit/client/template_engines/angular.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ describe('angular.js template engine', function () {

ss.root = ss.api.root = fixtures.project;

options.liveReload = false;

ss.api.bundler = bundlerMod(ss.api, options);

beforeEach(function() {

// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});

ss.client.formatters.add('html');
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit/client/template_engines/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ describe('default template engine', function () {

ss.root = ss.api.root = fixtures.project;

options.liveReload = false;

ss.api.bundler = bundlerMod(ss.api, options);

engineMod(ss.api,options);
Expand All @@ -23,6 +21,7 @@ describe('default template engine', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});

ss.client.formatters.add('html');
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/client/template_engines/ember.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Ember.js template engine', function () {
// back to initial client state
ss.client.assets.unload();
ss.client.assets.load();
ss.client.set({liveReload:false});

ss.client.formatters.add('html');
});
Expand Down

0 comments on commit e494c68

Please sign in to comment.