Skip to content

Commit

Permalink
[ci-visibility] Allow using after:run directly (#4090)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Feb 26, 2024
1 parent 0b370e9 commit 24df054
Show file tree
Hide file tree
Showing 6 changed files with 616 additions and 555 deletions.
1 change: 1 addition & 0 deletions ci/cypress/after-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../packages/datadog-plugin-cypress/src/after-run')
7 changes: 7 additions & 0 deletions integration-tests/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ module.exports = {
require('cypress-fail-fast/plugin')(on, config)
}
require('dd-trace/ci/cypress/plugin')(on, config)
if (process.env.CYPRESS_ENABLE_AFTER_RUN_CUSTOM) {
on('after:run', (...args) => {
// do custom stuff
// and call after-run at the end
require('dd-trace/ci/cypress/after-run')(...args)
})
}
}
},
video: false,
Expand Down
39 changes: 39 additions & 0 deletions integration-tests/cypress/cypress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,5 +824,44 @@ moduleType.forEach(({
}).catch(done)
})
})

it('works if after:run is explicitly used', (done) => {
const receiverPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSessionEvent = events.find(event => event.type === 'test_session_end')
assert.exists(testSessionEvent)
const testModuleEvent = events.find(event => event.type === 'test_module_end')
assert.exists(testModuleEvent)
const testSuiteEvents = events.filter(event => event.type === 'test_suite_end')
assert.equal(testSuiteEvents.length, 4)
const testEvents = events.filter(event => event.type === 'test')
assert.equal(testEvents.length, 9)
})

const {
NODE_OPTIONS, // NODE_OPTIONS dd-trace config does not work with cypress
...restEnvVars
} = getCiVisEvpProxyConfig(receiver.port)

childProcess = exec(
testCommand,
{
cwd,
env: {
...restEnvVars,
CYPRESS_BASE_URL: `http://localhost:${webAppPort}`,
CYPRESS_ENABLE_AFTER_RUN_CUSTOM: '1'
},
stdio: 'pipe'
}
)

childProcess.on('exit', () => {
receiverPromise.then(() => {
done()
}).catch(done)
})
})
})
})
3 changes: 3 additions & 0 deletions packages/datadog-plugin-cypress/src/after-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cypressPlugin = require('./cypress-plugin')

module.exports = cypressPlugin.afterRun.bind(cypressPlugin)
Loading

0 comments on commit 24df054

Please sign in to comment.