Skip to content

Use test fixtures #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@netlify/eslint-config-node": "^0.3.0",
"husky": "^4.3.0",
"jest": "^26.6.1",
"mock-fs": "^4.13.0",
"prettier": "^2.1.2",
"react": "^17.0.1",
"react-dom": "^17.0.1"
Expand All @@ -47,7 +46,8 @@
},
"jest": {
"testMatch": [
"**/test/**/*.js"
"**/test/**/*.js",
"!**/test/fixtures/**"
],
"verbose": true
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/invalid_next_config/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
target: 'server',
}
18 changes: 11 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path')
const process = require('process')
const nextOnNetlify = require('next-on-netlify')
const makef = require('makef')
const makeDir = require('make-dir')
const cpx = require('cpx')
const mockFs = require('mock-fs')
const plugin = require('../index')

const utils = {
Expand Down Expand Up @@ -33,6 +33,14 @@ console.log('Initializing tests')

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

const FIXTURES_DIR = `${__dirname}/fixtures`

const useFixture = function (fixtureName) {
const originalCwd = process.cwd()
process.chdir(`${FIXTURES_DIR}/${fixtureName}`)
return process.chdir.bind(process, originalCwd)
}

describe('preBuild()', () => {
test('fail build if the app has static html export in npm script', async () => {
await plugin.onPreBuild({
Expand Down Expand Up @@ -98,11 +106,7 @@ describe('preBuild()', () => {
})

test(`fail build if the app's next config has an invalid target`, async () => {
mockFs({
'next.config.js': {
target: 'nonsense',
},
})
const restoreCwd = useFixture('invalid_next_config')

await plugin.onPreBuild({
netlifyConfig: {},
Expand All @@ -111,7 +115,7 @@ describe('preBuild()', () => {
constants: { FUNCTIONS_SRC: 'out_functions' },
})

mockFs.restore()
restoreCwd()

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