This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
forked from elastic/apm-agent-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
118 lines (98 loc) · 2.47 KB
/
test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict'
var path = require('path')
var readdir = require('fs').readdir
var spawn = require('child_process').spawn
var extname = path.extname
var join = path.join
var bin = join(process.cwd(), 'node_modules/.bin')
var PATH = process.env.PATH + ':' + bin
function run (test, cb) {
var fullPath = test.cwd ? join(test.cwd, test.file) : test.file
test.env = Object.assign({}, process.env, test.env || {})
test.env.PATH = PATH
console.log('running: ' + fullPath)
var ps = spawn('node', [ test.file ], {
stdio: 'inherit',
cwd: test.cwd,
env: test.env
})
ps.on('error', cb)
ps.on('close', function (code) {
if (code !== 0) {
const err = new Error('non-zero error code')
err.code = 'ENONZERO'
err.exitCode = code
return cb(err)
}
cb()
})
}
function series (tasks, cb) {
var results = []
var pos = 0
function done (err, result) {
if (err) return cb(err)
results.push(result)
if (++pos === tasks.length) {
cb(null, results)
} else {
tasks[pos](done)
}
}
setImmediate(tasks[pos], done)
}
function handlerBind (handler) {
return function (task) {
return handler.bind(null, task)
}
}
function mapSeries (tasks, handler, cb) {
series(tasks.map(handlerBind(handler)), cb)
}
var directories = [
'test',
'test/lambda',
'test/integration',
'test/integration/api-schema',
'test/sourcemaps',
'test/instrumentation',
'test/instrumentation/modules',
'test/instrumentation/modules/bluebird',
'test/instrumentation/modules/cassandra-driver',
'test/instrumentation/modules/fastify',
'test/instrumentation/modules/http',
'test/instrumentation/modules/koa-router',
'test/instrumentation/modules/mysql',
'test/instrumentation/modules/mysql2',
'test/instrumentation/modules/pg'
]
mapSeries(directories, readdir, function (err, directoryFiles) {
if (err) throw err
var tests = [
{
file: 'test.js',
cwd: 'test/start/env',
env: {
ELASTIC_APM_SERVICE_NAME: 'from-env'
}
},
{
file: 'test.js',
cwd: 'test/start/file'
}
]
directoryFiles.forEach(function (files, i) {
var directory = directories[i]
files.forEach(function (file) {
if (directory === 'test' && file === 'test.js') return
if (extname(file) !== '.js') return
if (file[0] === '_') return
tests.push({
file: join(directory, file)
})
})
})
mapSeries(tests, run, function (err) {
if (err) throw err
})
})