Skip to content

Commit 6e2a8cf

Browse files
committed
Use mocha+expect.js as testing framework.
1 parent 78218a3 commit 6e2a8cf

File tree

3 files changed

+87
-83
lines changed

3 files changed

+87
-83
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
"url": "http://www.opensource.org/licenses/MIT"
3636
}
3737
],
38+
"devDependencies": {
39+
"mocha": "latest",
40+
"expect.js": "latest"
41+
},
3842
"scripts": {
39-
"test": "node ./test/test.js"
43+
"test": "mocha --reporter spec"
4044
},
4145
"files": [
4246
"md5.js"

test/index.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
<head>
1616
<meta charset="utf-8">
1717
<title>JavaScript MD5 Test</title>
18-
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
18+
<link rel="stylesheet" href="http://blueimp.github.com/cdn/css/mocha.min.css">
1919
</head>
2020
<body>
21-
<h1 id="qunit-header">JavaScript MD5 Test</h1>
22-
<h2 id="qunit-banner"></h2>
23-
<div id="qunit-testrunner-toolbar"></div>
24-
<h2 id="qunit-userAgent"></h2>
25-
<ol id="qunit-tests"></ol>
26-
<div id="qunit-fixture"></div>
21+
<div id="mocha"></div>
22+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
23+
<script src="http://blueimp.github.com/cdn/js/mocha.min.js"></script>
24+
<script src="http://blueimp.github.com/cdn/js/expect.min.js"></script>
25+
<script>
26+
mocha.setup('bdd');
27+
$(function () {
28+
mocha.run();
29+
});
30+
</script>
2731
<script src="../md5.js"></script>
28-
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
2932
<script src="test.js"></script>
3033
</body>
3134
</html>

test/test.js

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,92 @@
99
* http://www.opensource.org/licenses/MIT
1010
*/
1111

12-
/*global require */
12+
/*global describe, it, expect, require */
1313

14-
(function ($) {
14+
(function (expect, md5) {
1515
'use strict';
1616

17-
var lifecycle = {
18-
setup: function () {},
19-
teardown: function () {}
20-
},
21-
nodeQunit = {
22-
setup: function () {},
23-
teardown: function () {}
24-
};
25-
26-
if (!$.module) {
27-
// Node.js QUnit compatible Testrunner:
28-
nodeQunit = require('node-qunit');
29-
$.module = nodeQunit.module;
30-
$.test = nodeQunit.test;
31-
$.strictEqual = nodeQunit.assert.strictEqual;
32-
$.md5 = require('../md5').md5;
33-
}
34-
35-
nodeQunit.setup();
36-
37-
$.module('Hex-encoded MD5', lifecycle);
38-
39-
$.test('Creating hex-encoded MD5 hash of an ASCII value', function () {
40-
$.strictEqual(
41-
$.md5('value'),
42-
'2063c1608d6e0baf80249c42e2be5804'
43-
);
44-
});
17+
describe('MD5 Hex-encoding', function () {
4518

46-
$.test('Creating hex-encoded MD5 hash of an UTF-8 value', function () {
47-
$.strictEqual(
48-
$.md5('日本'),
49-
'4dbed2e657457884e67137d3514119b3'
50-
);
51-
});
19+
it('should create a hex-encoded MD5 hash of an ASCII value', function () {
20+
expect(
21+
md5('value')
22+
).to.be(
23+
'2063c1608d6e0baf80249c42e2be5804'
24+
);
25+
});
5226

53-
$.module('Hex-encoded HMAC-MD5', lifecycle);
27+
it('should create a hex-encoded MD5 hash of an UTF-8 value', function () {
28+
expect(
29+
md5('日本')
30+
).to.be(
31+
'4dbed2e657457884e67137d3514119b3'
32+
);
33+
});
5434

55-
$.test('Creating hex-encoded HMAC-MD5 hash of an ASCII value and key', function () {
56-
$.strictEqual(
57-
$.md5('value', 'key'),
58-
'01433efd5f16327ea4b31144572c67f6'
59-
);
6035
});
6136

62-
$.test('Creating hex-encoded HMAC-MD5 hash of an UTF-8 value and key', function () {
63-
$.strictEqual(
64-
$.md5('日本', '日本'),
65-
'c78b8c7357926981cc04740bd3e9d015'
66-
);
67-
});
37+
describe('HMAC-MD5 Hex-encoding', function () {
6838

69-
$.module('Raw MD5', lifecycle);
39+
it('should create a hex-encoded HMAC-MD5 hash of an ASCII value and key', function () {
40+
expect(
41+
md5('value', 'key')
42+
).to.be(
43+
'01433efd5f16327ea4b31144572c67f6'
44+
);
45+
});
7046

71-
$.test('Creating raw MD5 hash of an ASCII value', function () {
72-
$.strictEqual(
73-
$.md5('value', null, true),
74-
' c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04'
75-
);
76-
});
47+
it('should create a hex-encoded HMAC-MD5 hash of an UTF-8 value and key', function () {
48+
expect(
49+
md5('日本', '日本')
50+
).to.be(
51+
'c78b8c7357926981cc04740bd3e9d015'
52+
);
53+
});
7754

78-
$.test('Creating raw MD5 hash of an UTF-8 value', function () {
79-
$.strictEqual(
80-
$.md5('日本', null, true),
81-
'M\xbe\xd2\xe6WEx\x84\xe6q7\xd3QA\x19\xb3'
82-
);
8355
});
8456

85-
$.module('Raw HMAC-MD5', lifecycle);
57+
describe('MD5 raw encoding', function () {
8658

87-
$.test('Creating raw HMAC-MD5 hash of an ASCII value and key', function () {
88-
$.strictEqual(
89-
$.md5('value', 'key', true),
90-
'\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6'
91-
);
92-
});
59+
it('should create a raw MD5 hash of an ASCII value', function () {
60+
expect(
61+
md5('value', null, true)
62+
).to.be(
63+
' c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04'
64+
);
65+
});
66+
67+
it('should create a raw MD5 hash of an UTF-8 value', function () {
68+
expect(
69+
md5('日本', null, true)
70+
).to.be(
71+
'M\xbe\xd2\xe6WEx\x84\xe6q7\xd3QA\x19\xb3'
72+
);
73+
});
9374

94-
$.test('Creating raw HMAC-MD5 hash of an UTF-8 value and key', function () {
95-
$.strictEqual(
96-
$.md5('日本', '日本', true),
97-
'\xc7\x8b\x8csW\x92i\x81\xcc\x04t\x0b\xd3\xe9\xd0\x15'
98-
);
9975
});
10076

101-
nodeQunit.teardown();
77+
describe('HMAC-MD5 raw encoding', function () {
78+
79+
it('should create a raw HMAC-MD5 hash of an ASCII value and key', function () {
80+
expect(
81+
md5('value', 'key', true)
82+
).to.be(
83+
'\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6'
84+
);
85+
});
86+
87+
it('should create a raw HMAC-MD5 hash of an UTF-8 value and key', function () {
88+
expect(
89+
md5('日本', '日本', true)
90+
).to.be(
91+
'\xc7\x8b\x8csW\x92i\x81\xcc\x04t\x0b\xd3\xe9\xd0\x15'
92+
);
93+
});
94+
95+
});
10296

103-
}(this));
97+
}(
98+
this.expect || require('expect.js'),
99+
this.md5 || require('../md5').md5
100+
));

0 commit comments

Comments
 (0)