You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/configuration.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,16 +68,18 @@ For TypeScript test files in CodeceptJS 4.x, use the [`tsx`](https://tsx.is) loa
68
68
// codecept.conf.ts
69
69
exportconst config = {
70
70
tests: './**/*_test.ts',
71
-
require: ['tsx/cjs'],
71
+
require: ['tsx/esm'],
72
72
helpers: {},
73
73
include: {},
74
74
}
75
75
```
76
76
77
+
This requires `"type": "module"` in `package.json` so `.ts` test files are compiled as ES Modules.
78
+
77
79
Combine several modules:
78
80
79
81
```ts
80
-
require: ['tsx/cjs', 'should', './lib/testSetup']
82
+
require: ['tsx/esm', 'should', './lib/testSetup']
81
83
```
82
84
83
85
The config file itself (`codecept.conf.ts`) and helpers are transpiled automatically — only test files need the loader. See [TypeScript](/typescript) for the full setup.
const workers = new Workers(null, { testConfig: './codecept.conf.js' })
114
114
115
115
// split the suite into 2 groups, run each group on two browsers
116
-
const groups = workers.createGroupsOfSuites(2)
116
+
const groups = await workers.createGroupsOfSuites(2)
117
117
for (const browser of ['chromium', 'firefox']) {
118
118
for (const group of groups) {
119
119
const worker = workers.spawn()
@@ -136,7 +136,7 @@ try {
136
136
Building blocks:
137
137
138
138
- `new Workers(N, { testConfig, options })`— `N` workers; pass `null` to spawn them yourself with `spawn()`.
139
-
- `createGroupsOfTests(n)`/ `createGroupsOfSuites(n)` — split the suite into `n` groups.
139
+
- `await createGroupsOfTests(n)` / `await createGroupsOfSuites(n)` — split the suite into `n` groups (async: test files are loaded as ES Modules).
140
140
- `worker.addTests(group)`/ `worker.addConfig(partialConfig)` — assign tests and config overrides to a spawned worker.
141
141
- `bootstrapAll()`→ `run()` → `teardownAll()` — lifecycle (wrap `run()` in `try/finally` so teardown always runs).
142
142
- Events on the `workers` object: `event.test.passed`, `event.test.failed`, `event.all.result`, plus `'message'` for anything a child worker sends. `printResults()` prints the standard summary; `result.hasFailed()` and `result.stats` give the totals.
* Fixes run-rerun by @DenysKuchma in https://github.com/codeceptjs/CodeceptJS/pull/5667
13
+
* fix(core): load Mocha test files as ES Modules (fixes internal-API imports from tests, #5636) by @DavertMik in https://github.com/codeceptjs/CodeceptJS/pull/5640
14
+
* chore(deps): bump @xmldom/xmldom from 0.9.8 to 0.9.10 by @ElVisPL in https://github.com/codeceptjs/CodeceptJS/pull/5651
15
+
* fix(appium): replace deprecated setNetworkConnection/getNetworkConnection with mobile: setConnectivity/getConnectivity by @mirao in https://github.com/codeceptjs/CodeceptJS/pull/5662
16
+
* fix(typings): add ARIA locators to ILocator by @patryk-przybysz in https://github.com/codeceptjs/CodeceptJS/pull/5665
17
+
* chore(deps-dev): bump eslint-plugin-mocha from 11.2.0 to 11.3.0 by @dependabot[bot] in https://github.com/codeceptjs/CodeceptJS/pull/5629
18
+
* chore(deps-dev): bump graphql from 16.12.0 to 16.14.2 by @dependabot[bot] in https://github.com/codeceptjs/CodeceptJS/pull/5627
19
+
* chore(deps): bump monocart-coverage-reports from 2.12.9 to 2.12.12 by @dependabot[bot] in https://github.com/codeceptjs/CodeceptJS/pull/5625
20
+
21
+
### New Contributors
22
+
*@ElVisPL made their first contribution in https://github.com/codeceptjs/CodeceptJS/pull/5651
23
+
*@patryk-przybysz made their first contribution in https://github.com/codeceptjs/CodeceptJS/pull/5665
It writes `codecept.conf.ts` and `*_test.ts` files. The **config file** and helpers are transpiled automatically. **Test files** need a loader — CodeceptJS 4.x is ESM, and Mocha loads test files through CommonJS hooks, so use [`tsx`](https://tsx.is) (fast, esbuild-based, no `tsconfig.json` required):
15
+
It writes `codecept.conf.ts` and `*_test.ts` files. The **config file** and helpers are transpiled automatically. **Test files** need a loader — CodeceptJS 4.x is ESM and loads test files as ES Modules, so use [`tsx`](https://tsx.is) (fast, esbuild-based, no `tsconfig.json` required):
16
16
17
17
```sh
18
18
npm i tsx --save-dev
@@ -22,16 +22,16 @@ npm i tsx --save-dev
22
22
// codecept.conf.ts
23
23
exportconst config = {
24
24
tests: './**/*_test.ts',
25
-
require: ['tsx/cjs'], // loads the *_test.ts files
25
+
require: ['tsx/esm'], // loads the *_test.ts files as ES Modules
Set `"type": "module"` in `package.json` so `tsx` compiles your `.ts` test files as ES Modules. Then run the tests with `npx codeceptjs run`.
33
33
34
-
> Adding TypeScript to an existing project: set `"type": "module"` in `package.json`, rename the config to `codecept.conf.ts` with `export const config = {}`, install `tsx`, and add `require: ['tsx/cjs']`.
34
+
> Adding TypeScript to an existing project: set `"type": "module"` in `package.json`, rename the config to `codecept.conf.ts` with `export const config = {}`, install `tsx`, and add `require: ['tsx/esm']`.
> **Cannot find module** or **Unexpected token** while running tests means the loader isn't wired up — check that `tsx` is installed and `require: ['tsx/cjs']` is in the config.
59
+
> **Cannot find module** or **Unexpected token** while running tests means the loader isn't wired up — check that `tsx` is installed and `require: ['tsx/esm']` is in the config.
60
+
>
61
+
> **`ERR_REQUIRE_CYCLE_MODULE`** means `tsx` is compiling your `.ts` tests as CommonJS — add `"type": "module"` to the nearest `package.json`.
0 commit comments