Skip to content

Commit

Permalink
Merge pull request #25 from tuanthanh2067/add-e2e-test
Browse files Browse the repository at this point in the history
Added e2e test
  • Loading branch information
hlavu authored Nov 18, 2021
2 parents 5039371 + 796301e commit e3d3064
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/__snapshots__/e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`end-to-end integration prints help message when --help option is passed 1`] = `
"Usage: index.js --input <filename> [-s <css-link>] [-l <lang-code>]
Options:
-i, --input .txt or .md file name [array]
-c, --config configuration file [array] [default: \\"\\"]
-a, --assets path to assets folder [array] [default: \\"\\"]
-s, --stylesheet css link [string]
-l, --lang language used in HTML [string]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]"
`;
exports[`end-to-end integration prints version when --version option is passed 1`] = `"ssg-cli 1.0.0"`;
19 changes: 19 additions & 0 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const run = require("./run");

describe("end-to-end integration", () => {
test("prints help message when --help option is passed", async () => {
const { stderr, stdout, exitCode } = await run("--help");

expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
expect(stderr).toEqual("");
});

test("prints version when --version option is passed", async () => {
const { stderr, stdout, exitCode } = await run("--version");

expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
expect(stderr).toEqual("");
});
});
12 changes: 12 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const execa = require("execa");

async function run(...args) {
try {
const results = await execa.node("./bin/index.js", args);
return results;
} catch (err) {
return err;
}
}

module.exports = run;

0 comments on commit e3d3064

Please sign in to comment.