mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
* Install and configure XState * userXService - typegen not working yet * Lint, fix error transitions * Lint * Change initial state to handle loss of state * Fix gitignore * Fix types by hook or by crook * Use xservice in all pages * Glue/visual component separation * Fix dependency merge * Lint * Remove UserContext * Remove inspector * Add typegen command to site/out * Fix index page redirects * DRY up nav and redirects * Moves based on merge * Moving Page helpers into Page dir * Move xservice into src, update script * Move and storybook navbarview * Update docs * Install MSW * Reorganization, with apologies * Missed spots * Add mock handlers * Configure jest for msw * Fix typos * Shift unit test to NavbarView * Fix test types * Rename NavbarView test * Attempt at test, wip * Fix config * Be logged out, only warn * Conditionally show text to help test * Use a Context for MSW's sake * mocks -> test_helpers * Enable dev tools * Format * Fix import * Fixes * Lint * run typegen postinstall Co-authored-by: Bryan Phelps <bryan@coder.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { server } from "./src/test_helpers/server"
|
|
|
|
// Establish API mocking before all tests through MSW.
|
|
beforeAll(() =>
|
|
server.listen({
|
|
onUnhandledRequest: "warn",
|
|
}),
|
|
)
|
|
|
|
// Reset any request handlers that we may add during the tests,
|
|
// so they don't affect other tests.
|
|
afterEach(() => server.resetHandlers())
|
|
|
|
// Clean up after the tests are finished.
|
|
afterAll(() => server.close())
|
|
|
|
// Helper utility to fail jest tests if a console.error is logged
|
|
// Pulled from this blog post:
|
|
// https://www.benmvp.com/blog/catch-warnings-jest-tests/
|
|
|
|
// For now, I limited this to just 'error' - but failing on warnings
|
|
// would be a nice next step! We may need to filter out some noise
|
|
// from material-ui though.
|
|
const CONSOLE_FAIL_TYPES = ["error" /* 'warn' */]
|
|
|
|
// Throw errors when a `console.error` or `console.warn` happens
|
|
// by overriding the functions
|
|
CONSOLE_FAIL_TYPES.forEach((logType: string) => {
|
|
// Suppressing the no-explicit-any to override certain console functions for testing
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const consoleAsAny = global.console as any
|
|
consoleAsAny[logType] = (message: string): void => {
|
|
throw new Error(`Failing due to console.${logType} while running test!\n\n${message}`)
|
|
}
|
|
})
|
|
|
|
// This is needed because we are compiling under `--isolatedModules`
|
|
export {}
|