Skip to content

Commit 30eb153

Browse files
committed
fix: fix tests
1 parent 8fb953f commit 30eb153

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

helpers/usesBuildCommand.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ const usesBuildCommand = ({ build, scripts, command }) => {
1111
return false
1212
}
1313
// This resolves the npm script that is actually being run
14-
const { raw } = parseNpmScript({ scripts }, build.command)
15-
16-
return raw.some((script) => script.includes(command))
14+
try {
15+
const { raw } = parseNpmScript({ scripts }, build.command)
16+
return raw.some((script) => script.includes(command))
17+
} catch (error) {
18+
console.error('There was an error parsing your build command', error)
19+
}
1720
}
1821

1922
module.exports = usesBuildCommand

test/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ beforeEach(async () => {
7979
afterEach(async () => {
8080
jest.clearAllMocks()
8181
jest.resetAllMocks()
82-
82+
delete process.env.NEXT_PRIVATE_TARGET
8383
// Cleans up the temporary directory from `getTmpDir()` and do not make it
8484
// the current directory anymore
8585
this.restoreCwd()
8686
await this.cleanup()
8787
})
8888

89-
const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
90-
const netlifyConfig = { build: { command: 'next build' } }
89+
const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0', scripts: { build: 'next build' } }
90+
const netlifyConfig = { build: { command: 'npm run build' } }
9191

9292
describe('preBuild()', () => {
9393
test('do nothing if the app has no build command', async () => {
9494
await plugin.onPreBuild({
9595
netlifyConfig: { build: { command: '' } },
96-
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { build: 'next build' } },
96+
packageJson: DUMMY_PACKAGE_JSON,
9797
utils,
9898
constants: { FUNCTIONS_SRC: 'out_functions' },
9999
})
@@ -115,7 +115,7 @@ describe('preBuild()', () => {
115115
test('run plugin if the app has next export in an unused script', async () => {
116116
await plugin.onPreBuild({
117117
netlifyConfig,
118-
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { export: 'next export' } },
118+
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { export: 'next export', build: 'next build' } },
119119
utils,
120120
constants: {},
121121
})
@@ -135,6 +135,7 @@ describe('preBuild()', () => {
135135

136136
test('do nothing if app has next-on-netlify installed', async () => {
137137
const packageJson = {
138+
...DUMMY_PACKAGE_JSON,
138139
dependencies: { 'next-on-netlify': '123' },
139140
}
140141
await plugin.onPreBuild({
@@ -148,7 +149,7 @@ describe('preBuild()', () => {
148149

149150
test('do nothing if app has next-on-netlify postbuild script', async () => {
150151
const packageJson = {
151-
scripts: { postbuild: 'next-on-netlify' },
152+
scripts: { build: 'next build', postbuild: 'next-on-netlify' },
152153
}
153154
await plugin.onPreBuild({
154155
netlifyConfig,
@@ -180,7 +181,7 @@ describe('preBuild()', () => {
180181
test('run plugin if app has build-storybook in an unused script', async () => {
181182
await plugin.onPreBuild({
182183
netlifyConfig,
183-
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { storybook: 'build-storybook' } },
184+
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { storybook: 'build-storybook', build: 'next build' } },
184185
utils,
185186
})
186187
expect(process.env.NEXT_PRIVATE_TARGET).toBe('serverless')
@@ -237,7 +238,7 @@ describe('preBuild()', () => {
237238
describe('onBuild()', () => {
238239
test('does not run onBuild if using next-on-netlify', async () => {
239240
const packageJson = {
240-
scripts: { postbuild: 'next-on-netlify' },
241+
scripts: { postbuild: 'next-on-netlify', build: 'next build' },
241242
}
242243
await useFixture('publish_copy_files')
243244
await moveNextDist()

0 commit comments

Comments
 (0)