Skip to content

Commit

Permalink
feat: added MOCHA_CONSTANTS.ts to make mocharc.ts more flexible
Browse files Browse the repository at this point in the history
Signed-off-by: mdolhalo <[email protected]>
  • Loading branch information
mdolhalo committed Sep 11, 2023
1 parent e5e1d68 commit 3f7994f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/e2e/configs/mocharc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@

'use strict';

import { TIMEOUT_CONSTANTS } from '../constants/TIMEOUT_CONSTANTS';
import { MOCHA_CONSTANTS } from '../constants/MOCHA_CONSTANTS';

/**
* full available options list https://mochajs.org/api/mocha
*/

module.exports = {
timeout: 1200000,
timeout: MOCHA_CONSTANTS.MOCHA_DEFAULT_TIMEOUT,
reporter: 'dist/utils/CheReporter.js',
ui: 'tdd',
require: ['dist/specs/MochaHooks.js', 'ts-node/register'],
bail: true,
bail: MOCHA_CONSTANTS.MOCHA_BAIL,
'full-trace': true,
spec:
// variable MOCHA_DIRECTORY uses in command "test-all-devfiles" and sets up automatically.
// you can set it up to run files from specific directory with export environmental variable.
process.env.MOCHA_DIRECTORY
MOCHA_CONSTANTS.MOCHA_DIRECTORY
? // to run one file (name without extension). uses in "test", "test-all-devfiles".
process.env.USERSTORY
? `dist/specs/${process.env.MOCHA_DIRECTORY}/${process.env.USERSTORY}.spec.js`
: `dist/specs/${process.env.MOCHA_DIRECTORY}/**.spec.js`
: process.env.USERSTORY
? [`dist/specs/**/${process.env.USERSTORY}.spec.js`, `dist/specs/${process.env.USERSTORY}.spec.js`]
MOCHA_CONSTANTS.MOCHA_USERSTORY
? `dist/specs/${MOCHA_CONSTANTS.MOCHA_DIRECTORY}/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`
: `dist/specs/${MOCHA_CONSTANTS.MOCHA_DIRECTORY}/**.spec.js`
: MOCHA_CONSTANTS.MOCHA_USERSTORY
? [`dist/specs/**/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`, `dist/specs/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`]
: ['dist/specs/**/**.spec.js', 'dist/specs/**.spec.js'],
retries: TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_ATTEMPTS
retries: MOCHA_CONSTANTS.MOCHA_RETRIES
};
27 changes: 27 additions & 0 deletions tests/e2e/constants/MOCHA_CONSTANTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** *******************************************************************
* copyright (c) 2020-2023 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

export const MOCHA_CONSTANTS: {
MOCHA_DEFAULT_TIMEOUT: string | number;
MOCHA_DIRECTORY: string | undefined;
MOCHA_USERSTORY: undefined | string;
MOCHA_RETRIES: string | number;
MOCHA_BAIL: boolean;
} = {
MOCHA_DIRECTORY: process.env.MOCHA_DIRECTORY || undefined,

MOCHA_USERSTORY: process.env.USERSTORY || undefined,

MOCHA_BAIL: process.env.MOCHA_BAIL !== 'false',

MOCHA_DEFAULT_TIMEOUT: process.env.MOCHA_DEFAULT_TIMEOUT || 1200000,

MOCHA_RETRIES: process.env.MOCHA_RETRIES || 3
};

0 comments on commit 3f7994f

Please sign in to comment.