Skip to content

Commit 0f2d663

Browse files
kibanamachinecsr
andauthored
[9.0] Fix leaky Jest mock that causes the Scout Reporter to not some collect test events (#237837) (#238095)
# Backport This will backport the following commits from `main` to `9.0`: - [Fix leaky Jest mock that causes the Scout Reporter to not some collect test events (#237837)](#237837) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Cesare de Cal","email":"cesare.decal@elastic.co"},"sourceCommit":{"committedDate":"2025-10-08T15:45:42Z","message":"Fix leaky Jest mock that causes the Scout Reporter to not some collect test events (#237837)\n\nWe noticed we weren't collecting some Scout Reporter events for the\n`src/cli_encryption_keys/jest.config.js` Jest config (we were just\ncollecting a single `run-begin` event, nothing more).\n\nUpon further investigation, we noticed we were mocking/overwriting\n`fs.writeFileSync` the method that the [Scout Jest\nreporter](https://github.com/elastic/kibana/blob/main/src/platform/packages/private/kbn-scout-reporting/src/reporting/jest/reporter.ts)\nrelies on.","sha":"75d57f32a789c5325a5e07ecd9bd9d1632158589","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.3.0"],"title":"Fix leaky Jest mock that causes the Scout Reporter to not some collect test events","number":237837,"url":"https://github.com/elastic/kibana/pull/237837","mergeCommit":{"message":"Fix leaky Jest mock that causes the Scout Reporter to not some collect test events (#237837)\n\nWe noticed we weren't collecting some Scout Reporter events for the\n`src/cli_encryption_keys/jest.config.js` Jest config (we were just\ncollecting a single `run-begin` event, nothing more).\n\nUpon further investigation, we noticed we were mocking/overwriting\n`fs.writeFileSync` the method that the [Scout Jest\nreporter](https://github.com/elastic/kibana/blob/main/src/platform/packages/private/kbn-scout-reporting/src/reporting/jest/reporter.ts)\nrelies on.","sha":"75d57f32a789c5325a5e07ecd9bd9d1632158589"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/237837","number":237837,"mergeCommit":{"message":"Fix leaky Jest mock that causes the Scout Reporter to not some collect test events (#237837)\n\nWe noticed we weren't collecting some Scout Reporter events for the\n`src/cli_encryption_keys/jest.config.js` Jest config (we were just\ncollecting a single `run-begin` event, nothing more).\n\nUpon further investigation, we noticed we were mocking/overwriting\n`fs.writeFileSync` the method that the [Scout Jest\nreporter](https://github.com/elastic/kibana/blob/main/src/platform/packages/private/kbn-scout-reporting/src/reporting/jest/reporter.ts)\nrelies on.","sha":"75d57f32a789c5325a5e07ecd9bd9d1632158589"}}]}] BACKPORT--> Co-authored-by: Cesare de Cal <cesare.decal@elastic.co>
1 parent ae8d7bf commit 0f2d663

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/cli_encryption_keys/interactive.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ describe('encryption key generation interactive', () => {
4949
.mockResolvedValueOnce(true);
5050
jest.spyOn(prompt, 'question').mockResolvedValue('/foo/bar');
5151
jest.spyOn(crypto, 'randomBytes').mockReturnValue('random-key');
52-
fs.writeFileSync = jest.fn();
52+
const writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
5353
await generate(encryptionConfig, { interactive: true });
54-
expect(fs.writeFileSync.mock.calls).toMatchSnapshot();
54+
expect(writeFileSyncSpy.mock.calls).toMatchSnapshot();
55+
writeFileSyncSpy.mockRestore();
5556
});
5657
afterEach(() => {
5758
jest.restoreAllMocks();

0 commit comments

Comments
 (0)