@@ -91,134 +91,139 @@ versions.forEach((version) => {
9191 const poolConfig = [ 'forks' , 'threads' ]
9292
9393 poolConfig . forEach ( ( poolConfig ) => {
94- it ( `can run and report tests with pool=${ poolConfig } ` , ( done ) => {
95- receiver . gatherPayloadsMaxTimeout ( ( { url } ) => url === '/api/v2/citestcycle' , payloads => {
96- const metadataDicts = payloads . flatMap ( ( { payload } ) => payload . metadata )
94+ it ( `can run and report tests with pool=${ poolConfig } ` , async ( ) => {
95+ childProcess = exec (
96+ './node_modules/.bin/vitest run' ,
97+ {
98+ cwd,
99+ env : {
100+ ...getCiVisAgentlessConfig ( receiver . port ) ,
101+ NODE_OPTIONS : '--import dd-trace/register.js -r dd-trace/ci/init' , // ESM requires more flags
102+ DD_TEST_SESSION_NAME : 'my-test-session' ,
103+ POOL_CONFIG : poolConfig ,
104+ DD_SERVICE : undefined
105+ } ,
106+ stdio : 'pipe'
107+ }
108+ )
97109
98- metadataDicts . forEach ( metadata => {
99- for ( const testLevel of TEST_LEVEL_EVENT_TYPES ) {
100- assert . equal ( metadata [ testLevel ] [ TEST_SESSION_NAME ] , 'my-test-session' )
101- }
102- } )
110+ await Promise . all ( [
111+ once ( childProcess , 'exit' ) ,
112+ receiver . gatherPayloadsMaxTimeout ( ( { url } ) => url === '/api/v2/citestcycle' , payloads => {
113+ const metadataDicts = payloads . flatMap ( ( { payload } ) => payload . metadata )
103114
104- const events = payloads . flatMap ( ( { payload } ) => payload . events )
115+ metadataDicts . forEach ( metadata => {
116+ for ( const testLevel of TEST_LEVEL_EVENT_TYPES ) {
117+ assert . equal ( metadata [ testLevel ] [ TEST_SESSION_NAME ] , 'my-test-session' )
118+ }
119+ } )
105120
106- const testSessionEvent = events . find ( event => event . type === 'test_session_end' )
121+ const events = payloads . flatMap ( ( { payload } ) => payload . events )
107122
108- if ( poolConfig === 'threads' ) {
109- assert . equal ( testSessionEvent . content . meta [ VITEST_POOL ] , 'worker_threads' )
110- } else {
111- assert . equal ( testSessionEvent . content . meta [ VITEST_POOL ] , 'child_process' )
112- }
123+ const testSessionEvent = events . find ( event => event . type === 'test_session_end' )
113124
114- const testModuleEvent = events . find ( event => event . type === 'test_module_end' )
115- const testSuiteEvents = events . filter ( event => event . type === 'test_suite_end' )
116- const testEvents = events . filter ( event => event . type === 'test' )
125+ if ( poolConfig === 'threads' ) {
126+ assert . equal ( testSessionEvent . content . meta [ VITEST_POOL ] , 'worker_threads' )
127+ } else {
128+ assert . equal ( testSessionEvent . content . meta [ VITEST_POOL ] , 'child_process' )
129+ }
117130
118- assert . include ( testSessionEvent . content . resource , 'test_session.vitest run' )
119- assert . equal ( testSessionEvent . content . meta [ TEST_STATUS ] , 'fail' )
120- assert . include ( testModuleEvent . content . resource , 'test_module.vitest run' )
121- assert . equal ( testModuleEvent . content . meta [ TEST_STATUS ] , 'fail' )
122- assert . equal ( testSessionEvent . content . meta [ TEST_TYPE ] , 'test' )
123- assert . equal ( testModuleEvent . content . meta [ TEST_TYPE ] , 'test' )
131+ const testModuleEvent = events . find ( event => event . type === 'test_module_end' )
132+ const testSuiteEvents = events . filter ( event => event . type === 'test_suite_end' )
133+ const testEvents = events . filter ( event => event . type === 'test' )
124134
125- const passedSuite = testSuiteEvents . find (
126- suite => suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-passed-suite.mjs'
127- )
128- assert . equal ( passedSuite . content . meta [ TEST_STATUS ] , 'pass' )
135+ assert . include ( testSessionEvent . content . resource , 'test_session.vitest run' )
136+ assert . equal ( testSessionEvent . content . meta [ TEST_STATUS ] , 'fail' )
137+ assert . include ( testModuleEvent . content . resource , 'test_module.vitest run' )
138+ assert . equal ( testModuleEvent . content . meta [ TEST_STATUS ] , 'fail' )
139+ assert . equal ( testSessionEvent . content . meta [ TEST_TYPE ] , 'test' )
140+ assert . equal ( testModuleEvent . content . meta [ TEST_TYPE ] , 'test' )
129141
130- const failedSuite = testSuiteEvents . find (
131- suite => suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-suite.mjs'
132- )
133- assert . equal ( failedSuite . content . meta [ TEST_STATUS ] , 'fail' )
142+ const passedSuite = testSuiteEvents . find (
143+ suite =>
144+ suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-passed-suite.mjs'
145+ )
146+ assert . equal ( passedSuite . content . meta [ TEST_STATUS ] , 'pass' )
134147
135- const failedSuiteHooks = testSuiteEvents . find (
136- suite => suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs'
137- )
138- assert . equal ( failedSuiteHooks . content . meta [ TEST_STATUS ] , 'fail' )
139-
140- assert . includeMembers ( testEvents . map ( test => test . content . resource ) ,
141- [
142- 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
143- '.test-visibility-failed-suite-first-describe can report failed test' ,
144- 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
145- '.test-visibility-failed-suite-first-describe can report more' ,
146- 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
147- '.test-visibility-failed-suite-second-describe can report passed test' ,
148- 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
149- '.test-visibility-failed-suite-second-describe can report more' ,
150- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report passed test' ,
151- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report more' ,
152- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report passed test' ,
153- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report more' ,
154- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip' ,
155- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo' ,
156- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test' ,
157- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more' ,
158- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test' ,
159- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more' ,
160- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.no suite' ,
161- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.skip no suite' ,
162- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.programmatic skip no suite'
163- ]
164- )
148+ const failedSuite = testSuiteEvents . find (
149+ suite =>
150+ suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-suite.mjs'
151+ )
152+ assert . equal ( failedSuite . content . meta [ TEST_STATUS ] , 'fail' )
165153
166- const failedTests = testEvents . filter ( test => test . content . meta [ TEST_STATUS ] === 'fail' )
167-
168- assert . includeMembers (
169- failedTests . map ( test => test . content . resource ) ,
170- [
171- 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
172- '.test-visibility-failed-suite-first-describe can report failed test' ,
173- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test' ,
174- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more' ,
175- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test' ,
176- 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more'
177- ]
178- )
154+ const failedSuiteHooks = testSuiteEvents . find (
155+ suite =>
156+ suite . content . resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs'
157+ )
158+ assert . equal ( failedSuiteHooks . content . meta [ TEST_STATUS ] , 'fail' )
179159
180- const skippedTests = testEvents . filter ( test => test . content . meta [ TEST_STATUS ] === 'skip' )
160+ assert . includeMembers ( testEvents . map ( test => test . content . resource ) ,
161+ [
162+ 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
163+ '.test-visibility-failed-suite-first-describe can report failed test' ,
164+ 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
165+ '.test-visibility-failed-suite-first-describe can report more' ,
166+ 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
167+ '.test-visibility-failed-suite-second-describe can report passed test' ,
168+ 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
169+ '.test-visibility-failed-suite-second-describe can report more' ,
170+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report passed test' ,
171+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report more' ,
172+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report passed test' ,
173+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report more' ,
174+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip' ,
175+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo' ,
176+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test' ,
177+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more' ,
178+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test' ,
179+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more' ,
180+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.no suite' ,
181+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.skip no suite' ,
182+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.programmatic skip no suite'
183+ ]
184+ )
181185
182- assert . includeMembers (
183- skippedTests . map ( test => test . content . resource ) ,
184- [
185- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip' ,
186- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo' ,
187- 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can programmatic skip'
188- ]
189- )
186+ const failedTests = testEvents . filter ( test => test . content . meta [ TEST_STATUS ] === 'fail' )
190187
191- testEvents . forEach ( test => {
192- assert . equal ( test . content . meta [ TEST_COMMAND ] , 'vitest run' )
193- assert . exists ( test . content . metrics [ DD_HOST_CPU_COUNT ] )
194- assert . equal ( test . content . meta [ DD_TEST_IS_USER_PROVIDED_SERVICE ] , 'false' )
195- } )
188+ assert . includeMembers (
189+ failedTests . map ( test => test . content . resource ) ,
190+ [
191+ 'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' +
192+ '.test-visibility-failed-suite-first-describe can report failed test' ,
193+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test' ,
194+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more' ,
195+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test' ,
196+ 'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more'
197+ ]
198+ )
199+
200+ const skippedTests = testEvents . filter ( test => test . content . meta [ TEST_STATUS ] === 'skip' )
196201
197- testSuiteEvents . forEach ( testSuite => {
198- assert . equal ( testSuite . content . meta [ TEST_COMMAND ] , 'vitest run' )
199- assert . isTrue (
200- testSuite . content . meta [ TEST_SOURCE_FILE ] . startsWith ( 'ci-visibility/vitest-tests/test-visibility' )
202+ assert . includeMembers (
203+ skippedTests . map ( test => test . content . resource ) ,
204+ [
205+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip' ,
206+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo' ,
207+ 'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can programmatic skip'
208+ ]
201209 )
202- assert . equal ( testSuite . content . metrics [ TEST_SOURCE_START ] , 1 )
203- assert . exists ( testSuite . content . metrics [ DD_HOST_CPU_COUNT ] )
204- } )
205- // TODO: check error messages
206- } ) . then ( ( ) => done ( ) ) . catch ( done )
207210
208- childProcess = exec (
209- './node_modules/.bin/vitest run' ,
210- {
211- cwd,
212- env : {
213- ...getCiVisAgentlessConfig ( receiver . port ) ,
214- NODE_OPTIONS : '--import dd-trace/register.js -r dd-trace/ci/init' , // ESM requires more flags
215- DD_TEST_SESSION_NAME : 'my-test-session' ,
216- POOL_CONFIG : poolConfig ,
217- DD_SERVICE : undefined
218- } ,
219- stdio : 'pipe'
220- }
221- )
211+ testEvents . forEach ( test => {
212+ assert . equal ( test . content . meta [ TEST_COMMAND ] , 'vitest run' )
213+ assert . exists ( test . content . metrics [ DD_HOST_CPU_COUNT ] )
214+ assert . equal ( test . content . meta [ DD_TEST_IS_USER_PROVIDED_SERVICE ] , 'false' )
215+ } )
216+
217+ testSuiteEvents . forEach ( testSuite => {
218+ assert . equal ( testSuite . content . meta [ TEST_COMMAND ] , 'vitest run' )
219+ assert . isTrue (
220+ testSuite . content . meta [ TEST_SOURCE_FILE ] . startsWith ( 'ci-visibility/vitest-tests/test-visibility' )
221+ )
222+ assert . equal ( testSuite . content . metrics [ TEST_SOURCE_START ] , 1 )
223+ assert . exists ( testSuite . content . metrics [ DD_HOST_CPU_COUNT ] )
224+ } )
225+ } )
226+ ] )
222227 } )
223228 } )
224229
0 commit comments