Skip to content

Commit cc5a0a3

Browse files
authored
fix: Fix test mocking by deferring env var access (#115)
- Move VITE_APP_AZURESEARCH_* from module level to function body - Allows vi.stubEnv() to properly override environment variables in tests - Resolves timing issue where GitHub Actions empty string env prevented mocking
1 parent 59a0490 commit cc5a0a3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/components/SearchProcessor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ export const sortModes: SortMode[] = [
7979
},
8080
];
8181

82-
const { VITE_APP_AZURESEARCH_URL, VITE_APP_AZURESEARCH_KEY } = import.meta.env;
83-
8482
const SearchProcessor = (props: SearchProcessorProps): JSX.Element => {
8583
const [resultsCount, setResultsCount] = useState<number>(0);
8684
const [searching, setSearching] = useState<boolean>(false);
@@ -148,6 +146,8 @@ const SearchProcessor = (props: SearchProcessorProps): JSX.Element => {
148146
const abortController = new AbortController();
149147

150148
const fetchDataAsync = (abortSignal: AbortSignal): void => {
149+
const { VITE_APP_AZURESEARCH_URL, VITE_APP_AZURESEARCH_KEY } = import.meta.env;
150+
151151
setSearching(true);
152152

153153
if (!VITE_APP_AZURESEARCH_URL) {

0 commit comments

Comments
 (0)