From c2978bfde166ba68bf1af8192502541858ef8b28 Mon Sep 17 00:00:00 2001 From: Fabrizio Antonangeli Date: Sat, 13 Nov 2021 18:27:11 +0100 Subject: [PATCH] Moved getOptions to utils.ts --- src/common.ts | 14 +------------- src/utils.ts | 13 +++++++++++++ test/common.test.ts | 15 +-------------- test/utils.test.ts | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 test/utils.test.ts diff --git a/src/common.ts b/src/common.ts index cd0b62b..9de0f34 100644 --- a/src/common.ts +++ b/src/common.ts @@ -4,6 +4,7 @@ import * as child_process from 'child_process'; const exec = util.promisify(child_process.exec); import { Config } from './config'; import {OptionValues} from 'commander'; +import {getOptions} from './utils'; /** @@ -44,19 +45,6 @@ export function readMultiClaspConfig(): SingleClasp[] { return JSON.parse(fs.readFileSync(Config.MULTICLASP_FILENAME, Config.UTF_8 as BufferEncoding).toString()); } -/** - * Get the Options for the clasp command. - * - * @param args array of arguments - * @returns the string with the options, "" otherwise - */ -export function getOptions (args:string[]=process.argv):string { - if (!args) { - return ""; - } - return args.slice(3).join(' '); -} - /** * commander action to run clasp. * diff --git a/src/utils.ts b/src/utils.ts index 2cef108..57906ae 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,3 +9,16 @@ export const parseJsonOrDie = (value: string): T => { throw "Invalid json"; } }; + +/** + * Get the Options for the clasp command. + * + * @param args array of arguments + * @returns the string with the options, "" otherwise + */ +export function getOptions (args:string[]=process.argv):string { + if (!args) { + return ""; + } + return args.slice(3).join(' '); +} diff --git a/test/common.test.ts b/test/common.test.ts index e562b9a..8bffd07 100644 --- a/test/common.test.ts +++ b/test/common.test.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import { getOptions, runClasp } from '../src/common'; +import { runClasp } from '../src/common'; jest.mock('util', () => ({ promisify: jest.fn(() => { @@ -24,17 +24,4 @@ describe('common.js tests', () => { expect(fs.writeFile).toHaveBeenCalledTimes(1); }); }); - - describe('getOptions', () => { - test('wrong inputs', () => { - expect(getOptions([])).toBe(""); - expect(getOptions(undefined)).toBe(""); - }) - test('good inputs', () => { - expect(getOptions(["node", "multi-clasp", "push"])).toBe(""); - expect(getOptions(["node", "multi-clasp", "push", "-f"])).toBe("-f"); - expect(getOptions(["node", "multi-clasp", "push", "-f", "-g", "what"])).toBe("-f -g what"); - expect(getOptions(["node", "multi-clasp", "run", "-p", '\'["what"]\''])).toBe("-p '[\"what\"]'"); - }) - }); }); diff --git a/test/utils.test.ts b/test/utils.test.ts new file mode 100644 index 0000000..7ac8f01 --- /dev/null +++ b/test/utils.test.ts @@ -0,0 +1,16 @@ +import {getOptions} from "../src/utils"; + +describe('utils.js tests', () => { + describe('getOptions', () => { + test('wrong inputs', () => { + expect(getOptions([])).toBe(""); + expect(getOptions(undefined)).toBe(""); + }) + test('good inputs', () => { + expect(getOptions(["node", "multi-clasp", "push"])).toBe(""); + expect(getOptions(["node", "multi-clasp", "push", "-f"])).toBe("-f"); + expect(getOptions(["node", "multi-clasp", "push", "-f", "-g", "what"])).toBe("-f -g what"); + expect(getOptions(["node", "multi-clasp", "run", "-p", '\'["what"]\''])).toBe("-p '[\"what\"]'"); + }) + }); +});