native-promises.js
1.79 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict'
var agent = require('../..').start({
appId: 'test',
organizationId: 'test',
secretToken: 'test',
captureExceptions: false
})
var ins = agent._instrumentation
var semver = require('semver')
// Native promises wasn't available until Node.js 0.12
if (!semver.satisfies(process.version, '>=0.12')) process.exit()
var test = require('tape')
require('./_shared-promise-tests')(test, Promise, ins)
// non-standard v8
test('Promise.prototype.chain - short', function (t) {
t.plan(4)
twice(function () {
var trans = ins.startTransaction()
new Promise(function (resolve, reject) {
resolve('foo')
}).chain(function (data) {
t.equal(data, 'foo')
t.equal(ins.currentTransaction._uuid, trans._uuid)
}, function () {
t.fail('should not reject')
})
})
})
// non-standard v8
test('Promise.prototype.chain - long', function (t) {
t.plan(8)
twice(function () {
var trans = ins.startTransaction()
new Promise(function (resolve, reject) {
resolve('foo')
}).chain(function (data) {
t.equal(data, 'foo')
t.equal(ins.currentTransaction._uuid, trans._uuid)
return 'bar'
}, function () {
t.fail('should not reject')
}).chain(function (data) {
t.equal(data, 'bar')
t.equal(ins.currentTransaction._uuid, trans._uuid)
}, function () {
t.fail('should not reject')
})
})
})
// non-standard v8
test('Promise.accept', function (t) {
t.plan(4)
twice(function () {
var trans = ins.startTransaction()
Promise.accept('foo')
.then(function (data) {
t.equal(data, 'foo')
t.equal(ins.currentTransaction._uuid, trans._uuid)
})
.catch(function () {
t.fail('should not reject')
})
})
})
function twice (fn) {
setImmediate(fn)
setImmediate(fn)
}