File: index.js

package info (click to toggle)
node-date-now 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 140 kB
  • sloc: sh: 60; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var test = require("tape")
var setTimeout = require("timers").setTimeout

var now = require("../index")
var seeded = require("../seed")

test("date", function (assert) {
    var before = new Date().getTime()
    var ts = now()
    var after = new Date().getTime()
    assert.ok(before <= ts)
    assert.ok(after >= ts)
    assert.end()
})

test("seeded", function (assert) {
    var before = now()
    var time = seeded(40)
    var after = now()

    var bts = now()
    var ts = time()
    var ats = now()

    assert.ok(ts >= 40)
    assert.ok(ts <= ats - after + 40)

    setTimeout(function () {
        var bts = now()
        var ts = time()
        var ats = now()

        assert.ok(ts >= 40)
        assert.ok(ts <= ats - after + 40)

        assert.end()
    }, 50)
})