Skip to content

Commit 8b02ab9

Browse files
author
luijar
committed
Adding convenience script to run chapter test
1 parent af39c12 commit 8b02ab9

File tree

9 files changed

+53
-51
lines changed

9 files changed

+53
-51
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*-compiled*
22
*.log
33
node_modules
4-
.idea
4+
.idea
5+
.DS_Store

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Since this code uses ES6 artifacts, any code meant to run on the browser must be
1010
* Babel
1111
* Traceur
1212

13-
For Node.js users. This code requires:
13+
For Node.js users. This code requires:
1414

1515
node --version > 6.3.1
1616

17-
Please begin the project with
17+
Please begin the project with
1818

1919
~~~
2020
npm install
@@ -45,10 +45,10 @@ npm install rxjs
4545

4646

4747
##Running the tests
48-
Once QUnit is installed. You can run each test file with:
48+
Once QUnit is installed. You can run each test with the QUnit CLI by specifying the chapter number.
4949

5050
~~~
51-
$> node <path-to-qunit-cli.js> -t <chapter-num>/tests.js -c <chapter-num>/tests.js
51+
$> npm run ch[1-8]
5252
~~~
5353

54-
You can find "path-to-qunit-cli.js" in node_modules/qunit/bin/cli.js and "chapter-num" will be any of ch01...ch08
54+
You can find "path-to-qunit-cli.js" in node_modules/qunit/bin/cli.js and "chapter-num" will be any of ch01...ch08

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"blanket": "1.2.3",
99
"jscheck": "0.2.0",
1010
"lodash": "4.14.2",
11-
"qunit": "0.9.1",
11+
"performance-now": "^2.0.0",
12+
"qunit": "1.0.0",
1213
"ramda": "0.22.0",
1314
"rxjs": "^5.0.0-beta.11",
1415
"rxjs-es": "5.0.0-beta.11",
@@ -20,7 +21,14 @@
2021
"es2015-node5"
2122
]
2223
},
23-
"scripts" : {
24-
"test" : ""
25-
}
24+
"scripts": {
25+
"ch01": "qunit -t src/ch01/tests.js -c src/ch01/tests.js",
26+
"ch02": "qunit -t src/ch02/tests.js -c src/ch02/tests.js",
27+
"ch03": "qunit -t src/ch03/tests.js -c src/ch03/tests.js",
28+
"ch04": "qunit -t src/ch04/tests.js -c src/ch04/tests.js",
29+
"ch05": "qunit -t src/ch05/tests.js -c src/ch05/tests.js",
30+
"ch06": "qunit -t src/ch06/tests.js -c src/ch06/tests.js",
31+
"ch07": "qunit -t src/ch07/tests.js -c src/ch07/tests.js",
32+
"ch08": "qunit -t src/ch08/tests.js -c src/ch08/tests.js"
33+
}
2634
}

src/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*-compiled*
22
*.log
33
/node_modules
4-
.idea
4+
.idea
5+
.DS_Store

src/ch06/coverage/functional-program.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Functional Libraries used in this chapter
2-
const _ = require('lodash');
3-
const R = require('ramda');
42

53
// Monads/functors used
64
const Wrapper = require('../../model/Wrapper.js').Wrapper;

src/ch06/coverage/run-code-coverage.html

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

src/ch06/coverage/runme.md

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

src/ch07/tests.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,42 @@ QUnit.module('Chapter 7');
1010
// Installs memoization
1111
require('./memoization');
1212

13-
QUnit.test("Memoization test", function () {
14-
let rot13 = (s =>
13+
const now = require("performance-now")
14+
const R = require('ramda');
15+
const IO = require('../model/monad/IO.js').IO;
16+
17+
let rot13 = (s =>
1518
s.replace(/[a-zA-Z]/g, c =>
1619
String.fromCharCode((c <= 'Z' ? 90 : 122)
1720
>= (c = c.charCodeAt(0) + 13) ? c : c - 26))).memoize();
18-
21+
22+
QUnit.test("Memoization test", function () {
1923
assert.equal(rot13('functional_js_50_off'), 'shapgvbany_wf_50_bss');
2024
});
2125

26+
QUnit.test("Performance", function () {
27+
const start = () => now();
28+
const runs = [];
29+
const end = function (start) {
30+
let end = now();
31+
let result = (end - start).toFixed(3);
32+
runs.push(result);
33+
return result;
34+
};
35+
36+
const test = function (fn, input) {
37+
return () => fn(input);
38+
};
39+
40+
const testRot13 = IO.from(start)
41+
.map(R.tap(test(rot13, 'functional_js_50_off')))
42+
.map(end);
43+
44+
testRot13.run();
45+
testRot13.run();
46+
assert.ok(runs[0] >= runs[1]);
47+
});
48+
2249
/*
2350
The remaining code listings are based on previous functions that are memoized.
2451
Execution and results are exactly the same...

src/ch08/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ QUnit.test("Fetching student data with async calls", function (assert) {
7575
getJSON('/students')
7676
.then(R.tap(() => console.log('Hiding spinner'))) // <- simulate a spinner being hidden on the site
7777
.then(R.filter(s => s.address.country === 'US'))
78-
.then(R.sortBy(R.prop('ssn')))
78+
.then(R.sortBy(R.prop('_ssn')))
7979
.then(R.map(student => {
8080
return getJSON('/grades?ssn=' + student.ssn)
8181
.then(R.compose(Math.ceil, fork(R.divide, R.sum, R.length)))
@@ -89,7 +89,7 @@ QUnit.test("Fetching student data with async calls", function (assert) {
8989
.catch(function (error) {
9090
console.log('Error occurred: ' + error.message);
9191
});
92-
expect(0); // when run this code prints to the screen all of the outut through the IO monad, so nothing to expect
92+
expect(0); // when run this code prints to the screen all of the output through the IO monad, so nothing to expect
9393
});
9494

9595

0 commit comments

Comments
 (0)