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

test(command-build): don't run on forked repos #1768

Merged
merged 1 commit into from
Jan 18, 2021
Merged
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
133 changes: 68 additions & 65 deletions tests/command.build.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path')
const process = require('process')

const test = require('ava')
const execa = require('execa')
Expand Down Expand Up @@ -26,103 +27,105 @@ const runBuildCommand = async function (t, cwd, { exitCode: expectedExitCode = 0
t.is(exitCode, expectedExitCode)
}

test('should print output for a successful command', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
if (process.env.IS_FORK !== 'true') {
test('should print output for a successful command', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { output: 'testCommand' })
await runBuildCommand(t, builder.directory, { output: 'testCommand' })
})
})
})

test('should print output for a failed command', async (t) => {
await withSiteBuilder('failure-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'doesNotExist' } } })
test('should print output for a failed command', async (t) => {
await withSiteBuilder('failure-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'doesNotExist' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { exitCode: 2, output: 'doesNotExist' })
await runBuildCommand(t, builder.directory, { exitCode: 2, output: 'doesNotExist' })
})
})
})

test('should set the build mode to cli', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
test('should set the build mode to cli', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { output: 'mode: cli' })
await runBuildCommand(t, builder.directory, { output: 'mode: cli' })
})
})
})

test('should run in dry mode when the --dry flag is set', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
test('should run in dry mode when the --dry flag is set', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { flags: ['--dry'], output: 'If this looks good to you' })
})
})

test('should run the staging context command when the --context option is set to staging', async (t) => {
await withSiteBuilder('context-site', async (builder) => {
builder.withNetlifyToml({
config: {
build: { command: 'echo testCommand' },
context: { staging: { command: 'echo testStaging' } },
},
await runBuildCommand(t, builder.directory, { flags: ['--dry'], output: 'If this looks good to you' })
})
})

test('should run the staging context command when the --context option is set to staging', async (t) => {
await withSiteBuilder('context-site', async (builder) => {
builder.withNetlifyToml({
config: {
build: { command: 'echo testCommand' },
context: { staging: { command: 'echo testStaging' } },
},
})

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { flags: ['--context=staging'], output: 'testStaging' })
await runBuildCommand(t, builder.directory, { flags: ['--context=staging'], output: 'testStaging' })
})
})
})

test('should print debug information when the --debug flag is set', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
test('should print debug information when the --debug flag is set', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { flags: ['--debug'], output: 'Resolved config' })
await runBuildCommand(t, builder.directory, { flags: ['--debug'], output: 'Resolved config' })
})
})
})

test('should use root directory netlify.toml when runs in subdirectory', async (t) => {
await withSiteBuilder('subdir-site', async (builder) => {
builder
.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
.withContentFile({ path: path.join('subdir', '.gitkeep'), content: '' })
test('should use root directory netlify.toml when runs in subdirectory', async (t) => {
await withSiteBuilder('subdir-site', async (builder) => {
builder
.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
.withContentFile({ path: path.join('subdir', '.gitkeep'), content: '' })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, path.join(builder.directory, 'subdir'), { output: 'testCommand' })
await runBuildCommand(t, path.join(builder.directory, 'subdir'), { output: 'testCommand' })
})
})
})

test('should error when using invalid netlify.toml', async (t) => {
await withSiteBuilder('wrong-config-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: false } } })
test('should error when using invalid netlify.toml', async (t) => {
await withSiteBuilder('wrong-config-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: false } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, { exitCode: 1, output: 'Invalid syntax' })
await runBuildCommand(t, builder.directory, { exitCode: 1, output: 'Invalid syntax' })
})
})
})

test('should error when a site id is missing', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })
test('should error when a site id is missing', async (t) => {
await withSiteBuilder('success-site', async (builder) => {
builder.withNetlifyToml({ config: { build: { command: 'echo testCommand' } } })

await builder.buildAsync()
await builder.buildAsync()

await runBuildCommand(t, builder.directory, {
exitCode: 1,
output: 'Could not find the site ID',
env: { NODE_ENV: '' },
await runBuildCommand(t, builder.directory, {
exitCode: 1,
output: 'Could not find the site ID',
env: { NODE_ENV: '' },
})
})
})
})
}