mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
refactor: move test-modes into commons to avoid js files in frontend
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
804fa325fb
commit
49ec70f2aa
18 changed files with 29 additions and 32 deletions
|
@ -6,3 +6,4 @@
|
|||
|
||||
export * from './wait-for-other-promises-to-finish.js'
|
||||
export type { DeepPartial } from './deep-partial.js'
|
||||
export * from './test-modes.js'
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* @param {string} value The value to check
|
||||
* @return {boolean} {@code true} if the value describes a positive answer string
|
||||
*/
|
||||
const isPositiveAnswer = (value) => {
|
||||
export const isPositiveAnswer = (value: string) => {
|
||||
const lowerValue = value.toLowerCase()
|
||||
return lowerValue === 'yes' || lowerValue === '1' || lowerValue === 'true'
|
||||
}
|
||||
|
@ -23,37 +23,35 @@ const isPositiveAnswer = (value) => {
|
|||
* Defines if the current runtime is built in e2e test mode.
|
||||
* @type boolean
|
||||
*/
|
||||
const isTestMode = !!process.env.NEXT_PUBLIC_TEST_MODE && isPositiveAnswer(process.env.NEXT_PUBLIC_TEST_MODE)
|
||||
export const isTestMode =
|
||||
!!process.env.NEXT_PUBLIC_TEST_MODE &&
|
||||
isPositiveAnswer(process.env.NEXT_PUBLIC_TEST_MODE)
|
||||
|
||||
/**
|
||||
* Defines if the current runtime should use the mocked backend.
|
||||
* @type boolean
|
||||
*/
|
||||
const isMockMode = !!process.env.NEXT_PUBLIC_USE_MOCK_API && isPositiveAnswer(process.env.NEXT_PUBLIC_USE_MOCK_API)
|
||||
export const isMockMode =
|
||||
!!process.env.NEXT_PUBLIC_USE_MOCK_API &&
|
||||
isPositiveAnswer(process.env.NEXT_PUBLIC_USE_MOCK_API)
|
||||
|
||||
/**
|
||||
* Defines if the current runtime was built in development mode.
|
||||
* @type boolean
|
||||
*/
|
||||
const isDevMode = process.env.NODE_ENV === 'development'
|
||||
export const isDevMode = process.env.NODE_ENV === 'development'
|
||||
|
||||
/**
|
||||
* Defines if the current runtime contains the bundle analyzer and profiling metrics.
|
||||
* @type boolean
|
||||
*/
|
||||
const isProfilingMode = !!process.env.ANALYZE && isPositiveAnswer(process.env.ANALYZE)
|
||||
export const isProfilingMode =
|
||||
!!process.env.ANALYZE && isPositiveAnswer(process.env.ANALYZE)
|
||||
|
||||
/**
|
||||
* Defines if the currently running process is building or executing.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
const isBuildTime = !!process.env.BUILD_TIME && isPositiveAnswer(process.env.BUILD_TIME)
|
||||
|
||||
module.exports = {
|
||||
isTestMode,
|
||||
isMockMode,
|
||||
isDevMode,
|
||||
isProfilingMode,
|
||||
isBuildTime
|
||||
}
|
||||
export const isBuildTime =
|
||||
!!process.env.BUILD_TIME && isPositiveAnswer(process.env.BUILD_TIME)
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
const { isMockMode, isTestMode, isProfilingMode, isBuildTime } = require('./src/utils/test-modes')
|
||||
const { isMockMode, isTestMode, isProfilingMode, isBuildTime } = require('@hedgedoc/commons')
|
||||
const path = require('path')
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import { GetApiRequestBuilder } from '../common/api-request-builder/get-api-request-builder'
|
||||
import type { FrontendConfig } from './types'
|
||||
import { isBuildTime } from '../../utils/test-modes'
|
||||
import { isBuildTime } from '@hedgedoc/commons'
|
||||
|
||||
/**
|
||||
* Fetches the frontend config from the backend.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import { refreshHistoryState } from '../../../redux/history/methods'
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { isDevMode, isTestMode } from '../../../utils/test-modes'
|
||||
import { isDevMode, isTestMode } from '@hedgedoc/commons'
|
||||
import { fetchAndSetUser } from '../../login-page/auth/utils'
|
||||
import { loadDarkMode } from './load-dark-mode'
|
||||
import { setUpI18n } from './setupI18n'
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isDevMode } from '../../../utils/test-modes'
|
||||
import { isDevMode } from '@hedgedoc/commons'
|
||||
import type { ResourceKey } from 'i18next'
|
||||
import i18n, { use as i18nUse } from 'i18next'
|
||||
import LanguageDetector from 'i18next-browser-languagedetector'
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { concatCssClasses } from '../../../utils/concat-css-classes'
|
||||
import { cypressAttribute, cypressId } from '../../../utils/cypress-attribute'
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { isTestMode } from '../../../utils/test-modes'
|
||||
import { isTestMode } from '@hedgedoc/commons'
|
||||
import { useEditorToRendererCommunicator } from '../../editor-page/render-context/editor-to-renderer-communicator-context-provider'
|
||||
import type { ScrollProps } from '../../editor-page/synced-scroll/scroll-props'
|
||||
import { useExtensionEventEmitter } from '../../markdown-renderer/hooks/use-extension-event-emitter'
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
import { useApplicationState } from '../../../../../hooks/common/use-application-state'
|
||||
import { getGlobalState } from '../../../../../redux'
|
||||
import { setRealtimeConnectionState } from '../../../../../redux/realtime/methods'
|
||||
import { Logger } from '../../../../../utils/logger'
|
||||
import { isMockMode } from '../../../../../utils/test-modes'
|
||||
import { Logger, isMockMode } from '@hedgedoc/commons'
|
||||
import { FrontendWebsocketAdapter } from './frontend-websocket-adapter'
|
||||
import { useWebsocketUrl } from './use-websocket-url'
|
||||
import { MessageTransporter, MockedBackendTransportAdapter } from '@hedgedoc/commons'
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import { useApplicationState } from '../../../../../hooks/common/use-application-state'
|
||||
import { useBaseUrl } from '../../../../../hooks/common/use-base-url'
|
||||
import { isMockMode } from '../../../../../utils/test-modes'
|
||||
import { isMockMode } from '@hedgedoc/commons'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
const LOCAL_FALLBACK_URL = 'ws://localhost:8080/realtime/'
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { isDevMode } from '../../../utils/test-modes'
|
||||
import { Logger, isDevMode } from '@hedgedoc/commons'
|
||||
import { MarkdownRendererExtension } from './_base-classes/markdown-renderer-extension'
|
||||
import type MarkdownIt from 'markdown-it'
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isMockMode, isTestMode } from '../utils/test-modes'
|
||||
import { isMockMode, isTestMode } from '@hedgedoc/commons'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
export enum HttpMethod {
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
respondToMatchingRequest,
|
||||
respondToTestRequest
|
||||
} from '../../../handler-utils/respond-to-matching-request'
|
||||
import { isTestMode } from '../../../utils/test-modes'
|
||||
import { isTestMode } from '@hedgedoc/commons'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
const initialConfig: FrontendConfig = {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import type { MediaUpload } from '../../../api/media/types'
|
||||
import { HttpMethod, respondToMatchingRequest } from '../../../handler-utils/respond-to-matching-request'
|
||||
import { isMockMode, isTestMode } from '../../../utils/test-modes'
|
||||
import { isMockMode, isTestMode } from '@hedgedoc/commons'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isDevMode } from '../utils/test-modes'
|
||||
import { isDevMode } from '@hedgedoc/commons'
|
||||
import type { ApplicationState } from './application-state'
|
||||
import { allReducers } from './reducers'
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import type { BaseUrls } from '../components/common/base-url/base-url-context-provider'
|
||||
import { Logger } from './logger'
|
||||
import { isTestMode, isBuildTime } from './test-modes'
|
||||
import { isTestMode, isBuildTime } from '@hedgedoc/commons'
|
||||
import { NoSubdirectoryAllowedError, parseUrl } from '@hedgedoc/commons'
|
||||
import { Optional } from '@mrdrogdrog/optional'
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isTestMode } from './test-modes'
|
||||
import { isTestMode } from '@hedgedoc/commons'
|
||||
|
||||
export interface PropsWithDataCypressId {
|
||||
'data-cypress-id'?: string | undefined
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Mock } from 'ts-mockery'
|
|||
|
||||
let testMode = false
|
||||
let devMode = false
|
||||
jest.mock('./test-modes', () => ({
|
||||
jest.mock('@hedgedoc/commons', () => ({
|
||||
get isTestMode() {
|
||||
return testMode
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isDevMode, isTestMode } from './test-modes'
|
||||
import { isDevMode, isTestMode } from '@hedgedoc/commons'
|
||||
import { DateTime } from 'luxon'
|
||||
import pico from 'picocolors'
|
||||
|
||||
|
|
Loading…
Reference in a new issue