Merge pull request #1440 from acelaya-forks/feature/react-router-tests

Work around issue with react-router + vitest in node >22.10
This commit is contained in:
Alejandro Celaya 2025-02-06 09:43:17 +01:00 committed by GitHub
commit 6a8825ecb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -11,5 +11,5 @@ jobs:
ci: ci:
uses: shlinkio/github-actions/.github/workflows/web-app-ci.yml@main uses: shlinkio/github-actions/.github/workflows/web-app-ci.yml@main
with: with:
node-version: 22.10 node-version: 22.x
publish-coverage: true publish-coverage: true

View File

@ -2,7 +2,7 @@ services:
shlink_web_client_node: shlink_web_client_node:
container_name: shlink_web_client_node container_name: shlink_web_client_node
user: 1000:1000 # With this, files created via `indocker` script will belong to the host user user: 1000:1000 # With this, files created via `indocker` script will belong to the host user
image: node:22.10-alpine image: node:22.12-alpine
command: /bin/sh -c "cd /home/shlink/www && npm install && npm run start" command: /bin/sh -c "cd /home/shlink/www && npm install && npm run start"
volumes: volumes:
- ./:/home/shlink/www - ./:/home/shlink/www

View File

@ -1,9 +1,12 @@
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { VitePWA } from 'vite-plugin-pwa'; import { VitePWA } from 'vite-plugin-pwa';
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
import { manifest } from './manifest'; import { manifest } from './manifest';
import pack from './package.json' with { type: 'json' }; import pack from './package.json' with { type: 'json' };
const DEFAULT_NODE_VERSION = 'v22.10.0';
const nodeVersion = process.version ?? DEFAULT_NODE_VERSION;
const homepage = pack.homepage?.trim(); const homepage = pack.homepage?.trim();
/* eslint-disable-next-line no-restricted-exports */ /* eslint-disable-next-line no-restricted-exports */
@ -51,5 +54,15 @@ export default defineConfig({
lines: 95, lines: 95,
}, },
}, },
// Workaround for bug in react-router (or vitest module resolution) which causes different react-router versions to
// be resolved for the main package and dependencies who have a peer dependency in react-router.
// This ensures always the same version is resolved.
// See https://github.com/remix-run/react-router/issues/12785 for details
alias: nodeVersion > DEFAULT_NODE_VERSION
? {
'react-router': resolve(__dirname, 'node_modules/react-router/dist/development/index.mjs'),
}
: undefined,
}, },
}); });