@@ -8,24 +8,45 @@ const nextjsVersion = packageJson.dependencies.next;
88const buildStdout = fs . readFileSync ( '.tmp_build_stdout' , 'utf-8' ) ;
99const buildStderr = fs . readFileSync ( '.tmp_build_stderr' , 'utf-8' ) ;
1010
11- // Assert that there was no funky build time warning when we are on a stable (pinned) version
12- if ( nextjsVersion !== 'latest' && ! nextjsVersion . includes ( '-canary' ) && ! nextjsVersion . includes ( '-rc' ) ) {
13- assert . doesNotMatch ( buildStderr , / I m p o r t t r a c e f o r r e q u e s t e d m o d u l e / , `Build warning in output:\n${ buildStderr } ` ) ; // This is Next.js/Webpack speech for "something is off"
14- }
11+ const getLatestNextVersion = async ( ) => {
12+ try {
13+ const response = await fetch ( 'https://registry.npmjs.org/next/latest' ) ;
14+ const data = await response . json ( ) ;
15+ return data . version as string ;
16+ } catch ( error ) {
17+ return '0.0.0' ;
18+ }
19+ } ;
1520
16- // Assert that all static components stay static and all dynamic components stay dynamic
17- assert . match ( buildStdout , / ○ \/ c l i e n t - c o m p o n e n t / ) ;
18- assert . match ( buildStdout , / ● \/ c l i e n t - c o m p o n e n t \/ p a r a m e t e r \/ \[ \. \. \. p a r a m e t e r s \] / ) ;
19- assert . match ( buildStdout , / ● \/ c l i e n t - c o m p o n e n t \/ p a r a m e t e r \/ \[ p a r a m e t e r \] / ) ;
20- assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t / ) ;
21- assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t \/ p a r a m e t e r \/ \[ \. \. \. p a r a m e t e r s \] / ) ;
22- assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t \/ p a r a m e t e r \/ \[ p a r a m e t e r \] / ) ;
21+ ( async ( ) => {
22+ // Assert that there was no funky build time warning when we are on a stable (pinned) version
23+ if (
24+ ! nextjsVersion . includes ( '-canary' ) &&
25+ ! nextjsVersion . includes ( '-rc' ) &&
26+ // If we install latest we cannot assert on "latest" because the package json will contain the actual version number
27+ nextjsVersion !== ( await getLatestNextVersion ( ) )
28+ ) {
29+ assert . doesNotMatch (
30+ buildStderr ,
31+ / I m p o r t t r a c e f o r r e q u e s t e d m o d u l e / , // This is Next.js/Webpack speech for "something is off"
32+ `The E2E tests detected a build warning in the Next.js build output:\n\n--------------\n\n${ buildStderr } \n\n--------------\n\n` ,
33+ ) ;
34+ }
2335
24- // Read the contents of the directory
25- const files = fs . readdirSync ( path . join ( process . cwd ( ) , '.next' , 'static' ) ) ;
26- const mapFiles = files . filter ( file => path . extname ( file ) === '.map' ) ;
27- if ( mapFiles . length > 0 ) {
28- throw new Error ( 'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!' ) ;
29- }
36+ // Assert that all static components stay static and all dynamic components stay dynamic
37+ assert . match ( buildStdout , / ○ \/ c l i e n t - c o m p o n e n t / ) ;
38+ assert . match ( buildStdout , / ● \/ c l i e n t - c o m p o n e n t \/ p a r a m e t e r \/ \[ \. \. \. p a r a m e t e r s \] / ) ;
39+ assert . match ( buildStdout , / ● \/ c l i e n t - c o m p o n e n t \/ p a r a m e t e r \/ \[ p a r a m e t e r \] / ) ;
40+ assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t / ) ;
41+ assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t \/ p a r a m e t e r \/ \[ \. \. \. p a r a m e t e r s \] / ) ;
42+ assert . match ( buildStdout , / ( λ | ƒ ) \/ s e r v e r - c o m p o n e n t \/ p a r a m e t e r \/ \[ p a r a m e t e r \] / ) ;
3043
31- export { } ;
44+ // Read the contents of the directory
45+ const files = fs . readdirSync ( path . join ( process . cwd ( ) , '.next' , 'static' ) ) ;
46+ const mapFiles = files . filter ( file => path . extname ( file ) === '.map' ) ;
47+ if ( mapFiles . length > 0 ) {
48+ throw new Error (
49+ 'Client bundle .map files found even though `sourcemaps.deleteSourcemapsAfterUpload` option is set!' ,
50+ ) ;
51+ }
52+ } ) ( ) ;
0 commit comments