Permalink
Browse files

Merge pull request #613 from msand/fix-test-crossplatform

Fix test crossplatform support
  • Loading branch information...
2 parents e7cb63d + 9df128f commit 1ad3f8dbd4c62fedaf3a59a85dd70725c00a2948 @thepian thepian committed on GitHub Nov 23, 2016
View
@@ -19,7 +19,7 @@ var options = {};
function setDefaultOptions(options) {
// Determine if assets should be (re)packed on startup
- var packEnv = process.env['SS_PACK'];
+ var packEnv = process.env['SS_PACK'] && {all: true, keepOldFiles: true, id: shortid.generate()};
options.packedAssets = packEnv || false;
@@ -183,6 +183,9 @@ module.exports = function(ss) {
options.packedAssets = opts || true;
options.servePacked = opts || true;
options.liveReload = false;
+ ss.bundler.forEach(function(bundler) {
+ bundler.useLatestsPackedId();
+ });
// As it's safe to assume we're running in production mode at this point, if your app is not catching uncaught
// errors with its own custom error handling code, step in and prevent any exceptions from taking the server down
@@ -192,9 +195,6 @@ module.exports = function(ss) {
return log.error(err.stack);
});
}
- ss.bundler.forEach(function(bundler) {
- bundler.useLatestsPackedId();
- });
},
// Define a new Single Page Client
View
@@ -207,7 +207,7 @@ function unload() {
client.unload();
client.assets.unload();
http.unload();
- api.server.responders = undefined;
+ if (api.server) api.server.responders = undefined;
ws.unload();
}
@@ -224,12 +224,7 @@ function start() {
var plan = tasks.plan(arguments);
- // Hook in streaming if called with HTTP server
- if (plan.httpServer) {
- stream(plan.httpServer);
- }
-
- tasks.defaults();
+ tasks.defaults(plan);
tasks.start(plan.targets,plan.callback);
View
@@ -11,16 +11,21 @@ var http = require('http'),
module.exports = function(ss, router, options, orchestrator) {
- return function() {
+ return function(plan) {
+
+ plan = plan || {};
ss.defaultTask('start-server',function(done) {
- var server = http.Server(ss.http.middleware);
+ var server = plan.httpServer = http.Server(ss.http.middleware);
server.listen(3000, function() {
- ss.stream(server);
done();
});
});
+ ss.defaultTask('attach-stream', function() {
+ ss.stream(plan.httpServer);
+ });
+
ss.defaultTask('load-api', function() {
ss.load();
});
@@ -48,7 +53,7 @@ module.exports = function(ss, router, options, orchestrator) {
});
// if the server was passed in ss.start(httpServer) one shouldn't be started
- ss.defaultTask('load-socketstream', (ss.server.httpServer == null)? ['start-server','load-api']:['load-api']);
+ ss.defaultTask('load-socketstream', (plan.httpServer == null)? ['start-server','load-api', 'attach-stream']:['load-api', 'attach-stream']);
// task: ondemand
// Listen out for requests to async load new assets
View
@@ -40,7 +40,7 @@ module.exports = function(ss, router, options) {
orchestrator:orchestrator, //TODO remove it from here and ss.api
_packTasks: function(all) {
- var tasks = all? ['load-api']:['pack-prepare','load-api'];
+ var tasks = all? ['load-api', 'attach-stream']:['pack-prepare', 'load-api', 'attach-stream'];
ss.bundler.forEach(function(bundler){
if (all) {
tasks.push(bundler.client.name + ':pack');
View
@@ -85,9 +85,9 @@
"lint": "node_modules/.bin/jshint .",
"notes": "node_modules/.bin/notes",
"changelog": "node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -w",
- "test": "node_modules/.bin/mocha test/unit/**/* --reporter spec",
- "quick-test": "node_modules/.bin/mocha test/unit/**/* --reporter progress",
- "test-debug": "node_modules/.bin/mocha --debug-brk test/unit/**/* --reporter spec"
+ "test": "node_modules/.bin/mocha test/unit/**/*.js --reporter spec",
+ "quick-test": "node_modules/.bin/mocha test/unit/**/*.js --reporter progress",
+ "test-debug": "node_modules/.bin/mocha --debug-brk test/unit/**/*.js --reporter spec"
},
"pre-commit": [
"lint",
@@ -33,7 +33,8 @@ exports.setAbcPreviousAbcAssets = function() {
fs.closeSync(fs.openSync(path.join(__dirname,'project/client/static/assets/abc',id+'.html'),'w'));
};
-exports.expected_css = '/* style.css */\nbody {color:red;}\n';
-exports.expected_css_packed = 'body{color:red;}\n';
+var os = require('os'), EOL = os.EOL;
+exports.expected_css = '/* style.css */' + EOL + 'body {color:red;}' + EOL;
+exports.expected_css_packed = 'body{color:red;}' + EOL;
exports.expected_html_packed = fs.readFileSync(path.join(__dirname,'project/client/abc/expected.html'),'utf-8');
exports.expected_js_packed = fs.readFileSync(path.join(__dirname,'project/client/abc/expected.min.js'),'utf-8');
@@ -7,6 +7,7 @@ var path = require('path'),
options = ss.client.options,
defineAbcClient = require('../abcClient'),
fixtures = require('../../../fixtures');
+var os = require('os'), EOL = os.EOL;
describe('default bundler:', function () {
@@ -42,9 +43,9 @@ describe('default bundler:', function () {
client.id.should.be.type('string');
client.paths.should.be.type('object');
- client.paths.css.should.be.eql(['client/css/main']);
- client.paths.code.should.be.eql(['client/code/main/demo.coffee']);
- client.paths.view.should.be.eql('client/views/main.jade');
+ client.paths.css.should.be.eql([path.join('client', 'css', 'main')]);
+ client.paths.code.should.be.eql([path.join('client', 'code', 'main', 'demo.coffee')]);
+ client.paths.view.should.be.eql(path.join('client', 'views', 'main.jade'));
client.paths.tmpl.should.be.eql([]);
client.entryInitPath.should.be.equal('/client/code/main/demo');
@@ -141,10 +142,10 @@ describe('default bundler:', function () {
client.id.should.be.type('string');
client.paths.should.be.type('object');
- client.paths.css.should.be.eql(['client/css/main']);
- client.paths.code.should.be.eql(['client/code/main/demo.coffee']);
- client.paths.view.should.be.eql('client/views/main.jade');
- client.paths.tmpl.should.be.eql(['client/templates/chat/message.jade']);
+ client.paths.css.should.be.eql([path.join('client', 'css', 'main')]);
+ client.paths.code.should.be.eql([path.join('client', 'code', 'main', 'demo.coffee')]);
+ client.paths.view.should.be.eql(path.join('client', 'views', 'main.jade'));
+ client.paths.tmpl.should.be.eql([path.join('client', 'templates', 'chat', 'message.jade')]);
});
});
@@ -172,10 +173,10 @@ describe('default bundler:', function () {
client.id.should.be.type('string');
client.paths.should.be.type('object');
- client.paths.css.should.be.eql(['more/a']);
- client.paths.code.should.be.eql(['more/a/a.js']);
- client.paths.view.should.be.eql('more/a/a.html');
- client.paths.tmpl.should.be.eql(['more/a/a.html']);
+ client.paths.css.should.be.eql([path.join('more', 'a')]);
+ client.paths.code.should.be.eql([path.join('more', 'a', 'a.js')]);
+ client.paths.view.should.be.eql(path.join('more', 'a', 'a.html'));
+ client.paths.tmpl.should.be.eql([path.join('more', 'a', 'a.html')]);
});
});
@@ -229,9 +230,9 @@ describe('default bundler:', function () {
client.id.should.be.type('string');
client.paths.should.be.type('object');
- client.paths.css.should.be.eql(['client/abc/style.css']);
- client.paths.code.should.be.eql(['client/abc/index.js']);
- client.paths.view.should.be.eql('client/abc/abc.html');
+ client.paths.css.should.be.eql([path.join('client', 'abc', 'style.css')]);
+ client.paths.code.should.be.eql([path.join('client', 'abc', 'index.js')]);
+ client.paths.view.should.be.eql(path.join('client', 'abc', 'abc.html'));
client.paths.tmpl.should.be.eql([]);
client.entryInitPath.should.be.equal('/client/abc/index');
@@ -362,7 +363,7 @@ describe('default bundler:', function () {
// css entries
entriesCSS[0].file.should.be.equal('client/abc/style.css');
- entriesCSS[0].importedBy.should.be.equal('client/abc/style.css');
+ entriesCSS[0].importedBy.should.be.equal(path.join('client', 'abc', 'style.css'));
});
it('should return no entries for css if not in includes', function() {
@@ -407,7 +408,7 @@ describe('default bundler:', function () {
// mod TODO
entriesJS[4].file.should.be.equal('client/abc/index.js');
- entriesJS[4].importedBy.should.be.equal('client/abc/index.js');
+ entriesJS[4].importedBy.should.be.equal(path.join('client', 'abc', 'index.js'));
//entriesJS[4].type.should.be.equal('mod');
//entriesJS.should.be.equal([{ path:'./abc.js'}]);
@@ -441,7 +442,7 @@ describe('default bundler:', function () {
// mod TODO
entriesJS[4].file.should.be.equal('client/abc/index.js');
- entriesJS[4].importedBy.should.be.equal('client/abc/index.js');
+ entriesJS[4].importedBy.should.be.equal(path.join('client', 'abc', 'index.js'));
//entriesJS[4].type.should.be.equal('mod');
// start TODO
@@ -464,7 +465,7 @@ describe('default bundler:', function () {
// mod TODO
entriesJS[0].file.should.be.equal('client/abc/index.js');
- entriesJS[0].importedBy.should.be.equal('client/abc/index.js');
+ entriesJS[0].importedBy.should.be.equal(path.join('client', 'abc', 'index.js'));
});
it('should render css asset file as empty if includes is false');
@@ -494,7 +495,7 @@ describe('default bundler:', function () {
// css
entriesCSS[0].file.should.be.equal('client/abc/style.css');
- entriesCSS[0].importedBy.should.be.equal('client/abc');
+ entriesCSS[0].importedBy.should.be.equal(path.join('client', 'abc'));
entriesCSS[0].assetType.should.be.equal('css');
// libs
@@ -511,7 +512,7 @@ describe('default bundler:', function () {
// mod TODO
entriesJS[4].file.should.be.equal('client/abc/index.js');
- entriesJS[4].importedBy.should.be.equal('client/abc/index.js');
+ entriesJS[4].importedBy.should.be.equal(path.join('client', 'abc', 'index.js'));
//entriesJS[4].type.should.be.equal('mod');
// start TODO
@@ -576,8 +577,8 @@ describe('default bundler:', function () {
'<html>',
'<head><title>ABC</title></head>',
'<body><p>ABC</p><script>var abcl={"b":"b"};\nrequire("/client/abc/index");</script></body>',
- '</html>\n'
- ].join('\n'))
+ '</html>' + EOL
+ ].join(EOL))
});
});
@@ -599,8 +600,8 @@ describe('default bundler:', function () {
'<html>',
'<head><title>ABC</title></head>',
'<body><p>ABC</p><script>var abcg={"a":"a"};\nvar abcl={"b":"b"};\nrequire("/client/abc/index");</script></body>',
- '</html>\n'
- ].join('\n'));
+ '</html>' + EOL
+ ].join(EOL));
done();
});
});
@@ -625,8 +626,8 @@ describe('default bundler:', function () {
'<html>',
'<head><title>ABC</title></head>',
'<body><p>ABC</p><script>var abcg={"b":"b"};\nrequire("/client/abc/index");</script></body>',
- '</html>\n'
- ].join('\n'))
+ '</html>' + EOL
+ ].join(EOL))
});
});
@@ -831,8 +832,8 @@ describe('default bundler:', function () {
'<html>',
'<head><title>ABC</title></head>',
'<body><p>ABC</p><script>require("/client/abc/index");</script></body>',
- '</html>\n'
- ].join('\n'))
+ '</html>' + EOL
+ ].join(EOL))
});
});
@@ -851,8 +852,8 @@ describe('default bundler:', function () {
'<html>',
'<head><title>ABC</title></head>',
'<body><p>ABC</p></body>',
- '</html>\n'
- ].join('\n'))
+ '</html>' + EOL
+ ].join(EOL))
});
});
@@ -28,9 +28,9 @@ describe('bundler', function () {
tmpl: 'main.html'
});
- paths.css.should.eql(['client/css/main.css']);
- paths.code.should.eql(['client/code/main.js']);
- paths.tmpl.should.eql(['client/templates/main.html']);
+ paths.css.should.eql([path.join('client', 'css', 'main.css')]);
+ paths.code.should.eql([path.join('client', 'code', 'main.js')]);
+ paths.tmpl.should.eql([path.join('client', 'templates', 'main.html')]);
});
it('should return bundler given id', function() {
@@ -117,7 +117,7 @@ describe('bundler', function () {
var templates = ss.api.bundler.entries(client,'tmpl');
templates.should.eql([{
- file: 'client/templates/main.html', importedBy: 'client/templates/main.html', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html'
+ file: 'client/templates/main.html', importedBy: path.join('client','templates','main.html'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html'
}]);
@@ -133,9 +133,9 @@ describe('bundler', function () {
var templates = ss.api.bundler.entries(client,'tmpl');
templates.should.eql([
- { file: 'client/templates/main.html', importedBy: 'client/templates/main.html', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
- { file: 'client/templates/abc/1.html', importedBy: 'client/templates/abc/1.html', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
- { file: 'client/templates/abc/2.html', importedBy: 'client/templates/abc/2.html', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' }
+ { file: 'client/templates/main.html', importedBy: path.join('client','templates','main.html'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
+ { file: 'client/templates/abc/1.html', importedBy: path.join('client','templates','abc','1.html'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
+ { file: 'client/templates/abc/2.html', importedBy: path.join('client','templates','abc','2.html'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' }
]);
});
@@ -150,8 +150,8 @@ describe('bundler', function () {
var templates = ss.api.bundler.entries(client,'tmpl');
templates.should.eql([
- { file: 'client/templates/abc/1.html', importedBy: 'client/templates/abc', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
- { file: 'client/templates/abc/2.html', importedBy: 'client/templates/abc', includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' }
+ { file: 'client/templates/abc/1.html', importedBy: path.join('client', 'templates', 'abc'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' },
+ { file: 'client/templates/abc/2.html', importedBy: path.join('client', 'templates', 'abc'), includeType: 'html', ext:'html', bundle:'tmpl', assetType:'html' }
]);
});
@@ -5,6 +5,7 @@ var ss = require( '../../../lib/socketstream'),
Router = require('../../../lib/http/router').Router,
defineAbcClient = require('./abcClient');
+var os = require('os'), EOL = os.EOL;
var view = require('../../../lib/client/view');
var responseStub = {
@@ -130,12 +131,12 @@ describe('constants',function() {
ss.client.formatters.add('html');
});
- var expectedHtml = '<html>\n'+
- '<head><title>ABC</title></head>\n'+
+ var expectedHtml = '<html>'+ EOL +
+ '<head><title>ABC</title></head>'+ EOL +
'<body><p>ABC</p>'+
'<script>var abc="abc";\nvar def="def";\nrequire("/client/abc/index");</script>'+
- '</body>\n'+
- '</html>\n';
+ '</body>'+ EOL +
+ '</html>'+ EOL;
view(ss.api, client, options, function(output) {
output.should.equal(expectedHtml);
@@ -4,6 +4,7 @@ var path = require('path'),
ss = require( '../../../../lib/socketstream'),
fixtures = require('../../../fixtures');
+var os = require('os'), EOL = os.EOL;
describe('html formatter', function () {
@@ -41,7 +42,7 @@ describe('html formatter', function () {
var output;
concrete.call(path.join(fixtures.project,'client/abc/ss.html'),{},function(out) {
output = out;
- out.should.be.equal('<html>\n<head><title>ABC</title><SocketStream/></head>\n<body><p>ABC</p></body>\n</html>\n');
+ out.should.be.equal(['<html>', '<head><title>ABC</title><SocketStream/></head>', '<body><p>ABC</p></body>', '</html>' + EOL].join(EOL));
},function(err) {
should(err).be.equal(undefined);
});
Oops, something went wrong.

0 comments on commit 1ad3f8d

Please sign in to comment.