90poe / vscode-cy-helper

VS Code IDE Extension for Cypress.io

Home Page:https://marketplace.visualstudio.com/items?itemName=Shelex.vscode-cy-helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add "spec" instead of "testFiles" for cypress open with "run"

ambrt opened this issue · comments

commented

To make things shorter (and skip gui cypress app) i tried to use "cypress run" as an open command.

It doesn't work b/c cli version uses 'spec' as input of files and not 'testFiles'

So this won't work

cypress run --headed  "--no-exit" "--browser" "chrome" "--config" "testFiles=/home/path/src/__tests__/front/stores/auth.store.cy-spec.js"``

but this will

cypress run --headed  "--no-exit" "--browser" "chrome" "--config" "spec=/home/path/src/__tests__/front/stores/auth.store.cy-spec.js"``

Hi @ambrt
Thank you for opening an issue.
Could not reproduce with cypress v4.8.0 and macos 10.15.7
Could you please provide more information: cypress version, os version, exact value used in cypressHelper.commandForOpen?

commented

Hi @Shelex
I'm using cypress 5.6.0, Ubuntu 18.04

In package.json

"cy:r: "cypress run",

The commandForOpen is npm run cy:r -- --headed --browser chrome --no-exit
It launches
cypress run "--headed" "--browser" "chrome" "--no-exit" "--config" "testFiles=/home/project/src/__tests__/front/stores/login.store.cy-spec.js"

Problem with this is that cypress fails to load this script and gives 404 in console
login.store.cy-spec.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)

I also tested it with commandForOpen npx cypress run --headed --browser chrome
to exclude possibility something going wrong when passing args to npm script (cy:r)

What does work is:

"cy:3": "cypress run --headed \"--browser\" \"chrome\" \"--no-exit\" \"--spec\" \"/home/project/src/__tests__/front/stores/login.store.cy-spec.js\"",

or

npx cypress run --no-exit --headed --browser chrome  --spec /home/project/src/__tests__/front/stores/login.store.cy-spec.js

The problem seems to be how cypress is launching spec.

When launching correctly (with --spec ), the url in chrome is
http://localhost:35549/__/#/tests/component/__tests__/front/stores/login.store.cy-spec.js
but when its launched with "--config" "testFiles=(...)" the url is
http://localhost:35031/__/#/tests/../src/__tests__/front/stores/login.store.cy-spec.js

Bellow is my cypress.json

{
    "experimentalComponentTesting": true,
    "experimentalNetworkStubbing":true,
    "experimentalFetchPolyfill":true,
    "componentFolder": "src",
    
    "reporter": "cypress-multi-reporters",
    "reporterOptions": {
        "reporterEnabled": "mochawesome",
        "mochawesomeReporterOptions": {
            "reportDir": "cypress/reports",
            "quite": true,
            "overwrite": false,
            "html": false,
            "json": true
        }
    },

    "nodeVersion":"system",
    "ignoreTestFiles":["**/examples/*.js"],
    "video": false,
    "mode":"development",
    "testFiles": ["**/*.cy-spec.js"]
    
}

@ambrt In version 1.0.2 have added option to also use cypress run where --spec arg is used. However it is disabled by default, so in order to turn it on please set:

"cypressHelper.commandForRun": "command you are using for running cypress"

and in menu items enable code lense "Run Cypress".

"cypressHelper.menuItems": {
        "RunCypress": true
}
commented

Ok, thanks for making this option. I'm closing the issue.