|
1 | | -var sinon = require('sinon'); |
2 | | -const isEqual = require('lodash.isequal'); |
3 | 1 |
|
4 | 2 | // If we are running under Node, we need to add expect and load our module |
5 | 3 | if (typeof module !== 'undefined' && module.exports) { |
6 | 4 | global.expect = require('expect.js'); |
| 5 | + global.isEqual = require('lodash.isequal'); |
7 | 6 | global.Timecode = require('../smpte-timecode.js'); |
| 7 | + global.sinon = require('sinon'); |
| 8 | + var runInBrowser = false; |
| 9 | +} |
| 10 | +else { |
| 11 | + var runInBrowser = true; |
8 | 12 | } |
9 | 13 |
|
10 | 14 | describe('Constructor tests', function(){ |
@@ -221,50 +225,54 @@ describe('Date() operations', function(){ |
221 | 225 | }); |
222 | 226 |
|
223 | 227 | 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 | + }); |
269 | 277 |
|
270 | 278 | }); |
0 commit comments