From 3d61a79efadc1413435b7370ec85cbca88b7bf04 Mon Sep 17 00:00:00 2001 From: Cody Kaup Date: Mon, 23 Sep 2024 17:07:40 -0500 Subject: [PATCH] Allow null values in test files --- eslint.config.mjs | 1 + node-src/git/getParentCommits.test.ts | 2 +- node-src/index.test.ts | 2 +- node-src/lib/findChangedPackageFiles.test.ts | 3 +-- node-src/lib/getDependentStoryFiles.test.ts | 10 +++++----- node-src/tasks/report.test.ts | 4 ++-- node-src/tasks/verify.test.ts | 16 ++++++---------- node-src/ui/tasks/verify.stories.ts | 4 +++- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 761c9ce51..bd13530d3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -258,6 +258,7 @@ export default [ 'no-secrets/no-secrets': 'warn', 'max-lines': 'warn', 'jsdoc/require-jsdoc': 'off', + 'unicorn/no-null': 'off', // GraphQL returns `null` when there is no value }, }, ]; diff --git a/node-src/git/getParentCommits.test.ts b/node-src/git/getParentCommits.test.ts index fa2889271..3c35c5823 100644 --- a/node-src/git/getParentCommits.test.ts +++ b/node-src/git/getParentCommits.test.ts @@ -397,7 +397,7 @@ describe('getParentCommits', () => { const mockIndex = createMockIndex(repository, [['A', 'main']]); const mockIndexWithNullFirstBuildCommittedAt = (queryName, variables) => { if (queryName === 'FirstCommittedAtQuery') { - return { app: { firstBuild: {} } }; + return { app: { firstBuild: { committedAt: null } } }; } return mockIndex(queryName, variables); }; diff --git a/node-src/index.test.ts b/node-src/index.test.ts index cfd671700..8ad6fc790 100644 --- a/node-src/index.test.ts +++ b/node-src/index.test.ts @@ -180,7 +180,7 @@ vi.mock('node-fetch', () => ({ } if (query?.match('FirstCommittedAtQuery')) { - return { data: { app: { firstBuild: {} } } }; + return { data: { app: { firstBuild: { committedAt: null } } } }; } if (query?.match('HasBuildsWithCommitsQuery')) { diff --git a/node-src/lib/findChangedPackageFiles.test.ts b/node-src/lib/findChangedPackageFiles.test.ts index 4c05a09a7..744cbaa3d 100644 --- a/node-src/lib/findChangedPackageFiles.test.ts +++ b/node-src/lib/findChangedPackageFiles.test.ts @@ -141,7 +141,7 @@ describe('findChangedPackageFiles', () => { it('considers the file changed if it fails to parse', async () => { mockFileContents({ 'package.json': { - A: '', + A: null, HEAD: { dependencies: { a: '2' } }, }, }); @@ -445,7 +445,6 @@ describe('arePackageDependenciesEqual', () => { }); it('returns true if dependencies are null', () => { - // eslint-disable-next-line unicorn/no-null expect(arePackageDependenciesEqual({ dependencies: null }, { dependencies: null })).toBe(true); }); }); diff --git a/node-src/lib/getDependentStoryFiles.test.ts b/node-src/lib/getDependentStoryFiles.test.ts index 62e5bd17e..ed24ce2ad 100644 --- a/node-src/lib/getDependentStoryFiles.test.ts +++ b/node-src/lib/getDependentStoryFiles.test.ts @@ -221,7 +221,7 @@ describe('getDependentStoryFiles', () => { const changedFiles = ['src/foo.css']; const modules = [ { - id: '', + id: null, name: './src/foo.css?ngResource ', reasons: [{ moduleName: './src/foo.component.ts' }], }, @@ -614,22 +614,22 @@ describe('getDependentStoryFiles', () => { ], }, { - id: '', + id: null, name: './src/stories/Page.jsx', // changed reasons: [{ moduleName: './src/stories/Page.stories.jsx' }], }, { - id: '', + id: null, name: './src/stories/button.css', reasons: [{ moduleName: './src/stories/Button.jsx' }], }, { - id: '', + id: null, name: './src/stories/header.css', reasons: [{ moduleName: './src/stories/Header.jsx' }], }, { - id: '', + id: null, name: './src/stories/page.css', reasons: [{ moduleName: './src/stories/Page.jsx' }], }, diff --git a/node-src/tasks/report.test.ts b/node-src/tasks/report.test.ts index 49ae9148a..9cb5342a8 100644 --- a/node-src/tasks/report.test.ts +++ b/node-src/tasks/report.test.ts @@ -32,14 +32,14 @@ const mockTests = [ result: '', spec: { name: '', component: { name: '' } }, parameters: { viewportIsDefault: true, viewport: 1080 }, - mode: { name: '' }, + mode: { name: null }, }, { status: 'FAILED', result: '', spec: { name: '', component: { name: '' } }, parameters: { viewportIsDefault: false, viewport: 1080 }, - mode: { name: '' }, + mode: { name: null }, }, ]; diff --git a/node-src/tasks/verify.test.ts b/node-src/tasks/verify.test.ts index 4fe52ccca..9cbe66cee 100644 --- a/node-src/tasks/verify.test.ts +++ b/node-src/tasks/verify.test.ts @@ -60,12 +60,7 @@ describe('verifyBuild', () => { app: {}, startedAt: Date.now(), }; - const publishedBuild = { - ...build, - status: 'PUBLISHED', - startedAt: undefined, - upgradeBuilds: [], - }; + const publishedBuild = { ...build, status: 'PUBLISHED', startedAt: null, upgradeBuilds: [] }; const client = { runQuery: vi.fn() }; client.runQuery // We can safely poll three times without hitting the timeout @@ -111,6 +106,7 @@ describe('verifyBuild', () => { status: 'PUBLISHED', features: { uiTests: true, uiReview: false }, app: {}, + startedAt: null, upgradeBuilds: [], }; const client = { runQuery: vi.fn() }; @@ -129,9 +125,9 @@ describe('verifyBuild', () => { app: {}, startedAt: Date.now(), }; - const upgradeBuilds = [{}]; + const upgradeBuilds = [{ completedAt: null }]; const completed = [{ completedAt: Date.now() }]; - const publishedBuild = { ...build, status: 'PUBLISHED', startedAt: undefined, upgradeBuilds }; + const publishedBuild = { ...build, status: 'PUBLISHED', startedAt: null, upgradeBuilds }; const client = { runQuery: vi.fn() }; client.runQuery // Polling while upgrade builds are in progress is irrelevant @@ -159,8 +155,8 @@ describe('verifyBuild', () => { app: {}, startedAt: Date.now(), }; - const upgradeBuilds = [{}]; - const publishedBuild = { ...build, status: 'PUBLISHED', startedAt: undefined, upgradeBuilds }; + const upgradeBuilds = [{ completedAt: null }]; + const publishedBuild = { ...build, status: 'PUBLISHED', startedAt: null, upgradeBuilds }; const client = { runQuery: vi.fn() }; client.runQuery.mockReturnValue({ app: { build: publishedBuild } }); diff --git a/node-src/ui/tasks/verify.stories.ts b/node-src/ui/tasks/verify.stories.ts index 6b007f6b5..b7bfd4ea2 100644 --- a/node-src/ui/tasks/verify.stories.ts +++ b/node-src/ui/tasks/verify.stories.ts @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/no-null -- GraphQL returns `null` if a value doesn't exist */ import task from '../components/task'; import { awaitingUpgrades, @@ -46,7 +47,8 @@ export const RunOnlyNames = () => options: { onlyStoryNames: ['MyComponent/**'] }, } as any); -export const AwaitingUpgrades = () => awaitingUpgrades({} as any, [{ completedAt: 123 }, {}]); +export const AwaitingUpgrades = () => + awaitingUpgrades({} as any, [{ completedAt: 123 }, { completedAt: null }]); export const Started = () => success({ build } as any);