|
1 | | -import codeceptjs from 'codeceptjs' |
| 1 | +// CodeceptJS handle, looked up from the in-process registry the framework sets |
| 2 | +// on globalThis. Avoids a top-level `import 'codeceptjs'`, which fails to |
| 3 | +// resolve inside the codeceptjs repo's own CI (the project IS the codeceptjs |
| 4 | +// package). Each named export is a Proxy that forwards property access to the |
| 5 | +// live framework module at call time, so hooks register against the same |
| 6 | +// singletons the runner is using. |
2 | 7 |
|
3 | | -if (!codeceptjs?.config?.addHook) { |
4 | | - throw new Error('CodeceptJS >= 4.0.0 is required to use config hooks. For older versions, install @codeceptjs/configure@^1.') |
| 8 | +function lazy(name) { |
| 9 | + return new Proxy({}, { |
| 10 | + get(_, key) { |
| 11 | + const cjs = globalThis.codeceptjs |
| 12 | + if (!cjs) { |
| 13 | + throw new Error('CodeceptJS host not available — call configure functions from inside a codecept.conf.js / codecept run, or make sure CodeceptJS >= 4.0 is loaded first.') |
| 14 | + } |
| 15 | + const target = cjs[name] |
| 16 | + if (!target) { |
| 17 | + throw new Error(`CodeceptJS does not expose ${name} on the host registry.`) |
| 18 | + } |
| 19 | + const v = target[key] |
| 20 | + return typeof v === 'function' ? v.bind(target) : v |
| 21 | + }, |
| 22 | + }) |
5 | 23 | } |
6 | 24 |
|
| 25 | +const codeceptjs = new Proxy({}, { |
| 26 | + get(_, key) { |
| 27 | + const cjs = globalThis.codeceptjs |
| 28 | + if (!cjs) throw new Error('CodeceptJS host not available — call configure functions from inside a codecept.conf.js / codecept run.') |
| 29 | + return cjs[key] |
| 30 | + }, |
| 31 | +}) |
| 32 | + |
7 | 33 | export default codeceptjs |
8 | | -export const config = codeceptjs.config |
9 | | -export const container = codeceptjs.container |
10 | | -export const event = codeceptjs.event |
11 | | -export const output = codeceptjs.output |
| 34 | +export const config = lazy('config') |
| 35 | +export const container = lazy('container') |
| 36 | +export const event = lazy('event') |
| 37 | +export const output = lazy('output') |
0 commit comments