-
-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathrun.js
More file actions
61 lines (51 loc) · 1.8 KB
/
run.js
File metadata and controls
61 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { getConfig, printError, getTestRoot, createOutputDir } from './utils.js'
import Config from '../config.js'
import store from '../store.js'
import Codecept from '../codecept.js'
import container from '../container.js'
export default async function (test, options) {
// registering options globally to use in config
// Backward compatibility for --profile
// TODO: remove in CodeceptJS 4
process.profile = options.profile
if (options.profile) {
process.env.profile = options.profile
}
if (options.verbose || options.debug) store.debugMode = true
const configFile = options.config
let config = await getConfig(configFile)
if (options.override) {
config = Config.append(JSON.parse(options.override))
}
const testRoot = getTestRoot(configFile)
createOutputDir(config, testRoot)
const codecept = new Codecept(config, options)
try {
await codecept.init(testRoot)
await codecept.bootstrap()
codecept.loadTests(test)
if (options.verbose) {
store.debugMode = true
const { getMachineInfo } = await import('./info.js')
await getMachineInfo()
}
await codecept.run()
} catch (err) {
printError(err)
process.exitCode = 1
} finally {
await codecept.teardown()
// Schedule a delayed exit to prevent process hanging due to browser helper event loops
// Only needed for Playwright/Puppeteer which keep the event loop alive
// Wait 1 second to allow final cleanup and output to complete
if (!process.env.CODECEPT_DISABLE_AUTO_EXIT) {
const helpers = container.helpers()
const hasBrowserHelper = helpers && (helpers.Playwright || helpers.Puppeteer || helpers.WebDriver)
if (hasBrowserHelper) {
setTimeout(() => {
process.exit(process.exitCode || 0)
}, 1000).unref()
}
}
}
}