Skip to content

Commit 8dee792

Browse files
authored
Merge pull request #1239 from joshunrau/fix-test
fix issue with tests failing due to `VITE_DEV_BYPASS_AUTH` being used
2 parents 937cc32 + 6f5259b commit 8dee792

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "tsc && NODE_ENV=production NODE_OPTIONS='--import=tsx' pnpm exec vite build",
99
"dev": "NODE_ENV=development NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite",
10-
"dev:test": "NODE_ENV=test NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite",
10+
"dev:test": "NODE_ENV=test NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite --mode test",
1111
"format": "prettier --write src",
1212
"format:translations": "find src/translations -name '*.json' -exec pnpm exec sort-json {} \\;",
1313
"inject": "pnpm exec import-meta-env -x .env.public -p dist/index.html",

apps/web/src/routes/auth/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const RouteComponent = () => {
8080

8181
export const Route = createFileRoute('/auth/login')({
8282
beforeLoad: async () => {
83-
if (import.meta.env.DEV && config.dev.isBypassAuthEnabled) {
83+
if (import.meta.env.DEV && import.meta.env.MODE !== 'test' && config.dev.isBypassAuthEnabled) {
8484
const { login } = useAppStore.getState();
8585
const response = await loginRequest({
8686
password: config.dev.password!,

apps/web/src/services/axios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import axios, { isAxiosError } from 'axios';
55
import { config } from '@/config';
66
import { useAppStore } from '@/store';
77

8-
axios.defaults.baseURL = import.meta.env.MODE !== 'test' ? config.setup.apiBaseUrl : undefined;
8+
axios.defaults.baseURL = config.setup.apiBaseUrl;
99

1010
axios.interceptors.request.use((config) => {
1111
const accessToken = useAppStore.getState().accessToken;

apps/web/vite.config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22

3+
import { parseNumber } from '@douglasneuroinformatics/libjs';
34
import importMetaEnv from '@import-meta-env/unplugin';
45
import { getReleaseInfo } from '@opendatacapture/release-info';
56
import runtime from '@opendatacapture/vite-plugin-runtime';
@@ -9,6 +10,15 @@ import react from '@vitejs/plugin-react-swc';
910
import { defineConfig } from 'vite';
1011
import viteCompression from 'vite-plugin-compression';
1112

13+
const apiPort = parseNumber(process.env.API_DEV_SERVER_PORT);
14+
const webPort = parseNumber(process.env.WEB_DEV_SERVER_PORT);
15+
16+
if (Number.isNaN(apiPort)) {
17+
throw new Error(`Expected API_DEV_SERVER_PORT to be number, got ${process.env.API_DEV_SERVER_PORT}`);
18+
} else if (Number.isNaN(webPort)) {
19+
throw new Error(`Expected WEB_DEV_SERVER_PORT to be number, got ${process.env.WEB_DEV_SERVER_PORT}`);
20+
}
21+
1222
export default defineConfig({
1323
build: {
1424
chunkSizeWarningLimit: 1000,
@@ -45,13 +55,13 @@ export default defineConfig({
4555
}
4656
},
4757
server: {
48-
port: parseInt(process.env.WEB_DEV_SERVER_PORT ?? '3000'),
58+
port: webPort,
4959
proxy: {
5060
'/api/': {
5161
rewrite: (path) => path.replace(/^\/api/, ''),
5262
target: {
5363
host: 'localhost',
54-
port: parseInt(process.env.API_DEV_SERVER_PORT ?? '5500')
64+
port: apiPort
5565
}
5666
}
5767
}

testing/e2e/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default defineConfig({
7575
stderr: 'pipe',
7676
stdout: process.env.CI ? 'pipe' : 'ignore',
7777
timeout: 10_000,
78-
url: `http://localhost:${apiPort}`
78+
url: `http://localhost:${apiPort}/v1/setup`
7979
},
8080
{
8181
command: 'pnpm dev:test',

testing/e2e/src/global/global.setup.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.describe.serial(() => {
1212
});
1313
test('should successfully setup', async ({ setupPage }) => {
1414
await setupPage.fillSetupForm(initAppOptions);
15-
await setupPage.expect.toHaveURL('/dashboard');
15+
await setupPage.expect.toHaveURL('/auth/login');
1616
});
1717
test('should be setup after initialization', async ({ request }) => {
1818
const response = await request.get('/api/v1/setup');

testing/e2e/src/pages/__root.page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from '@playwright/test';
22
import type { Page } from '@playwright/test';
33

44
export abstract class RootPage {
5-
protected readonly $ref: Page;
5+
readonly $ref: Page;
66
protected abstract readonly defaultUrl: string;
77

88
constructor(page: Page) {

0 commit comments

Comments
 (0)