Codium-ai / codiumai-vscode-release

266 stars 37 forks source link

Problem with running tests from Codium tab #167

Closed osszoi closed 3 months ago

osszoi commented 3 months ago

Hi, I was just trying CodiumAI for first time and it looks awesome. I'm able to copy generated test, create the file myself and run npm test . The problem is that I'm unable to run the test directly from the "Run|Run and auto-fix" button. I get this error:

Please note that running tests by copying&pasting into a file myself works, the auto run button is what is not working

Error: Jest: Failed to parse the TypeScript config file C:\Users\loren\Work\dawere\fe-admin\jest.config.ts
  Error: Must use import to load ES Module: C:\Users\loren\Work\dawere\fe-admin\jest.config.ts
require() of ES modules is not supported.
require() of C:\Users\loren\Work\dawere\fe-admin\jest.config.ts from c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-config\build\readConfigFileAndSetRootDir.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from C:\Users\loren\Work\dawere\fe-admin\package.json.

    at readConfigFileAndSetRootDir (c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-config\build\readConfigFileAndSetRootDir.js:116:13)
    at async readInitialOptions (c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-config\build\index.js:403:13)
    at async readConfig (c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-config\build\index.js:147:48)
    at async readConfigs (c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-config\build\index.js:424:26)
    at async runCLI (c:\Users\loren\Work\dawere\fe-admin\node_modules@jest\core\build\cli\index.js:151:59)
    at async Object.run (c:\Users\loren\Work\dawere\fe-admin\node_modules\jest-cli\build\run.js:130:37)

In output I see it's trying to run this:

npx jest --forceExit --coverage=false --runTestsByPath src\\utils\\codium_b5a1af2c-c2b1-40f1-aaf3-0f81d244580c_createQueryKey.test.ts --testNamePattern \"should return correct key array when given a single QUERY_KEYS argument\" --json
If I copy the arguments and pass them to the npm test it works, so I'm not sure how to make it call npm test instead of npx jest

npm test --forceExit --coverage=false --runTestsByPath src\utils\codium_b2663c58-85a4-4e30-b100-baa58c7fef15_createQueryKey.test.ts --testNamePattern "should return correct key array when given a single QUERY_KEYS argument" --json

fe-admin@0.17.0 test
jest src\utils\codium_b2663c58-85a4-4e30-b100-baa58c7fef15_createQueryKey.test.ts should return correct key array when given a single QUERY_KEYS argument

 PASS  src/utils/codium_b2663c58-85a4-4e30-b100-baa58c7fef15_createQueryKey.test.ts
  QUERY_KEYS
    √ should return correct key array when given a single QUERY_KEYS argument (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.08 s

I've tried adding this to .codiumai.toml

[tests.javascript]
overrideTestRunScript="npm test"

but all I get is for it to run npx npm test

osszoi commented 3 months ago

Solution was:

Change .codiumai.toml to

[tests.javascript] overrideTestRunScript="npx jest --config="./jest.config.js" --verbose --runTestsByPath TEST_FILEPATH"

and remove "type": "module" from package.json