mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-08 00:52:37 +01:00
📦 chore: npm audit bump (#12074)
* chore: npm audit - Bumped versions for several packages: `@hono/node-server` to 1.19.10, `@tootallnate/once` to 3.0.1, `hono` to 4.12.5, `serialize-javascript` to 7.0.4, and `svgo` to 2.8.2. - Removed deprecated `@trysound/sax` package from package-lock.json. - Updated integrity hashes and resolved URLs in package-lock.json to reflect the new versions. * chore: update dependencies and package versions - Bumped `jest-environment-jsdom` to version 30.2.0 in both package.json and client/package.json. - Updated related Jest packages to version 30.2.0 in package-lock.json, ensuring compatibility with the latest features and fixes. - Added `svgo` package with version 2.8.2 to package.json for improved SVG optimization. * chore: add @happy-dom/jest-environment and update test files - Added `@happy-dom/jest-environment` version 20.8.3 to `package.json` and `package-lock.json` for improved testing environment. - Updated test files to utilize the new Jest environment, replacing mock implementations of `window.location` with `window.history.replaceState` for better clarity and maintainability. - Refactored tests in `SourcesErrorBoundary`, `useFocusChatEffect`, `AuthContext`, and `StartupLayout` to enhance reliability and reduce complexity.
This commit is contained in:
parent
956f8fb6f0
commit
0ef369af9b
7 changed files with 566 additions and 1208 deletions
|
|
@ -39,14 +39,12 @@ describe('useFocusChatEffect', () => {
|
|||
state: { focusChat: true },
|
||||
});
|
||||
|
||||
// Mock window.location
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
// Set default window.location
|
||||
window.history.replaceState({}, '', '/c/new');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
window.history.replaceState({}, '', '/');
|
||||
});
|
||||
|
||||
describe('Basic functionality', () => {
|
||||
|
|
@ -115,14 +113,7 @@ describe('useFocusChatEffect', () => {
|
|||
testDescription: string;
|
||||
}) => {
|
||||
test(`${testDescription}`, () => {
|
||||
// Mock window.location
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: windowLocationSearch,
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', `/c/new${windowLocationSearch}`);
|
||||
|
||||
// Mock React Router's location
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
|
|
@ -144,13 +135,7 @@ describe('useFocusChatEffect', () => {
|
|||
};
|
||||
|
||||
test('should use window.location.search instead of location.search', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '?agent_id=test_agent_id',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new?agent_id=test_agent_id');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
@ -223,13 +208,7 @@ describe('useFocusChatEffect', () => {
|
|||
});
|
||||
|
||||
test('should handle navigation immediately after URL parameter changes', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '?endpoint=openAI&model=gpt-4',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new?endpoint=openAI&model=gpt-4');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
@ -249,13 +228,7 @@ describe('useFocusChatEffect', () => {
|
|||
|
||||
jest.clearAllMocks();
|
||||
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '?agent_id=agent123',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new?agent_id=agent123');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new_changed',
|
||||
|
|
@ -275,13 +248,7 @@ describe('useFocusChatEffect', () => {
|
|||
});
|
||||
|
||||
test('should handle undefined or null search params gracefully', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: undefined,
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
@ -301,14 +268,6 @@ describe('useFocusChatEffect', () => {
|
|||
|
||||
jest.clearAllMocks();
|
||||
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: null,
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
search: null,
|
||||
|
|
@ -327,13 +286,7 @@ describe('useFocusChatEffect', () => {
|
|||
});
|
||||
|
||||
test('should handle navigation when location.state is null', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '?agent_id=agent123',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new?agent_id=agent123');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
@ -348,13 +301,7 @@ describe('useFocusChatEffect', () => {
|
|||
});
|
||||
|
||||
test('should handle navigation when location.state.focusChat is undefined', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '?agent_id=agent123',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new?agent_id=agent123');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
@ -369,13 +316,7 @@ describe('useFocusChatEffect', () => {
|
|||
});
|
||||
|
||||
test('should handle navigation when both search params are empty', () => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
pathname: '/c/new',
|
||||
search: '',
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
window.history.replaceState({}, '', '/c/new');
|
||||
|
||||
(useLocation as jest.Mock).mockReturnValue({
|
||||
pathname: '/c/new',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue