Skip to content

Commit 8d323a4

Browse files
committed
fix: replace crypto.randomUUID to allow insecure environments (fix #9338)
crypto.randomUUID is not available in the browser in case it gets executed in an insecure environment Math.random() should suffice for mocking
1 parent 23ff7c3 commit 8d323a4

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/browser/src/client/public/esm-client-injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010

1111
const { evaluatedModules } = __vitest_worker__
12-
const moduleId = crypto.randomUUID()
12+
const moduleId = `${Math.random()}`
1313
const viteModule = evaluatedModules.ensureModule(moduleId, moduleId)
1414

1515
viteModule.evaluated = false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from "vitest";
2+
3+
test("basic", async () => {
4+
expect(1).toBe((await import("./dynamic-import")).default);
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 1;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os from "node:os";
2+
import { defineConfig } from "vitest/config";
3+
import { instances, provider } from "../../settings";
4+
5+
export default defineConfig({
6+
test: {
7+
browser: {
8+
enabled: true,
9+
headless: true,
10+
provider,
11+
instances,
12+
},
13+
},
14+
server: {
15+
host: os.hostname(),
16+
},
17+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from 'vitest'
2+
import { instances, runBrowserTests } from './utils'
3+
4+
test('server-host check dynamic import at insecure context', async () => {
5+
const { stdout, stderr } = await runBrowserTests({
6+
root: './fixtures/server-insecure',
7+
})
8+
9+
expect(stderr).toBe('')
10+
expect(stdout).toReportSummaryTestFiles({ passed: instances.length })
11+
})

0 commit comments

Comments
 (0)