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

feat: integration testing helper #461

Closed
wants to merge 3 commits into from
Closed

Conversation

bcoe
Copy link
Contributor

@bcoe bcoe commented Dec 21, 2016

What is this?

Creates an integration testing helper that's exposed via next/test/helper. This is useful for upstream apps that would like to test next.js using an integration server.

why? I'm OCD about unit-testing, and as far as I can tell existing tools like Enzyme don't work perfectly for next.js, since next.js' rendering helpers have quite a bit of magic (good magic, mind you):

  const doc = createElement(Document, {
    __NEXT_DATA__: {
      component,
      errorComponent,
      props,
      pathname,
      query,
      err: (err && dev) ? errorToJSON(err) : null
    },
    dev,
    staticMarkup,
    ...docProps
  })

The API

async setup():

Sets up the integration testing application.

SKIP_BUILD=1 can be provided, to avoid building an application between test runs -- this can be useful when you're adding unit-tests to an existing codebase.

async teardown():

Cleanup the integration testing application.

async render(path, query, req, res, opts):

Helper for rendering application:

The order of arguments is different than render/renderToHTML, to better server the most common use-case:

render('/some-path', {q: 'some params'})

The query-string module is used to magically populate req.url.

@coveralls
Copy link

coveralls commented Dec 21, 2016

Coverage Status

Coverage increased (+2.08%) to 60.487% when pulling 5bbc458 on bcoe:test-helper into fe962b1 on zeit:master.

@nkzawa
Copy link
Contributor

nkzawa commented Dec 21, 2016

👍 I wonder if this helper can be a different library.

@rauchg
Copy link
Member

rauchg commented Dec 21, 2016

same

@bcoe
Copy link
Contributor Author

bcoe commented Dec 21, 2016

@nkzawa if so, want to have dibs and create something in the zeit org?

@rauchg
Copy link
Member

rauchg commented Dec 22, 2016

@bcoe done, check your notifications. Closing for now

@rauchg rauchg closed this Dec 22, 2016
@bcoe
Copy link
Contributor Author

bcoe commented Dec 22, 2016

@rauchg awesome, I'll get a repo stubbed out tomorrow.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants