Skip to content

Commit d737d8d

Browse files
committed
Fix browser tests and make them easier to use
1 parent a205c76 commit d737d8d

File tree

7 files changed

+184
-170
lines changed

7 files changed

+184
-170
lines changed

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Contributions are very appreciated!
2+
3+
If you re-implement a PR from [Director](https://github.com/flatiron/director), please refer to that PR.
4+
5+
## Running tests
6+
7+
For now you need to run three commands to execute all tests.
8+
9+
Test the Node.js version:
10+
11+
```
12+
npm test
13+
```
14+
15+
Test the browser version with HTML5 routing:
16+
17+
```
18+
npm run test-html5
19+
```
20+
21+
Test the browser version with hash routing:
22+
23+
```
24+
npm run test-hash
25+
```
26+
27+
Note that the browser tests don't run automatically via Travis yet, they must be done manually.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"devDependencies": {
2323
"api-easy": "^0.4.0",
2424
"colors": "^1.1.2",
25+
"opn": "^4.0.2",
26+
"opn-cli": "^3.1.0",
2527
"qunitjs": "^2.0.1",
2628
"request": "^2.79.0",
2729
"rollup": "^0.36.4",
@@ -42,6 +44,8 @@
4244
"scripts": {
4345
"test": "vows test/server/*/*-test.js --spec",
4446
"build": "rm -f build/** && rollup -c && rollup -c rollup.minify.config.js",
47+
"test-html5": "node ./test/browser/backend/backend.js",
48+
"test-hash": "opn ./test/browser/routes-harness.html",
4549
"preversion": "npm run -s build",
4650
"version": "git add -A build"
4751
}

test/browser/backend/backend.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var http = require('http'),
22
fs = require('fs'),
33
path = require('path'),
4-
director = require('../../../lib/tarantino'),
4+
tarantino = require('../../../lib/tarantino'),
5+
opn = require('opn'),
56
index;
67

78
fs.readFile(path.join(__dirname, '..', 'html5-routes-harness.html'), function (err, data) {
@@ -52,7 +53,7 @@ function fileServer(folder, file) {
5253
});
5354
}
5455

55-
var router = new director.http.Router({
56+
var router = new tarantino.http.Router({
5657
'/files': {
5758
'/:folder': {
5859
'/(.+)': {
@@ -74,4 +75,8 @@ var server = http.createServer(function (req, res) {
7475
});
7576
});
7677

77-
server.listen(8080);
78+
server.listen(8080, function () {
79+
var url = 'http://localhost:8080/';
80+
console.log('Open your browser on ' + url);
81+
opn(url);
82+
});

test/browser/browserify-harness.html

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/browser/helpers/api.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module("Director.js", {
2-
setup: function() {
1+
QUnit.module("Director.js", {
2+
beforeEach: function() {
33
window.location.hash = "";
44
shared = {};
55
// Init needed keys earlier because of in HTML5 mode the route handler
@@ -10,7 +10,7 @@ module("Director.js", {
1010
shared.fired_count = 0;
1111
}
1212
},
13-
teardown: function() {
13+
afterEach: function() {
1414
window.location.hash = "";
1515
shared = {};
1616
}
@@ -21,28 +21,30 @@ var shared;
2121
function createTest(name, config, use, test, initialRoute) {
2222
// We rename to `RouterAlias` for the browserify tests, since we want to be
2323
// sure that no code is depending on `window.Router` being available.
24-
var Router = window.Router || window.RouterAlias;
24+
var Router = window.tarantino.Router;
2525

2626
if (typeof use === 'function') {
2727
test = use;
2828
use = undefined;
2929
}
3030

31+
if (use === undefined) {
32+
use = {};
33+
}
3134
if (HTML5TEST) {
32-
if (use === undefined) {
33-
use = {};
34-
}
3535

3636
if (use.run_handler_in_init === undefined) {
3737
use.run_handler_in_init = false;
3838
}
39-
use.html5history = true;
39+
} else {
40+
use.html5history = false;
4041
}
4142

4243
// Because of the use of setTimeout when defining onpopstate
4344
var innerTimeout = HTML5TEST === true ? 500 : 0;
4445

45-
asyncTest(name, function() {
46+
QUnit.test(name, function(assert) {
47+
var done = assert.async();
4648
setTimeout(function() {
4749
var router = new Router(config),
4850
context;
@@ -68,9 +70,9 @@ function createTest(name, config, use, test, initialRoute) {
6870
},
6971
finish: function() {
7072
router.destroy();
71-
start();
73+
done();
7274
}
73-
})
75+
}, assert)
7476
}, innerTimeout);
7577
}, 14);
7678
});

0 commit comments

Comments
 (0)