-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
698 additions
and
525 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { NpmInfo } from "@definitelytyped/utils"; | ||
import * as util from "util"; | ||
import { createTypingsVersionRaw, testo } from "./utils"; | ||
import { GitDiff, getNotNeededPackages, checkNotNeededPackage } from "../src/git"; | ||
import { NotNeededPackage, TypesDataFile, AllPackages } from "../src/packages"; | ||
|
@@ -65,94 +65,55 @@ 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) { | ||
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 target JS 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 target JS package. | ||
case "@types/nonexistent": // A nonexistent @types package. | ||
// eslint-disable-next-line no-throw-literal | ||
throw { code: "E404" }; | ||
} | ||
throw new Error(`Unexpected npm registry fetch: ${util.inspect(spec)}`); | ||
}, | ||
})); | ||
|
||
testo({ | ||
missingSource() { | ||
expect(() => checkNotNeededPackage(jestNotNeeded[0], undefined, empty)).toThrow( | ||
return expect(checkNotNeededPackage(new NotNeededPackage("jest", "nonexistent", "100.0.0"))).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(new NotNeededPackage("nonexistent", "jest", "100.0.0"))).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(new NotNeededPackage("jest", "jest", "50.0.0"))).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(new NotNeededPackage("jest", "jest", "4.0.0"))).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(new NotNeededPackage("jest", "jest", "999.0.0"))).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(new NotNeededPackage("jest", "jest", "100.0.0")); | ||
}, | ||
}); |
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
Oops, something went wrong.