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

[do not merge] Wait for feature element #1461

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/react-scripts/fixtures/kitchensink/integration/initDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const path = require('path')

let getMarkup
let resourceLoader
// this value could be tweaked in order to let the resource
// retriever get every file and jsdom execute react
let timeToWaitForJsToExecute
let initCallback

if (process.env.E2E_FILE) {
const file = path.isAbsolute(process.env.E2E_FILE)
Expand All @@ -22,7 +20,7 @@ if (process.env.E2E_FILE) {
fs.readFileSync(path.join(path.dirname(file), resource.url.pathname), 'utf8')
)

timeToWaitForJsToExecute = 0
initCallback = (doc, resolve) => doc.defaultView.addEventListener('load', () => resolve(doc), false)
} else if (process.env.E2E_URL) {
getMarkup = () => new Promise(resolve => {
http.get(process.env.E2E_URL, (res) => {
Expand All @@ -36,7 +34,7 @@ if (process.env.E2E_FILE) {
return resource.defaultFetch(callback)
}

timeToWaitForJsToExecute = 100
initCallback = (doc, resolve) => doc.addEventListener('fixture', () => resolve(doc), false)
} else {
it.only('can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)', () => {
expect(new Error('This isn\'t the error you are looking for.')).toBeUndefined()
Expand All @@ -47,16 +45,14 @@ export default feature => new Promise(async resolve => {
const markup = await getMarkup()
const host = process.env.E2E_URL || 'http://localhost:3000'
const doc = jsdom.jsdom(markup, {
features : {
FetchExternalResources : ['script', 'css'],
ProcessExternalResources : ['script'],
features: {
FetchExternalResources: ['script', 'css'],
ProcessExternalResources: ['script'],
},
resourceLoader,
url: `${host}#${feature}`,
virtualConsole: jsdom.createVirtualConsole().sendTo(console),
})

doc.defaultView.addEventListener('load', () => {
setTimeout(() => resolve(doc), timeToWaitForJsToExecute)
}, false)
initCallback(doc, resolve)
})
7 changes: 7 additions & 0 deletions packages/react-scripts/fixtures/kitchensink/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import fixtureEvent from './features/fixture-event';

class App extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -94,6 +95,12 @@ class App extends React.Component {
this.setState({ feature });
}

componentDidUpdate() {
const { feature } = this.state;
if (feature === null || React.Component.isPrototypeOf(feature)) return;
fixtureEvent(document);
}

render() {
const Feature = this.state.feature;
return Feature ? <Feature /> : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import load from 'absoluteLoad'
import fixtureEvent from '../fixture-event'

export default class extends React.Component {
constructor(props) {
Expand All @@ -13,6 +14,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-node-path">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default doc => {
const event = doc.createEvent('CustomEvent');
event.initCustomEvent('fixture', true, true, {});
doc.dispatchEvent(event);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load() {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-array-destructuring">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load(users) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-array-spread">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

async function load() {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-async-await">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

export default class extends React.Component {
users = [
Expand All @@ -8,6 +9,10 @@ export default class extends React.Component {
{ id: 4, name: '4' }
];

componentDidMount() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-class-properties">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load(prefix) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-computed-properties">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

const styled = ([style]) => style.trim()
.split(/\s*;\s*/)
Expand Down Expand Up @@ -26,6 +27,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
const veryInlineStyle = styled`
background: palevioletred;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load(id = 0) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-default-parameters">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

async function load() {
return { users: [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-destructuring-and-await">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function * load(limit) {
let i = 1;
Expand All @@ -23,6 +24,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-generators">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load() {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-object-destructuring">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load(baseUser) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-object-spread">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load() {
return Promise.resolve([
Expand All @@ -22,6 +23,10 @@ export default class extends React.Component {
});
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-promises">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load({ id, ...rest } = { id: 0, user: { id: 42, name: '42' } }) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-rest-and-default">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load({ id = 0, ...rest }) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-rest-parameters">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import fixtureEvent from '../fixture-event'

function load(name) {
return [
Expand All @@ -21,6 +22,10 @@ export default class extends React.Component {
this.setState({ users });
}

componentDidUpdate() {
fixtureEvent(document);
}

render() {
return (
<div id="feature-template-interpolation">
Expand Down