Skip to content

Commit f4268c0

Browse files
DavertMikclaude
andcommitted
refactor: drop lib/host.js, install registry inline in the runner
lib/host.js was a separate module that did one thing: assign globalThis.codeceptjs = { config, container, event, output, recorder, Helper }. Imported as a side effect from lib/codecept.js (the runner) and lib/plugin/browser.js (so the browser-plugin unit test would also get the registry, since it imports the plugin directly without going through the runner). The indirection wasn't earning its keep — and it read like we were quietly re-introducing the user-facing globals we just deprecated. - Inline the assignment at the top of lib/codecept.js. The runner is the one place that should own this; everything that goes through the CLI hits this module first. - Drop the import from lib/plugin/browser.js. Plugins shouldn't be responsible for installing framework registries. - The browser-plugin unit test bypasses the runner, so it now installs globalThis.codeceptjs in its setup — same pattern we use in the @codeceptjs/configure test suite. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0651205 commit f4268c0

4 files changed

Lines changed: 21 additions & 22 deletions

File tree

lib/codecept.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ import globalTimeoutListener from './listener/globalTimeout.js'
3232
import globalRetryListener from './listener/globalRetry.js'
3333
import exitListener from './listener/exit.js'
3434
import emptyRunListener from './listener/emptyRun.js'
35-
import './host.js'
35+
36+
// Register an in-process handle so companion packages (@codeceptjs/configure,
37+
// @codeceptjs/expect-helper, @codeceptjs/helper) can reach the running
38+
// framework without doing a top-level `import 'codeceptjs'` — that bare
39+
// specifier doesn't resolve in this repo's own checkout (the project IS the
40+
// codeceptjs package). End-user projects don't need this either way; npm
41+
// resolves `codeceptjs` from their node_modules and the bare import works.
42+
if (!globalThis.codeceptjs) {
43+
globalThis.codeceptjs = { config: Config, container, event, output, recorder, Helper }
44+
}
3645

3746
/**
3847
* CodeceptJS runner

lib/host.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/plugin/browser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import output from '../output.js'
2-
import '../host.js'
32

43
/**
54
* Overrides browser helper config from the command line. Works for all browser helpers

test/unit/plugin/browser_test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { expect } from 'chai'
2-
import browser from '../../../lib/plugin/browser.js'
32
import Config from '../../../lib/config.js'
3+
import container from '../../../lib/container.js'
4+
import event from '../../../lib/event.js'
5+
import output from '../../../lib/output.js'
6+
import recorder from '../../../lib/recorder.js'
7+
8+
// This test imports the plugin directly, bypassing the runner. The runner
9+
// (lib/codecept.js) is what normally installs globalThis.codeceptjs so that
10+
// @codeceptjs/configure can reach framework singletons; do the same here.
11+
globalThis.codeceptjs = { config: Config, container, event, output, recorder }
12+
13+
import browser from '../../../lib/plugin/browser.js'
414

515
async function applyAndCreate(args, base = {}) {
616
Config.reset()

0 commit comments

Comments
 (0)