Skip to content

Commit daba4cf

Browse files
committed
Use test fixtures
1 parent 4ceb71f commit daba4cf

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@netlify/eslint-config-node": "^0.3.0",
3636
"husky": "^4.3.0",
3737
"jest": "^26.6.1",
38-
"mock-fs": "^4.13.0",
3938
"prettier": "^2.1.2",
4039
"react": "^17.0.1",
4140
"react-dom": "^17.0.1"
@@ -47,7 +46,8 @@
4746
},
4847
"jest": {
4948
"testMatch": [
50-
"**/test/**/*.js"
49+
"**/test/**/*.js",
50+
"!**/test/fixtures/**"
5151
],
5252
"verbose": true
5353
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
target: 'server',
3+
}

test/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const path = require('path')
2+
const process = require('process')
23
const nextOnNetlify = require('next-on-netlify')
34
const makef = require('makef')
45
const makeDir = require('make-dir')
56
const cpx = require('cpx')
6-
const mockFs = require('mock-fs')
77
const plugin = require('../index')
88

99
const utils = {
@@ -33,6 +33,14 @@ console.log('Initializing tests')
3333

3434
const DUMMY_PACKAGE_JSON = { name: 'dummy', version: '1.0.0' }
3535

36+
const FIXTURES_DIR = `${__dirname}/fixtures`
37+
38+
const useFixture = function (fixtureName) {
39+
const originalCwd = process.cwd()
40+
process.chdir(`${FIXTURES_DIR}/${fixtureName}`)
41+
return process.chdir.bind(process, originalCwd)
42+
}
43+
3644
describe('preBuild()', () => {
3745
test('fail build if the app has static html export in npm script', async () => {
3846
await plugin.onPreBuild({
@@ -98,11 +106,7 @@ describe('preBuild()', () => {
98106
})
99107

100108
test(`fail build if the app's next config has an invalid target`, async () => {
101-
mockFs({
102-
'next.config.js': {
103-
target: 'nonsense',
104-
},
105-
})
109+
const restoreCwd = useFixture('invalid_next_config')
106110

107111
await plugin.onPreBuild({
108112
netlifyConfig: {},
@@ -111,7 +115,7 @@ describe('preBuild()', () => {
111115
constants: { FUNCTIONS_SRC: 'out_functions' },
112116
})
113117

114-
mockFs.restore()
118+
restoreCwd()
115119

116120
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
117121
expect(utils.build.failBuild.mock.calls[0][0]).toEqual(

0 commit comments

Comments
 (0)