-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathtest-helpers.mjs
More file actions
63 lines (55 loc) · 1.35 KB
/
test-helpers.mjs
File metadata and controls
63 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ESM Test Configuration
import { performance as perf } from 'perf_hooks'
export const testConfig = {
timeout: 10000,
slow: 2000,
nodeOptions: '--experimental-loader=esmock'
}
// Utility to create test servers with ESM modules
export async function createTestServer (options = {}) {
const { default: createApp } = await import('../index.mjs')
const defaultOptions = {
port: 0, // Random port
serverUri: 'https://localhost',
webid: true,
multiuser: false,
...options
}
const app = createApp(defaultOptions)
return app
}
// Utility to test ESM import functionality
export async function testESMImport (modulePath) {
try {
const module = await import(modulePath)
return {
success: true,
module,
hasDefault: 'default' in module,
namedExports: Object.keys(module).filter(key => key !== 'default')
}
} catch (error) {
return {
success: false,
error: error.message
}
}
}
// Performance measurement utilities
export class PerformanceTimer {
constructor () {
this.startTime = null
this.endTime = null
}
start () {
this.startTime = perf.now()
return this
}
end () {
this.endTime = perf.now()
return this.duration
}
get duration () {
return this.endTime - this.startTime
}
}