Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added tests, "disable" tests are skipped for now
  • Loading branch information
m59peacemaker authored and goto-bus-stop committed Mar 23, 2018
commit 581df67371850213483ef29a300f2b2d6f358988
62 changes: 62 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var test = require('tape')
var nanotiming = require('./')

test('nanotiming(name) returns endTiming function', function (t) {
var endTiming = nanotiming('foo')
var timings = window.performance.getEntries()
var timing = timings[timings.length - 1]
window.performance.clearMeasures(timing.name)
if (typeof endTiming === 'function') {
t.pass('is a function')
endTiming()
} else {
t.fail('should be a function, but is ' + typeof endTiming)
}
t.end()
})

test('endTiming.uuid is a string', function (t) {
var endTiming = nanotiming('foo')
var timings = window.performance.getEntries()
var timing = timings[timings.length - 1]
window.performance.clearMeasures(timing.name)
endTiming()
t.equal(typeof endTiming.uuid, 'string')
t.end()
})

test('endTiming callback receives the timing name', function (t) {
t.plan(1)
var endTiming = nanotiming('foo')
var timings = window.performance.getEntries()
var timing = timings[timings.length - 1]
window.performance.clearMeasures(timing.name)
endTiming(name => t.equal(name, 'foo', 'name: ' + name))
})

test.skip('is disabled when no window.performance.mark in environment', function (t) {
t.plan(1)

var mark = window.performance.mark
window.performance.mark = undefined
// TODO: need a way to run the "disabled" check again

var noop = nanotiming('foo')
noop(() => t.fail('called the callback, but should have been a noop'))
setTimeout(t.pass)

window.performance.mark = mark
})

test.skip('is disabled when window.localStorage.DISABLE_NANOTIMING === "true"', function (t) {
t.plan(1)

window.localStorage.DISABLE_NANOTIMING = true
// TODO: need a way to run the "disabled" check again

var noop = nanotiming('foo')
noop(() => t.fail('called the callback, but should have been a noop'))
setTimeout(t.pass)

window.localStorage.removeItem('DISABLE_NANOTIMING')
})