|
| 1 | +import internalMismatch from "../EXTERNAL_MISMATCH"; |
| 2 | +import { getWS, getFakeWS } from "../../test-helpers"; |
| 3 | + |
| 4 | +let rootWorkspace = getFakeWS("root"); |
| 5 | + |
| 6 | +it("should error if the ranges are valid and they are not equal", () => { |
| 7 | + let ws = getWS(); |
| 8 | + |
| 9 | + ws.get("pkg-1")!.packageJson.dependencies = { something: "1.0.0" }; |
| 10 | + |
| 11 | + let pkg2 = getFakeWS("pkg-2"); |
| 12 | + pkg2.packageJson.dependencies = { |
| 13 | + something: "2.0.0" |
| 14 | + }; |
| 15 | + ws.set("pkg-2", pkg2); |
| 16 | + |
| 17 | + let errors = internalMismatch.validate(pkg2, ws, rootWorkspace, {}); |
| 18 | + expect(errors.length).toEqual(0); |
| 19 | + |
| 20 | + errors = internalMismatch.validate(ws.get("pkg-1")!, ws, rootWorkspace, {}); |
| 21 | + expect(errors.length).toEqual(1); |
| 22 | + expect(errors).toMatchInlineSnapshot(` |
| 23 | + Array [ |
| 24 | + Object { |
| 25 | + "dependencyName": "something", |
| 26 | + "dependencyRange": "1.0.0", |
| 27 | + "highestDependencyRange": "2.0.0", |
| 28 | + "type": "EXTERNAL_MISMATCH", |
| 29 | + "workspace": Object { |
| 30 | + "dir": "some/fake/dir/pkg-1", |
| 31 | + "packageJson": Object { |
| 32 | + "dependencies": Object { |
| 33 | + "something": "1.0.0", |
| 34 | + }, |
| 35 | + "name": "pkg-1", |
| 36 | + "version": "1.0.0", |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + ] |
| 41 | + `); |
| 42 | +}); |
| 43 | + |
| 44 | +it("should not error if the value is not a valid semver range", () => { |
| 45 | + let ws = getWS(); |
| 46 | + |
| 47 | + ws.get("pkg-1")!.packageJson.dependencies = { something: "1.0.0" }; |
| 48 | + |
| 49 | + let pkg2 = getFakeWS("pkg-2"); |
| 50 | + pkg2.packageJson.dependencies = { |
| 51 | + something: "git:x" |
| 52 | + }; |
| 53 | + ws.set("pkg-2", pkg2); |
| 54 | + |
| 55 | + let errors = internalMismatch.validate(pkg2, ws, rootWorkspace, {}); |
| 56 | + expect(errors.length).toEqual(0); |
| 57 | + |
| 58 | + errors = internalMismatch.validate(ws.get("pkg-1")!, ws, rootWorkspace, {}); |
| 59 | + expect(errors.length).toEqual(0); |
| 60 | +}); |
0 commit comments