diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18e073c8f..29e0bf2fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,4 +40,4 @@ jobs: - name: Test Project run: yarn test - name: Build project - run: yarn build + run: yarn build:production diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 90cf7f96d..b4b5e6399 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -42,7 +42,7 @@ jobs: node-version: 14 - run: yarn install --frozen-lockfile --prefer-offline - - run: yarn build + - run: yarn build:test - uses: actions/upload-artifact@master with: name: build @@ -64,7 +64,7 @@ jobs: - uses: cypress-io/github-action@v2 with: browser: ${{ matrix.browser }} - start: 'yarn build:serve' + start: 'yarn serve:build' - uses: actions/upload-artifact@master if: always() with: diff --git a/README.md b/README.md index e4f2ad771..cca78a30c 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ Unit testing is done via jest. We use [cypress](https://cypress.io) for e2e tests. -1. Start the frontend with `yarn start` +1. Start the frontend with `yarn start:test` in dev test mode or build a test build with `yarn build:test` which you can serve with `yarn serve:build` + Don't use the regular start/build command, or the tests will fail! 2. Run `yarn cy:open` to open the cypress test loader 3. Choose your browser and test 4. Let the tests run diff --git a/package.json b/package.json index ae8777f42..4846b6f54 100644 --- a/package.json +++ b/package.json @@ -107,11 +107,13 @@ "vega-lite": "4.17.0" }, "scripts": { - "start": "PORT=3001 craco start", - "start:for-real-backend": "REACT_APP_BACKEND=http://localhost:3000 yarn start", - "build:serve": "http-server build/ -s -p 3001 -P \"http://127.0.0.1:3001?\"", - "build": "craco build", - "analyze": "cross-env ANALYZE=true craco build", + "start": "cross-env PORT=3001 craco start", + "start:test": "cross-env PORT=3001 REACT_APP_TEST_MODE=true craco start", + "start:for-real-backend": "cross-env REACT_APP_BACKEND=http://localhost:3000 yarn start", + "serve:build": "http-server build/ -s -p 3001 -P \"http://127.0.0.1:3001?\"", + "build:test": "cross-env REACT_APP_TEST_MODE=true craco build", + "build:production": "craco build", + "analyze": "cross-env ANALYZE=true craco build:production", "test": "craco test", "lint": "eslint --max-warnings=0 --ext .ts,.tsx src", "eject": "react-scripts eject", diff --git a/src/index.tsx b/src/index.tsx index 4d3bdec25..85ebef6d2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -23,6 +23,7 @@ import { store } from './redux' import * as serviceWorkerRegistration from './service-worker-registration' import './style/dark.scss' import './style/index.scss' +import { isTestMode } from './utils/is-test-mode' const Editor = React.lazy(() => import(/* webpackPrefetch: true */ './components/editor/editor')) @@ -80,6 +81,10 @@ ReactDOM.render( , document.getElementById('root') ) +if (isTestMode()) { + console.log("This build runs in test mode") +} + // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA diff --git a/src/utils/is-test-mode.ts b/src/utils/is-test-mode.ts new file mode 100644 index 000000000..f94227908 --- /dev/null +++ b/src/utils/is-test-mode.ts @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export const isTestMode = (): boolean => { + return !!process.env.REACT_APP_TEST_MODE +}