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

fix(frontend): fix test flakiness #1162

Merged
merged 7 commits into from
Apr 29, 2021
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
1 change: 0 additions & 1 deletion amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ frontend:
build:
commands:
- npm run build
- CI=true npm run test
- npm run upload-source-map
artifacts:
# IMPORTANT - Please verify your build output directory
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { InitializeOptions } from 'react-ga'
// Re-export these later on as constants
let gaInitializeOptions: InitializeOptions
let gaTrackingId: string
let announcementActive: string

/**
* Configs differentiated between environments
Expand All @@ -17,6 +18,9 @@ if (process.env.NODE_ENV === 'test') {
gaInitializeOptions = {
testMode: true,
}

// Disable announcements in test environments
announcementActive = 'false'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about disabling announcements for tests? I think it's fine since none of our tests rely on announcements currently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine. Given that for most of the flows, that's not the main thing we're testing for.

} else {
/**
* React env vars are used for injecting variables at build time
Expand Down Expand Up @@ -44,6 +48,9 @@ if (process.env.NODE_ENV === 'test') {
gaInitializeOptions = {
debug: false, // Set to true only on development
}

// `REACT_APP_ANNOUNCEMENT_ACTIVE` must be set to `true` in Amplify if we want the modal to display
announcementActive = process.env.REACT_APP_ANNOUNCEMENT_ACTIVE as string
}

/**
Expand Down Expand Up @@ -86,16 +93,10 @@ export const SENTRY_ENVIRONMENT =
(process.env.REACT_APP_SENTRY_ENVIRONMENT as string) || 'development'
export const INFO_BANNER = process.env.REACT_APP_INFO_BANNER as string

// `REACT_APP_ANNOUNCEMENT_ACTIVE` must be set to `true` in Amplify if we want the modal to display
function getAnnouncementActive() {
const envVar = process.env.REACT_APP_ANNOUNCEMENT_ACTIVE as string
return envVar === 'true'
}

// Feature Launch Announcements
// If `isActive` is false, the modal will not proc for ANY user
export const ANNOUNCEMENT: Record<string, any> = {
isActive: getAnnouncementActive(),
isActive: announcementActive === 'true',
title: t`announcement.title`,
subtext: t`announcement.subtext`,
mediaUrl: t`announcement.mediaUrl`,
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { Crypto } from '@peculiar/webcrypto'
import 'locales' // Locales necessary for I18nProvider
import { server } from './test-utils'

// Some tests take longer than the default 5s to run.
// Hence, allow the test timeout to be configured.
const TEST_TIMEOUT = +(process.env.REACT_APP_TEST_TIMEOUT ?? 20000)
jest.setTimeout(TEST_TIMEOUT)

// Mock WebCrypto APIs
// Redeclare the type of `global` as it does not include the `crypto` prop
interface Global extends NodeJS.Global {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/test-utils/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ function mockSettingsApis(state: State) {
})
)
}),
rest.put('/settings/announcement-version', (req, res, ctx) => {
const { announcement_version } = req.body as {
announcement_version?: string
}
if (!announcement_version) {
return res(ctx.status(400))
}
return res(ctx.status(200))
}),
rest.get('/settings/email/from', (_req, res, ctx) => {
return res(
ctx.status(200),
Expand Down