MCPcopy
hub / github.com/codeceptjs/CodeceptJS / run

Method run

lib/codecept.js:268–333  ·  view source on GitHub ↗

* Run a specific test or all loaded tests. * * @param {string} [test] * @returns {Promise }

(test)

Source from the content-addressed store, hash-verified

266 * @returns {Promise<void>}
267 */
268 async run(test) {
269 await container.started()
270
271 // Check TypeScript loader configuration before running tests
272 const tsValidation = validateTypeScriptSetup(this.testFiles, this.requiringModules || [])
273 if (tsValidation.hasError) {
274 output.error(tsValidation.message)
275 process.exit(1)
276 }
277
278 // Show warning if ts-node/esm is being used
279 const tsWarning = getTSNodeESMWarning(this.requiringModules || [])
280 if (tsWarning) {
281 output.print(output.colors.yellow(tsWarning))
282 }
283
284 // Ensure translations are loaded for Gherkin features
285 try {
286 const { loadTranslations } = await import('./mocha/gherkin.js')
287 await loadTranslations()
288 } catch (e) {
289 // Ignore if gherkin module not available
290 }
291
292 // Sort test files alphabetically for consistent execution order,
293 // but skip sorting when --shuffle is active so the randomised order is preserved.
294 if (!this.opts.shuffle) {
295 this.testFiles.sort()
296 }
297
298 return new Promise((resolve, reject) => {
299 const mocha = container.mocha()
300 mocha.files = this.testFiles
301
302 if (test) {
303 if (!fsPath.isAbsolute(test)) {
304 test = fsPath.join(store.codeceptDir, test)
305 }
306 const testBasename = fsPath.basename(test, '.js')
307 const testFeatureBasename = fsPath.basename(test, '.feature')
308 mocha.files = mocha.files.filter(t => {
309 return fsPath.basename(t, '.js') === testBasename || fsPath.basename(t, '.feature') === testFeatureBasename || t === test
310 })
311 }
312
313 const done = async (failures) => {
314 event.emit(event.all.result, container.result())
315 event.emit(event.all.after, this)
316 // Wait for any recorder tasks added by event.all.after handlers
317 await recorder.promise()
318 // Set exit code based on test failures
319 if (failures) {
320 process.exitCode = 1
321 }
322 resolve()
323 }
324
325 try {

Callers

nothing calls this directly

Calls 7

validateTypeScriptSetupFunction · 0.90
getTSNodeESMWarningFunction · 0.90
loadTranslationsFunction · 0.85
doneFunction · 0.85
startedMethod · 0.80
mochaMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected