@@ -19,8 +19,10 @@ function setup() {
1919 fetches += 1 ;
2020 return fetches ;
2121 } ) . pipe ( Atom . keepAlive ) ;
22- const mount = ( revision : string | null | undefined ) => {
22+ const mount = async ( revision : string | null | undefined ) => {
2323 const release = registry . mount ( revisionedQuery ( query , revision ) ) ;
24+ // A stale read refetches in a microtask, after the render that read it.
25+ await Promise . resolve ( ) ;
2426 return ( ) => {
2527 release ( ) ;
2628 for ( const task of scheduled . splice ( 0 ) ) task ( ) ;
@@ -30,73 +32,73 @@ function setup() {
3032}
3133
3234describe ( "revisionedQuery" , ( ) => {
33- it ( "refetches once per new revision, not on the first read or a remount" , ( ) => {
35+ it ( "refetches once per new revision, not on the first read or a remount" , async ( ) => {
3436 const { mount, fetches } = setup ( ) ;
3537
36- mount ( "mutation-1" ) ( ) ;
38+ ( await mount ( "mutation-1" ) ) ( ) ;
3739 expect ( fetches ( ) ) . toBe ( 1 ) ;
3840
39- mount ( "mutation-1" ) ( ) ;
41+ ( await mount ( "mutation-1" ) ) ( ) ;
4042 expect ( fetches ( ) ) . toBe ( 1 ) ;
4143
42- mount ( "mutation-2" ) ( ) ;
44+ ( await mount ( "mutation-2" ) ) ( ) ;
4345 expect ( fetches ( ) ) . toBe ( 2 ) ;
4446 } ) ;
4547
46- it ( "does not ping-pong while readers of the old and new revision overlap" , ( ) => {
48+ it ( "does not ping-pong while readers of the old and new revision overlap" , async ( ) => {
4749 const { mount, fetches } = setup ( ) ;
4850
49- const releaseOld = mount ( "mutation-1" ) ;
50- const releaseNew = mount ( "mutation-2" ) ;
51+ const releaseOld = await mount ( "mutation-1" ) ;
52+ const releaseNew = await mount ( "mutation-2" ) ;
5153 expect ( fetches ( ) ) . toBe ( 2 ) ;
5254 releaseOld ( ) ;
5355 releaseNew ( ) ;
5456 } ) ;
5557
56- it ( "refetches when an earlier revision is read again" , ( ) => {
58+ it ( "refetches when an earlier revision is read again" , async ( ) => {
5759 const { mount, fetches } = setup ( ) ;
5860
59- mount ( "mutation-1" ) ( ) ;
60- mount ( "mutation-2" ) ( ) ;
61- mount ( "mutation-1" ) ( ) ;
61+ ( await mount ( "mutation-1" ) ) ( ) ;
62+ ( await mount ( "mutation-2" ) ) ( ) ;
63+ ( await mount ( "mutation-1" ) ) ( ) ;
6264 expect ( fetches ( ) ) . toBe ( 3 ) ;
6365 } ) ;
6466
65- it ( "refetches a query another reader already cached on its first revisioned read" , ( ) => {
67+ it ( "refetches a query another reader already cached on its first revisioned read" , async ( ) => {
6668 const { mount, fetches } = setup ( ) ;
6769
68- mount ( undefined ) ( ) ;
70+ ( await mount ( undefined ) ) ( ) ;
6971 expect ( fetches ( ) ) . toBe ( 1 ) ;
7072
71- mount ( "mutation-1" ) ( ) ;
73+ ( await mount ( "mutation-1" ) ) ( ) ;
7274 expect ( fetches ( ) ) . toBe ( 2 ) ;
7375
74- mount ( "mutation-1" ) ( ) ;
76+ ( await mount ( "mutation-1" ) ) ( ) ;
7577 expect ( fetches ( ) ) . toBe ( 2 ) ;
7678 } ) ;
7779
78- it ( "does not refetch a cached query on a first read before any workspace change" , ( ) => {
80+ it ( "does not refetch a cached query on a first read before any workspace change" , async ( ) => {
7981 const { mount, fetches } = setup ( ) ;
8082
81- mount ( undefined ) ( ) ;
82- mount ( null ) ( ) ;
83+ ( await mount ( undefined ) ) ( ) ;
84+ ( await mount ( null ) ) ( ) ;
8385 expect ( fetches ( ) ) . toBe ( 1 ) ;
8486 } ) ;
8587
86- it ( "leaves the query alone when read without a revision" , ( ) => {
88+ it ( "leaves the query alone when read without a revision" , async ( ) => {
8789 const { mount, query, fetches } = setup ( ) ;
8890
89- mount ( "mutation-1" ) ( ) ;
91+ ( await mount ( "mutation-1" ) ) ( ) ;
9092 expect ( revisionedQuery ( query , undefined ) ) . toBe ( query ) ;
91- mount ( undefined ) ( ) ;
92- mount ( "mutation-1" ) ( ) ;
93+ ( await mount ( undefined ) ) ( ) ;
94+ ( await mount ( "mutation-1" ) ) ( ) ;
9395 expect ( fetches ( ) ) . toBe ( 1 ) ;
9496 } ) ;
9597
96- it ( "refetches the query when the reader is refreshed" , ( ) => {
98+ it ( "refetches the query when the reader is refreshed" , async ( ) => {
9799 const { registry, query, mount, fetches } = setup ( ) ;
98100
99- const release = mount ( "mutation-1" ) ;
101+ const release = await mount ( "mutation-1" ) ;
100102 registry . refresh ( revisionedQuery ( query , "mutation-1" ) ) ;
101103 expect ( fetches ( ) ) . toBe ( 2 ) ;
102104 release ( ) ;
0 commit comments