1- const tty = require ( 'tty' )
1+ import tty from 'tty'
22
33if ( ! tty . getWindowSize ) {
44 // this is really old method, long removed from Node, but Mocha
@@ -7,22 +7,18 @@ if (!tty.getWindowSize) {
77 tty . getWindowSize = ( ) => [ 40 , 80 ]
88}
99
10- const { parentPort, workerData } = require ( 'worker_threads' )
11- const eventModule = require ( '../../event' )
12- const event = eventModule . default || eventModule
13- const containerModule = require ( '../../container' )
14- const container = containerModule . default || containerModule
15- const { getConfig } = require ( '../utils' )
16- const utilsModule = require ( '../../utils' )
17- const { tryOrDefault, deepMerge } = utilsModule . default || utilsModule
10+ import { parentPort , workerData } from 'worker_threads'
11+ import event from '../../event.js'
12+ import container from '../../container.js'
13+ import { getConfig } from '../utils.js'
14+ import { tryOrDefault , deepMerge } from '../../utils.js'
1815
1916let stdout = ''
2017
2118const stderr = ''
2219
23- // Requiring of Codecept need to be after tty.getWindowSize is available.
24- const CodeceptModule = require ( process . env . CODECEPT_CLASS_PATH || '../../codecept' )
25- const Codecept = CodeceptModule . default || CodeceptModule
20+ // Importing of Codecept need to be after tty.getWindowSize is available.
21+ import Codecept from '../../codecept.js'
2622
2723const { options, tests, testRoot, workerIndex } = workerData
2824
@@ -39,44 +35,45 @@ const overrideConfigs = tryOrDefault(() => JSON.parse(options.override), {})
3935const config = deepMerge ( getConfig ( options . config || testRoot ) , overrideConfigs )
4036
4137// Load test and run
42- const codecept = new Codecept ( config , options )
43- codecept . init ( testRoot )
44- codecept . loadTests ( )
45- const mocha = container . mocha ( )
46- filterTests ( )
47-
48- // run tests
4938; ( async function ( ) {
50- if ( mocha . suite . total ( ) ) {
51- await runTests ( )
39+ const codecept = new Codecept ( config , options )
40+ await codecept . init ( testRoot )
41+ codecept . loadTests ( )
42+ const mocha = container . mocha ( )
43+
44+ function filterTests ( ) {
45+ const files = codecept . testFiles
46+ mocha . files = files
47+ mocha . loadFiles ( )
48+
49+ for ( const suite of mocha . suite . suites ) {
50+ suite . tests = suite . tests . filter ( test => tests . indexOf ( test . uid ) >= 0 )
51+ }
5252 }
53- } ) ( )
5453
55- async function runTests ( ) {
56- try {
57- await codecept . bootstrap ( )
58- } catch ( err ) {
59- throw new Error ( `Error while running bootstrap file :${ err } ` )
60- }
61- listenToParentThread ( )
62- initializeListeners ( )
63- disablePause ( )
64- try {
65- await codecept . run ( )
66- } finally {
67- await codecept . teardown ( )
54+ async function runTests ( ) {
55+ try {
56+ await codecept . bootstrap ( )
57+ } catch ( err ) {
58+ throw new Error ( `Error while running bootstrap file :${ err } ` )
59+ }
60+ listenToParentThread ( )
61+ initializeListeners ( )
62+ disablePause ( )
63+ try {
64+ await codecept . run ( )
65+ } finally {
66+ await codecept . teardown ( )
67+ }
6868 }
69- }
7069
71- function filterTests ( ) {
72- const files = codecept . testFiles
73- mocha . files = files
74- mocha . loadFiles ( )
70+ filterTests ( )
7571
76- for ( const suite of mocha . suite . suites ) {
77- suite . tests = suite . tests . filter ( test => tests . indexOf ( test . uid ) >= 0 )
72+ // run tests
73+ if ( mocha . suite . total ( ) ) {
74+ await runTests ( )
7875 }
79- }
76+ } ) ( )
8077
8178function initializeListeners ( ) {
8279 // suite
0 commit comments