question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--config [JSON] + projects doesn't seem to work

See original GitHub issue

🐛 Bug Report

When passing serialized JSON for the --config option that contains projects, I get the following error:

Error: Jest: Cannot use configuration as an object without a file path.
    at readConfig (~/github/benmvp/benmvp-cli/node_modules/jest-config/build/index.js:139:13)
    at projects.filter.map.root ~/github/benmvp/benmvp-cli/node_modules/jest-cli/build/cli/index.js:487:62)
    ....

The parsed JSON looks like:

{
    "projects": [
        {
            "moduleFileExtensions": ["ts", "js"],
            "transform": {
                "^.+\\.(ts|js)$": "babel-jest"
            },
            "testMatch": [
                "<rootDir>/src/**/*.ts"
            ],
            "runner": "jest-runner-tsc",
            "displayName": "typescript"
        },
        {
            "moduleFileExtensions": ["ts", "js"],
            "transform": {
                "^.+\\.(ts|js)$": "babel-jest"
            },
            "testMatch": [
                "<rootDir>/src/**/*.spec.ts"
            ],
            "displayName": "test"
        }
    ],
    "rootDir": "."
}

To Reproduce

Just run:

npx jest --config '{"projects":[{"moduleFileExtensions":["ts","js"],"transform":{"^.+\\.(ts|js)$":"babel-jest"},"testMatch":["<rootDir>/src/**/*.ts"],"runner":"jest-runner-tsc","displayName":"typescript"},{"moduleFileExtensions":["ts","js"],"transform":{"^.+\\.(ts|js)$":"babel-jest"},"testMatch":["<rootDir>/src/**/*.spec.ts"],"displayName":"test"}],"rootDir":"."}'

Expected behavior

I expect to be able to run the projects just like if they were defined in a config file (which does work).

Link to repl or repo (highly encouraged)

See repro command. Happy to contribute a PR, I just don’t know what to fix. 😄

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Binaries:
    Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.12.0/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

Debugging

1/ I tried moving the JSON back to a .js file and it works (my current workaround). I need the contents to be dynamic, which is why I want to pass JSON

2/ I did a whole bunch of code spelunking to try to get it to work. I narrowed down the problem to readConfigs in jest-config. It seems that after successfully parsing the JSON, it maps over each project to readConfig on each (passing configPath). The problem is that configPath is null so readConfig complains. And the reason configPath is null is because when the JSON was originally parsed (also by readConfig), I guess there is no configPath to set so it remains null. That’s as far as I got since I don’t understand the why of the code.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rickhanloniicommented, Nov 27, 2018

Hey @benmvp thanks for filing! Confirmed - I’ll take a look

0reactions
github-actions[bot]commented, May 24, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The configuration file 'appsettings.json' was not found and is ...
In My case the file appsettings.json existed in project folder, but it was set to Do not copy , I changed the setting...
Read more >
Don't Use JSON as a Configuration File Format ... - Revelry Labs
First, it doesn't allow comments. You may want to explain your configuration or any configuration options. JSON doesn't allow that. There are ...
Read more >
staticwebapp.config.json doesn't take effect - Microsoft Q&A
I tried moving the config file staticwebapp.config.json to the /www folder, and moved it back to the root, but it doesn't seem to...
Read more >
Value of sfdcLoginUrl in sfdx-project.json doesn't seem to matter
From Salesforce DX Project Configuration, the sfdcLoginUrl ... Use the command palette with ( Ctrl+Shift+P ): SFDX: Set a Default Org.
Read more >
Working with JavaScript in Visual Studio Code
json file defined inside a workspace. You will want to do this so that the source code in one project does not appear...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found