generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dry-run): always print publish results in dry run
- Loading branch information
Showing
9 changed files
with
156 additions
and
49 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,23 +16,31 @@ vi.mock("../compare-versions"); | |
vi.mock("../get-arguments"); | ||
|
||
describe("compareAndPublish", () => { | ||
const manifest = { | ||
packageSpec: ".", | ||
name: "fizzbuzz", | ||
version: "1.2.3", | ||
} as PackageManifest; | ||
|
||
const logger = { debug: (message: string) => void message } as Logger; | ||
const normalizedOptions = { | ||
token: "abc123", | ||
ignoreScripts: { value: false }, | ||
logger, | ||
} as NormalizedOptions; | ||
const environment: NpmCliEnvironment = { foo: "bar" }; | ||
const npmViewResult = { versions: ["0.0.1"], "dist-tags": {} }; | ||
const npmPublishResult = { id: "[email protected]", files: [] }; | ||
const npmPublishResult = { | ||
id: "[email protected]", | ||
files: [{ path: "package.json", size: 42 }], | ||
}; | ||
|
||
let manifest: PackageManifest; | ||
let normalizedOptions: NormalizedOptions; | ||
|
||
beforeEach(() => { | ||
manifest = { | ||
packageSpec: ".", | ||
name: "fizzbuzz", | ||
version: "1.2.3", | ||
} as PackageManifest; | ||
|
||
normalizedOptions = { | ||
token: "abc123", | ||
ignoreScripts: { value: false }, | ||
dryRun: { value: false }, | ||
logger, | ||
} as NormalizedOptions; | ||
|
||
when(getViewArguments) | ||
.calledWith("fizzbuzz", normalizedOptions) | ||
.thenReturn(["fizzbuzz"]); | ||
|
@@ -83,7 +91,24 @@ describe("compareAndPublish", () => { | |
|
||
expect(result).toEqual({ | ||
id: "[email protected]", | ||
files: [], | ||
files: [{ path: "package.json", size: 42 }], | ||
oldVersion: "0.0.1", | ||
type: "major", | ||
}); | ||
}); | ||
|
||
it("should get versions, compare, and publish in dry run", async () => { | ||
normalizedOptions.dryRun.value = true; | ||
|
||
const result = await subject.compareAndPublish( | ||
manifest, | ||
normalizedOptions, | ||
environment | ||
); | ||
|
||
expect(result).toEqual({ | ||
id: "[email protected]", | ||
files: [{ path: "package.json", size: 42 }], | ||
oldVersion: "0.0.1", | ||
type: "major", | ||
}); | ||
|
@@ -118,6 +143,31 @@ describe("compareAndPublish", () => { | |
); | ||
}); | ||
|
||
it("should run publish if version exists but dry run", async () => { | ||
normalizedOptions.dryRun.value = true; | ||
|
||
when(compareVersions) | ||
.calledWith( | ||
"1.2.3", | ||
{ versions: ["0.0.1"], "dist-tags": {} }, | ||
normalizedOptions | ||
) | ||
.thenReturn({ type: undefined, oldVersion: "0.0.1" }); | ||
|
||
const result = await subject.compareAndPublish( | ||
manifest, | ||
normalizedOptions, | ||
environment | ||
); | ||
|
||
expect(result).toEqual({ | ||
id: undefined, | ||
files: [{ path: "package.json", size: 42 }], | ||
oldVersion: "0.0.1", | ||
type: undefined, | ||
}); | ||
}); | ||
|
||
it("should handle an E404 from npm view", async () => { | ||
when(callNpmCli<"view">) | ||
.calledWith("view", ["fizzbuzz"], { | ||
|
@@ -146,7 +196,7 @@ describe("compareAndPublish", () => { | |
|
||
expect(result).toEqual({ | ||
id: "[email protected]", | ||
files: [], | ||
files: [{ path: "package.json", size: 42 }], | ||
oldVersion: "0.0.1", | ||
type: "major", | ||
}); | ||
|
@@ -260,7 +310,7 @@ describe("compareAndPublish", () => { | |
|
||
expect(result).toEqual({ | ||
id: "[email protected]", | ||
files: [], | ||
files: [{ path: "package.json", size: 42 }], | ||
oldVersion: "0.0.1", | ||
type: "major", | ||
}); | ||
|
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