Skip to content

Commit e5c0194

Browse files
[test optimization] Move plugin jest tests to integration tests (#6837)
1 parent a5cf5d3 commit e5c0194

File tree

23 files changed

+546
-653
lines changed

23 files changed

+546
-653
lines changed

.github/workflows/test-optimization.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,32 @@ jobs:
9595
NODE_OPTIONS: '-r ./ci/init'
9696
MOCHA_VERSION: ${{ matrix.mocha-version }}
9797

98+
integration-jest:
99+
strategy:
100+
matrix:
101+
version: [oldest, latest]
102+
jest-version: [24.8.0, latest]
103+
runs-on: ubuntu-latest
104+
env:
105+
DD_SERVICE: dd-trace-js-integration-tests
106+
DD_CIVISIBILITY_AGENTLESS_ENABLED: 1
107+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
108+
steps:
109+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
110+
- uses: ./.github/actions/node
111+
with:
112+
version: ${{ matrix.version }}
113+
- uses: ./.github/actions/install
114+
- run: yarn test:integration:jest
115+
env:
116+
NODE_OPTIONS: '-r ./ci/init'
117+
JEST_VERSION: ${{ matrix.jest-version }}
118+
98119
integration-ci:
99120
strategy:
100121
matrix:
101122
version: [oldest, latest]
102-
framework: [cucumber, selenium, jest]
123+
framework: [cucumber, selenium]
103124
runs-on: ubuntu-latest
104125
env:
105126
DD_SERVICE: dd-trace-js-integration-tests
@@ -193,25 +214,3 @@ jobs:
193214
- uses: ./.github/actions/plugins/test
194215
with:
195216
dd_api_key: ${{ secrets.DD_API_KEY }}
196-
197-
# TODO: fix performance issues and test more Node versions
198-
plugin-jest:
199-
runs-on: ubuntu-latest
200-
env:
201-
PLUGINS: jest
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

integration-tests/ci-visibility/automatic-log-submission/config-jest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ module.exports = {
66
cache: false,
77
testMatch: [
88
'**/ci-visibility/automatic-log-submission/automatic-log-submission-*'
9-
]
9+
],
10+
testRunner: 'jest-circus/runner',
11+
testEnvironment: 'node'
1012
}

packages/datadog-plugin-jest/test/jest-inject-globals.js renamed to integration-tests/ci-visibility/jest-plugin-tests/jest-inject-globals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { describe, it, expect } = require('../../../versions/@jest/globals').get()
3+
const { describe, it, expect } = require('@jest/globals')
44

55
describe('jest-inject-globals', () => {
66
it('will be run', () => {

packages/datadog-plugin-jest/test/jest-test.js renamed to integration-tests/ci-visibility/jest-plugin-tests/jest-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const http = require('http')
44

55
const tracer = require('dd-trace')
66

7+
const ENDPOINT_URL = process.env.DD_CIVISIBILITY_AGENTLESS_URL ||
8+
`http://127.0.0.1:${process.env.DD_TRACE_AGENT_PORT}`
9+
710
describe('jest-test-suite', () => {
811
jest.setTimeout(400)
912

@@ -40,7 +43,7 @@ describe('jest-test-suite', () => {
4043
})
4144

4245
it('can do integration http', (done) => {
43-
const req = http.request('http://test:123', (res) => {
46+
const req = http.request(`${ENDPOINT_URL}/info`, { agent: false }, (res) => {
4447
expect(res.statusCode).toEqual(200)
4548
done()
4649
})

integration-tests/ci-visibility/run-jest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ const jest = require('jest')
55
const options = {
66
projects: [__dirname],
77
testPathIgnorePatterns: ['/node_modules/'],
8+
modulePathIgnorePatterns: ['<rootDir>/\\.bun/'],
89
cache: false,
910
testRegex: process.env.TESTS_TO_RUN ? new RegExp(process.env.TESTS_TO_RUN) : /test\/ci-visibility-test/,
1011
coverage: !!process.env.ENABLE_CODE_COVERAGE,
1112
runInBand: true,
1213
shard: process.env.TEST_SHARD || undefined,
13-
setupFilesAfterEnv: process.env.SETUP_FILES_AFTER_ENV ? process.env.SETUP_FILES_AFTER_ENV.split(',') : []
14+
setupFilesAfterEnv: process.env.SETUP_FILES_AFTER_ENV ? process.env.SETUP_FILES_AFTER_ENV.split(',') : [],
15+
testRunner: 'jest-circus/runner',
16+
testEnvironment: 'node'
1417
}
1518

1619
if (process.env.RUN_IN_PARALLEL) {
@@ -34,6 +37,10 @@ if (process.env.COLLECT_COVERAGE_FROM) {
3437
options.collectCoverageFrom = process.env.COLLECT_COVERAGE_FROM.split(',')
3538
}
3639

40+
if (process.env.DO_NOT_INJECT_GLOBALS) {
41+
options.injectGlobals = false
42+
}
43+
3744
jest.runCLI(
3845
options,
3946
options.projects
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

3-
const assert = require('node:assert')
43
const sum = require('../sum')
54

65
describe('ci visibility 2', () => {
76
it('can report tests 2', () => {
8-
assert.strictEqual(sum(1, 2), 3)
7+
expect(sum(1, 2)).toEqual(3)
98
})
109
})
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

3-
const assert = require('node:assert')
43
const sum = require('../sum')
54

65
describe('ci visibility 3', () => {
76
it('can report tests 3', () => {
8-
assert.strictEqual(sum(1, 2), 3)
7+
expect(sum(1, 2)).toEqual(3)
98
})
109
})

0 commit comments

Comments
 (0)