Skip to content

Commit 856a012

Browse files
committed
Fix SDK's browser tests
1 parent c45177f commit 856a012

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

packages/browser-test-runner/src/createKarmaConfig.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import type { Configuration, ExternalItem } from 'webpack'
44

55
const DEBUG_MODE = process.env.BROWSER_TEST_DEBUG_MODE ?? false
66

7+
export interface KarmaConfigOptions {
8+
// File patterns to serve but not include in the test bundle (e.g. worker files)
9+
servedFiles?: string[]
10+
}
11+
712
export const createKarmaConfig = (
8-
testPaths: string[], webpackConfig: () => Configuration, localDirectory?: string
13+
testPaths: string[],
14+
webpackConfig: () => Configuration,
15+
localDirectory?: string,
16+
options: KarmaConfigOptions = {}
917
): (config: any) => any => {
1018
const setupFiles = [fileURLToPath(new URL('./karma-setup.js', import.meta.url))]
1119

@@ -57,7 +65,13 @@ export const createKarmaConfig = (
5765
reporters: ['spec'],
5866
files: [
5967
...setupFiles,
60-
...testPaths
68+
...testPaths,
69+
...(options.servedFiles ?? []).map((pattern) => ({
70+
pattern,
71+
included: false,
72+
served: true,
73+
watched: false
74+
}))
6175
],
6276
preprocessors,
6377
customLaunchers: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { createKarmaConfig } from './createKarmaConfig'
2+
export type { KarmaConfigOptions } from './createKarmaConfig'
23
export { createWebpackConfig } from './createWebpackConfig'

packages/sdk/createKarmaConfig.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function createKarmaConfig(testPaths: string[]): ReturnType<typeof create
1515
'test/test-utils/jestGlobalsMock.ts'
1616
),
1717
'@streamr/dht': resolve(__dirname, '../dht/dist/exports-browser.cjs'),
18+
"@/createSignatureValidationWorker": resolve(__dirname, 'src/_karma/createSignatureValidationWorker.ts'),
1819
'@': resolve(__dirname, 'src/_browser'),
1920
},
2021
fallback: {
@@ -30,6 +31,9 @@ export function createKarmaConfig(testPaths: string[]): ReturnType<typeof create
3031
'node:timers/promises': 'timers/promises',
3132
},
3233
}),
33-
__dirname
34+
__dirname,
35+
{
36+
servedFiles: ['dist/*.mjs']
37+
}
3438
)
3539
}

packages/sdk/rollup.config.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ const browserAliases: Alias[] = [
2929
]
3030

3131
export default defineConfig([
32+
workerNodejs(),
33+
workerBrowser(),
3234
nodejs(),
3335
nodejsTypes(),
3436
browser(),
3537
browserTypes(),
3638
umd(),
3739
umdMinified(),
38-
workerNodejs(),
39-
workerBrowser(),
4040
])
4141

4242
function onwarn(log: RollupLog, rollupWarn: (log: RollupLog) => void): void {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Browser-specific signature validation worker factory.
3+
*/
4+
import Worker from 'web-worker'
5+
6+
export function createSignatureValidationWorker(): InstanceType<typeof Worker> {
7+
return new Worker(
8+
new URL('../../dist/workers/SignatureValidationWorker.browser.mjs', import.meta.url),
9+
{ type: 'module' }
10+
)
11+
}

0 commit comments

Comments
 (0)