Skip to content

Commit 90b1e57

Browse files
committed
fix some tests
1 parent 292fbf5 commit 90b1e57

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

__tests__/options.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ describe('options', () => {
196196
describe('parseFileOption', () => {
197197
it('parses file', () => {
198198
expect(
199-
parseFileOption(join(__dirname, 'fixtures', 'synthetics.config.ts'))
199+
parseFileOption('test')(
200+
join(__dirname, 'fixtures', 'synthetics.config.ts')
201+
)
200202
).toBeInstanceOf(Buffer);
201203
});
202204
it('parses string', () => {
203-
expect(parseFileOption('test')).toEqual('test');
205+
expect(parseFileOption('test')('test')).toEqual('test');
204206
});
205207
});
206208

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ program
305305
.option(
306306
'--proxy-ca <path>',
307307
'provide a CA override for proxy endpoint, as a path to be loaded or as string',
308-
collectOpts('ca', proxySettings, parseFileOption)
308+
collectOpts('ca', proxySettings, parseFileOption('--proxy-ca'))
309309
)
310310
.option(
311311
'--proxy-cert <path>',
312312
'provide a cert override for proxy endpoint, as a path to be loaded or as string',
313-
collectOpts('cert', proxySettings, parseFileOption)
313+
collectOpts('cert', proxySettings, parseFileOption('--proxy-cert'))
314314
)
315315
.option(
316316
'--proxy-no-verify',

src/options.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { createOption } from 'commander';
2828
import { readConfig } from './config';
2929
import type { CliArgs, RunOptions } from './common_types';
3030
import { isFile, THROTTLING_WARNING_MSG, warn } from './helpers';
31-
import path from 'path';
3231
import { readFileSync } from 'fs';
3332

3433
type Mode = 'run' | 'push';
@@ -305,18 +304,18 @@ function parseAsBuffer(value: any): Buffer {
305304
}
306305
}
307306

308-
export function parseFileOption(value: string) {
309-
const filePath = path.resolve(value);
310-
311-
if (!isFile(filePath)) {
312-
return value;
313-
}
307+
export function parseFileOption(opt: string) {
308+
return (value: string) => {
309+
if (!isFile(value)) {
310+
return value;
311+
}
314312

315-
try {
316-
return readFileSync(filePath);
317-
} catch (e) {
318-
throw new Error(`could not be read provided path ${filePath}: ${e}`);
319-
}
313+
try {
314+
return readFileSync(value);
315+
} catch (e) {
316+
throw new Error(`${opt} - could not read provided path ${value}: ${e}`);
317+
}
318+
};
320319
}
321320

322321
// This is a generic util to collect multiple options into a single

0 commit comments

Comments
 (0)