Skip to content

Commit

Permalink
Moved getOptions to utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
fantonangeli committed Nov 13, 2021
1 parent dc15c1a commit c2978bf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
14 changes: 1 addition & 13 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ export const parseJsonOrDie = <T>(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(' ');
}
15 changes: 1 addition & 14 deletions test/common.test.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -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\"]'");
})
});
});
16 changes: 16 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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\"]'");
})
});
});

0 comments on commit c2978bf

Please sign in to comment.