@@ -11,10 +11,12 @@ const FIXTURES_DIR = `${__dirname}/fixtures`
1111
1212const utils = {
1313 run : {
14- command : jest . fn ( ) ,
14+ command ( ) { } ,
1515 } ,
1616 build : {
17- failBuild : jest . fn ( ) ,
17+ failBuild ( message ) {
18+ throw new Error ( message )
19+ } ,
1820 } ,
1921}
2022
@@ -41,8 +43,6 @@ beforeEach(async () => {
4143} )
4244
4345afterEach ( async ( ) => {
44- utils . build . failBuild . mockReset ( )
45- utils . run . command . mockReset ( )
4646 jest . clearAllMocks ( )
4747 jest . resetAllMocks ( )
4848
@@ -58,53 +58,47 @@ const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
5858
5959describe ( 'preBuild()' , ( ) => {
6060 test ( 'fail build if the app has static html export in npm script' , async ( ) => {
61- await plugin . onPreBuild ( {
62- netlifyConfig : { } ,
63- packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
64- utils,
65- constants : { FUNCTIONS_SRC : 'out_functions' } ,
66- } )
67-
68- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
69- '** Static HTML export next.js projects do not require this plugin **' ,
70- )
61+ await expect (
62+ plugin . onPreBuild ( {
63+ netlifyConfig : { } ,
64+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
65+ utils,
66+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
67+ } ) ,
68+ ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
7169 } )
7270
7371 test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
74- const netlifyConfig = { build : { command : 'next build && next export' } }
75-
76- await plugin . onPreBuild ( {
77- netlifyConfig,
78- packageJson : DUMMY_PACKAGE_JSON ,
79- utils,
80- constants : { FUNCTIONS_SRC : 'out_functions' } ,
81- } )
82-
83- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
84- '** Static HTML export next.js projects do not require this plugin **' ,
85- )
72+ await expect (
73+ plugin . onPreBuild ( {
74+ netlifyConfig : { build : { command : 'next build && next export' } } ,
75+ packageJson : DUMMY_PACKAGE_JSON ,
76+ utils,
77+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
78+ } ) ,
79+ ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
8680 } )
8781
8882 test ( 'fail build if the app has no package.json' , async ( ) => {
89- await plugin . onPreBuild ( {
90- netlifyConfig : { } ,
91- packageJson : { } ,
92- utils ,
93- constants : { FUNCTIONS_SRC : 'out_functions' } ,
94- } )
95-
96- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual ( `Could not find a package.json for this project` )
83+ await expect (
84+ plugin . onPreBuild ( {
85+ netlifyConfig : { } ,
86+ packageJson : { } ,
87+ utils ,
88+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
89+ } ) ,
90+ ) . rejects . toThrow ( `Could not find a package.json for this project` )
9791 } )
9892
9993 test ( 'fail build if the app has no functions directory defined' , async ( ) => {
100- await plugin . onPreBuild ( {
101- netlifyConfig : { } ,
102- packageJson : DUMMY_PACKAGE_JSON ,
103- utils ,
104- constants : { } ,
105- } )
106-
107- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
94+ await expect (
95+ plugin . onPreBuild ( {
96+ netlifyConfig : { } ,
97+ packageJson : DUMMY_PACKAGE_JSON ,
98+ utils ,
99+ constants : { } ,
100+ } ) ,
101+ ) . rejects . toThrow (
108102 `You must designate a functions directory named "out_functions" in your netlify.toml or in your app's build settings on Netlify. See docs for more info: https://docs.netlify.com/functions/configure-and-deploy/#configure-the-functions-folder` ,
109103 )
110104 } )
@@ -122,18 +116,15 @@ describe('preBuild()', () => {
122116
123117 test ( `fail build if the app's next config has an invalid target` , async ( ) => {
124118 const { restoreCwd } = useFixture ( 'invalid_next_config' )
125- await plugin . onPreBuild ( {
126- netlifyConfig : { } ,
127- packageJson : DUMMY_PACKAGE_JSON ,
128- utils,
129- constants : { FUNCTIONS_SRC : 'out_functions' } ,
130- } )
119+ await expect (
120+ plugin . onPreBuild ( {
121+ netlifyConfig : { } ,
122+ packageJson : DUMMY_PACKAGE_JSON ,
123+ utils,
124+ constants : { FUNCTIONS_SRC : 'out_functions' } ,
125+ } ) ,
126+ ) . rejects . toThrow ( `next.config.js must be one of: serverless, experimental-serverless-trace` )
131127 restoreCwd ( )
132-
133- const acceptableTargets = [ 'serverless' , 'experimental-serverless-trace' ]
134- expect ( utils . build . failBuild . mock . calls [ 0 ] [ 0 ] ) . toEqual (
135- `next.config.js must be one of: ${ acceptableTargets . join ( ', ' ) } ` ,
136- )
137128 } )
138129} )
139130
0 commit comments