Skip to content

feat: programmatic API with getSuites(), executeSuite(), executeTest()#5518

Open
DavertMik wants to merge 3 commits into4.xfrom
feat/programmatic-api
Open

feat: programmatic API with getSuites(), executeSuite(), executeTest()#5518
DavertMik wants to merge 3 commits into4.xfrom
feat/programmatic-api

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

Summary

  • Add getSuites(pattern?) to Codecept class — returns parsed suites with tests as plain objects, using a temporary Mocha instance to avoid polluting container state
  • Add executeSuite(suite) and executeTest(test) — clean execution methods that accept objects returned by getSuites()
  • Refactor workers.jscreateGroupsOfTests() and createGroupsOfSuites() now use getSuites() instead of duplicated Mocha boilerplate (~30 lines removed)
  • Refactor dryRun.jsprintTests() now uses getSuites(), removing direct Container.mocha() dependency
  • Export Result class from lib/index.js
  • Rewrite "Custom Runner" section in docs/internal-api.md as full "Programmatic API" reference

Usage

import { Codecept, container } from 'codeceptjs'

const codecept = new Codecept(config, { steps: true })
await codecept.init(__dirname)

// List tests
const suites = codecept.getSuites()
for (const suite of suites) {
  console.log(suite.title)
  for (const test of suite.tests) {
    console.log(' -', test.title, test.tags)
  }
}

// Execute
await codecept.bootstrap()
for (const suite of suites) {
  await codecept.executeSuite(suite)
}
const result = container.result()
await codecept.teardown()

Test plan

  • dry-run command works with refactored getSuites() (tested with grep filtering)
  • Unit tests pass (401 passing, 7 pre-existing AI test failures unrelated)
  • Shard tests pass
  • Workers should be tested with run-workers 2

🤖 Generated with Claude Code

…est()

Add clean programmatic API to Codecept class that wraps Mocha internals,
eliminating duplicated boilerplate across dryRun, workers, and custom scripts.

- getSuites(pattern?) returns parsed suites with tests as plain objects
- executeSuite(suite) runs all tests in a suite
- executeTest(test) runs a single test by fullTitle
- Refactor workers.js to use getSuites() (removes ~30 lines of Mocha boilerplate)
- Refactor dryRun.js to use getSuites() (removes Container.mocha() dependency)
- Export Result class from lib/index.js
- Rewrite docs/internal-api.md with full programmatic API reference

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik force-pushed the feat/programmatic-api branch from f28103a to c8a7be8 Compare April 12, 2026 19:09
DavertMik and others added 2 commits April 12, 2026 22:40
- Create lib/runner.js with Runner class that owns all Mocha interactions:
  getSuites(), run(), runSuite(), runTest() backed by a single _execute() core
- Codecept.run/runSuite/runTest/getSuites now delegate to this.runner
- Remove duplicated executeTest() that was copy of run()
- Refactor check.js to use codecept.getSuites() instead of manual Mocha
- Export Runner from lib/index.js

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…yRunConfig

- Remove dead code: activeWorkers Map, maxWorkers, empty recorder placeholder
- Simplify _initializeTestPool to 4 lines
- Remove redundant configWithoutFunctions variable in WorkerObject.addConfig
- Remove hardcoded mochawesome/mocha-junit-reporter path manipulation from
  createWorkerObjects — fragile, incomplete, and redundant with output dir override
- Extract getOverridenConfig to Config.applyRunConfig() in lib/config.js,
  shared by both workers.js and run-multiple.js

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant