Skip to content

Commit

Permalink
chore: remove cached bundle feature flag (#3638)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov authored Jan 10, 2025
1 parent ac9e926 commit bd76de4
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import { MemoryRouter, Route } from 'react-router-dom'

import CommitBundleAnalysis from './CommitBundleAnalysis'

const mocks = vi.hoisted(() => ({
useFlags: vi.fn(),
}))

vi.mock('shared/featureFlags', () => ({
useFlags: mocks.useFlags,
}))

vi.mock('./CommitBundleAnalysisTable', () => ({
default: () => <div>CommitBundleAnalysisTable</div>,
}))
Expand Down Expand Up @@ -190,7 +182,6 @@ interface SetupArgs {
firstPullRequest?: boolean
comparisonError?: boolean
hasCachedBundle?: boolean
featureFlag?: boolean
}

describe('CommitBundleAnalysis', () => {
Expand All @@ -203,7 +194,6 @@ describe('CommitBundleAnalysis', () => {
firstPullRequest = false,
comparisonError = false,
hasCachedBundle = false,
featureFlag = false,
}: SetupArgs = {
coverageEnabled: true,
bundleAnalysisEnabled: true,
Expand All @@ -212,11 +202,8 @@ describe('CommitBundleAnalysis', () => {
firstPullRequest: false,
comparisonError: false,
hasCachedBundle: false,
featureFlag: false,
}
) {
mocks.useFlags.mockReturnValue({ displayCachedBundleBanner: featureFlag })

server.use(
graphql.query('CommitPageData', () => {
return HttpResponse.json({
Expand Down Expand Up @@ -259,32 +246,30 @@ describe('CommitBundleAnalysis', () => {
expect(commitBundleAnalysisTable).toBeInTheDocument()
})

describe('feature flag is enabled', () => {
describe('there are cached bundles', () => {
it('renders CachedBundleContentBanner', async () => {
setup({ featureFlag: true, hasCachedBundle: true })
render(<CommitBundleAnalysis />, { wrapper })
describe('there are cached bundles', () => {
it('renders CachedBundleContentBanner', async () => {
setup({ hasCachedBundle: true })
render(<CommitBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
})

describe('there are no cached bundles', () => {
it('does not render CachedBundleContentBanner', async () => {
setup({ featureFlag: true, hasCachedBundle: false })
render(<CommitBundleAnalysis />, { wrapper })
describe('there are no cached bundles', () => {
it('does not render CachedBundleContentBanner', async () => {
setup({ hasCachedBundle: false })
render(<CommitBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())
await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
})

Expand Down Expand Up @@ -562,32 +547,30 @@ describe('CommitBundleAnalysis', () => {
})
})

describe('feature flag is enabled', () => {
describe('there are cached bundles', () => {
it('renders CachedBundleContentBanner', async () => {
setup({ featureFlag: true, hasCachedBundle: true })
render(<CommitBundleAnalysis />, { wrapper })
describe('there are cached bundles', () => {
it('renders CachedBundleContentBanner', async () => {
setup({ hasCachedBundle: true })
render(<CommitBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
})

describe('there are no cached bundles', () => {
it('does not render CachedBundleContentBanner', async () => {
setup({ featureFlag: true, hasCachedBundle: false })
render(<CommitBundleAnalysis />, { wrapper })
describe('there are no cached bundles', () => {
it('does not render CachedBundleContentBanner', async () => {
setup({ hasCachedBundle: false })
render(<CommitBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())
await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useParams } from 'react-router-dom'

import { CachedBundleContentBanner } from 'shared/CachedBundleContentBanner/CachedBundleContentBanner'
import ComparisonErrorBanner from 'shared/ComparisonErrorBanner'
import { useFlags } from 'shared/featureFlags'
import { ReportUploadType } from 'shared/utils/comparison'
import Spinner from 'ui/Spinner'

Expand Down Expand Up @@ -43,10 +42,6 @@ const BundleContent: React.FC<BundleContentProps> = ({
bundleCompareType,
hasCachedBundle,
}) => {
const { displayCachedBundleBanner } = useFlags({
displayCachedBundleBanner: false,
})

if (bundleCompareType === 'FirstPullRequest') {
return (
<>
Expand All @@ -70,9 +65,7 @@ const BundleContent: React.FC<BundleContentProps> = ({

return (
<>
{hasCachedBundle && displayCachedBundleBanner ? (
<CachedBundleContentBanner />
) : null}
{hasCachedBundle ? <CachedBundleContentBanner /> : null}
<Suspense fallback={<Loader />}>
<CommitBundleAnalysisTable />
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ import PullBundleAnalysis from './PullBundleAnalysis'

import { TBundleAnalysisComparisonResult } from '../queries/PullPageDataQueryOpts'

const mocks = vi.hoisted(() => ({
useFlags: vi.fn(),
}))

vi.mock('shared/featureFlags', () => ({
useFlags: mocks.useFlags,
}))

vi.mock('./EmptyTable', () => ({
default: () => <div>EmptyTable</div>,
}))
Expand Down Expand Up @@ -159,7 +151,6 @@ interface SetupArgs {
coverageEnabled?: boolean
bundleAnalysisEnabled?: boolean
hasCachedBundle?: boolean
featureFlag?: boolean
}

describe('PullBundleAnalysis', () => {
Expand All @@ -169,10 +160,7 @@ describe('PullBundleAnalysis', () => {
coverageEnabled = false,
bundleAnalysisEnabled = false,
hasCachedBundle = false,
featureFlag = false,
}: SetupArgs) {
mocks.useFlags.mockReturnValue({ displayCachedBundleBanner: featureFlag })

server.use(
graphql.query('PullPageData', () => {
return HttpResponse.json({
Expand Down Expand Up @@ -217,42 +205,38 @@ describe('PullBundleAnalysis', () => {
expect(table).toBeInTheDocument()
})

describe('feature flag is enabled', () => {
describe('there is a cached bundle', () => {
it('renders the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: true,
bundleAnalysisEnabled: true,
hasCachedBundle: true,
featureFlag: true,
})
render(<PullBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
describe('there is a cached bundle', () => {
it('renders the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: true,
bundleAnalysisEnabled: true,
hasCachedBundle: true,
})
render(<PullBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
})

describe('there is not a cached bundle', () => {
it('does not render the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: true,
bundleAnalysisEnabled: true,
hasCachedBundle: false,
featureFlag: true,
})
render(<PullBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
describe('there is not a cached bundle', () => {
it('does not render the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: true,
bundleAnalysisEnabled: true,
hasCachedBundle: false,
})
render(<PullBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
})
})
Expand Down Expand Up @@ -371,42 +355,38 @@ describe('PullBundleAnalysis', () => {
expect(table).toBeInTheDocument()
})

describe('feature flag is enabled', () => {
describe('there is a cached bundle', () => {
it('renders the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: false,
bundleAnalysisEnabled: true,
hasCachedBundle: true,
featureFlag: true,
})
render(<PullBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
describe('there is a cached bundle', () => {
it('renders the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: false,
bundleAnalysisEnabled: true,
hasCachedBundle: true,
})
render(<PullBundleAnalysis />, { wrapper })

const cachedBundleContentBanner = await screen.findByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).toBeInTheDocument()
})
})

describe('there is not a cached bundle', () => {
it('does not render the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: false,
bundleAnalysisEnabled: true,
hasCachedBundle: false,
featureFlag: true,
})
render(<PullBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
describe('there is not a cached bundle', () => {
it('does not render the CachedBundleContentBanner', async () => {
setup({
coverageEnabled: false,
bundleAnalysisEnabled: true,
hasCachedBundle: false,
})
render(<PullBundleAnalysis />, { wrapper })

await waitFor(() => queryClientV5.isFetching())
await waitFor(() => !queryClientV5.isFetching())

const cachedBundleContentBanner = screen.queryByText(
'The reported bundle size includes cached data from previous commits'
)
expect(cachedBundleContentBanner).not.toBeInTheDocument()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useParams } from 'react-router-dom'

import { CachedBundleContentBanner } from 'shared/CachedBundleContentBanner/CachedBundleContentBanner'
import ComparisonErrorBanner from 'shared/ComparisonErrorBanner'
import { useFlags } from 'shared/featureFlags'
import { ReportUploadType } from 'shared/utils/comparison'
import Spinner from 'ui/Spinner'

Expand Down Expand Up @@ -46,10 +45,6 @@ const BundleContent: React.FC<BundleContentProps> = ({
headHasBundle,
hasCachedBundle,
}) => {
const { displayCachedBundleBanner } = useFlags({
displayCachedBundleBanner: false,
})

if (bundleCompareType === 'FirstPullRequest') {
return (
<>
Expand Down Expand Up @@ -85,9 +80,7 @@ const BundleContent: React.FC<BundleContentProps> = ({

return (
<>
{hasCachedBundle && displayCachedBundleBanner ? (
<CachedBundleContentBanner />
) : null}
{hasCachedBundle ? <CachedBundleContentBanner /> : null}
<Suspense fallback={<Loader />}>
<PullBundleComparisonTable />
</Suspense>
Expand Down

0 comments on commit bd76de4

Please sign in to comment.