From c9a66f228d2f86287b6919da57a52fe8bea4bde8 Mon Sep 17 00:00:00 2001 From: benhancock Date: Wed, 9 Oct 2024 12:56:06 -0400 Subject: [PATCH 1/5] fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer --- src/commands/logs/build.ts | 5 +++++ tests/integration/commands/logs/build.test.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/commands/logs/build.ts b/src/commands/logs/build.ts index 502d1b97d92..044ac59f72d 100644 --- a/src/commands/logs/build.ts +++ b/src/commands/logs/build.ts @@ -39,6 +39,11 @@ export const logsBuild = async (options: OptionValues, command: BaseCommand) => const { id: siteId } = site const userId = command.netlify.globalConfig.get('userId') + if (!siteId) { + log("You must link a site before attempting to view deploy logs") + return + } + const deploys = await client.listSiteDeploys({ siteId, state: 'building' }) if (deploys.length === 0) { diff --git a/tests/integration/commands/logs/build.test.ts b/tests/integration/commands/logs/build.test.ts index dc1e654f039..2d8dd14d270 100644 --- a/tests/integration/commands/logs/build.test.ts +++ b/tests/integration/commands/logs/build.test.ts @@ -5,6 +5,7 @@ import { createLogsBuildCommand } from '../../../../src/commands/logs/index.js' import { getWebSocket } from '../../../../src/utils/websockets/index.js' import { startMockApi } from '../../utils/mock-api-vitest.js' import { getEnvironmentVariables } from '../../utils/mock-api.js' +import { callCli } from '../../utils/call-cli.js' vi.mock('../../../../src/utils/websockets/index.js', () => ({ getWebSocket: vi.fn(), @@ -107,4 +108,10 @@ describe('logs:deploy command', () => { expect(body.site_id).toEqual('site_id') expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN) }) + + test.only('should instruct user to link a site if one is not linked', async () => { + expect(process.env.NETLIFY_SITE_ID).toBe(undefined) + const stdout = await callCli(['logs:deploy']) + expect(stdout).toContain('You must link a site before attempting to view deploy logs') + }) }) From e1b190fd144e81e85ca8e2c854aa3a8d061999ce Mon Sep 17 00:00:00 2001 From: Ben Hancock Date: Wed, 9 Oct 2024 14:54:42 -0400 Subject: [PATCH 2/5] fix: logs: deploy command instructs user to link to a site if one is not linked --- tests/integration/commands/logs/build.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/commands/logs/build.test.ts b/tests/integration/commands/logs/build.test.ts index 2d8dd14d270..8c872c32e55 100644 --- a/tests/integration/commands/logs/build.test.ts +++ b/tests/integration/commands/logs/build.test.ts @@ -109,7 +109,7 @@ describe('logs:deploy command', () => { expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN) }) - test.only('should instruct user to link a site if one is not linked', async () => { + test('should instruct user to link a site if one is not linked', async () => { expect(process.env.NETLIFY_SITE_ID).toBe(undefined) const stdout = await callCli(['logs:deploy']) expect(stdout).toContain('You must link a site before attempting to view deploy logs') From aa5dac1e3716d08399b6dc6ff0028595fd3f7bab Mon Sep 17 00:00:00 2001 From: benhancock Date: Wed, 9 Oct 2024 16:22:35 -0400 Subject: [PATCH 3/5] fix: logs:deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer --- src/commands/logs/build.ts | 2 +- tests/integration/commands/logs/build.test.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/logs/build.ts b/src/commands/logs/build.ts index 044ac59f72d..d16fdf43bd4 100644 --- a/src/commands/logs/build.ts +++ b/src/commands/logs/build.ts @@ -40,7 +40,7 @@ export const logsBuild = async (options: OptionValues, command: BaseCommand) => const userId = command.netlify.globalConfig.get('userId') if (!siteId) { - log("You must link a site before attempting to view deploy logs") + log('You must link a site before attempting to view deploy logs') return } diff --git a/tests/integration/commands/logs/build.test.ts b/tests/integration/commands/logs/build.test.ts index 2d8dd14d270..9ef6d16051b 100644 --- a/tests/integration/commands/logs/build.test.ts +++ b/tests/integration/commands/logs/build.test.ts @@ -48,12 +48,14 @@ const routes = [ describe('logs:deploy command', () => { let program: BaseCommand + const originalEnv = { ...process.env } afterEach(() => { vi.clearAllMocks() }) beforeEach(() => { + process.env = { ...originalEnv } program = new BaseCommand('netlify') createLogsBuildCommand(program) @@ -109,7 +111,7 @@ describe('logs:deploy command', () => { expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN) }) - test.only('should instruct user to link a site if one is not linked', async () => { + test('should instruct user to link a site if one is not linked', async () => { expect(process.env.NETLIFY_SITE_ID).toBe(undefined) const stdout = await callCli(['logs:deploy']) expect(stdout).toContain('You must link a site before attempting to view deploy logs') From 4175d897f7b39f6eb0c6e60808f56bde831c3625 Mon Sep 17 00:00:00 2001 From: benhancock Date: Thu, 10 Oct 2024 10:31:29 -0400 Subject: [PATCH 4/5] fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer --- tests/integration/commands/logs/build.test.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/integration/commands/logs/build.test.ts b/tests/integration/commands/logs/build.test.ts index 9ef6d16051b..aadee4ed8c3 100644 --- a/tests/integration/commands/logs/build.test.ts +++ b/tests/integration/commands/logs/build.test.ts @@ -6,6 +6,9 @@ import { getWebSocket } from '../../../../src/utils/websockets/index.js' import { startMockApi } from '../../utils/mock-api-vitest.js' import { getEnvironmentVariables } from '../../utils/mock-api.js' import { callCli } from '../../utils/call-cli.js' +import { getCLIOptions, withMockApi } from '../../utils/mock-api.js' +import { withSiteBuilder } from '../../utils/site-builder.ts' +import { join } from 'path' vi.mock('../../../../src/utils/websockets/index.js', () => ({ getWebSocket: vi.fn(), @@ -111,9 +114,20 @@ describe('logs:deploy command', () => { expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN) }) - test('should instruct user to link a site if one is not linked', async () => { - expect(process.env.NETLIFY_SITE_ID).toBe(undefined) - const stdout = await callCli(['logs:deploy']) - expect(stdout).toContain('You must link a site before attempting to view deploy logs') + test('should instruct user to link a site if one is not linked', async (t) => { + await withSiteBuilder(t, async (builder) => { + const projectPath = join('projects', 'project1') + await builder.withNetlifyToml({ config: {}, pathPrefix: projectPath }).build() + + await withMockApi( + routes, + async ({ apiUrl }) => { + const options = getCLIOptions({ builder, apiUrl, env: { NETLIFY_SITE_ID: '' }}) + const stdout = await callCli(['logs:deploy'], { ...options, cwd: join(builder.directory, projectPath) }) + expect(stdout).toContain('You must link a site before attempting to view deploy logs') + }, + true, + ) + }) }) }) From c4556f890d3ed8473e5b40d70e4e8abc4297664e Mon Sep 17 00:00:00 2001 From: benhancock Date: Thu, 10 Oct 2024 10:34:38 -0400 Subject: [PATCH 5/5] fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer --- tests/integration/commands/logs/build.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/commands/logs/build.test.ts b/tests/integration/commands/logs/build.test.ts index aadee4ed8c3..956bab228a4 100644 --- a/tests/integration/commands/logs/build.test.ts +++ b/tests/integration/commands/logs/build.test.ts @@ -122,7 +122,7 @@ describe('logs:deploy command', () => { await withMockApi( routes, async ({ apiUrl }) => { - const options = getCLIOptions({ builder, apiUrl, env: { NETLIFY_SITE_ID: '' }}) + const options = getCLIOptions({ builder, apiUrl, env: { NETLIFY_SITE_ID: '' } }) const stdout = await callCli(['logs:deploy'], { ...options, cwd: join(builder.directory, projectPath) }) expect(stdout).toContain('You must link a site before attempting to view deploy logs') },