[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: replace crypto.randomUUID to allow insecure environments (fix #9… (#9339)

authored by

Carlo Jeske and committed by
GitHub
(Dec 29, 2025, 3:42 PM +0100) e6a3f8cc acfbe8a0

+40 -1
+13
test/browser/specs/insecure-context.test.ts
··· 1 + import os from 'node:os' 2 + import { expect, test } from 'vitest' 3 + import { instances, runBrowserTests } from './utils' 4 + 5 + // server.host = os.hostname // doesnt work on mac, therefore the test is only run on linux 6 + test.runIf(os.platform() === 'linux')('server-host check dynamic import at insecure context', async () => { 7 + const { stdout, stderr } = await runBrowserTests({ 8 + root: './fixtures/insecure-context', 9 + }) 10 + 11 + expect(stderr).toBe('') 12 + expect(stdout).toReportSummaryTestFiles({ passed: instances.length }) 13 + })
+19
test/browser/fixtures/insecure-context/vitest.config.ts
··· 1 + import { fileURLToPath } from "node:url"; 2 + import os from "node:os"; 3 + import { defineConfig } from "vitest/config"; 4 + import { instances, provider } from "../../settings"; 5 + 6 + export default defineConfig({ 7 + cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)), 8 + test: { 9 + browser: { 10 + enabled: true, 11 + headless: true, 12 + provider, 13 + instances, 14 + }, 15 + }, 16 + server: { 17 + host: os.hostname(), // To force an insecure-context, a host which is not 127.0.0.1 or localhost is needed 18 + }, 19 + });
+1 -1
packages/browser/src/client/public/esm-client-injector.js
··· 9 9 } 10 10 11 11 const { evaluatedModules } = __vitest_worker__ 12 - const moduleId = crypto.randomUUID() 12 + const moduleId = `${Math.random()}` 13 13 const viteModule = evaluatedModules.ensureModule(moduleId, moduleId) 14 14 15 15 viteModule.evaluated = false
+6
test/browser/fixtures/insecure-context/src/basic.test.ts
··· 1 + import { expect, test } from "vitest"; 2 + 3 + test("basic", async () => { 4 + expect(window.isSecureContext).toBe(false); 5 + expect(1).toBe((await import("./dynamic-import")).default); 6 + });
+1
test/browser/fixtures/insecure-context/src/dynamic-import.ts
··· 1 + export default 1;