|
1 | | -import { NpmInfo } from "@definitelytyped/utils"; |
| 1 | +import * as util from "util"; |
2 | 2 | import { createTypingsVersionRaw, testo } from "./utils"; |
3 | 3 | import { GitDiff, getNotNeededPackages, checkNotNeededPackage } from "../src/git"; |
4 | 4 | import { NotNeededPackage, TypesDataFile, AllPackages } from "../src/packages"; |
@@ -65,94 +65,55 @@ testo({ |
65 | 65 | // TODO: Test with dependents, etc etc |
66 | 66 | }); |
67 | 67 |
|
68 | | -const empty: NpmInfo = { |
69 | | - homepage: "", |
70 | | - distTags: new Map(), |
71 | | - versions: new Map(), |
72 | | - time: new Map(), |
73 | | -}; |
| 68 | +jest.mock("pacote", () => ({ |
| 69 | + async manifest(spec: string) { |
| 70 | + switch (spec) { |
| 71 | + case "[email protected]": // Older than the @types/jest package. |
| 72 | + case "[email protected]": // The same version as the @types/jest package. |
| 73 | + case "[email protected]": // Newer than the @types/jest package. |
| 74 | + // These versions exist (don't throw). |
| 75 | + return; |
| 76 | + case "[email protected]": // A nonexistent version of the target JS package. |
| 77 | + // eslint-disable-next-line no-throw-literal |
| 78 | + throw { code: "ETARGET" }; |
| 79 | + case "@types/jest": // The @types/jest package. |
| 80 | + return { version: "50.0.0" }; |
| 81 | + case "[email protected]": // A nonexistent target JS package. |
| 82 | + case "@types/nonexistent": // A nonexistent @types package. |
| 83 | + // eslint-disable-next-line no-throw-literal |
| 84 | + throw { code: "E404" }; |
| 85 | + } |
| 86 | + throw new Error(`Unexpected npm registry fetch: ${util.inspect(spec)}`); |
| 87 | + }, |
| 88 | +})); |
| 89 | + |
74 | 90 | testo({ |
75 | 91 | missingSource() { |
76 | | - expect(() => checkNotNeededPackage(jestNotNeeded[0], undefined, empty)).toThrow( |
| 92 | + return expect(checkNotNeededPackage(new NotNeededPackage("jest", "nonexistent", "100.0.0"))).rejects.toThrow( |
77 | 93 | "The entry for @types/jest in notNeededPackages.json" |
78 | 94 | ); |
79 | 95 | }, |
80 | 96 | missingTypings() { |
81 | | - expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, undefined)).toThrow( |
82 | | - "@types package not found for @types/jest" |
83 | | - ); |
84 | | - }, |
85 | | - missingTypingsLatest() { |
86 | | - expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, empty)).toThrow( |
87 | | - '@types/jest is missing the "latest" tag' |
| 97 | + return expect(checkNotNeededPackage(new NotNeededPackage("nonexistent", "jest", "100.0.0"))).rejects.toThrow( |
| 98 | + "@types package not found for @types/nonexistent" |
88 | 99 | ); |
89 | 100 | }, |
90 | 101 | deprecatedSameVersion() { |
91 | | - expect(() => { |
92 | | - checkNotNeededPackage(jestNotNeeded[0], empty, { |
93 | | - homepage: "jest.com", |
94 | | - distTags: new Map([["latest", "100.0.0"]]), |
95 | | - versions: new Map(), |
96 | | - time: new Map([["modified", ""]]), |
97 | | - }); |
98 | | - }).toThrow(`The specified version 100.0.0 of jest must be newer than the version |
99 | | -it is supposed to replace, 100.0.0 of @types/jest.`); |
| 102 | + return expect(checkNotNeededPackage(new NotNeededPackage("jest", "jest", "50.0.0"))).rejects |
| 103 | + .toThrow(`The specified version 50.0.0 of jest must be newer than the version |
| 104 | +it is supposed to replace, 50.0.0 of @types/jest.`); |
100 | 105 | }, |
101 | 106 | deprecatedOlderVersion() { |
102 | | - expect(() => { |
103 | | - checkNotNeededPackage(jestNotNeeded[0], empty, { |
104 | | - homepage: "jest.com", |
105 | | - distTags: new Map([["latest", "999.0.0"]]), |
106 | | - versions: new Map(), |
107 | | - time: new Map([["modified", ""]]), |
108 | | - }); |
109 | | - }).toThrow(`The specified version 100.0.0 of jest must be newer than the version |
110 | | -it is supposed to replace, 999.0.0 of @types/jest.`); |
| 107 | + return expect(checkNotNeededPackage(new NotNeededPackage("jest", "jest", "4.0.0"))).rejects |
| 108 | + .toThrow(`The specified version 4.0.0 of jest must be newer than the version |
| 109 | +it is supposed to replace, 50.0.0 of @types/jest.`); |
111 | 110 | }, |
112 | 111 | missingNpmVersion() { |
113 | | - expect(() => { |
114 | | - checkNotNeededPackage(jestNotNeeded[0], empty, { |
115 | | - homepage: "jest.com", |
116 | | - distTags: new Map([["latest", "4.0.0"]]), |
117 | | - versions: new Map(), |
118 | | - time: new Map([["modified", ""]]), |
119 | | - }); |
120 | | - }).toThrow("The specified version 100.0.0 of jest is not on npm."); |
121 | | - }, |
122 | | - olderNpmVersion() { |
123 | | - expect(() => |
124 | | - checkNotNeededPackage( |
125 | | - jestNotNeeded[0], |
126 | | - { |
127 | | - homepage: "jest.com", |
128 | | - distTags: new Map(), |
129 | | - versions: new Map([["50.0.0", {}]]), |
130 | | - time: new Map([["modified", ""]]), |
131 | | - }, |
132 | | - { |
133 | | - homepage: "jest.com", |
134 | | - distTags: new Map([["latest", "4.0.0"]]), |
135 | | - versions: new Map(), |
136 | | - time: new Map([["modified", ""]]), |
137 | | - } |
138 | | - ) |
139 | | - ).toThrow("The specified version 100.0.0 of jest is not on npm."); |
| 112 | + return expect(checkNotNeededPackage(new NotNeededPackage("jest", "jest", "999.0.0"))).rejects.toThrow( |
| 113 | + "The specified version 999.0.0 of jest is not on npm." |
| 114 | + ); |
140 | 115 | }, |
141 | 116 | ok() { |
142 | | - checkNotNeededPackage( |
143 | | - jestNotNeeded[0], |
144 | | - { |
145 | | - homepage: "jest.com", |
146 | | - distTags: new Map(), |
147 | | - versions: new Map([["100.0.0", {}]]), |
148 | | - time: new Map([["modified", ""]]), |
149 | | - }, |
150 | | - { |
151 | | - homepage: "jest.com", |
152 | | - distTags: new Map([["latest", "4.0.0"]]), |
153 | | - versions: new Map(), |
154 | | - time: new Map([["modified", ""]]), |
155 | | - } |
156 | | - ); |
| 117 | + return checkNotNeededPackage(new NotNeededPackage("jest", "jest", "100.0.0")); |
157 | 118 | }, |
158 | 119 | }); |
0 commit comments