|
| 1 | +import { getWS, getFakeWS, getRootWS } from "../../test-helpers"; |
| 2 | +import makeCheck from "../WORKSPACE_REQUIRED"; |
| 3 | +let rootWorkspace = getRootWS(); |
| 4 | + |
| 5 | +test("should not error if not using workspaceProtocol: require", () => { |
| 6 | + let ws = getWS(); |
| 7 | + let dependsOnOne = getFakeWS("depends-on-one"); |
| 8 | + dependsOnOne.packageJson.dependencies = { |
| 9 | + "pkg-1": "^1.0.0", |
| 10 | + }; |
| 11 | + ws.set("depends-on-one", dependsOnOne); |
| 12 | + let errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, {}); |
| 13 | + expect(errors.length).toEqual(0); |
| 14 | +}); |
| 15 | + |
| 16 | +test("should error if using workspaceProtocol: require", () => { |
| 17 | + let ws = getWS(); |
| 18 | + let dependsOnOne = getFakeWS("depends-on-one"); |
| 19 | + dependsOnOne.packageJson.dependencies = { |
| 20 | + "pkg-1": "^1.0.0", |
| 21 | + }; |
| 22 | + ws.set("depends-on-one", dependsOnOne); |
| 23 | + let errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, { |
| 24 | + workspaceProtocol: "require", |
| 25 | + }); |
| 26 | + expect(errors).toEqual([ |
| 27 | + { |
| 28 | + type: "WORKSPACE_REQUIRED", |
| 29 | + workspace: dependsOnOne, |
| 30 | + depName: "pkg-1", |
| 31 | + depType: "dependencies", |
| 32 | + }, |
| 33 | + ]); |
| 34 | +}); |
| 35 | + |
| 36 | +test("should fix if using workspaceProtocol: require", () => { |
| 37 | + let ws = getWS(); |
| 38 | + let dependsOnOne = getFakeWS("depends-on-one"); |
| 39 | + dependsOnOne.packageJson.dependencies = { |
| 40 | + "pkg-1": "^1.0.0", |
| 41 | + }; |
| 42 | + ws.set("depends-on-one", dependsOnOne); |
| 43 | + const errors = makeCheck.validate(dependsOnOne, ws, rootWorkspace, { |
| 44 | + workspaceProtocol: "require", |
| 45 | + }); |
| 46 | + expect(errors).toHaveLength(1); |
| 47 | + const result = makeCheck.fix(errors[0], { |
| 48 | + workspaceProtocol: "require", |
| 49 | + }); |
| 50 | + expect(dependsOnOne.packageJson.dependencies).toEqual({ |
| 51 | + "pkg-1": "workspace:^", |
| 52 | + }); |
| 53 | + expect(result).toEqual({ requiresInstall: true }); |
| 54 | +}); |
0 commit comments