From 1bc79eea08f2db96a97effdea636d74ad0543251 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Fri, 5 Jul 2024 05:26:03 +0200 Subject: [PATCH] Rewrite brittle test to more resilient, ignoring FORCE_COLOR (#187539) ## Summary We've seen the tests go both ways on the new infra. Sometimes the received object would have, sometimes it wouldn't have `FORCE_COLOR`. The value comes from here: https://github.com/elastic/kibana/blob/41eb6e2b12aa23ea03c852869cfe908fd80b02bc/packages/kbn-cli-dev-mode/src/using_server_process.ts#L39 - meaning `process.stdout.isTTY` is not always true? Here, it fails because the snapshot doesn't have the flag: https://buildkite.com/elastic/kibana-on-merge/builds/47027#01907bbb-3fae-48c4-95ca-85118ba2c2b8 Here, it because the snapshot has the flag: https://buildkite.com/elastic/kibana-pull-request/builds/219429 This PR tries to ignore that part of the received object. --- .../kbn-cli-dev-mode/src/dev_server.test.ts | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/packages/kbn-cli-dev-mode/src/dev_server.test.ts b/packages/kbn-cli-dev-mode/src/dev_server.test.ts index 4b4b0496f8851..d3f4ee4e09391 100644 --- a/packages/kbn-cli-dev-mode/src/dev_server.test.ts +++ b/packages/kbn-cli-dev-mode/src/dev_server.test.ts @@ -122,31 +122,17 @@ describe('#run$', () => { it('starts the dev server with the right options', () => { run(new DevServer(defaultOptions)).unsubscribe(); - expect(execa.node.mock.calls).toMatchInlineSnapshot(` - Array [ - Array [ - "some/script", - Array [ - "foo", - "bar", - "--logging.json=false", - ], - Object { - "env": Object { - "": true, - "ELASTIC_APM_SERVICE_NAME": "kibana", - "isDevCliChild": "true", - }, - "nodeOptions": Array [ - "--inheritted", - "--exec", - "--argv", - ], - "stdio": "pipe", - }, - ], - ] - `); + expect(execa.node.mock.calls).toBeDefined(); + + const [scriptName, scriptArgs, execaOptions] = execa.node.mock.calls[0]; + + expect(scriptName).toBe('some/script'); + expect(scriptArgs).toEqual(['foo', 'bar', '--logging.json=false']); + expect(execaOptions).toMatchObject({ + env: expect.objectContaining({ ELASTIC_APM_SERVICE_NAME: 'kibana', isDevCliChild: 'true' }), + nodeOptions: ['--inheritted', '--exec', '--argv'], + stdio: 'pipe', + }); }); it('writes stdout and stderr lines to logger', () => {