Skip to content

Commit b1c41b8

Browse files
authored
test: fix type issues in test optimization tests (#7297)
These are mostly passing through stdio as argument to exec, which does not support that argument. In addition, fix a couple of process.env types and add some more types to test helpers. There is one spot where `parallel` was defined was not used in the test. That is removed as well as activating the no-undef eslint rule for test-optimization code. On top, the assertObjectContains helper got improved to always generate a diff in the future, even on older Node.js versions.
1 parent b4af38d commit b1c41b8

File tree

13 files changed

+346
-536
lines changed

13 files changed

+346
-536
lines changed

eslint.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,14 @@ export default [
640640
plugins: {
641641
mocha: eslintPluginMocha,
642642
},
643+
languageOptions: {
644+
globals: {
645+
afterAll: 'readonly',
646+
expect: 'readonly',
647+
jest: 'readonly',
648+
},
649+
},
643650
rules: {
644-
'no-undef': 'off',
645651
'mocha/max-top-level-suites': 'off',
646652
'mocha/no-pending-tests': 'off',
647653
}

integration-tests/ci-visibility/automatic-log-submission.spec.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ describe('test optimization automatic log submission', () => {
3434
// *Be advised*: this means that we'll only be using chromium for this test suite
3535
execSync('npx playwright install --with-deps chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
3636
webAppServer.listen(0, () => {
37-
webAppPort = webAppServer.address().port
37+
const address = webAppServer.address()
38+
if (!address || typeof address === 'string') {
39+
return done(new Error('Failed to determine web app server port'))
40+
}
41+
webAppPort = address.port
3842
done()
3943
})
4044
})
@@ -82,7 +86,8 @@ describe('test optimization automatic log submission', () => {
8286

8387
context(`with ${name}`, () => {
8488
it('can automatically submit logs', async () => {
85-
let logIds, testIds
89+
let logIds = {}
90+
let testIds = {}
8691

8792
const logsPromise = receiver
8893
.gatherPayloadsMaxTimeout(({ url }) => url.includes('/api/v2/logs'), payloads => {
@@ -134,13 +139,12 @@ describe('test optimization automatic log submission', () => {
134139
DD_SERVICE: 'my-service',
135140
...getExtraEnvVars()
136141
},
137-
stdio: 'pipe'
138142
}
139143
)
140-
childProcess.stdout.on('data', (chunk) => {
144+
childProcess.stdout?.on('data', (chunk) => {
141145
testOutput += chunk.toString()
142146
})
143-
childProcess.stderr.on('data', (chunk) => {
147+
childProcess.stderr?.on('data', (chunk) => {
144148
testOutput += chunk.toString()
145149
})
146150

@@ -176,13 +180,12 @@ describe('test optimization automatic log submission', () => {
176180
DD_SERVICE: 'my-service',
177181
...getExtraEnvVars()
178182
},
179-
stdio: 'pipe'
180183
}
181184
)
182-
childProcess.stdout.on('data', (chunk) => {
185+
childProcess.stdout?.on('data', (chunk) => {
183186
testOutput += chunk.toString()
184187
})
185-
childProcess.stderr.on('data', (chunk) => {
188+
childProcess.stderr?.on('data', (chunk) => {
186189
testOutput += chunk.toString()
187190
})
188191

@@ -218,14 +221,13 @@ describe('test optimization automatic log submission', () => {
218221
DD_API_KEY: '',
219222
...getExtraEnvVars()
220223
},
221-
stdio: 'pipe'
222224
}
223225
)
224226

225-
childProcess.stdout.on('data', (chunk) => {
227+
childProcess.stdout?.on('data', (chunk) => {
226228
testOutput += chunk.toString()
227229
})
228-
childProcess.stderr.on('data', (chunk) => {
230+
childProcess.stderr?.on('data', (chunk) => {
229231
testOutput += chunk.toString()
230232
})
231233

integration-tests/ci-visibility/test-api-manual.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ describe('test-api-manual', () => {
6666
{
6767
cwd,
6868
env: getCiVisAgentlessConfig(receiver.port),
69-
stdio: 'pipe'
7069
}
7170
)
7271
childProcess.on('exit', () => {
@@ -89,7 +88,6 @@ describe('test-api-manual', () => {
8988
...getCiVisAgentlessConfig(receiver.port),
9089
DD_CIVISIBILITY_MANUAL_API_ENABLED: 'false'
9190
},
92-
stdio: 'pipe'
9391
}
9492
)
9593
childProcess.on('exit', () => {

integration-tests/ci-visibility/test-optimization-startup.spec.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ describe('test optimization startup', () => {
3838
NODE_OPTIONS: '-r dd-trace/ci/init',
3939
DD_TRACE_DEBUG: '1'
4040
},
41-
stdio: 'pipe'
4241
}
4342
)
4443

45-
childProcess.stdout.on('data', (chunk) => {
44+
childProcess.stdout?.on('data', (chunk) => {
4645
processOutput += chunk.toString()
4746
})
48-
childProcess.stderr.on('data', (chunk) => {
47+
childProcess.stderr?.on('data', (chunk) => {
4948
processOutput += chunk.toString()
5049
})
5150

@@ -68,14 +67,13 @@ describe('test optimization startup', () => {
6867
NODE_OPTIONS: '-r dd-trace/ci/init',
6968
DD_TRACE_DEBUG: '1'
7069
},
71-
stdio: 'pipe'
7270
}
7371
)
7472

75-
childProcess.stdout.on('data', (chunk) => {
73+
childProcess.stdout?.on('data', (chunk) => {
7674
processOutput += chunk.toString()
7775
})
78-
childProcess.stderr.on('data', (chunk) => {
76+
childProcess.stderr?.on('data', (chunk) => {
7977
processOutput += chunk.toString()
8078
})
8179

@@ -99,14 +97,13 @@ describe('test optimization startup', () => {
9997
DD_CIVISIBILITY_AGENTLESS_ENABLED: '1',
10098
DD_API_KEY: '',
10199
},
102-
stdio: 'pipe'
103100
}
104101
)
105102

106-
childProcess.stdout.on('data', (chunk) => {
103+
childProcess.stdout?.on('data', (chunk) => {
107104
processOutput += chunk.toString()
108105
})
109-
childProcess.stderr.on('data', (chunk) => {
106+
childProcess.stderr?.on('data', (chunk) => {
110107
processOutput += chunk.toString()
111108
})
112109

@@ -131,14 +128,13 @@ describe('test optimization startup', () => {
131128
DD_API_KEY: '',
132129
JEST_WORKER_ID: '1' // worker id is set in jest workers
133130
},
134-
stdio: 'pipe'
135131
}
136132
)
137133

138-
childProcess.stdout.on('data', (chunk) => {
134+
childProcess.stdout?.on('data', (chunk) => {
139135
processOutput += chunk.toString()
140136
})
141-
childProcess.stderr.on('data', (chunk) => {
137+
childProcess.stderr?.on('data', (chunk) => {
142138
processOutput += chunk.toString()
143139
})
144140

integration-tests/ci-visibility/test-optimization-wrong-init.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,14 @@ testFrameworks.forEach(({ testFramework, command, expectedOutput, extraTestConte
100100
DD_TRACE_DEBUG: '1',
101101
...extraTestContext
102102
},
103-
stdio: 'pipe'
104103
}
105104
)
106105

107-
childProcess.stderr.on('data', (chunk) => {
106+
childProcess.stderr?.on('data', (chunk) => {
108107
processOutput += chunk.toString()
109108
})
110109

111-
childProcess.stdout.on('data', (chunk) => {
110+
childProcess.stdout?.on('data', (chunk) => {
112111
processOutput += chunk.toString()
113112
})
114113

0 commit comments

Comments
 (0)