Skip to content

Commit

Permalink
fix: solve pretty complains running npm run format cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Granado committed Nov 8, 2019
1 parent f8c5cf2 commit d915fa3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/test-cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ test("handles debug flag", () => {
});

describe("Handle json flag", () => {
test('option --json', () => {
test("option --json", () => {
const inputArgs = [".", "--json"];

const parsedArgs: IArgs = parseInputParameters(inputArgs);

expect(parsedArgs.json).toBeTruthy();
});

test('option -j', () => {
test("option -j", () => {
const inputArgs = [".", "-j"];

const parsedArgs: IArgs = parseInputParameters(inputArgs);
Expand Down
66 changes: 33 additions & 33 deletions src/__tests__/test-main-runCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ test("validate stderr captured", async () => {
expect(res.stderr.trim()).toBe("error");
});

describe('Assemble Snyk command', () => {
describe("Assemble Snyk command", () => {
test("Command without options", () => {
const imageName = 'someImage';
const imageName = "someImage";
const optionsList = {};

const cmd = mainModule.assembleSnykCommand(imageName, optionsList);
Expand All @@ -71,7 +71,7 @@ describe('Assemble Snyk command', () => {
});

test("Command with json option", () => {
const imageName = 'someImage';
const imageName = "someImage";
const optionsList = { json: true };

const cmd = mainModule.assembleSnykCommand(imageName, optionsList);
Expand All @@ -80,8 +80,8 @@ describe('Assemble Snyk command', () => {
});
});

describe('Handle results', () => {
test('Handle text result for simple image', () => {
describe("Handle results", () => {
test("Handle text result for simple image", () => {
const optionsList = {};
const commandResult = [
{
Expand All @@ -95,18 +95,18 @@ describe('Handle results', () => {
Introduced through: meta-common-packages@meta
From: meta-common-packages@meta > tar@1.29b-1.1
`
}
}
];
const expectedResult = `Image: ${commandResult[0].image}
${commandResult[0].result}
`
`;

const resultHandled = mainModule.handleResult(commandResult, optionsList)
const resultHandled = mainModule.handleResult(commandResult, optionsList);

expect(resultHandled).toEqual(expectedResult);
});

test('Handle text result for multi image', () => {
test("Handle text result for multi image", () => {
const optionsList = {};
const commandResult = [
{
Expand All @@ -132,21 +132,21 @@ ${commandResult[0].result}
Introduced through: meta-common-packages@meta
From: meta-common-packages@meta > tar@1.29b-1.1
`
}
}
];
const expectedResult = `Image: ${commandResult[0].image}
${commandResult[0].result}
Image: ${commandResult[1].image}
${commandResult[1].result}
`
`;

const resultHandled = mainModule.handleResult(commandResult, optionsList)
const resultHandled = mainModule.handleResult(commandResult, optionsList);

expect(resultHandled).toEqual(expectedResult);
});

test('Handle json result for simple image', () => {
const optionsList = {json: true};
test("Handle json result for simple image", () => {
const optionsList = { json: true };
const commandResult = [
{
image: "MyImage",
Expand All @@ -159,7 +159,7 @@ ${commandResult[1].result}
Introduced through: meta-common-packages@meta
From: meta-common-packages@meta > tar@1.29b-1.1
`
}
}
];
const expectedResult = [
{
Expand All @@ -168,13 +168,13 @@ ${commandResult[1].result}
}
];

const resultHandled = mainModule.handleResult(commandResult, optionsList)
const resultHandled = mainModule.handleResult(commandResult, optionsList);

expect(resultHandled).toEqual(expectedResult);
});

test('Handle json result for multi image', () => {
const optionsList = {json: true};
test("Handle json result for multi image", () => {
const optionsList = { json: true };
const commandResult = [
{
image: "MyImage1",
Expand All @@ -199,7 +199,7 @@ ${commandResult[1].result}
Introduced through: meta-common-packages@meta
From: meta-common-packages@meta > tar@1.29b-1.1
`
}
}
];
const expectedResult = [
{
Expand All @@ -212,17 +212,17 @@ ${commandResult[1].result}
}
];

const resultHandled = mainModule.handleResult(commandResult, optionsList)
const resultHandled = mainModule.handleResult(commandResult, optionsList);

expect(resultHandled).toEqual(expectedResult);
});
});

describe('Handle output', () => {
test('Output without options', () => {
describe("Handle output", () => {
test("Output without options", () => {
const optionsList = {};
const expectedOutput = 'summary';
const log = jest.spyOn(global.console, 'log');
const expectedOutput = "summary";
const log = jest.spyOn(global.console, "log");

mainModule.handleOutput(expectedOutput, optionsList);

Expand All @@ -232,31 +232,31 @@ describe('Handle output', () => {
test('Output with "json" option', () => {
const optionsList = { json: true };
const expectedOutput = {
"result": "test"
result: "test"
};
const log = jest.spyOn(global.console, 'log');
const log = jest.spyOn(global.console, "log");

mainModule.handleOutput(expectedOutput, optionsList);

expect(log).toHaveBeenCalledWith(JSON.stringify(expectedOutput, null, 2));
});

test('Output with "output" option', () => {
const optionsList = { output: '/tmp/file.html'};
const expectedOutput = 'summary';
const writeFile = jest.spyOn(fs, 'writeFileSync');
const optionsList = { output: "/tmp/file.html" };
const expectedOutput = "summary";
const writeFile = jest.spyOn(fs, "writeFileSync");

mainModule.handleOutput(expectedOutput, optionsList);

expect(writeFile).toHaveBeenCalledWith(optionsList.output, expectedOutput);
});

test('Output with "json" and "output" options', () => {
const optionsList = { output: '/tmp/file.json', json: true };
const optionsList = { output: "/tmp/file.json", json: true };
const expectedOutput = {
"result": "test"
result: "test"
};
const writeFile = jest.spyOn(fs, 'writeFileSync');
const writeFile = jest.spyOn(fs, "writeFileSync");

mainModule.handleOutput(expectedOutput, optionsList);

Expand Down
2 changes: 1 addition & 1 deletion src/cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function parseInputParameters(inputArgs): IArgs {

if (argv.json) {
returnObj.json = argv.json;
}
}

if (argv.output) {
returnObj.output = argv.output;
Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function runSnykTestWithDocker(snykToken: string, snykCLIImageName: string

export function assembleSnykCommand(imageName: string, options: any) {
let command = `snyk test --docker ${imageName}`;
if (options.json) command = command + ' --json';
if (options.json) command = command + " --json";
if (options.debug) console.debug(command);
if (options.debug) console.debug(options);

Expand Down Expand Up @@ -203,10 +203,10 @@ export async function mainWithParams(args: IArgs, snykToken: string) {
}

getHelmChartLabelForOutput(args.inputDirectory);
const allOutputData:SnykResult[] = [];
const allOutputData: SnykResult[] = [];
for (const imageName of allImages) {
try {
const response: SnykResult = {image: imageName, result: ""};
const response: SnykResult = { image: imageName, result: "" };
if (doTest) {
await pullImage(imageName);
const rawResult = await runSnykTestWithDocker(snykToken, SNYK_CLI_DOCKER_IMAGE_NAME, imageName, args);
Expand All @@ -227,10 +227,10 @@ export function handleResult(results: SnykResult[], options) {
if (options.json) return results;
let output = "";
for (const result of results) {
output += `Image: ${result.image}\n`
output += `${result.result}\n`
output += `Image: ${result.image}\n`;
output += `${result.result}\n`;
}

return output;
}

Expand Down

0 comments on commit d915fa3

Please sign in to comment.