@@ -84,6 +84,7 @@ beforeEach(function setupPublishPackagesTestState() {
8484} ) ;
8585
8686afterEach ( function restoreConsoleSpy ( ) {
87+ jest . useRealTimers ( ) ;
8788 consoleLogSpy . mockRestore ( ) ;
8889} ) ;
8990
@@ -207,7 +208,7 @@ describe("publishPackages", function describePublishPackages() {
207208} ) ;
208209
209210describe ( "verifyPackageDistTags" , function describeVerifyPackageDistTags ( ) {
210- test ( "it accepts package dist-tags that point to the current versions" , function testMatchingDistTags ( ) {
211+ test ( "it accepts package dist-tags that point to the current versions" , async function testMatchingDistTags ( ) {
211212 publishPackagesExecFileSyncMock . mockImplementation (
212213 function mockExecFile ( command , args , options ) {
213214 execCalls . push ( {
@@ -220,10 +221,55 @@ describe("verifyPackageDistTags", function describeVerifyPackageDistTags() {
220221 } ,
221222 ) ;
222223
223- expect ( ( ) => verifyPackageDistTags ( "next" ) ) . not . toThrow ( ) ;
224+ await expect ( verifyPackageDistTags ( "next" ) ) . resolves . toBeUndefined ( ) ;
224225 } ) ;
225226
226- test ( "it explains how to repair mismatched package dist-tags" , function testMismatchedDistTag ( ) {
227+ test ( "it retries stale package dist-tags until npm returns the current version" , async function testStaleDistTagRetry ( ) {
228+ jest . useFakeTimers ( ) ;
229+
230+ publishPackagesExecFileSyncMock . mockImplementation (
231+ function mockExecFile ( command , args , options ) {
232+ execCalls . push ( {
233+ command : String ( command ) ,
234+ args : Array . isArray ( args ) ? [ ...args ] : [ ] ,
235+ options,
236+ } ) ;
237+
238+ if (
239+ command === "npm" &&
240+ Array . isArray ( args ) &&
241+ args [ 1 ] === "@daypicker/react@next"
242+ ) {
243+ const packageReads = execCalls . filter (
244+ ( call ) => call . args [ 1 ] === "@daypicker/react@next" ,
245+ ) ;
246+ return packageReads . length < 3
247+ ? "10.0.0-next.0\n"
248+ : "10.0.0-next.1\n" ;
249+ }
250+
251+ return "10.0.0-next.1\n" ;
252+ } ,
253+ ) ;
254+
255+ const verification = verifyPackageDistTags ( "next" ) ;
256+ await jest . advanceTimersByTimeAsync ( 10_000 ) ;
257+ await verification ;
258+
259+ expect (
260+ execCalls
261+ . filter ( ( call ) => call . args [ 1 ] === "@daypicker/react@next" )
262+ . map ( ( call ) => call . args ) ,
263+ ) . toEqual ( [
264+ [ "view" , "@daypicker/react@next" , "version" ] ,
265+ [ "view" , "@daypicker/react@next" , "version" ] ,
266+ [ "view" , "@daypicker/react@next" , "version" ] ,
267+ ] ) ;
268+ } ) ;
269+
270+ test ( "it explains how to repair mismatched package dist-tags" , async function testMismatchedDistTag ( ) {
271+ jest . useFakeTimers ( ) ;
272+
227273 publishPackagesExecFileSyncMock . mockImplementation (
228274 function mockExecFile ( command , args , options ) {
229275 execCalls . push ( {
@@ -244,8 +290,12 @@ describe("verifyPackageDistTags", function describeVerifyPackageDistTags() {
244290 } ,
245291 ) ;
246292
247- expect ( ( ) => verifyPackageDistTags ( "next" ) ) . toThrow (
293+ const verification = verifyPackageDistTags ( "next" ) ;
294+ const expectation = expect ( verification ) . rejects . toThrow (
248295 "Expected npm dist-tag next for @daypicker/react to point to 10.0.0-next.1, got 10.0.0-next.0. Trusted publishing only authenticates npm publish, so repair the tag manually with: npm dist-tag add @daypicker/react@10.0.0-next.1 next" ,
249296 ) ;
297+
298+ await jest . advanceTimersByTimeAsync ( 60_000 ) ;
299+ await expectation ;
250300 } ) ;
251301} ) ;
0 commit comments