-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use cached npm metadata * Simply read the npm cache * Use pacote
- Loading branch information
Showing
23 changed files
with
719 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { NpmInfo } from "@definitelytyped/utils"; | ||
import * as util from "util"; | ||
import * as pacote from "pacote"; | ||
import { createTypingsVersionRaw, testo } from "./utils"; | ||
import { GitDiff, getNotNeededPackages, checkNotNeededPackage } from "../src/git"; | ||
import { NotNeededPackage, TypesDataFile, AllPackages } from "../src/packages"; | ||
|
@@ -65,94 +66,62 @@ testo({ | |
// TODO: Test with dependents, etc etc | ||
}); | ||
|
||
const empty: NpmInfo = { | ||
homepage: "", | ||
distTags: new Map(), | ||
versions: new Map(), | ||
time: new Map(), | ||
}; | ||
jest.mock("pacote", () => ({ | ||
async manifest(spec: string, opts: pacote.Options) { | ||
switch (spec) { | ||
case "[email protected]": // Older than the @types/jest package. | ||
case "[email protected]": // The same version as the @types/jest package. | ||
case "[email protected]": // Newer than the @types/jest package. | ||
// These versions exist (don't throw). | ||
return; | ||
case "[email protected]": // A nonexistent version of the replacement package. | ||
// eslint-disable-next-line no-throw-literal | ||
throw { code: "ETARGET" }; | ||
case "@types/jest": // The @types/jest package. | ||
return { version: "50.0.0" }; | ||
case "[email protected]": // A nonexistent replacement package. | ||
case "@types/nonexistent": // A nonexistent @types package. | ||
// eslint-disable-next-line no-throw-literal | ||
throw { code: opts.offline ? "ENOTCACHED" : "E404" }; | ||
} | ||
throw new Error(`Unexpected npm registry fetch: ${util.inspect(spec)}`); | ||
}, | ||
})); | ||
|
||
const newerReplacement = new NotNeededPackage("jest", "jest", "100.0.0"); | ||
const olderReplacement = new NotNeededPackage("jest", "jest", "4.0.0"); | ||
const sameVersion = new NotNeededPackage("jest", "jest", "50.0.0"); | ||
const nonexistentReplacementVersion = new NotNeededPackage("jest", "jest", "999.0.0"); | ||
const nonexistentReplacementPackage = new NotNeededPackage("jest", "nonexistent", "100.0.0"); | ||
const nonexistentTypesPackage = new NotNeededPackage("nonexistent", "jest", "100.0.0"); | ||
|
||
testo({ | ||
missingSource() { | ||
expect(() => checkNotNeededPackage(jestNotNeeded[0], undefined, empty)).toThrow( | ||
return expect(checkNotNeededPackage(nonexistentReplacementPackage)).rejects.toThrow( | ||
"The entry for @types/jest in notNeededPackages.json" | ||
); | ||
}, | ||
missingTypings() { | ||
expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, undefined)).toThrow( | ||
"@types package not found for @types/jest" | ||
); | ||
}, | ||
missingTypingsLatest() { | ||
expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, empty)).toThrow( | ||
'@types/jest is missing the "latest" tag' | ||
return expect(checkNotNeededPackage(nonexistentTypesPackage)).rejects.toThrow( | ||
"@types package not found for @types/nonexistent" | ||
); | ||
}, | ||
deprecatedSameVersion() { | ||
expect(() => { | ||
checkNotNeededPackage(jestNotNeeded[0], empty, { | ||
homepage: "jest.com", | ||
distTags: new Map([["latest", "100.0.0"]]), | ||
versions: new Map(), | ||
time: new Map([["modified", ""]]), | ||
}); | ||
}).toThrow(`The specified version 100.0.0 of jest must be newer than the version | ||
it is supposed to replace, 100.0.0 of @types/jest.`); | ||
return expect(checkNotNeededPackage(sameVersion)).rejects | ||
.toThrow(`The specified version 50.0.0 of jest must be newer than the version | ||
it is supposed to replace, 50.0.0 of @types/jest.`); | ||
}, | ||
deprecatedOlderVersion() { | ||
expect(() => { | ||
checkNotNeededPackage(jestNotNeeded[0], empty, { | ||
homepage: "jest.com", | ||
distTags: new Map([["latest", "999.0.0"]]), | ||
versions: new Map(), | ||
time: new Map([["modified", ""]]), | ||
}); | ||
}).toThrow(`The specified version 100.0.0 of jest must be newer than the version | ||
it is supposed to replace, 999.0.0 of @types/jest.`); | ||
return expect(checkNotNeededPackage(olderReplacement)).rejects | ||
.toThrow(`The specified version 4.0.0 of jest must be newer than the version | ||
it is supposed to replace, 50.0.0 of @types/jest.`); | ||
}, | ||
missingNpmVersion() { | ||
expect(() => { | ||
checkNotNeededPackage(jestNotNeeded[0], empty, { | ||
homepage: "jest.com", | ||
distTags: new Map([["latest", "4.0.0"]]), | ||
versions: new Map(), | ||
time: new Map([["modified", ""]]), | ||
}); | ||
}).toThrow("The specified version 100.0.0 of jest is not on npm."); | ||
}, | ||
olderNpmVersion() { | ||
expect(() => | ||
checkNotNeededPackage( | ||
jestNotNeeded[0], | ||
{ | ||
homepage: "jest.com", | ||
distTags: new Map(), | ||
versions: new Map([["50.0.0", {}]]), | ||
time: new Map([["modified", ""]]), | ||
}, | ||
{ | ||
homepage: "jest.com", | ||
distTags: new Map([["latest", "4.0.0"]]), | ||
versions: new Map(), | ||
time: new Map([["modified", ""]]), | ||
} | ||
) | ||
).toThrow("The specified version 100.0.0 of jest is not on npm."); | ||
return expect(checkNotNeededPackage(nonexistentReplacementVersion)).rejects.toThrow( | ||
"The specified version 999.0.0 of jest is not on npm." | ||
); | ||
}, | ||
ok() { | ||
checkNotNeededPackage( | ||
jestNotNeeded[0], | ||
{ | ||
homepage: "jest.com", | ||
distTags: new Map(), | ||
versions: new Map([["100.0.0", {}]]), | ||
time: new Map([["modified", ""]]), | ||
}, | ||
{ | ||
homepage: "jest.com", | ||
distTags: new Map([["latest", "4.0.0"]]), | ||
versions: new Map(), | ||
time: new Map([["modified", ""]]), | ||
} | ||
); | ||
return checkNotNeededPackage(newerReplacement); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
bin/ | ||
cache/ | ||
data/ | ||
logs/ | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.