Lewis Munene
Lewis Munene

Reputation: 164

How do I run CodeceptJS tests with the config file in a different directory from the root directory

I have a CodeceptJS project whose directory structure looks like this:

root
|
├──node_modules
│  
├──packages
|  |
│  ├──package1
│  │   ├──node_modules
|  |   ├──ui_tests
|  |   |  ├──codecept.conf.ts
|  |   |  └──login_ui_test.ts
|  |   |
|  |   ├──api_tests
|  |   |  ├──codecept.conf.ts
|  |   |  └──login_api_test.ts
|  |   |  
│  │   └──package.json
|  |   
│  └──package2
│     ├──node_modules
|     ├──ui_tests
|     ├──api_tests
│     └──package.json
|  
└──package.json

Notice that codecept.conf.ts is located three levels down from the root directory. This is desired so that UI tests and API tests can each have their own separate configs. All this is set up as a monorepo using pnpm workspaces. The problem is that with this kind of setup, I get the following error when I run pnpm exec codeceptjs run --config ./package1/api_tests/codecept.conf.ts :

error TS2503: Cannot find namespace 'CodeceptJS'.

2 export const config: CodeceptJS.MainConfig = {


    at createTSError (xxx\packages\package1\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (xxx\packages\package1\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (xxx\packages\package1\node_modules\ts-node\src\index.ts:1077:36)
    at Object.compile (xxx\packages\package1\node_modules\ts-node\src\index.ts:1433:41)
    at Module.m._compile (xxx\packages\package1\node_modules\ts-node\src\index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (xxx\packages\package1\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)

When I edit codecept.conf.ts and add import Codecept from "codeceptjs", the error disappears but the tests do not run due to this other error:

  1) login
       test login:
     Object of type _a is not defined in container
      at getInjectedArguments (node_modules\codeceptjs\lib\scenario.js:213:13)
      at Context.test.fn (node_modules\codeceptjs\lib\scenario.js:92:25)

Upvotes: 1

Views: 123

Answers (0)

Related Questions