Skip to content

Commit 51b35cf

Browse files
[test optimization] Move plugin cypress tests to integration tests (#6876)
1 parent 34a0619 commit 51b35cf

File tree

18 files changed

+131
-286
lines changed

18 files changed

+131
-286
lines changed

.github/workflows/test-optimization.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,6 @@ jobs:
194194
with:
195195
dd_api_key: ${{ secrets.DD_API_KEY }}
196196

197-
# TODO: fix performance issues and test more Node versions
198-
plugin-cypress:
199-
runs-on: ubuntu-latest
200-
env:
201-
PLUGINS: cypress
202-
steps:
203-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
204-
- uses: ./.github/actions/testagent/start
205-
- uses: ./.github/actions/node/latest
206-
- uses: ./.github/actions/install
207-
- run: yarn test:plugins:ci
208-
- if: always()
209-
uses: ./.github/actions/testagent/logs
210-
with:
211-
suffix: plugins-${{ github.job }}
212-
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
213-
- uses: DataDog/junit-upload-github-action@762867566348d59ac9bcf479ebb4ec040db8940a # v2.0.0
214-
if: always()
215-
with:
216-
api_key: ${{ secrets.DD_API_KEY }}
217-
service: dd-trace-js-tests
218-
219197
# TODO: fix performance issues and test more Node versions
220198
plugin-jest:
221199
runs-on: ubuntu-latest

integration-tests/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# CODEOWNERS for testing purposes
22
ci-visibility/subproject @datadog-dd-trace-js
33
ci-visibility/ @datadog-dd-trace-js
4+
cypress/ @datadog-dd-trace-js

integration-tests/cypress/cypress.spec.js

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const {
2323
TEST_STATUS,
2424
TEST_COMMAND,
2525
TEST_MODULE,
26+
TEST_FRAMEWORK,
2627
TEST_FRAMEWORK_VERSION,
28+
TEST_TYPE,
2729
TEST_TOOLCHAIN,
2830
TEST_CODE_COVERAGE_ENABLED,
2931
TEST_ITR_SKIPPING_ENABLED,
@@ -63,7 +65,7 @@ const {
6365
TEST_IS_MODIFIED
6466
} = require('../../packages/dd-trace/src/plugins/util/test')
6567
const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env')
66-
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')
68+
const { ERROR_MESSAGE, ERROR_TYPE, COMPONENT } = require('../../packages/dd-trace/src/constants')
6769
const { DD_MAJOR, NODE_MAJOR } = require('../../version')
6870

6971
const RECEIVER_STOP_TIMEOUT = 20000
@@ -129,10 +131,10 @@ moduleTypes.forEach(({
129131
testCommand = testCommand(version)
130132
}
131133

134+
// cypress-fail-fast is required as an incompatible plugin
132135
useSandbox([`cypress@${version}`, 'cypress-fail-fast@7.1.0'], true)
133136

134137
before(async () => {
135-
// cypress-fail-fast is required as an incompatible plugin
136138
cwd = sandboxCwd()
137139

138140
const { NODE_OPTIONS, ...restOfEnv } = process.env
@@ -176,6 +178,95 @@ moduleTypes.forEach(({
176178
}
177179
})
178180

181+
it('instruments tests with the APM protocol (old agents)', async () => {
182+
receiver.setInfoResponse({ endpoints: [] })
183+
184+
const receiverPromise = receiver
185+
.gatherPayloadsMaxTimeout(({ url }) => url === '/v0.4/traces', (payloads) => {
186+
const testSpans = payloads.flatMap(({ payload }) => payload.flatMap(trace => trace))
187+
188+
const passedTestSpan = testSpans.find(span =>
189+
span.resource === 'cypress/e2e/basic-pass.js.basic pass suite can pass'
190+
)
191+
const failedTestSpan = testSpans.find(span =>
192+
span.resource === 'cypress/e2e/basic-fail.js.basic fail suite can fail'
193+
)
194+
195+
assert.exists(passedTestSpan, 'passed test span should exist')
196+
assert.equal(passedTestSpan.name, 'cypress.test')
197+
assert.equal(passedTestSpan.resource, 'cypress/e2e/basic-pass.js.basic pass suite can pass')
198+
assert.equal(passedTestSpan.type, 'test')
199+
assert.equal(passedTestSpan.meta[TEST_STATUS], 'pass')
200+
assert.equal(passedTestSpan.meta[TEST_NAME], 'basic pass suite can pass')
201+
assert.equal(passedTestSpan.meta[TEST_SUITE], 'cypress/e2e/basic-pass.js')
202+
assert.equal(passedTestSpan.meta[TEST_FRAMEWORK], 'cypress')
203+
assert.equal(passedTestSpan.meta[TEST_TYPE], 'browser')
204+
assert.exists(passedTestSpan.meta[TEST_SOURCE_FILE])
205+
assert.include(passedTestSpan.meta[TEST_SOURCE_FILE], 'cypress/e2e/basic-pass.js')
206+
assert.exists(passedTestSpan.meta[TEST_FRAMEWORK_VERSION])
207+
assert.exists(passedTestSpan.meta[COMPONENT])
208+
assert.exists(passedTestSpan.metrics[TEST_SOURCE_START])
209+
assert.equal(passedTestSpan.meta[TEST_CODE_OWNERS], JSON.stringify(['@datadog-dd-trace-js']))
210+
assert.equal(passedTestSpan.meta.customTag, 'customValue')
211+
assert.equal(passedTestSpan.meta.addTagsBeforeEach, 'customBeforeEach')
212+
assert.equal(passedTestSpan.meta.addTagsAfterEach, 'customAfterEach')
213+
214+
assert.exists(failedTestSpan, 'failed test span should exist')
215+
assert.equal(failedTestSpan.name, 'cypress.test')
216+
assert.equal(failedTestSpan.resource, 'cypress/e2e/basic-fail.js.basic fail suite can fail')
217+
assert.equal(failedTestSpan.type, 'test')
218+
assert.equal(failedTestSpan.meta[TEST_STATUS], 'fail')
219+
assert.equal(failedTestSpan.meta[TEST_NAME], 'basic fail suite can fail')
220+
assert.equal(failedTestSpan.meta[TEST_SUITE], 'cypress/e2e/basic-fail.js')
221+
assert.equal(failedTestSpan.meta[TEST_FRAMEWORK], 'cypress')
222+
assert.equal(failedTestSpan.meta[TEST_TYPE], 'browser')
223+
assert.exists(failedTestSpan.meta[TEST_SOURCE_FILE])
224+
assert.include(failedTestSpan.meta[TEST_SOURCE_FILE], 'cypress/e2e/basic-fail.js')
225+
assert.exists(failedTestSpan.meta[TEST_FRAMEWORK_VERSION])
226+
assert.exists(failedTestSpan.meta[COMPONENT])
227+
assert.exists(failedTestSpan.meta[ERROR_MESSAGE])
228+
assert.include(failedTestSpan.meta[ERROR_MESSAGE], 'expected')
229+
assert.exists(failedTestSpan.meta[ERROR_TYPE])
230+
assert.exists(failedTestSpan.metrics[TEST_SOURCE_START])
231+
assert.equal(passedTestSpan.meta[TEST_CODE_OWNERS], JSON.stringify(['@datadog-dd-trace-js']))
232+
assert.equal(failedTestSpan.meta.customTag, 'customValue')
233+
assert.equal(failedTestSpan.meta.addTagsBeforeEach, 'customBeforeEach')
234+
assert.equal(failedTestSpan.meta.addTagsAfterEach, 'customAfterEach')
235+
// Tags added after failure should not be present because test failed
236+
assert.notProperty(failedTestSpan.meta, 'addTagsAfterFailure')
237+
}, 60000)
238+
239+
const {
240+
NODE_OPTIONS,
241+
...restEnvVars
242+
} = getCiVisEvpProxyConfig(receiver.port)
243+
244+
const specToRun = 'cypress/e2e/basic-*.js'
245+
246+
// For Cypress 6.7.0, we need to override the --spec flag that's hardcoded in testCommand
247+
const command = version === '6.7.0'
248+
? `./node_modules/.bin/cypress run --config-file cypress-config.json --spec "${specToRun}"`
249+
: testCommand
250+
251+
childProcess = exec(
252+
command,
253+
{
254+
cwd,
255+
env: {
256+
...restEnvVars,
257+
CYPRESS_BASE_URL: `http://localhost:${webAppPort}`,
258+
SPEC_PATTERN: specToRun
259+
},
260+
stdio: 'pipe'
261+
}
262+
)
263+
264+
await Promise.all([
265+
once(childProcess, 'exit'),
266+
receiverPromise
267+
])
268+
})
269+
179270
if (version === '6.7.0') {
180271
// to be removed when we drop support for cypress@6.7.0
181272
it('logs a warning if using a deprecated version of cypress', async () => {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable */
2+
describe('basic fail suite', () => {
3+
beforeEach(() => {
4+
cy.visit('/')
5+
cy.task('dd:addTags', { addTagsBeforeEach: 'customBeforeEach' })
6+
})
7+
8+
afterEach(() => {
9+
cy.task('dd:addTags', { addTagsAfterEach: 'customAfterEach' })
10+
})
11+
12+
it('can fail', () => {
13+
cy.task('dd:addTags', { customTag: 'customValue' })
14+
cy.get('.hello-world')
15+
.should('have.text', 'Hello warld')
16+
cy.task('dd:addTags', { addTagsAfterFailure: 'customAfterFailure' })
17+
})
18+
})
19+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable */
2+
describe('basic pass suite', () => {
3+
beforeEach(() => {
4+
cy.visit('/')
5+
cy.task('dd:addTags', { addTagsBeforeEach: 'customBeforeEach' })
6+
})
7+
8+
afterEach(() => {
9+
cy.task('dd:addTags', { addTagsAfterEach: 'customAfterEach' })
10+
})
11+
12+
it('can pass', () => {
13+
cy.task('dd:addTags', { customTag: 'customValue' })
14+
cy.get('.hello-world')
15+
.should('have.text', 'Hello World')
16+
})
17+
})
18+

packages/datadog-plugin-cypress/test/app-10/app-server.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/datadog-plugin-cypress/test/app-10/cypress.config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/datadog-plugin-cypress/test/app-10/cypress/integration/integration-test.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/datadog-plugin-cypress/test/app-10/cypress/plugins/index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/datadog-plugin-cypress/test/app-10/cypress/support/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)