Skip to content

Commit e98569b

Browse files
DavertMikclaude
andcommitted
feat: deprecate globals, default noGlobals: true for new projects
- noGlobals: true skips ALL globals including Mocha DSL (Feature, Scenario, etc.) - noGlobals: false (default for existing projects) prints deprecation warning - New projects generated via `codeceptjs init` get noGlobals: true by default - Store noGlobals flag in store so initMochaGlobals respects it Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8bcc70b commit e98569b

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/command/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const defaultConfig = {
1919
output: '',
2020
helpers: {},
2121
include: {},
22+
noGlobals: true,
2223
plugins: {
2324
},
2425
}

lib/globals.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ export async function initCodeceptGlobals(dir, config, container) {
2020
outputDir: fsPath.resolve(dir, config.output),
2121
})
2222

23+
store.noGlobals = config.noGlobals || false
24+
store.maskSensitiveData = config.maskSensitiveData || false
25+
2326
// Keep globals for backward compat with external plugins
2427
global.codecept_dir = dir
2528
global.output_dir = fsPath.resolve(dir, config.output)
2629

2730
if (config.noGlobals) return;
2831

32+
output.print(output.styles.debug('Global functions are deprecated. Use `import { Helper, pause, within, session } from "codeceptjs"` instead. Set `noGlobals: true` in config to disable globals.'));
33+
2934
const HelperModule = await import('@codeceptjs/helper')
3035
global.Helper = global.codecept_helper = HelperModule.default || HelperModule
3136

@@ -75,7 +80,6 @@ export async function initCodeceptGlobals(dir, config, container) {
7580
global.DefineParameterType = stepDefinitions.defineParameterType
7681

7782
// mask sensitive data
78-
store.maskSensitiveData = config.maskSensitiveData || false
7983
global.maskSensitiveData = config.maskSensitiveData || false
8084

8185
}
@@ -85,6 +89,8 @@ export async function initCodeceptGlobals(dir, config, container) {
8589
* Called from mocha/ui.js pre-require event
8690
*/
8791
export function initMochaGlobals(context) {
92+
if (store.noGlobals) return;
93+
8894
// Mocha test framework globals
8995
global.BeforeAll = context.BeforeAll
9096
global.AfterAll = context.AfterAll

lib/store.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ const store = {
5757
*/
5858
maskSensitiveData: false,
5959

60+
/**
61+
* noGlobals mode — user imports everything
62+
* @type {boolean}
63+
*/
64+
noGlobals: false,
65+
6066
// --- State (tracks current execution, changes constantly) ---
6167

6268
/**

0 commit comments

Comments
 (0)