@@ -16,23 +16,31 @@ vi.mock("../compare-versions");
1616vi . mock ( "../get-arguments" ) ;
1717
1818describe ( "compareAndPublish" , ( ) => {
19- const manifest = {
20- packageSpec : "." ,
21- name : "fizzbuzz" ,
22- version : "1.2.3" ,
23- } as PackageManifest ;
24-
2519 const logger = { debug : ( message : string ) => void message } as Logger ;
26- const normalizedOptions = {
27- token : "abc123" ,
28- ignoreScripts : { value : false } ,
29- logger,
30- } as NormalizedOptions ;
3120 const environment : NpmCliEnvironment = { foo : "bar" } ;
3221 const npmViewResult = { versions : [ "0.0.1" ] , "dist-tags" : { } } ;
33- const npmPublishResult = { id : "fizzbuzz@1.2.3" , files : [ ] } ;
22+ const npmPublishResult = {
23+ id : "fizzbuzz@1.2.3" ,
24+ files : [ { path : "package.json" , size : 42 } ] ,
25+ } ;
26+
27+ let manifest : PackageManifest ;
28+ let normalizedOptions : NormalizedOptions ;
3429
3530 beforeEach ( ( ) => {
31+ manifest = {
32+ packageSpec : "." ,
33+ name : "fizzbuzz" ,
34+ version : "1.2.3" ,
35+ } as PackageManifest ;
36+
37+ normalizedOptions = {
38+ token : "abc123" ,
39+ ignoreScripts : { value : false } ,
40+ dryRun : { value : false } ,
41+ logger,
42+ } as NormalizedOptions ;
43+
3644 when ( getViewArguments )
3745 . calledWith ( "fizzbuzz" , normalizedOptions )
3846 . thenReturn ( [ "fizzbuzz" ] ) ;
@@ -83,7 +91,24 @@ describe("compareAndPublish", () => {
8391
8492 expect ( result ) . toEqual ( {
8593 id : "fizzbuzz@1.2.3" ,
86- files : [ ] ,
94+ files : [ { path : "package.json" , size : 42 } ] ,
95+ oldVersion : "0.0.1" ,
96+ type : "major" ,
97+ } ) ;
98+ } ) ;
99+
100+ it ( "should get versions, compare, and publish in dry run" , async ( ) => {
101+ normalizedOptions . dryRun . value = true ;
102+
103+ const result = await subject . compareAndPublish (
104+ manifest ,
105+ normalizedOptions ,
106+ environment
107+ ) ;
108+
109+ expect ( result ) . toEqual ( {
110+ id : "fizzbuzz@1.2.3" ,
111+ files : [ { path : "package.json" , size : 42 } ] ,
87112 oldVersion : "0.0.1" ,
88113 type : "major" ,
89114 } ) ;
@@ -118,6 +143,31 @@ describe("compareAndPublish", () => {
118143 ) ;
119144 } ) ;
120145
146+ it ( "should run publish if version exists but dry run" , async ( ) => {
147+ normalizedOptions . dryRun . value = true ;
148+
149+ when ( compareVersions )
150+ . calledWith (
151+ "1.2.3" ,
152+ { versions : [ "0.0.1" ] , "dist-tags" : { } } ,
153+ normalizedOptions
154+ )
155+ . thenReturn ( { type : undefined , oldVersion : "0.0.1" } ) ;
156+
157+ const result = await subject . compareAndPublish (
158+ manifest ,
159+ normalizedOptions ,
160+ environment
161+ ) ;
162+
163+ expect ( result ) . toEqual ( {
164+ id : undefined ,
165+ files : [ { path : "package.json" , size : 42 } ] ,
166+ oldVersion : "0.0.1" ,
167+ type : undefined ,
168+ } ) ;
169+ } ) ;
170+
121171 it ( "should handle an E404 from npm view" , async ( ) => {
122172 when ( callNpmCli < "view" > )
123173 . calledWith ( "view" , [ "fizzbuzz" ] , {
@@ -146,7 +196,7 @@ describe("compareAndPublish", () => {
146196
147197 expect ( result ) . toEqual ( {
148198 id : "fizzbuzz@1.2.3" ,
149- files : [ ] ,
199+ files : [ { path : "package.json" , size : 42 } ] ,
150200 oldVersion : "0.0.1" ,
151201 type : "major" ,
152202 } ) ;
@@ -260,7 +310,7 @@ describe("compareAndPublish", () => {
260310
261311 expect ( result ) . toEqual ( {
262312 id : "fizzbuzz@1.2.3" ,
263- files : [ ] ,
313+ files : [ { path : "package.json" , size : 42 } ] ,
264314 oldVersion : "0.0.1" ,
265315 type : "major" ,
266316 } ) ;
0 commit comments