File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
2626const debug = require ( 'debug' ) ( 'mocha:cli:run' ) ;
2727const defaults = require ( '../mocharc.json' ) ;
2828const { types, aliases} = require ( './run-option-metadata' ) ;
29+ const { isCI} = require ( '../utils' ) ;
2930
3031/**
3132 * Logical option groups
@@ -124,7 +125,7 @@ exports.builder = yargs =>
124125 'forbid-only' : {
125126 description : 'Fail if exclusive test(s) encountered' ,
126127 group : GROUPS . RULES ,
127- default : ! ! process . env . CI ,
128+ default : isCI ( )
128129 } ,
129130 'forbid-pending' : {
130131 description : 'Fail if pending test(s) encountered' ,
Original file line number Diff line number Diff line change 99
1010const { format} = require ( 'node:util' ) ;
1111const { constants } = require ( './error-constants.js' ) ;
12+ const { isCI } = require ( './utils' ) ;
1213
1314/**
1415 * Contains error codes, factory functions to create throwable error objects,
@@ -329,11 +330,17 @@ function createMultipleDoneError(runnable, originalErr) {
329330 * @returns {Error } Error with code {@link constants.FORBIDDEN_EXCLUSIVITY}
330331 */
331332function createForbiddenExclusivityError ( mocha ) {
332- var err = new Error (
333- mocha . isWorker
334- ? '`.only` is not supported in parallel mode'
335- : '`.only` forbidden by --forbid-only'
336- ) ;
333+ var message ;
334+ if ( mocha . isWorker ) {
335+ message = '`.only` is not supported in parallel mode' ;
336+ } else {
337+ message = '`.only` forbidden by --forbid-only' ;
338+ if ( isCI ( ) ) {
339+ message += ' (default in CI, add `--no-forbid-only` to allow `.only`)' ;
340+ }
341+ }
342+
343+ var err = new Error ( message ) ;
337344 err . code = constants . FORBIDDEN_EXCLUSIVITY ;
338345 return err ;
339346}
Original file line number Diff line number Diff line change @@ -696,3 +696,17 @@ exports.breakCircularDeps = inputObj => {
696696exports . isNumeric = input => {
697697 return ! isNaN ( parseFloat ( input ) ) ;
698698} ;
699+
700+ /**
701+ * Checks if being ran in a CI environment.
702+ *
703+ * This uses the CI env variable, which is set by most popular CI providers. Some
704+ * examples include:
705+ * Github: https://docs.github.com/en/actions/reference/workflows-and-actions/variables
706+ * Gitlab: https://docs.gitlab.com/ci/variables/predefined_variables/
707+ * CircleCI: https://circleci.com/docs/reference/variables/#built-in-environment-variables
708+ * Bitbucket: https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
709+ */
710+ exports . isCI = ( ) => {
711+ return ! ! process . env . CI ;
712+ } ;
You can’t perform that action at this time.
0 commit comments