@@ -14,6 +14,23 @@ const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`)
14
14
const manifest = { }
15
15
const filesToRevert = { }
16
16
17
+ let _CFLAGS_ = {
18
+ GATSBY_MAJOR : `4` ,
19
+ }
20
+ if ( process . env . COMPILER_OPTIONS ) {
21
+ // COMPILER_OPTIONS syntax is key=value,key2=value2
22
+ _CFLAGS_ = process . env . COMPILER_OPTIONS . split ( `,` ) . reduce ( ( acc , curr ) => {
23
+ const [ key , value ] = curr . split ( `=` )
24
+
25
+ if ( key ) {
26
+ acc [ key ] = value
27
+ }
28
+
29
+ return acc
30
+ } , _CFLAGS_ )
31
+ }
32
+
33
+ let SLICES_ENABLED = _CFLAGS_ . GATSBY_MAJOR === `5` && process . env . GATSBY_SLICES
17
34
let exitCode
18
35
19
36
function runGatsbyWithRunTestSetup ( runNumber = 1 ) {
@@ -694,101 +711,146 @@ describe(`Second run (different pages created, data changed)`, () => {
694
711
assertNodeCorrectness ( runNumber )
695
712
} )
696
713
697
- describe ( `Third run (js change, all pages are recreated)` , ( ) => {
698
- const runNumber = 3
699
-
700
- const expectedPages = [
701
- `/stale-pages/only-not-in-first` ,
702
- `/page-query-dynamic-3/` ,
703
- `/page-that-will-have-trailing-slash-removed` ,
704
- `/stale-pages/sometimes-i-have-trailing-slash-sometimes-i-dont` ,
705
- ]
706
-
707
- const unexpectedPages = [
708
- `/stale-pages/only-in-first/` ,
709
- `/page-query-dynamic-1/` ,
710
- `/page-query-dynamic-2/` ,
711
- `/stateful-page-not-recreated-in-third-run/` ,
712
- ]
713
-
714
- let changedFileOriginalContent
715
- const changedFileAbspath = path . join (
716
- process . cwd ( ) ,
717
- `src` ,
718
- `pages` ,
719
- `gatsby-browser.js`
720
- )
714
+ describe (
715
+ SLICES_ENABLED
716
+ ? `Third run (js template change, just pages of that template are recreated, all pages are stitched)`
717
+ : `Third run (js change, all pages are recreated)` ,
718
+
719
+ ( ) => {
720
+ const runNumber = 3
721
+
722
+ const expectedPagesToRemainFromPreviousBuild = [
723
+ `/stale-pages/stable/` ,
724
+ `/page-query-stable/` ,
725
+ `/page-query-changing-but-not-invalidating-html/` ,
726
+ `/static-query-result-tracking/stable/` ,
727
+ `/static-query-result-tracking/rerun-query-but-dont-recreate-html/` ,
728
+ `/page-that-will-have-trailing-slash-removed` ,
729
+ ]
730
+
731
+ const expectedPagesToBeGenerated = [
732
+ // this is page that gets template change
733
+ `/gatsby-browser/` ,
734
+ // those change happen on every build
735
+ `/page-query-dynamic-3/` ,
736
+ `/stale-pages/sometimes-i-have-trailing-slash-sometimes-i-dont` ,
737
+ `/changing-context/` ,
738
+ ]
739
+
740
+ const expectedPages = [
741
+ // this page should remain from first build
742
+ ...expectedPagesToRemainFromPreviousBuild ,
743
+ // those pages should have been (re)created
744
+ ...expectedPagesToBeGenerated ,
745
+ ]
746
+
747
+ const unexpectedPages = [
748
+ `/stale-pages/only-in-first/` ,
749
+ `/page-query-dynamic-1/` ,
750
+ `/page-query-dynamic-2/` ,
751
+ `/stateful-page-not-recreated-in-third-run/` ,
752
+ ]
753
+
754
+ let changedFileOriginalContent
755
+ const changedFileAbspath = path . join (
756
+ process . cwd ( ) ,
757
+ `src` ,
758
+ `pages` ,
759
+ `gatsby-browser.js`
760
+ )
721
761
722
- beforeAll ( async ( ) => {
723
- // make change to some .js
724
- changedFileOriginalContent = fs . readFileSync ( changedFileAbspath , `utf-8` )
725
- filesToRevert [ changedFileAbspath ] = changedFileOriginalContent
762
+ beforeAll ( async ( ) => {
763
+ // make change to some .js
764
+ changedFileOriginalContent = fs . readFileSync ( changedFileAbspath , `utf-8` )
765
+ filesToRevert [ changedFileAbspath ] = changedFileOriginalContent
726
766
727
- const newContent = changedFileOriginalContent . replace ( / s a d / g, `not happy` )
767
+ const newContent = changedFileOriginalContent . replace ( / s a d / g, `not happy` )
728
768
729
- if ( newContent === changedFileOriginalContent ) {
730
- throw new Error ( `Test setup failed` )
731
- }
769
+ if ( newContent === changedFileOriginalContent ) {
770
+ throw new Error ( `Test setup failed` )
771
+ }
732
772
733
- fs . writeFileSync ( changedFileAbspath , newContent )
734
- await runGatsbyWithRunTestSetup ( runNumber ) ( )
735
- } )
773
+ fs . writeFileSync ( changedFileAbspath , newContent )
774
+ await runGatsbyWithRunTestSetup ( runNumber ) ( )
775
+ } )
736
776
737
- assertExitCode ( runNumber )
777
+ assertExitCode ( runNumber )
738
778
739
- describe ( `html files` , ( ) => {
740
- const type = `html`
779
+ describe ( `html files` , ( ) => {
780
+ const type = `html`
741
781
742
- describe ( `should have expected html files` , ( ) => {
743
- assertFileExistenceForPagePaths ( {
744
- pagePaths : expectedPages ,
745
- type,
746
- shouldExist : true ,
782
+ describe ( `should have expected html files` , ( ) => {
783
+ assertFileExistenceForPagePaths ( {
784
+ pagePaths : expectedPages ,
785
+ type,
786
+ shouldExist : true ,
787
+ } )
747
788
} )
748
- } )
749
789
750
- describe ( `shouldn't have unexpected html files` , ( ) => {
751
- assertFileExistenceForPagePaths ( {
752
- pagePaths : unexpectedPages ,
753
- type,
754
- shouldExist : false ,
790
+ describe ( `shouldn't have unexpected html files` , ( ) => {
791
+ assertFileExistenceForPagePaths ( {
792
+ pagePaths : unexpectedPages ,
793
+ type,
794
+ shouldExist : false ,
795
+ } )
755
796
} )
756
- } )
757
797
758
- it ( `should recreate all html files` , ( ) => {
759
- expect ( manifest [ runNumber ] . generated . sort ( ) ) . toEqual (
760
- manifest [ runNumber ] . allPages . sort ( )
761
- )
798
+ if ( SLICES_ENABLED ) {
799
+ it ( `should recreate only some html files` , ( ) => {
800
+ expect ( manifest [ runNumber ] . generated . sort ( ) ) . toEqual (
801
+ expectedPagesToBeGenerated . sort ( )
802
+ )
803
+ } )
804
+
805
+ it ( `should stitch fragments back in all html files (browser bundle changed)` , ( ) => {
806
+ expect ( manifest [ runNumber ] . stitched . sort ( ) ) . toEqual (
807
+ manifest [ runNumber ] . allPages . sort ( )
808
+ )
809
+ } )
810
+ } else {
811
+ it ( `should recreate all html files` , ( ) => {
812
+ expect ( manifest [ runNumber ] . generated . sort ( ) ) . toEqual (
813
+ manifest [ runNumber ] . allPages . sort ( )
814
+ )
815
+ } )
816
+ }
762
817
} )
763
- } )
764
818
765
- describe ( `page-data files` , ( ) => {
766
- const type = `page-data`
819
+ describe ( `page-data files` , ( ) => {
820
+ const type = `page-data`
767
821
768
- describe ( `should have expected page-data files` , ( ) => {
769
- assertFileExistenceForPagePaths ( {
770
- pagePaths : expectedPages ,
771
- type,
772
- shouldExist : true ,
822
+ describe ( `should have expected page-data files` , ( ) => {
823
+ assertFileExistenceForPagePaths ( {
824
+ pagePaths : expectedPages ,
825
+ type,
826
+ shouldExist : true ,
827
+ } )
773
828
} )
774
- } )
775
829
776
- describe ( `shouldn't have unexpected page-data files` , ( ) => {
777
- assertFileExistenceForPagePaths ( {
778
- pagePaths : unexpectedPages ,
779
- type,
780
- shouldExist : false ,
830
+ describe ( `shouldn't have unexpected page-data files` , ( ) => {
831
+ assertFileExistenceForPagePaths ( {
832
+ pagePaths : unexpectedPages ,
833
+ type,
834
+ shouldExist : false ,
835
+ } )
781
836
} )
782
837
} )
783
- } )
784
838
785
- // third run - we modify module used by both ssr and browser bundle - both bundles should change
786
- assertWebpackBundleChanges ( { browser : true , ssr : true , runNumber } )
839
+ if ( SLICES_ENABLED ) {
840
+ // third run - we modify template used by both ssr and browser bundle - global, shared SSR won't change
841
+ // as the change is localized in just one of templates, which in Gatsby 5 doesn't invalidate all html
842
+ // files anymore
843
+ assertWebpackBundleChanges ( { browser : true , ssr : false , runNumber } )
844
+ } else {
845
+ // third run - we modify module used by both ssr and browser bundle - both bundles should change
846
+ assertWebpackBundleChanges ( { browser : true , ssr : true , runNumber } )
847
+ }
787
848
788
- assertHTMLCorrectness ( runNumber )
849
+ assertHTMLCorrectness ( runNumber )
789
850
790
- assertNodeCorrectness ( runNumber )
791
- } )
851
+ assertNodeCorrectness ( runNumber )
852
+ }
853
+ )
792
854
793
855
describe ( `Fourth run (gatsby-browser change - cache get invalidated)` , ( ) => {
794
856
const runNumber = 4
0 commit comments