Skip to content

Commit d154d0e

Browse files
committedJun 7, 2019
tests: fix failing ones
1 parent 7608d4b commit d154d0e

File tree

2 files changed

+32
-51
lines changed

2 files changed

+32
-51
lines changed
 

‎packages/utils/__tests__/package-manager.test.ts

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
import * as path from "path";
43
import * as packageManager from "../package-manager";
54

65
jest.mock("cross-spawn");
@@ -54,20 +53,16 @@ describe("package-manager", () => {
5453

5554
jest.spyOn(spawn, "sync").mockReturnValue(defaultSyncResult);
5655

57-
it("should return 'yarn' from getPackageManager if it's installed", () => {
58-
expect(packageManager.getPackageManager()).toEqual("yarn");
59-
});
60-
61-
it("should return 'npm' from getPackageManager if yarn is not installed", () => {
56+
it("should return 'npm' from getPackageManager", () => {
6257
mockSpawnErrorOnce();
6358
expect(packageManager.getPackageManager()).toEqual("npm");
6459
});
6560

66-
it("should spawn yarn add from spawnChild", () => {
61+
it("should spawn npm from spawnChild", () => {
6762
const packageName = "some-pkg";
6863

6964
packageManager.spawnChild(packageName);
70-
expect(spawn.sync).toHaveBeenLastCalledWith("yarn", ["global", "add", packageName], { stdio: "inherit" });
65+
expect(spawn.sync).toHaveBeenLastCalledWith("npm", ["install", "-g", packageName], { stdio: "inherit" });
7166
});
7267

7368
it("should spawn yarn upgrade from spawnChild", () => {
@@ -96,21 +91,6 @@ describe("package-manager", () => {
9691
expect(spawn.sync).toHaveBeenLastCalledWith("npm", ["update", "-g", packageName], { stdio: "inherit" });
9792
});
9893

99-
it("should return the yarn global dir from getPathToGlobalPackages if yarn is installed", () => {
100-
const yarnDir = "/Users/test/.config/yarn/global";
101-
// Mock confirmation that yarn is installed
102-
spawn.sync.mockReturnValueOnce(defaultSyncResult);
103-
// Mock stdout of `yarn global dir`
104-
spawn.sync.mockReturnValueOnce({
105-
stdout: {
106-
toString: () => `${yarnDir}\n`
107-
}
108-
});
109-
const globalPath = packageManager.getPathToGlobalPackages();
110-
const expected = path.join(yarnDir, "node_modules");
111-
expect(globalPath).toBe(expected);
112-
});
113-
11494
it("should return the npm global dir from getPathToGlobalPackages if yarn is not installed", () => {
11595
mockSpawnErrorOnce();
11696
const globalPath = packageManager.getPathToGlobalPackages();

‎packages/webpack-scaffold/__tests__/index.test.ts

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"use strict";
22
import * as utils from "../index";
33

4-
describe.skip("utils", () => {
4+
describe("utils", () => {
5+
beforeEach(() => {
6+
this.mockSelf = {
7+
prompt: arg => {
8+
return arg[0];
9+
}
10+
};
11+
});
512
describe("createArrowFunction", () => {
613
it("should stringify an arrow function", () => {
714
expect(utils.createArrowFunction("app.js")).toMatchSnapshot();
@@ -44,12 +51,9 @@ describe.skip("utils", () => {
4451
});
4552
});
4653
describe("Inquirer", () => {
47-
it("should make a List object", () => {
48-
expect(utils.List("entry", "does it work?", ["Yes", "Maybe"])).toEqual({
49-
choices: ["Yes", "Maybe"],
50-
message: "does it work?",
51-
name: "entry",
52-
type: "list"
54+
it("should make default value for a List", () => {
55+
expect(utils.List(this.mockSelf, "entry", "does it work?", ["Yes", "Maybe"], "Yes", true)).toEqual({
56+
entry: "Yes"
5357
});
5458
});
5559
it("should make a RawList object", () => {
@@ -68,42 +72,39 @@ describe.skip("utils", () => {
6872
type: "checkbox"
6973
});
7074
});
71-
it("should make an Input object", () => {
72-
expect(utils.Input("plugins", "what is your plugin?")).toEqual({
73-
message: "what is your plugin?",
75+
it("should emulate a prompt for list input", () => {
76+
expect(utils.Input(this.mockSelf, "plugins", "what is your plugin?", "openJSF", false)).toEqual({
77+
type: "input",
7478
name: "plugins",
75-
type: "input"
79+
message: "what is your plugin?",
80+
default: "openJSF"
7681
});
7782
});
78-
it("should make an Input object", () => {
79-
expect(utils.Input("plugins", "what is your plugin?", "my-plugin")).toEqual({
80-
default: "my-plugin",
81-
message: "what is your plugin?",
82-
name: "plugins",
83-
type: "input"
83+
it("should return a default Input object value", () => {
84+
expect(utils.Input(this.mockSelf, "plugins", "what is your plugin?", "my-plugin", true)).toEqual({
85+
plugins: "my-plugin"
8486
});
8587
});
86-
it("should make a Confirm object", () => {
87-
expect(utils.Confirm("context", "what is your context?")).toEqual({
88+
it("should emulate a prompt for confirm", () => {
89+
expect(utils.Confirm(this.mockSelf, "context", "what is your context?", true, false)).toEqual({
90+
name: "context",
8891
default: true,
8992
message: "what is your context?",
90-
name: "context",
9193
type: "confirm"
9294
});
9395
});
94-
it("should make a Confirm object with No as default", () => {
95-
expect(utils.Confirm("context", "what is your context?", false)).toEqual({
96-
default: false,
97-
message: "what is your context?",
98-
name: "context",
99-
type: "confirm"
96+
it("should make a Confirm object with yes as default", () => {
97+
expect(utils.Confirm(this.mockSelf, "context", "what is your context?", true, true)).toEqual({
98+
context: true
10099
});
101100
});
102101
it("should make an Input object with validation", () => {
103-
expect(utils.InputValidate("plugins", "what is your plugin?", () => true)).toMatchSnapshot();
102+
expect(utils.InputValidate(this.mockSelf, "plugins", "what is your plugin?", () => true)).toMatchSnapshot();
104103
});
105104
it("should make an Input object with validation and default value", () => {
106-
expect(utils.InputValidate("plugins", "what is your plugin?", () => true, "my-plugin")).toMatchSnapshot();
105+
expect(
106+
utils.InputValidate(this.mockSelf, "plugins", "what is your plugin?", () => true, "my-plugin")
107+
).toMatchSnapshot();
107108
});
108109
});
109110
});

0 commit comments

Comments
 (0)
Please sign in to comment.