E2e jsdom fix (#1470)

* E2E: run tests when react is ready

* Entangle e2e with callbacks

* Remove unused e2e lines
This commit is contained in:
Fabrizio Castellarin
2017-01-30 20:24:12 +01:00
committed by Dan Abramov
parent bc2fc80898
commit 1d586aaf31
20 changed files with 124 additions and 72 deletions

View File

@@ -5,9 +5,6 @@ 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
if (process.env.E2E_FILE) {
const file = path.isAbsolute(process.env.E2E_FILE)
@@ -21,8 +18,6 @@ if (process.env.E2E_FILE) {
null,
fs.readFileSync(path.join(path.dirname(file), resource.url.pathname), 'utf8')
)
timeToWaitForJsToExecute = 0
} else if (process.env.E2E_URL) {
getMarkup = () => new Promise(resolve => {
http.get(process.env.E2E_URL, (res) => {
@@ -32,11 +27,7 @@ if (process.env.E2E_FILE) {
})
})
resourceLoader = (resource, callback) => {
return resource.defaultFetch(callback)
}
timeToWaitForJsToExecute = 100
resourceLoader = (resource, callback) => resource.defaultFetch(callback)
} 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()
@@ -47,16 +38,16 @@ 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'],
},
created: (_, win) => win.addEventListener('ReactFeatureDidMount', () => resolve(doc), true),
deferClose: true,
resourceLoader,
url: `${host}#${feature}`,
virtualConsole: jsdom.createVirtualConsole().sendTo(console),
})
doc.defaultView.addEventListener('load', () => {
setTimeout(() => resolve(doc), timeToWaitForJsToExecute)
}, false)
doc.close()
})