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

Timed out waiting for a url #375

Open
RosyCloudsLee opened this issue Nov 28, 2023 · 5 comments
Open

Timed out waiting for a url #375

RosyCloudsLee opened this issue Nov 28, 2023 · 5 comments

Comments

@RosyCloudsLee
Copy link

Environment
start-server-and-test:2.0.3
node: 20.9.0
pnpm: 8.9.0
npm: 10.1.0
os: ubuntu 20.04

In package.json,
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e --browser firefox'"

Run pnpm test:e2e,show

1: starting server using command "npm run preview"
and when url "[ 'http://localhost:4173' ]" is responding with HTTP status code 200
running tests using command "cypress run --e2e --browser firefox"

 xx-yy@3.0.7 preview
 vite preview

  ➜  Local:   http://localhost:4173/

Error: Timed out waiting for: http://localhost:4173
    at /home/xx/Documents/work/xx-yy/node_modules/.pnpm/wait-on@7.2.0_debug@4.3.4/node_modules/wait-on/lib/wait-on.js:131:31
    at doInnerSub (/home/xx/Documents/work/xx-yy/node_modules/.pnpm/rxjs@7.8.1/node_modules/rxjs/dist/cjs/internal/operators/mergeInternals.js:22:31)

When stopping vite preview, visit http://localhost:4173 successfully.
Use npx cypress run --e2e --browser firefox ok

@Robbson
Copy link

Robbson commented Nov 30, 2023

I've got the same issue. Switching back to v2.0.1 makes it working again.

@RosyCloudsLee
Copy link
Author

I switched back to v2.0.1. It also has this problem

@chenweiyi
Copy link

chenweiyi commented Dec 14, 2023

I can do this.
First, check start-server-and-test version is >=2.0.3
Second, set vite.config.js :

server: {
    host: '0.0.0.0'
  },
  preview: {
    host: '0.0.0.0',
    port: 4173
  }

@rkrisztian
Copy link

rkrisztian commented Jan 10, 2024

I have the same issue (tested on Linux). Version 2.0.2 works, version 2.0.3 does not. The only change that happened in this version was:

v2.0.2...v2.0.3

I'll check if this is a known issue with wait-on.

@rkrisztian
Copy link

I couldn't tie this problem to either the wait-on or axios version change. I think it's related to how start-server-and-test uses wait-on, although I'm not sure. Here's some details.

Test 1: Testing wait-on alone in an empty project using a test script:

$ npm i wait-on@7.1.0 && npm list axios && node test.js 
(...)
waiton2@1.0.0 tempProjects/waiton2
└─┬ wait-on@7.1.0
  └── axios@0.27.2

waiting for 1 resources: http://127.0.0.1:5173
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) result for http://127.0.0.1:5173: {
  status: 200,
  statusText: 'OK',
  headers: {
    'access-control-allow-origin': '*',
    'content-type': 'text/html',
    'cache-control': 'no-cache',
    etag: 'W/"4f2-OGT49f3kLhD7R/gJSN/I4kYS59M"',
    date: 'Wed, 10 Jan 2024 12:35:08 GMT',
    connection: 'close'
  },
  data: ''
}
wait-on(439093) complete
waitOn finished successfully


$ npm i wait-on@7.2.0 && npm list axios && node test.js 
(...)
waiton2@1.0.0 tempProjects/waiton2
└─┬ wait-on@7.2.0
  └── axios@1.6.5

waiting for 1 resources: http://127.0.0.1:5173
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) result for http://127.0.0.1:5173: {
  status: 200,
  statusText: 'OK',
  headers: Object [AxiosHeaders] {
    'access-control-allow-origin': '*',
    'content-type': 'text/html',
    'cache-control': 'no-cache',
    etag: 'W/"4f2-OGT49f3kLhD7R/gJSN/I4kYS59M"',
    date: 'Wed, 10 Jan 2024 12:34:58 GMT',
    connection: 'close'
  },
  data: ''
}
wait-on(439031) complete
waitOn finished successfully

My test script was the following. I tried to approximate as much as I could to what start-server-and-test does:

const waitOn = require('wait-on');

const url = 'http://127.0.0.1:5173';

// Options for wait-on
const options = {
  resources: [url],
  delay: 1000, // initial delay in ms, default 0
  timeout: 10000, // timeout in ms, default Infinity
  interval: 2000,
  window: 1000,
  log: true, // Enables logging
  verbose: true,
  headers: {
    Accept: 'text/html, application/json, text/plain, */*',
  },
  validateStatus: (status) => (status >= 200 && status < 300) || status === 304,
};

// Wait for the resource to become available
waitOn(options, (err) => {
  if (err) {
    console.log('error waiting for url', url);
    console.log(err.message);
    return;
  }
  console.log('waitOn finished successfully');
});

Test 2: However, when I used start-server-and-test, I had different results in a freshly-created Vite project (created with command npm create vite@latest -- --template vanilla):

$ npm i -D start-server-and-test@2.0.2 && npm list axios
(...)
vite-project@0.0.0 tempProjects/waiton
└─┬ start-server-and-test@2.0.2
  └─┬ wait-on@7.1.0
    └── axios@0.27.2


$ DEBUG=start-server-and-test:* npm test

> vite-project@0.0.0 test
> start-server-and-test preview 5173 'echo successful'

1: starting server using command "npm run preview"
and when url "[ 'http://127.0.0.1:5173' ]" is responding with HTTP status code 200
running tests using command "echo successful"

waiting for 1 resources: http://127.0.0.1:5173
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) error for http://127.0.0.1:5173 Error: connect ECONNREFUSED 127.0.0.1:5173

> vite-project@0.0.0 preview
> vite preview --port 5173

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) result for http://127.0.0.1:5173: {
  status: 200,
  statusText: 'OK',
  headers: {
    'access-control-allow-origin': '*',
    'content-type': 'text/html',
    'cache-control': 'no-cache',
    etag: 'W/"1c6-uOcU/FEPRFIQaiTkxuyeY9g0IwA"',
    date: 'Wed, 10 Jan 2024 12:47:08 GMT',
    connection: 'close'
  },
  data: ''
}
wait-on(440429) complete
successful


$ npm i -D start-server-and-test@2.0.3 && npm list axios
(...)
vite-project@0.0.0 tempProjects/waiton
└─┬ start-server-and-test@2.0.3
  └─┬ wait-on@7.2.0
    └── axios@1.6.5

$ DEBUG=start-server-and-test:* npm test

> vite-project@0.0.0 test
> start-server-and-test preview 5173 'echo successful'

1: starting server using command "npm run preview"
and when url "[ 'http://127.0.0.1:5173' ]" is responding with HTTP status code 200
running tests using command "echo successful"

waiting for 1 resources: http://127.0.0.1:5173
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) error for http://127.0.0.1:5173 AxiosError: Request failed with status code 504

> vite-project@0.0.0 preview
> vite preview --port 5173

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) error for http://127.0.0.1:5173 AxiosError: Request failed with status code 504
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
  HTTP(S) error for http://127.0.0.1:5173 AxiosError: Request failed with status code 504
making HTTP(S) head request to  url:http://127.0.0.1:5173 ...
^C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants