kibana/packages/kbn-dev-utils/src/run/run_with_commands.test.ts
Jon ac50132159
[7.17] Test cypress OOM and chrome upgrade (#163363)
This PR introduces several changes to the Cypress config for 7.17 that
tries to mimic the state we currently have on main. The most notable
changes are the upgrade to cypress v12 and the addition of the
parallelisation. Both have required fundamentally bigger changes to what
we had before on that branch.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Co-authored-by: Patryk Kopycinski <contact@patrykkopycinski.com>
2023-08-15 02:01:14 +01:00

68 lines
1.9 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { RunWithCommands } from './run_with_commands';
import { ToolingLog, ToolingLogCollectingWriter } from '../tooling_log';
import { ProcRunner } from '../proc_runner';
import { FlagsReader } from './flags_reader';
jest.mock('./metrics');
const testLog = new ToolingLog();
const testLogWriter = new ToolingLogCollectingWriter();
testLog.setWriters([testLogWriter]);
const testCli = new RunWithCommands({
usage: 'node scripts/test_cli [...options]',
description: 'test cli',
extendContext: async () => {
return {
extraContext: true,
};
},
globalFlags: {
boolean: ['some-bool'],
help: `
--some-bool description
`,
},
});
beforeEach(() => {
process.argv = ['node', 'scripts/test_cli', 'foo', '--some-bool'];
jest.clearAllMocks();
});
it('extends the context using extendContext()', async () => {
const context: any = await new Promise((resolve) => {
testCli.command({ name: 'foo', description: 'some command', run: resolve }).execute();
});
expect(context).toEqual({
log: expect.any(ToolingLog),
flags: expect.any(Object),
flagsReader: expect.any(FlagsReader),
addCleanupTask: expect.any(Function),
procRunner: expect.any(ProcRunner),
statsMeta: undefined,
extraContext: true,
});
expect(context.flags).toMatchInlineSnapshot(`
Object {
"_": Array [],
"debug": false,
"help": false,
"quiet": false,
"silent": false,
"some-bool": true,
"unexpected": Array [],
"v": false,
"verbose": false,
}
`);
});