Skip to content

Commit c901a7e

Browse files
committed
fixes to browser Mocha testing, docs
1 parent 4250800 commit c901a7e

File tree

4 files changed

+87
-70
lines changed

4 files changed

+87
-70
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ To run tests, make sure you run
9393

9494
The tests can be run in Node using:
9595

96-
npx mocha
96+
npm test
9797
npm run coverage
9898

9999
To run the tests in a browser environment, open the `test/smpte-timecode-test.html` file
100100
in a browser.
101101

102102
## Update History
103+
- 1.3.2
104+
- fixed to browser-based tests, documentation.
103105
- 1.3.1
104106
- Coverage tests changed to nyc
105107
- Support for fractional framerates and framerates above 60fps

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smpte-timecode",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "JavaScript implementation of SMPTE timecode type",
55
"main": "smpte-timecode.js",
66
"scripts": {

test/smpte-timecode-test.html

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
<html>
2-
<head>
3-
<meta charset="utf-8">
4-
<title>Mocha Tests</title>
5-
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
6-
</head>
7-
<body>
8-
<div id="mocha"></div>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Mocha Tests</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
8+
</head>
9+
<body>
10+
<div id="mocha"></div>
11+
<script src="https://unpkg.com/chai/chai.js"></script>
12+
<script src="https://unpkg.com/mocha/mocha.js"></script>
913

10-
<script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>
11-
<script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
12-
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
13-
14-
<script>mocha.setup('bdd')</script>
15-
<script src="../smpte-timecode.js"></script>
16-
<script src="smpte-timecode-test.js"></script>
17-
<script>
18-
mocha.checkLeaks();
19-
mocha.globals(['jQuery']);
20-
mocha.run();
21-
</script>
22-
</body>
14+
<script class="mocha-init">
15+
mocha.setup('bdd');
16+
mocha.checkLeaks();
17+
mocha.globals(['jQuery']);
18+
</script>
19+
<script src="../node_modules/expect.js/index.js"></script>
20+
<script src="../node_modules/lodash/lodash.js"></script>
21+
<script class="mocha-init">
22+
var isEqual = _.isEqual;
23+
</script>
24+
<script src="../smpte-timecode.js"></script>
25+
<script src="smpte-timecode-test.js"></script>
26+
<script class="mocha-exec">
27+
mocha.run();
28+
</script>
29+
</body>
2330
</html>

test/smpte-timecode-test.js

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
var sinon = require('sinon');
2-
const isEqual = require('lodash.isequal');
31

42
// If we are running under Node, we need to add expect and load our module
53
if (typeof module !== 'undefined' && module.exports) {
64
global.expect = require('expect.js');
5+
global.isEqual = require('lodash.isequal');
76
global.Timecode = require('../smpte-timecode.js');
7+
global.sinon = require('sinon');
8+
var runInBrowser = false;
9+
}
10+
else {
11+
var runInBrowser = true;
812
}
913

1014
describe('Constructor tests', function(){
@@ -221,50 +225,54 @@ describe('Date() operations', function(){
221225
});
222226

223227
describe('DST handling', function() {
224-
var clock;
225-
226-
function clearDate(d) {
227-
d.setYear(0);
228-
d.setMonth(0);
229-
d.setDate(1);
230-
}
231-
232-
function checkDst(d) {
233-
// we need to fake out 'new Date()', since this issue only happens day of.
234-
clock = sinon.useFakeTimers(d);
235-
236-
var t = new Timecode(d, 29.97, true);
237-
var o = t.toDate();
238-
// console.log(d.toString(), '->', o.toString());
239-
clearDate(d);
240-
clearDate(o);
241-
expect(o.toString()).to.be(d.toString());
242-
}
243-
244-
afterEach(function() {
245-
clock.restore();
246-
});
247-
248-
it ('handles DST start 1am', function() {
249-
checkDst(new Date(2018,2,11,1,0,0,200));
250-
checkDst(new Date(2018,2,11,1,59,59,200));
251-
});
252-
253-
it ('handles DST start 2am', function() {
254-
checkDst(new Date(2018,2,11,2,0,0,200));
255-
checkDst(new Date(2018,2,11,2,59,59,200));
256-
checkDst(new Date(2018,2,11,3,0,0,200));
257-
});
258-
259-
it ('handles DST end 1am', function() {
260-
checkDst(new Date(2018,10,4,1,0,0,200));
261-
checkDst(new Date(2018,10,4,1,59,59,200));
262-
});
263-
264-
it ('handles DST end 2am', function() {
265-
checkDst(new Date(2018,10,4,2,0,0,200));
266-
checkDst(new Date(2018,10,4,2,59,59,200));
267-
checkDst(new Date(2018,10,4,3,0,0,200));
268-
});
228+
var clock;
229+
230+
function clearDate(d) {
231+
d.setYear(0);
232+
d.setMonth(0);
233+
d.setDate(1);
234+
}
235+
236+
function checkDst(d) {
237+
// we need to fake out 'new Date()', since this issue only happens day of.
238+
clock = sinon.useFakeTimers(d);
239+
240+
var t = new Timecode(d, 29.97, true);
241+
var o = t.toDate();
242+
// console.log(d.toString(), '->', o.toString());
243+
clearDate(d);
244+
clearDate(o);
245+
expect(o.toString()).to.be(d.toString());
246+
}
247+
248+
afterEach(function() {
249+
if (!runInBrowser) clock.restore();
250+
});
251+
252+
it ('handles DST start 1am', function() {
253+
if (runInBrowser) this.skip();
254+
checkDst(new Date(2018,2,11,1,0,0,200));
255+
checkDst(new Date(2018,2,11,1,59,59,200));
256+
});
257+
258+
it ('handles DST start 2am', function() {
259+
if (runInBrowser) this.skip();
260+
checkDst(new Date(2018,2,11,2,0,0,200));
261+
checkDst(new Date(2018,2,11,2,59,59,200));
262+
checkDst(new Date(2018,2,11,3,0,0,200));
263+
});
264+
265+
it ('handles DST end 1am', function() {
266+
if (runInBrowser) this.skip();
267+
checkDst(new Date(2018,10,4,1,0,0,200));
268+
checkDst(new Date(2018,10,4,1,59,59,200));
269+
});
270+
271+
it ('handles DST end 2am', function() {
272+
if (runInBrowser) this.skip();
273+
checkDst(new Date(2018,10,4,2,0,0,200));
274+
checkDst(new Date(2018,10,4,2,59,59,200));
275+
checkDst(new Date(2018,10,4,3,0,0,200));
276+
});
269277

270278
});

0 commit comments

Comments
 (0)