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.

Use server origin by default

See original GitHub issue

🚀 Feature Proposal

I would love to be able to do page.goto('/') instead of page.goto('http://localhost:3000/'). Currently if I try that I get

Protocol error (Page.navigate): Cannot navigate to invalid URL

      1 | describe('MyApp: /', () => {
      2 |   beforeAll(async () => {
    > 3 |     await page.goto('/')
        |                ^
      4 |   })

Motivation

Not having to specify the protocol, host, and port in each test makes tests easier to write. It also makes it easier to change the way all tests are run, e.g. changing http: to https:.

Example

// jest-puppeteer.config.js:
module.exports = {
  server: {
    command: 'yarn run start',
    port: 3000,
  },
}

// if no origin is provided, use the one from the jest-puppeteer config:
await page.goto('/')

// but you can always tell the browser to go elsewhere if needed:
await page.goto('https://some-third-party-provider.com')

Pitch

Jest Puppeteer already knows about the protocol, host, and port from jest-puppeteer.config.js. It can use this information to make writing tests easier.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
xiaoyuhencommented, Mar 15, 2019

hi @jamesarosen

Very useful feature and a very nice solution. Could you take a PR to do this?

1reaction
jamesarosencommented, Mar 14, 2019

I can do this with a custom environment:

const PuppeteerEnvironment = require('jest-environment-puppeteer')

class CustomEnvironment extends PuppeteerEnvironment {
async setup() {
    await super.setup()

    const server = this.global.puppeteerConfig || {}
    const host = server.host || 'localhost'
    const port = server.port || 3000
    const protocol = server.protocol || 'http'
    const originalGoto = this.global.page.goto

    this.global.page.goto = async function goto(pathOrURL) {
      const url = /^\//.test(pathOrURL)
        ? `${protocol}://${host}:${port}${pathOrURL}`
        : pathOrURL
      return originalGoto.call(this, url)
    }
  }
}

module.exports = CustomEnvironment
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure the Origin Server behavior
Origin Server is a mandatory behavior in the Default Rule. An error message is revealed if you delete it, and you need to...
Read more >
What is an origin server? | Origin server definition
The purpose of an origin server is to process and respond to incoming Internet requests from Internet clients.
Read more >
Origin - HTTP - MDN Web Docs
The domain name or the IP address of the origin server. ... If no port is given, the default port for the requested...
Read more >
15.12 Tuning Connections to Origin Servers
Idle timeout: This parameter specifies the maximum duration, in seconds, for which a connection to the origin server can remain idle. The default...
Read more >
Changing origins based on user location | Fastly Help Guides
First, create a header for the default origin server to serve content to the majority of users. Follow these instructions to create the...
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