Skip to content

Commit

Permalink
feat: lang arg + test
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Jun 11, 2020
1 parent ba6dd51 commit b52b92c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
22 changes: 12 additions & 10 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const onLoad = async (targetDir, version, argv) => {
const questions = [
{
type: "autocomplete",
name: "lang",
name: "langChoice",
message: "Select language",
choices: langListOut,
suggest: async (input, choices) => {
Expand All @@ -86,15 +86,17 @@ const onLoad = async (targetDir, version, argv) => {
},
},
];

let { lang } = await prompts(questions);
if (lang === "custom") {
let { customLang } = await prompts({
type: "text",
name: "customLang",
message: "Enter custom language code",
});
lang = customLang;
let lang = argv.lang || null;
if (!lang) {
let { langChoice } = await prompts(questions);
if (langChoice === "custom") {
let { customLang } = await prompts({
type: "text",
name: "customLang",
message: "Enter custom language code",
});
langChoice = customLang;
}
}
try {
const indexFile = targetDir + "/index.html";
Expand Down
22 changes: 21 additions & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ const cases = [
const versionFolder = (version = null) =>
version ? `./out/${version}` : defaultDir;

const runCli = async ({ version = null, dir = null, skip = false }) => {
const runCli = async ({
version = null,
dir = null,
skip = false,
lang = null,
}) => {
let argvs = [];
let prevCwd;
if (dir) {
Expand All @@ -51,6 +56,9 @@ const runCli = async ({ version = null, dir = null, skip = false }) => {
if (skip) {
argvs.push("-y");
}
if (lang) {
argvs.push("--lang=" + lang);
}

await cli(argvs);
if (prevCwd) {
Expand Down Expand Up @@ -158,3 +166,15 @@ describe("Unexpected errors", () => {
}
});
});

describe("lang", () => {
test("lang", async () => {
await runCli({
lang: "en-US",
dir: "./out/lang_en-US",
});
const fileContent = await fs.readFile("./out/lang_en-US/index.html");
expect(fileContent.indexOf(`lang="en-US"`) > -1).toBe(true);
// await fs.remove(versionFolder(version));
});
});

0 comments on commit b52b92c

Please sign in to comment.