Commit 90985293 authored by David Sveningsson's avatar David Sveningsson

fix(cli): fix `--init` not creating configuration unless overwriting

parent 2374a6b0
Pipeline #94806909 passed with stages
in 8 minutes and 54 seconds
......@@ -54,6 +54,21 @@ it("should not overwrite configuration unless requested", async () => {
expect(fs.writeFile).not.toHaveBeenCalled();
});
it("should always create configuration when config is missing", async () => {
expect.assertions(1);
fs.existsSync.mockReturnValue(false);
inquirer.prompt.mockResolvedValue({
write: undefined,
frameworks: [],
});
await cli.init(".");
expect(fs.writeFile).toHaveBeenCalledWith(
"./.htmlvalidate.json",
expect.anything(),
expect.anything()
);
});
it("should propagate errors from fs.writeFile", async () => {
expect.assertions(1);
fs.existsSync.mockReturnValue(false);
......
......@@ -80,7 +80,9 @@ export async function init(cwd: string): Promise<InitResult> {
/* prompt user for questions */
const answers = await inquirer.prompt(questions);
if (!answers.write) {
/* dont overwrite configuration unless explicitly requested */
if (exists && !answers.write) {
return Promise.reject();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment