Skip to content

Commit

Permalink
test: Add test for showVersion() (#28)
Browse files Browse the repository at this point in the history
* test: Rename index.test.ts to main.test.ts
* test: Add test for showVersion()
  • Loading branch information
peaceiris authored Jan 3, 2020
1 parent 03cf133 commit 8bd8aaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 17 additions & 0 deletions __tests__/index.test.ts → __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,20 @@ describe('run()', () => {
expect(result.output).toMatch(/mdbook v/);
});
});

describe('showVersion()', () => {
let result: main.actionResult = {
exitcode: 0,
output: '',
error: ''
};

test('Success case', async () => {
result = await main.showVersion('git', ['--version']);
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(/git version/);
});

// test('Failure case', async () => {
// });
});
17 changes: 13 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import getLatestVersion from './get-latest-version';
import installer from './installer';

export interface actionResult {
exitcode: number;
output: string;
error: string;
}

async function showVersion(cmd: string, args: string[]): Promise<actionResult> {
export async function showVersion(
cmd: string,
args: string[]
): Promise<actionResult> {
let result: actionResult = {
exitcode: 0,
output: '',
error: ''
};
Expand All @@ -25,7 +30,10 @@ async function showVersion(cmd: string, args: string[]): Promise<actionResult> {
}
};

await exec.exec(cmd, args, options);
result.exitcode = await exec.exec(cmd, args, options);
core.debug(`exit code: ${result.exitcode}`);
core.debug(`stdout: ${result.output}`);
core.debug(`stderr: ${result.error}`);
return result;
}

Expand All @@ -35,6 +43,7 @@ export async function run(): Promise<any> {
const mdbookVersion: string = core.getInput('mdbook-version');

let result: actionResult = {
exitcode: 0,
output: '',
error: ''
};
Expand All @@ -47,13 +56,13 @@ export async function run(): Promise<any> {
);
console.log(`mdbook version: ${latestVersion} (${mdbookVersion})`);
await installer(latestVersion);
result = await showVersion('mdbook', ['--version']);
} else {
console.log(`mdbook version: ${mdbookVersion}`);
await installer(mdbookVersion);
result = await showVersion('mdbook', ['--version']);
}

result = await showVersion('mdbook', ['--version']);

return result;
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 8bd8aaa

Please sign in to comment.