bahmutov / start-server-and-test

Starts server, waits for URL, then runs test command; when the tests end, shuts down server
MIT License
1.53k stars 95 forks source link

feature request: CRA #220

Open artivilla opened 4 years ago

artivilla commented 4 years ago

Feature Request. I'm currently running cypress using the following configuration. Is there a way to hook into the existing CRA start process and not have to setup serve to do this. This works but looking for a better approach:

        "start": "react-scripts start",
        "start-https": "HTTPS=true && react-scripts start",
        "build": "react-scripts build",
        "test": "is-ci test:cypress:run test:cypress:dev",
        "cy:run": "cypress run",
        "cy:open": "cypress open",
        "pretest:cypress:run": "npm run build",
        "test:cypress:run": "server-test serve :3000 cy:run",
        "test:cypress:dev": "npm-run-all --parallel --race start cy:open",
        "serve": "npx serve -n -s --listen 3000 build",
robert-skarzycki commented 4 years ago

@artivilla, what do you want to achieve? if you want to run start script with server-test you can just have this: "test:cypress:run": server-test start http://localhost:3000 cy:run - this is what I'm using.

shedali commented 4 years ago

Just trying this now; the start script works but it does not continue running the test script (react-scripts 3.0.1)

bahmutov commented 4 years ago

@artivilla why can't you use "test:cypress:run": "server-test serve :3000 cy:run"? Is it not responding? Maybe CRA app does not handle OPTIONS requests and instead you need to use "test:cypress:run": "server-test serve http-get://localhost:3000 cy:run" to prove with HTTP GET

artivilla commented 4 years ago

Yeah the first one you mentioned doesn't work. We landed up just using the open cmd instead and in the CI the server runs using the cypress-io/cypress@1.13.0 orb

"test": "source .env.dev && npm-run-all --parallel --race start:instrument cypress:open",
"test:CI": "source .env.dev && npm-run-all --parallel --race start:instrument cypress:run && npm run report:summary",

for circle/config.yml:

            - cypress/run:
                requires:
                  - cypress/install
                start: 'npm run start:instrument'
                wait-on: 'http://localhost:3000'

posting incase anyone else wants to use this. thanks for the follow up though!