Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running jest via the programmatic interface with "projects" gives an error. #11213

Closed
nicojs opened this issue Mar 19, 2021 · 1 comment · Fixed by #11307
Closed

Running jest via the programmatic interface with "projects" gives an error. #11213

nicojs opened this issue Mar 19, 2021 · 1 comment · Fixed by #11307

Comments

@nicojs
Copy link
Contributor

nicojs commented Mar 19, 2021

🐛 Bug Report

Running jest via the programmatic interface with "projects" gives an error:

Error: Jest: Cannot use configuration as an object without a file path.
    at readConfig (/home/nicojs/github/jest-issue-projects/node_modules/jest-config/build/index.js:188:13)
    at /home/nicojs/github/jest-issue-projects/node_modules/jest-config/build/index.js:447:18
    at Array.map (<anonymous>)
    at readConfigs (/home/nicojs/github/jest-issue-projects/node_modules/jest-config/build/index.js:441:10)
    at async runCLI (/home/nicojs/github/jest-issue-projects/node_modules/@jest/core/build/cli/index.js:230:59)

To Reproduce

I've created a small repro repo:

jest-cli-issue-projects.zip

  1. Unzip, cd into the dir, npm i.
  2. Running jest works: npx jest.
  3. Running jest via the programmatic API doesn't: node run-jest.js

The code of run-jest.js is this:

const { runCLI } = require('jest');
const config = require('./jest.config');

runCLI({ config: JSON.stringify(config) }, [process.cwd()])
 .then(() => console.log('✅ Done'))
 .catch(err => {
    console.error(err);
    process.exitCode = 1;
});

Expected behavior

 PASS   server  server/server.test.js
 PASS   client  client/client.test.js

The reason for the error is that the readConfig logic of jests demands there to be a config file, so that it can resolve the projects from that directory. I would expect it to fall back on the location of this project, which is provided as process.cwd().

envinfo

  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Binaries:
    Node: 12.20.0 - ~/.nvm/versions/node/v12.20.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.20.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v12.20.0/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant