Skip to content

Commit 45825ec

Browse files
[release-22.0] vtadmin: upgrade vite to the latest (#18803) (#18811)
Signed-off-by: Nick Van Wiggeren <[email protected]> Co-authored-by: Nick Van Wiggeren <[email protected]>
1 parent 40f5067 commit 45825ec

File tree

17 files changed

+1715
-6770
lines changed

17 files changed

+1715
-6770
lines changed

web/vtadmin/package-lock.json

Lines changed: 1625 additions & 927 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/vtadmin/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"@headlessui/react": "^1.7.8",
1212
"@types/d3": "^7.4.3",
1313
"@types/jest": "^29.4.0",
14-
"@types/node": "^16.11.7",
1514
"@types/react-router-dom": "^5.3.3",
1615
"classnames": "^2.3.2",
1716
"d3": "^7.9.0",
@@ -80,9 +79,10 @@
8079
"@testing-library/react-hooks": "^5.0.3",
8180
"@testing-library/user-event": "^14.2.0",
8281
"@types/lodash-es": "^4.17.4",
82+
"@types/node": "^24.9.1",
8383
"@types/react": "^18.0.31",
8484
"@types/react-dom": "^18.0.11",
85-
"@vitejs/plugin-react": "^3.1.0",
85+
"@vitejs/plugin-react": "^5.1.0",
8686
"autoprefixer": "^10.4.2",
8787
"cross-fetch": "^3.1.5",
8888
"eslint": "^8.37.0",
@@ -100,9 +100,9 @@
100100
"stylelint-config-standard-scss": "^3.0.0",
101101
"tailwindcss": "^3.0.18",
102102
"typescript": "^5.0.2",
103-
"vite": "^4.5.14",
103+
"vite": "^7.1.12",
104104
"vite-plugin-eslint": "^1.8.1",
105-
"vite-plugin-svgr": "^2.4.0",
106-
"vitest": "^0.29.8"
105+
"vite-plugin-svgr": "^4.5.0",
106+
"vitest": "^4.0.3"
107107
}
108108
}

web/vtadmin/src/api/http.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ import {
2424
MALFORMED_HTTP_RESPONSE_ERROR,
2525
} from '../errors/errorTypes';
2626
import * as errorHandler from '../errors/errorHandler';
27-
import { describe, it, expect, vi } from 'vitest';
27+
import { describe, it, expect, vi, afterEach } from 'vitest';
2828

2929
vi.mock('../errors/errorHandler');
3030

31+
// Preserve import.meta.env to restore after each test
32+
const ORIGINAL_ENV = { ...import.meta.env };
33+
3134
// mockServerJson configures an HttpOkResponse containing the given `json`
3235
// for all requests made against the given `endpoint`.
3336
const mockServerJson = (endpoint: string, json: object, status: number = 200) => {
@@ -36,6 +39,20 @@ const mockServerJson = (endpoint: string, json: object, status: number = 200) =>
3639
};
3740

3841
describe('api/http', () => {
42+
afterEach(() => {
43+
// Restore import.meta.env after each test to prevent leakage
44+
// First, delete any keys that weren't in the original
45+
for (const key in import.meta.env) {
46+
if (!(key in ORIGINAL_ENV)) {
47+
delete import.meta.env[key];
48+
}
49+
}
50+
// Then restore the original values
51+
Object.assign(import.meta.env, ORIGINAL_ENV);
52+
// Reset all mocks to prevent leakage
53+
vi.clearAllMocks();
54+
});
55+
3956
describe('vtfetch', () => {
4057
it('parses and returns JSON, given an HttpOkResponse response', async () => {
4158
const endpoint = `/api/tablets`;
@@ -141,6 +158,9 @@ describe('api/http', () => {
141158
});
142159

143160
it('uses the fetch default `credentials` property by default', async () => {
161+
// Explicitly unset VITE_FETCH_CREDENTIALS to test default behavior
162+
delete import.meta.env.VITE_FETCH_CREDENTIALS;
163+
144164
vi.spyOn(global, 'fetch');
145165

146166
const endpoint = `/api/tablets`;
@@ -157,7 +177,7 @@ describe('api/http', () => {
157177
});
158178

159179
it('throws an error if an invalid value used for `credentials`', async () => {
160-
(process as any).env.VITE_FETCH_CREDENTIALS = 'nope';
180+
import.meta.env.VITE_FETCH_CREDENTIALS = 'nope';
161181

162182
vi.spyOn(global, 'fetch');
163183

@@ -185,7 +205,7 @@ describe('api/http', () => {
185205
});
186206

187207
it('allows GET requests when in read only mode', async () => {
188-
(process as any).env.VITE_READONLY_MODE = 'true';
208+
import.meta.env.VITE_READONLY_MODE = 'true';
189209

190210
const endpoint = `/api/tablets`;
191211
const response = { ok: true, result: null };
@@ -199,7 +219,7 @@ describe('api/http', () => {
199219
});
200220

201221
it('throws an error when executing a write request in read only mode', async () => {
202-
(process as any).env.VITE_READONLY_MODE = 'true';
222+
import.meta.env.VITE_READONLY_MODE = 'true';
203223

204224
vi.spyOn(global, 'fetch');
205225

web/vtadmin/src/components/ReadOnlyGate.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const ORIGINAL_PROCESS_ENV = { ...import.meta.env };
2323

2424
describe('ReadOnlyGate', () => {
2525
afterEach(() => {
26-
import.meta.env = ORIGINAL_PROCESS_ENV;
26+
Object.assign(import.meta.env, ORIGINAL_PROCESS_ENV);
2727
});
2828

2929
it('hides children when in read-only mode', () => {
30-
(process as any).env.VITE_READONLY_MODE = 'true';
30+
import.meta.env.VITE_READONLY_MODE = 'true';
3131

3232
render(
3333
<ReadOnlyGate>
@@ -40,6 +40,8 @@ describe('ReadOnlyGate', () => {
4040
});
4141

4242
it('shows children when not in read-only mode', () => {
43+
import.meta.env.VITE_READONLY_MODE = 'false';
44+
4345
render(
4446
<ReadOnlyGate>
4547
<div data-testid="child">🌶🌶🌶</div>

0 commit comments

Comments
 (0)