-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy pathinstrument.spec.js
63 lines (50 loc) · 1.74 KB
/
instrument.spec.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
require('../../../dd-trace/test/setup/tap')
const { executionAsyncId } = require('async_hooks')
const { expect } = require('chai')
const { storage } = require('../../../datadog-core')
const { AsyncResource } = require('../../src/helpers/instrument')
describe('helpers/instrument', () => {
describe('AsyncResource', () => {
it('should bind statically', () => {
storage('legacy').run('test1', () => {
const tested = AsyncResource.bind(() => {
expect(storage('legacy').getStore()).to.equal('test1')
})
storage('legacy').run('test2', () => {
tested()
})
})
})
it('should bind with the right `this` value statically', () => {
const self = 'test'
const tested = AsyncResource.bind(function (a, b, c) {
expect(this).to.equal(self)
expect(test.asyncResource.asyncId()).to.equal(executionAsyncId())
expect(test).to.have.length(3)
}, 'test', self)
tested()
})
it('should bind a specific instance', () => {
storage('legacy').run('test1', () => {
const asyncResource = new AsyncResource('test')
storage('legacy').run('test2', () => {
const tested = asyncResource.bind((a, b, c) => {
expect(storage('legacy').getStore()).to.equal('test1')
expect(test.asyncResource).to.equal(asyncResource)
expect(test).to.have.length(3)
})
tested()
})
})
})
it('should bind with the right `this` value with an instance', () => {
const self = 'test'
const asyncResource = new AsyncResource('test')
const tested = asyncResource.bind(function () {
expect(this).to.equal(self)
}, self)
tested()
})
})
})