Repository: Redocly/redocly-cli
Pull request #1149 (2023-07-04 10:11:16)

fix: pass files from '--files' option to config
## What/Why/How?

Fix problem with `--files` option in `push` command

## Reference

Related: https://github.com/Redocly/redocly-cli/issues/1148

## Testing

## Screenshots (optional)

## Check yourself

- [x] Code is linted
- [x] Tested with redoc/reference-docs/workflows
- [x] All new/updated code is covered with tests

## Security

- [x] Security impact of change has been considered
- [x] Code follows company security practices and guidelines


github-actions[bot]: | Command | Mean [s] | Min [s] | Max [s] | Relative |
|:---|---:|---:|---:|---:|
| `REDOCLY_TELEMETRY=off redocly lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.286 ± 0.024 | 1.255 | 1.324 | 1.00 |
| `REDOCLY_TELEMETRY=off redocly-next lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.305 ± 0.026 | 1.266 | 1.349 | 1.01 ± 0.03 |

<!-- thollander/actions-comment-pull-request "hyperfine-comparison" -->
github-actions[bot]: <!-- jest coverage report action for options with hash 3339ae53a38c44382c0fb4491bdb282d -->

## Coverage report 



| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | Category   | Percentage | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :--------- | :-------------: |
|                                                                           🟡                                                                           | Statements | 74.42%     |    3706/4980    |
|                                                                           🟡                                                                           | Branches   | 65.42%     |    2060/3149    |
|                                                                           🟡                                                                           | Functions  | 66.67%     |     616/924     |
|                                                                           🟡                                                                           | Lines      | 74.49%     |    3457/4641    |


## Test suite run success
613 tests passing in 88 suites.

<p align="right">Report generated by <a href="https://github.com/ArtiomTr/jest-coverage-report-action">🧪jest coverage report action</a> from 0321c3e325a8afca806a50c16ec32ce32ba74595</p>


Patch:
diff --git a/packages/cli/src/wrapper.ts b/packages/cli/src/wrapper.ts
index 756e0c3a..2e1fa85d 100644
--- a/packages/cli/src/wrapper.ts
+++ b/packages/cli/src/wrapper.ts
@@ -20,7 +20,7 @@ export function commandWrapper<T extends CommandOptions>(
         configPath: argv.config,
         customExtends: argv.extends as string[] | undefined,
         region: argv.region as Region,
-        files: argv.file as string[] | undefined,
+        files: argv.files as string[] | undefined,
         processRawConfig: lintConfigCallback(argv as T & Record<string, undefined>, version),
       })) as Config;
       telemetry = config.telemetry;


Test patch:
diff --git a/packages/cli/src/__tests__/wrapper.test.ts b/packages/cli/src/__tests__/wrapper.test.ts
index 553b6a67..d5ab7b78 100644
--- a/packages/cli/src/__tests__/wrapper.test.ts
+++ b/packages/cli/src/__tests__/wrapper.test.ts
@@ -2,7 +2,8 @@ import { loadConfigAndHandleErrors, sendTelemetry } from '../utils';
 import * as process from 'process';
 import { commandWrapper } from '../wrapper';
 import { handleLint } from '../commands/lint';
-import nodeFetch from 'node-fetch';
+import { Arguments } from 'yargs';
+import { handlePush, PushOptions } from '../commands/push';
 
 jest.mock('node-fetch');
 jest.mock('../utils', () => ({
@@ -40,4 +41,17 @@ describe('commandWrapper', () => {
 
     expect(sendTelemetry).toHaveBeenCalledTimes(0);
   });
+
+  it('should pass files from arguments to config', async () => {
+    const filesToPush = ['test1.yaml', 'test2.yaml'];
+
+    const loadConfigMock = loadConfigAndHandleErrors as jest.Mock<any, any>;
+
+    const argv = {
+      files: filesToPush,
+    } as Arguments<PushOptions>;
+
+    await commandWrapper(handlePush)(argv);
+    expect(loadConfigMock).toHaveBeenCalledWith(expect.objectContaining({ files: filesToPush }));
+  });
 });