|
1 | 1 | 'use strict' |
2 | 2 |
|
| 3 | +const assert = require('assert') |
3 | 4 | const semver = require('semver') |
4 | 5 | const { |
5 | 6 | runAndCheckWithTelemetry: testFile, |
@@ -99,70 +100,98 @@ function testRuntimeVersionChecks (arg, filename) { |
99 | 100 | } |
100 | 101 | } |
101 | 102 |
|
102 | | - if (!currentVersionIsSupported) { |
103 | | - context('when node version is less than engines field', () => { |
104 | | - useEnv({ NODE_OPTIONS }) |
| 103 | + let pkgPath |
| 104 | + let pkgStr |
105 | 105 |
|
106 | | - it('should not initialize the tracer', () => doTest('false\n', [])) |
| 106 | + before(() => { |
| 107 | + pkgPath = `${sandboxCwd()}/node_modules/dd-trace/package.json` |
| 108 | + pkgStr = fs.readFileSync(pkgPath, 'utf8') |
| 109 | + }) |
107 | 110 |
|
108 | | - context('with DD_INJECTION_ENABLED', () => { |
109 | | - useEnv({ DD_INJECTION_ENABLED }) |
| 111 | + after(() => { |
| 112 | + fs.writeFileSync(pkgPath, pkgStr) |
| 113 | + }) |
110 | 114 |
|
111 | | - context('without debug', () => { |
112 | | - it('should not initialize the tracer', () => doTest('false\n', telemetryAbort)) |
| 115 | + it('should be able to use the engines field', () => { |
| 116 | + const engines = require(`${sandboxCwd()}/node_modules/dd-trace/package.json`).engines.node |
113 | 117 |
|
114 | | - it('should initialize the tracer, if DD_INJECT_FORCE', () => doTestForced('true\n', telemetryForced)) |
115 | | - }) |
| 118 | + assert.match(engines, /^>=[\d]+(\.[\d]+){0,2} <[\d]+(\.[\d]+){0,2}?/) |
| 119 | + }) |
116 | 120 |
|
117 | | - context('with debug', () => { |
118 | | - useEnv({ DD_TRACE_DEBUG }) |
| 121 | + context('when node version is out of range of the engines field', () => { |
| 122 | + useEnv({ NODE_OPTIONS }) |
| 123 | + |
| 124 | + before(() => { |
| 125 | + const pkg = JSON.parse(pkgStr) |
| 126 | + pkg.engines.node = '>=0 <0' |
| 127 | + fs.writeFileSync(pkgPath, JSON.stringify(pkg)) |
| 128 | + }) |
119 | 129 |
|
120 | | - it('should not initialize the tracer', () => |
121 | | - doTest(`Aborting application instrumentation due to incompatible_runtime. |
| 130 | + it('should not initialize the tracer', () => doTest('false\n', [])) |
| 131 | + |
| 132 | + context('with DD_INJECTION_ENABLED', () => { |
| 133 | + useEnv({ DD_INJECTION_ENABLED }) |
| 134 | + |
| 135 | + context('without debug', () => { |
| 136 | + it('should not initialize the tracer', () => doTest('false\n', telemetryAbort)) |
| 137 | + |
| 138 | + it('should initialize the tracer, if DD_INJECT_FORCE', () => doTestForced('true\n', telemetryForced)) |
| 139 | + }) |
| 140 | + |
| 141 | + context('with debug', () => { |
| 142 | + useEnv({ DD_TRACE_DEBUG }) |
| 143 | + |
| 144 | + it('should not initialize the tracer', () => |
| 145 | + doTest(`Aborting application instrumentation due to incompatible_runtime. |
122 | 146 | Found incompatible runtime Node.js ${process.versions.node}, Supported runtimes: Node.js \ |
123 | | -${engines.node}. |
| 147 | +>=0 <0. |
124 | 148 | false |
125 | 149 | `, telemetryAbort)) |
126 | 150 |
|
127 | | - it('should initialize the tracer, if DD_INJECT_FORCE', () => |
128 | | - doTestForced(`Aborting application instrumentation due to incompatible_runtime. |
| 151 | + it('should initialize the tracer, if DD_INJECT_FORCE', () => |
| 152 | + doTestForced(`Aborting application instrumentation due to incompatible_runtime. |
129 | 153 | Found incompatible runtime Node.js ${process.versions.node}, Supported runtimes: Node.js \ |
130 | | -${engines.node}. |
| 154 | +>=0 <0. |
131 | 155 | DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing. |
132 | 156 | Application instrumentation bootstrapping complete |
133 | 157 | true |
134 | 158 | `, telemetryForced)) |
135 | | - }) |
136 | 159 | }) |
137 | 160 | }) |
138 | | - } else { |
139 | | - context('when node version is more than engines field', () => { |
140 | | - useEnv({ NODE_OPTIONS }) |
| 161 | + }) |
| 162 | + |
| 163 | + context('when node version is in range of the engines field', () => { |
| 164 | + useEnv({ NODE_OPTIONS }) |
| 165 | + |
| 166 | + before(() => { |
| 167 | + const pkg = JSON.parse(pkgStr) |
| 168 | + pkg.engines.node = '>=0 <1000' |
| 169 | + fs.writeFileSync(pkgPath, JSON.stringify(pkg)) |
| 170 | + }) |
141 | 171 |
|
142 | | - it('should initialize the tracer, if no DD_INJECTION_ENABLED', () => doTest('true\n', [], 'manual')) |
| 172 | + it('should initialize the tracer, if no DD_INJECTION_ENABLED', () => doTest('true\n', [], 'manual')) |
143 | 173 |
|
144 | | - context('with DD_INJECTION_ENABLED', () => { |
145 | | - useEnv({ DD_INJECTION_ENABLED }) |
| 174 | + context('with DD_INJECTION_ENABLED', () => { |
| 175 | + useEnv({ DD_INJECTION_ENABLED }) |
146 | 176 |
|
147 | | - context('without debug', () => { |
148 | | - it('should initialize the tracer', () => doTest('true\n', telemetryGood, 'ssi')) |
| 177 | + context('without debug', () => { |
| 178 | + it('should initialize the tracer', () => doTest('true\n', telemetryGood, 'ssi')) |
149 | 179 |
|
150 | | - it('should initialize the tracer, if DD_INJECT_FORCE', () => |
151 | | - doTestForced('true\n', telemetryGood, 'ssi')) |
152 | | - }) |
| 180 | + it('should initialize the tracer, if DD_INJECT_FORCE', () => |
| 181 | + doTestForced('true\n', telemetryGood, 'ssi')) |
| 182 | + }) |
153 | 183 |
|
154 | | - context('with debug', () => { |
155 | | - useEnv({ DD_TRACE_DEBUG }) |
| 184 | + context('with debug', () => { |
| 185 | + useEnv({ DD_TRACE_DEBUG }) |
156 | 186 |
|
157 | | - it('should initialize the tracer', () => |
158 | | - doTest('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi')) |
| 187 | + it('should initialize the tracer', () => |
| 188 | + doTest('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi')) |
159 | 189 |
|
160 | | - it('should initialize the tracer, if DD_INJECT_FORCE', () => |
161 | | - doTestForced('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi')) |
162 | | - }) |
| 190 | + it('should initialize the tracer, if DD_INJECT_FORCE', () => |
| 191 | + doTestForced('Application instrumentation bootstrapping complete\ntrue\n', telemetryGood, 'ssi')) |
163 | 192 | }) |
164 | 193 | }) |
165 | | - } |
| 194 | + }) |
166 | 195 | }) |
167 | 196 | } |
168 | 197 |
|
|
0 commit comments