Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Nov 27, 2024
1 parent 5c6d126 commit 6b8b308
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('office-addin-mock')

function sum (a, b) {
return a + b
}

module.exports = sum
6 changes: 6 additions & 0 deletions integration-tests/ci-visibility/office-addin-mock/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const sum = require('./dependency')
const { expect } = require('chai')

test('can sum', () => {
expect(sum(1, 2)).to.equal(3)
})
50 changes: 49 additions & 1 deletion integration-tests/jest/jest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ describe('jest CommonJS', () => {
let testOutput = ''

before(async function () {
sandbox = await createSandbox(['jest', 'chai@v4', 'jest-jasmine2', 'jest-environment-jsdom'], true)
sandbox = await createSandbox([
'jest',
'chai@v4',
'jest-jasmine2',
'jest-environment-jsdom',
'office-addin-mock'
], true)
cwd = sandbox.folder
startupTestFile = path.join(cwd, testFile)
})
Expand Down Expand Up @@ -2604,4 +2610,46 @@ describe('jest CommonJS', () => {
})
})
})

// This happens when using office-addin-mock
context('a test imports a file whose name includes a library we should bypass jest require cache for', () => {
it('does not crash', (done) => {
receiver.setSettings({
itr_enabled: false,
code_coverage: false,
tests_skipping: false,
flaky_test_retries_enabled: false,
early_flake_detection: {
enabled: false
}
})

const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)

const tests = events.filter(event => event.type === 'test').map(event => event.content)

assert.equal(tests.length, 1)
})

childProcess = exec(runTestsWithCoverageCommand,
{
cwd,
env: {
...getCiVisAgentlessConfig(receiver.port),
TESTS_TO_RUN: 'office-addin-mock/test'
},
stdio: 'inherit'
}
)

childProcess.on('exit', (code) => {
eventsPromise.then(() => {
assert.equal(code, 0)
done()
}).catch(done)
})
})
})
})
2 changes: 1 addition & 1 deletion packages/datadog-instrumentations/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = [

function shouldBypassJestRequireEngine (moduleName) {
return (
LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.some(library => moduleName.includes(library))
LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.some(library => moduleName === library)
)
}

Expand Down

0 comments on commit 6b8b308

Please sign in to comment.