1
- const tty = require ( 'tty' )
1
+ import tty from 'tty'
2
2
3
3
if ( ! tty . getWindowSize ) {
4
4
// this is really old method, long removed from Node, but Mocha
@@ -7,22 +7,18 @@ if (!tty.getWindowSize) {
7
7
tty . getWindowSize = ( ) => [ 40 , 80 ]
8
8
}
9
9
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'
18
15
19
16
let stdout = ''
20
17
21
18
const stderr = ''
22
19
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'
26
22
27
23
const { options, tests, testRoot, workerIndex } = workerData
28
24
@@ -39,44 +35,45 @@ const overrideConfigs = tryOrDefault(() => JSON.parse(options.override), {})
39
35
const config = deepMerge ( getConfig ( options . config || testRoot ) , overrideConfigs )
40
36
41
37
// 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
49
38
; ( 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
+ }
52
52
}
53
- } ) ( )
54
53
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
+ }
68
68
}
69
- }
70
69
71
- function filterTests ( ) {
72
- const files = codecept . testFiles
73
- mocha . files = files
74
- mocha . loadFiles ( )
70
+ filterTests ( )
75
71
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 ( )
78
75
}
79
- }
76
+ } ) ( )
80
77
81
78
function initializeListeners ( ) {
82
79
// suite
0 commit comments