infernojs / inferno

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces

Home Page:https://infernojs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SSR tests are run in JSDOM env and rely on document

jhsware opened this issue · comments

Observed Behaviour

All server rendering tests are run with JSDOM-environment exposing document which isn't available in node during SSR.

Expected Current Behaviour

We should run *.spec.server.jsx with separate config file and testEnvironment: "node"

it would be great if inferno_hydrate could use a configurable dom object, as in

import { hydrate } from 'inferno-hydrate';
import jsdom from 'jsdom'

const dom = new jsdom.JSDOM(
  '<!DOCTYPE html><body><div></div></body>')

hydrate(
  createElement('div', { className: 'test' }, "I'm a child!"),
  dom.window.document.body.firstChild,
  dom // optional, configurable dom definition 
);

This would allow inferno_hydrate to be used in concurrently running unit-tests inside a node runtime and without setting global dom variables. Currently, using inferno_hydrate inside node requires global variables and so concurrent tests cannot be used. eg, currently something like this is needed...

import { hydrate } from 'inferno-hydrate';
import jsdom from 'jsdom'

const dom = new jsdom.JSDOM(
  '<!DOCTYPE html><body><div></div></body>')
global.window = dom.window
global.document = dom.window.document

hydrate(
  createElement('div', { className: 'test' }, "I'm a child!"),
  dom.window.document.body.firstChild);

Good idea. Do you want to submit a PR for it?

This could probably be a inferno-wide option to set the DOM.

thanks for the welcoming reply I will think about it