Skip to content

Commit 630cb1a

Browse files
committed
fix: fix tests
1 parent a1ab7bf commit 630cb1a

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

Diff for: test/index.js

+15-34
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const path = require('path')
22
const process = require('process')
3+
4+
const cpy = require('cpy')
35
const pathExists = require('path-exists')
46
const { dir: getTmpDir } = require('tmp-promise')
5-
const cpy = require('cpy')
67

78
const plugin = require('..')
9+
const getNextConfig = require('../helpers/getNextConfig')
810

911
const FIXTURES_DIR = `${__dirname}/fixtures`
1012
const SAMPLE_PROJECT_DIR = `${__dirname}/sample`
@@ -47,6 +49,11 @@ const useFixture = async function (fixtureName) {
4749
// In each test, we change cwd to a temporary directory.
4850
// This allows us not to have to mock filesystem operations.
4951
beforeEach(async () => {
52+
delete process.env.NEXT_PRIVATE_TARGET
53+
delete require.cache[require.resolve('next/dist/telemetry/ci-info')]
54+
delete require.cache[require.resolve('next/dist/next-server/server/config')]
55+
56+
getNextConfig.clear()
5057
const { path, cleanup } = await getTmpDir({ unsafeCleanup: true })
5158
const restoreCwd = changeCwd(path)
5259
Object.assign(this, { cleanup, restoreCwd })
@@ -66,17 +73,6 @@ const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
6673
const netlifyConfig = { build: {} }
6774

6875
describe('preBuild()', () => {
69-
test('create next.config.js with correct target if file does not exist', async () => {
70-
await plugin.onPreBuild({
71-
netlifyConfig,
72-
packageJson: DUMMY_PACKAGE_JSON,
73-
utils,
74-
constants: { FUNCTIONS_SRC: 'out_functions' },
75-
})
76-
77-
expect(await pathExists('next.config.js')).toBeTruthy()
78-
})
79-
8076
test('do nothing if the app has static html export in npm script', async () => {
8177
await plugin.onPreBuild({
8278
netlifyConfig: { build: { command: 'npm run build' } },
@@ -89,14 +85,15 @@ describe('preBuild()', () => {
8985
})
9086

9187
test('run plugin if the app has next export in an unused script', async () => {
88+
process.env.hi = 'ok'
9289
await plugin.onPreBuild({
9390
netlifyConfig,
9491
packageJson: { ...DUMMY_PACKAGE_JSON, scripts: { export: 'next export' } },
9592
utils,
9693
constants: {},
9794
})
98-
99-
expect(await pathExists('next.config.js')).toBeTruthy()
95+
expect(process.env.NEXT_PRIVATE_TARGET).toBe('serverless')
96+
// expect(await pathExists('next.config.js')).toBeTruthy()
10097
})
10198

10299
test('do nothing if app has static html export in toml/ntl config', async () => {
@@ -107,7 +104,7 @@ describe('preBuild()', () => {
107104
constants: { FUNCTIONS_SRC: 'out_functions' },
108105
})
109106

110-
expect(await pathExists('next.config.js')).toBeFalsy()
107+
expect(process.env.NEXT_PRIVATE_TARGET).toBeUndefined()
111108
})
112109

113110
test('do nothing if app has next-on-netlify installed', async () => {
@@ -120,7 +117,7 @@ describe('preBuild()', () => {
120117
utils,
121118
})
122119

123-
expect(await pathExists('next.config.js')).toBeFalsy()
120+
expect(process.env.NEXT_PRIVATE_TARGET).toBeUndefined()
124121
})
125122

126123
test('do nothing if app has next-on-netlify postbuild script', async () => {
@@ -133,7 +130,7 @@ describe('preBuild()', () => {
133130
utils,
134131
})
135132

136-
expect(await pathExists('next.config.js')).toBeFalsy()
133+
expect(process.env.NEXT_PRIVATE_TARGET).toBeUndefined()
137134
})
138135

139136
test('fail build if the app has no package.json', async () => {
@@ -185,6 +182,7 @@ describe('preBuild()', () => {
185182
})
186183

187184
describe('onBuild()', () => {
185+
// eslint-disable-next-line max-lines
188186
test('does not run onBuild if using next-on-netlify', async () => {
189187
const packageJson = {
190188
scripts: { postbuild: 'next-on-netlify' },
@@ -202,23 +200,6 @@ describe('onBuild()', () => {
202200
expect(await pathExists(`${PUBLISH_DIR}/index.html`)).toBeFalsy()
203201
})
204202

205-
test.each(['invalid_next_config', 'deep_invalid_next_config'])(
206-
`do nothing if the app's next config has an invalid target`,
207-
async (fixtureName) => {
208-
await useFixture(fixtureName)
209-
const PUBLISH_DIR = 'publish'
210-
await plugin.onBuild({
211-
netlifyConfig,
212-
packageJson: DUMMY_PACKAGE_JSON,
213-
utils,
214-
constants: { FUNCTIONS_SRC: 'out_functions' },
215-
utils,
216-
})
217-
218-
expect(await pathExists(`${PUBLISH_DIR}/index.html`)).toBeFalsy()
219-
},
220-
)
221-
222203
test('copy files to the publish directory', async () => {
223204
await useFixture('publish_copy_files')
224205
await moveNextDist()

0 commit comments

Comments
 (0)