From 2a9f829b0eef4519166773406ca691682713498c Mon Sep 17 00:00:00 2001 From: Hemal Patel Date: Tue, 6 Nov 2018 16:16:05 +0530 Subject: [PATCH] tests(webpack-scaffold): moved to typescript --- ...{index.test.js.snap => index.test.ts.snap} | 0 .../{index.test.js => index.test.ts} | 36 +++++++++---------- packages/webpack-scaffold/index.ts | 8 ++--- 3 files changed, 22 insertions(+), 22 deletions(-) rename packages/webpack-scaffold/__tests__/__snapshots__/{index.test.js.snap => index.test.ts.snap} (100%) rename packages/webpack-scaffold/__tests__/{index.test.js => index.test.ts} (88%) diff --git a/packages/webpack-scaffold/__tests__/__snapshots__/index.test.js.snap b/packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap similarity index 100% rename from packages/webpack-scaffold/__tests__/__snapshots__/index.test.js.snap rename to packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap diff --git a/packages/webpack-scaffold/__tests__/index.test.js b/packages/webpack-scaffold/__tests__/index.test.ts similarity index 88% rename from packages/webpack-scaffold/__tests__/index.test.js rename to packages/webpack-scaffold/__tests__/index.test.ts index 3c3e2981449..5e955bc7f96 100755 --- a/packages/webpack-scaffold/__tests__/index.test.js +++ b/packages/webpack-scaffold/__tests__/index.test.ts @@ -1,5 +1,5 @@ "use strict"; -const utils = require("../index"); +import * as utils from "../index"; describe("utils", () => { describe("createArrowFunction", () => { @@ -18,7 +18,7 @@ describe("utils", () => { }); it("should stringify an array", () => { expect( - utils.createDynamicPromise(["app.js", "index.js"]) + utils.createDynamicPromise(["app.js", "index.js"]), ).toMatchSnapshot(); }); }); @@ -48,49 +48,49 @@ describe("utils", () => { describe("Inquirer", () => { it("should make an List object", () => { expect(utils.List("entry", "does it work?", ["Yes", "Maybe"])).toEqual({ - type: "list", - name: "entry", + choices: ["Yes", "Maybe"], message: "does it work?", - choices: ["Yes", "Maybe"] + name: "entry", + type: "list", }); }); it("should make an RawList object", () => { expect( - utils.RawList("output", "does it work?", ["Yes", "Maybe"]) + utils.RawList("output", "does it work?", ["Yes", "Maybe"]), ).toEqual({ - type: "rawlist", - name: "output", + choices: ["Yes", "Maybe"], message: "does it work?", - choices: ["Yes", "Maybe"] + name: "output", + type: "rawlist", }); }); it("should make an CheckList object", () => { expect( - utils.CheckList("context", "does it work?", ["Yes", "Maybe"]) + utils.CheckList("context", "does it work?", ["Yes", "Maybe"]), ).toEqual({ - type: "checkbox", - name: "context", + choices: ["Yes", "Maybe"], message: "does it work?", - choices: ["Yes", "Maybe"] + name: "context", + type: "checkbox", }); }); it("should make an Input object", () => { expect(utils.Input("plugins", "what is your plugin?")).toEqual({ - type: "input", + message: "what is your plugin?", name: "plugins", - message: "what is your plugin?" + type: "input", }); }); it("should make an Confirm object", () => { expect(utils.Confirm("context", "what is your context?")).toEqual({ - type: "confirm", + message: "what is your context?", name: "context", - message: "what is your context?" + type: "confirm", }); }); it("should make an Input object with validation", () => { expect( - utils.InputValidate("plugins", "what is your plugin?", () => {}) + utils.InputValidate("plugins", "what is your plugin?", () => true), ).toMatchSnapshot(); }); }); diff --git a/packages/webpack-scaffold/index.ts b/packages/webpack-scaffold/index.ts index 01cf53a3558..fc9e3211897 100755 --- a/packages/webpack-scaffold/index.ts +++ b/packages/webpack-scaffold/index.ts @@ -20,19 +20,19 @@ export interface IInquirerInput extends IInquirerScaffoldObject { validate?: (input: string) => string | boolean; } -export function createArrowFunction(value: Function): string { +export function createArrowFunction(value: string): string { return `() => '${value}'`; } -export function createRegularFunction(value: Function): string { +export function createRegularFunction(value: string): string { return `function () {\n return '${value}'\n}`; } -export function createDynamicPromise(arrOrString: Function[] | string): string { +export function createDynamicPromise(arrOrString: string[] | string): string { if (Array.isArray(arrOrString)) { return ( "() => new Promise((resolve) => resolve([" + - arrOrString.map((func: Function) => { + arrOrString.map((func: string) => { return "'" + func + "'"; }) + "]))"