Skip to content
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

Add tests for netlify build #837

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 48 additions & 0 deletions src/tests/build.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const test = require('ava')
const execa = require('execa')

const BIN_PATH = `${__dirname}/../../bin/run`
const FIXTURE_DIR = __dirname

// Runs `netlify build ...flags` then verify:
// - its exit code is `exitCode`
// - that its output contains `output`
// The command is run in the fixture directory `fixtureSubDir`.
const runBuildCommand = async function(t, fixtureSubDir, { exitCode: expectedExitCode = 0, output, flags = [] } = {}) {
const { all, exitCode } = await execa(BIN_PATH, ['build', ...flags], {
reject: false,
cwd: `${FIXTURE_DIR}/${fixtureSubDir}`,
env: { FORCE_COLOR: '1' },
all: true
})
t.is(exitCode, expectedExitCode)
t.true(all.includes(output))
}

test('build command - succeeds', async t => {
await runBuildCommand(t, 'success-site', { output: 'testCommand' })
})

test('build command - fails', async t => {
await runBuildCommand(t, 'failure-site', { exitCode: 1, output: 'doesNotExist' })
})

test('build command - uses the CLI mode', async t => {
await runBuildCommand(t, 'success-site', { output: 'mode: cli' })
})

test('build command - can use the --dry flag', async t => {
await runBuildCommand(t, 'success-site', { flags: ['--dry'], output: 'If this looks good to you' })
})

test('build command - can use the --context flag', async t => {
await runBuildCommand(t, 'context-site', { flags: ['--context=staging'], output: 'testStaging' })
})

test('build command - can run in subdirectories', async t => {
await runBuildCommand(t, 'subdir-site/subdir', { output: 'testCommand' })
})

test('build command - wrong config', async t => {
await runBuildCommand(t, 'wrong-config-site', { exitCode: 1, output: 'Invalid syntax' })
})
5 changes: 5 additions & 0 deletions src/tests/context-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
command = "echo testCommand"

[context.staging]
command = "echo testStaging"
2 changes: 2 additions & 0 deletions src/tests/failure-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = "doesNotExist"
2 changes: 2 additions & 0 deletions src/tests/subdir-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = "echo testCommand"
Empty file.
2 changes: 2 additions & 0 deletions src/tests/success-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = "echo testCommand"
2 changes: 2 additions & 0 deletions src/tests/wrong-config-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = false