start-server-and-test icon indicating copy to clipboard operation
start-server-and-test copied to clipboard

When used with Gatsby's --https flag, the test command is never run

Open Undistraction opened this issue 5 years ago • 10 comments

Is this a bug report or a feature request?

I guess it's a bug if it is supposed to work and a feature request if it isn't.

  • version 1.7.12
  • platform OSX

Reproduction using Gatsby's default starter here.

Expected behavior

With the following npm scripts:

"develop": "gatsby develop --https",
"start": "npm run develop",
"cy:open": "cypress open",
"test:e2e": "start-server-and-test develop https://localhost:8000 cy:open"

I should be able to run npm run test:e2e, see Gatsby run the development server, and Cypress open in a new window.

Actual behavior

Gatsby runs the development server but Cypress never opens.

Discussion

This works fine without the --https flag for gatsby develop.

Undistraction avatar Mar 19 '19 16:03 Undistraction

Hmm, you would need to debug what is going on using DEBUG environment variable to see where the problem happens - is this because wait-on does not connect?

bahmutov avatar Mar 20 '19 13:03 bahmutov

I tried that. The only thing that is output from this lib is:

starting server using command "npm run develop" and when url "https://localhost:8000" is responding running tests using command "cy:open"

The full output:

> [email protected] test:e2e /Users/pedrbrowne/Desktop/ssat/ssat-https
> DEBUG=1 start-server-and-test develop https://localhost:8000 cy:open

starting server using command "npm run develop"
and when url "https://localhost:8000" is responding
running tests using command "cy:open"

> [email protected] develop /Users/pedrbrowne/Desktop/ssat/ssat-https
> gatsby develop --https

info setting up automatic SSL certificate (may require sudo)

success open and validate gatsby-configs — 0.006 s
success load plugins — 0.183 s
success onPreInit — 0.588 s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's not any stale
data
success initialize cache — 0.076 s
success copy gatsby files — 0.095 s
success onPreBootstrap — 0.014 s
success source and transform nodes — 0.066 s
success building schema — 0.240 s
success createPages — 0.001 s
success createPagesStatefully — 0.042 s
success onPreExtractQueries — 0.004 s
success update schema — 0.091 s
success extract queries from components — 0.075 s
success run graphql queries — 0.082 s — 8/8 99.32 queries/second
success write out page data — 0.003 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.108 s

info bootstrap finished - 5.68 s

 DONE  Compiled successfully in 3193ms                                                                                                                                                                                     14:03:30


You can now view gatsby-starter-default in the browser.

  https://localhost:8000/

View GraphiQL, an in-browser IDE, to explore your site's data and schema

  https://localhost:8000/___graphql

Note that the development build is not optimized.
To create a production build, use npm run build

ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.
 WAIT  Compiling...                                                                                                                                                                                                        14:03:30

ℹ 「wdm」: Compiling...
 DONE  Compiled successfully in 27ms                                                                                                                                                                                       14:03:31

ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.

Undistraction avatar Mar 20 '19 14:03 Undistraction

no, I meant debugging using DEBUG=... env variable like shown here: https://github.com/bahmutov/start-server-and-test#debugging

bahmutov avatar Mar 20 '19 14:03 bahmutov

Ah sorry. Moving between different projects:

> $ npm run test:e2e

> [email protected] test:e2e /Users/me/repro/ssat/ssat-https
> DEBUG=start-server-and-test start-server-and-test develop https://localhost:8000 cy:open

starting server using command "npm run develop"
and when url "https://localhost:8000" is responding
running tests using command "cy:open"
  start-server-and-test starting server, verbose mode? true +0ms
  start-server-and-test starting waitOn https://localhost:8000 +8ms

> [email protected] develop /Users/pedrbrowne/Desktop/ssat/ssat-https
> gatsby develop --https

child next [ { 'https://localhost:8000': -999 } ]
wait-on(77214) waiting for: https://localhost:8000
child complete
info setting up automatic SSL certificate (may require sudo)

success open and validate gatsby-configs — 0.006 s
success load plugins — 0.148 s
success onPreInit — 0.346 s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's not any stale
data
success initialize cache — 0.071 s
success copy gatsby files — 0.089 s
success onPreBootstrap — 0.011 s
success source and transform nodes — 0.062 s
success building schema — 0.212 s
success createPages — 0.001 s
success createPagesStatefully — 0.043 s
success onPreExtractQueries — 0.004 s
⠁ child next []
child complete
success update schema — 0.115 s
success extract queries from components — 0.077 s
success run graphql queries — 0.070 s — 8/8 116.09 queries/second
success write out page data — 0.003 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.105 s

info bootstrap finished - 3.933 s

child next []
child complete
 DONE  Compiled successfully in 2932ms                                                                                                                                                                                     14:47:24


You can now view gatsby-starter-default in the browser.

  https://localhost:8000/

View GraphiQL, an in-browser IDE, to explore your site's data and schema

  https://localhost:8000/___graphql

Note that the development build is not optimized.
To create a production build, use npm run build

ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.
 WAIT  Compiling...                                                                                                                                                                                                        14:47:25

ℹ 「wdm」: Compiling...
child next []
child complete
 DONE  Compiled successfully in 28ms                                                                                                                                                                                       14:47:25

ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.
child next []
child complete
child next []
child complete
child next []
child complete
child next []
child complete
child next []
child complete
child next []
child complete
child next []
etc

Undistraction avatar Mar 20 '19 14:03 Undistraction

Weird, seems wait-on does not work correctly against this local https certificate. Is this a project I can clone and run myself?

Sent from my iPhone

On Mar 20, 2019, at 10:49, Pedr Browne [email protected] wrote:

Ah sorry. Moving between different projects:

$ npm run test:e2e

[email protected] test:e2e /Users/me/repro/ssat/ssat-https DEBUG=start-server-and-test start-server-and-test develop https://localhost:8000 cy:open

starting server using command "npm run develop" and when url "https://localhost:8000" is responding running tests using command "cy:open" start-server-and-test starting server, verbose mode? true +0ms start-server-and-test starting waitOn https://localhost:8000 +8ms

[email protected] develop /Users/pedrbrowne/Desktop/ssat/ssat-https gatsby develop --https

child next [ { 'https://localhost:8000': -999 } ] wait-on(77214) waiting for: https://localhost:8000 child complete info setting up automatic SSL certificate (may require sudo)

success open and validate gatsby-configs — 0.006 s success load plugins — 0.148 s success onPreInit — 0.346 s info One or more of your plugins have changed since the last time you ran Gatsby. As a precaution, we're deleting your site's cache to ensure there's not any stale data success initialize cache — 0.071 s success copy gatsby files — 0.089 s success onPreBootstrap — 0.011 s success source and transform nodes — 0.062 s success building schema — 0.212 s success createPages — 0.001 s success createPagesStatefully — 0.043 s success onPreExtractQueries — 0.004 s ⠁ child next [] child complete success update schema — 0.115 s success extract queries from components — 0.077 s success run graphql queries — 0.070 s — 8/8 116.09 queries/second success write out page data — 0.003 s success write out redirect data — 0.001 s success onPostBootstrap — 0.105 s

info bootstrap finished - 3.933 s

child next [] child complete DONE Compiled successfully in 2932ms 14:47:24

You can now view gatsby-starter-default in the browser.

https://localhost:8000/

View GraphiQL, an in-browser IDE, to explore your site's data and schema

https://localhost:8000/___graphql

Note that the development build is not optimized. To create a production build, use npm run build

ℹ 「wdm」: ℹ 「wdm」: Compiled successfully. WAIT Compiling... 14:47:25

ℹ 「wdm」: Compiling... child next [] child complete DONE Compiled successfully in 28ms 14:47:25

ℹ 「wdm」: ℹ 「wdm」: Compiled successfully. child next [] child complete child next [] child complete child next [] child complete child next [] child complete child next [] child complete child next [] child complete child next [] — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

bahmutov avatar Mar 20 '19 14:03 bahmutov

Yes. You can:

  • Clone https://github.com/Undistraction/ssat-https.git
  • cd ssat-https
  • npm install
  • npm run test:e2e

Note that this is just a reproduction to isolate the issue, but in our real project we hit the same issue using our own certs:

gatsby develop --open --https --host example.local --cert-file ./certificates/example.local .crt --key-file ./certificates/example.local.key

Undistraction avatar Mar 20 '19 15:03 Undistraction

Facing the same problem. I think the problem is with wait-on. This worked:

yarn concurrently "yarn start" "yarn wait-on http://localhost:3000/login && yarn test:e2e"

while changing to https and running the https server failed

yarn concurrently "yarn start" "yarn wait-on https://localhost:3000/login && yarn test:e2e"
yarn concurrently "yarn start" "yarn wait-on https-get://localhost:3000/login && yarn test:e2e"

Using concurrently: https://www.npmjs.com/package/concurrently

azizhk avatar Mar 20 '19 16:03 azizhk

yeah, can you start the https local site and try to use "wait-on" by itself to query it?

On Wed, Mar 20, 2019 at 12:11 PM Aziz Khambati [email protected] wrote:

Facing the same problem. I think the problem is with wait-on https://www.npmjs.com/package/wait-on. This worked:

yarn concurrently "yarn start" "yarn wait-on http://localhost:3000/login && yarn test:e2e"

while changing to https and running the https server failed

yarn concurrently "yarn start" "yarn wait-on https://localhost:3000/login && yarn test:e2e"

yarn concurrently "yarn start" "yarn wait-on https-get://localhost:3000/login && yarn test:e2e"

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bahmutov/start-server-and-test/issues/152#issuecomment-474906449, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHAphPnbWEYVni-5vXPPGP3v1jj_ExWks5vYl2TgaJpZM4b8mtN .

-- Dr. Gleb Bahmutov, PhD

Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov [email protected] @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov

bahmutov avatar Mar 20 '19 16:03 bahmutov

Tried that In one terminal window: yarn start In another: yarn wait-on https://local.anarock.com:3000/login && yarn test:e2e Did not work.

azizhk avatar Mar 20 '19 16:03 azizhk

Well so I'm using self-signed certs, so I guess I will either need to pass http options to wait-on or set environment variable NODE_TLS_REJECT_UNAUTHORIZED=0 https://github.com/jeffbski/wait-on/issues/2 https://github.com/jeffbski/wait-on/pull/3

Edit: Idiot me. I should have used https://github.com/bahmutov/start-server-and-test#disable-https-certificate-checks START_SERVER_AND_TEST_INSECURE=1

azizhk avatar Mar 20 '19 16:03 azizhk