Skip to content

Commit

Permalink
Merge pull request #29 from derbyjs/update-test-deps
Browse files Browse the repository at this point in the history
expect.js => chai & use browserify to bundle
  • Loading branch information
nateps authored Dec 4, 2019
2 parents 213ea38 + 427f180 commit 2ed44c8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 78 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 17 additions & 0 deletions test/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Derby Tests</title>
<link rel="stylesheet" href="/mocha.css">

<body>

<div id="mocha"></div>
<script src="/mocha.js"></script>
<script>mocha.setup('bdd')</script>

<script src="/test.js"></script>

<script>
mocha.checkLeaks();
mocha.run();
</script>
2 changes: 1 addition & 1 deletion test/serialize.mocha.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var expect = require('expect.js');
var expect = require('chai').expect;
var templates = require('../index');
var expressions = require('../example/expressions');

Expand Down
36 changes: 0 additions & 36 deletions test/test.html

This file was deleted.

11 changes: 5 additions & 6 deletions test/test.mocha.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -493,7 +492,7 @@ describe('attachTo', function() {
]);
expect(function() {
renderAndAttach(template);
}).to.throwException();
}).throw(Error);
});

});
Expand Down
47 changes: 16 additions & 31 deletions test/testServer.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 2ed44c8

Please sign in to comment.