diff --git a/package.json b/package.json index 4204eba..5e6ad8f 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,10 @@ "serialize-object": "^1.0.0" }, "devDependencies": { - "expect.js": "^0.3.1", - "finalhandler": "^1.1.1", - "mocha": "^5.2.0", - "serve-static": "^1.13.2" + "browserify": "^16.5.0", + "chai": "^4.2.0", + "express": "^4.17.1", + "mocha": "^6.2.2" }, "optionalDependencies": {}, "testling": { diff --git a/test/public/index.html b/test/public/index.html new file mode 100644 index 0000000..441ae99 --- /dev/null +++ b/test/public/index.html @@ -0,0 +1,17 @@ + + +Derby Tests + + + + +
+ + + + + + diff --git a/test/serialize.mocha.js b/test/serialize.mocha.js index bc8beb6..a342230 100644 --- a/test/serialize.mocha.js +++ b/test/serialize.mocha.js @@ -1,4 +1,4 @@ -var expect = require('expect.js'); +var expect = require('chai').expect; var templates = require('../index'); var expressions = require('../example/expressions'); diff --git a/test/test.html b/test/test.html deleted file mode 100644 index 439ec27..0000000 --- a/test/test.html +++ /dev/null @@ -1,36 +0,0 @@ - - -Saddle Tests - - - - -
- - - - - - - - - - - - - - - diff --git a/test/test.mocha.js b/test/test.mocha.js index 5e0babe..e0218eb 100644 --- a/test/test.mocha.js +++ b/test/test.mocha.js @@ -1,8 +1,7 @@ -if ((typeof require) === 'function') { - var expect = require('expect.js'); - var saddle = require('../index'); - var expressions = require('../example/expressions'); -} +var chai = require('chai'); +var expect = chai.expect; +var saddle = require('../index'); +var expressions = require('../example/expressions'); //add fixture to page //only 90s kids will remember this @@ -493,7 +492,7 @@ describe('attachTo', function() { ]); expect(function() { renderAndAttach(template); - }).to.throwException(); + }).throw(Error); }); }); diff --git a/test/testServer.js b/test/testServer.js index e1ee54b..78756ef 100644 --- a/test/testServer.js +++ b/test/testServer.js @@ -1,36 +1,21 @@ -var finalhandler = require('finalhandler'); -var http = require('http'); -var path = require('path'); -var serveStatic = require('serve-static'); +var browserify = require('browserify'); +var express = require('express'); +var expressApp = express(); +expressApp.use(express.static(__dirname + '/public')); +expressApp.use(express.static(__dirname + '/../node_modules/mocha')); -// Default port is 5555. Override it with `PORT=____`, -// or `PORT=0` to let Node pick an unused port. -var port = parseInt(process.env.PORT, 10); -if (!Number.isInteger(port)) { - port = 5555; -} -// The test server only serves to this local machine by default. -// To access it from any other network device, use `HOST=0.0.0.0`, -// but be sure you trust the network you're on. -var bindHost = process.env.HOST || '127.0.0.1'; - - -// Serve files under Saddle's base directory, since test.html -// loads Mocha from node_modules with a relative path. -var serveTestDir = serveStatic(path.dirname(__dirname)); -var server = http.createServer(function onRequest(req, res) { - serveTestDir(req, res, finalhandler(req, res)); +expressApp.get('/test.js', function(req, res, next) { + var bundle = browserify({debug: true}); + bundle.add(__dirname + '/test.mocha.js'); + bundle.bundle(function(err, code) { + if (err) return next(err); + res.type('js'); + res.send(code); + }); }); -server.listen(port, bindHost, function(err) { - if (err) { - console.log('Error starting browser test server:', err); - server.close(); - } else { - var testUrl = 'http://127.0.0.1:' + port + '/test/test.html'; - console.log('Test server started on network interface ' + bindHost + '.'); - console.log('\nTo run browser tests, visit this URL:\n'); - console.log(' ' + testUrl); - } +var port = process.env.PORT || 5555; +var server = expressApp.listen(port, function(err) { + console.log('%d listening. Go to: http://localhost:%d/', process.pid, port); });