Skip to content

Commit

Permalink
fix(openApp): Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsonchuong committed Jan 4, 2019
1 parent c36ca75 commit e7f848b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import React from 'react'
import { render } from 'react-dom'

Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* @flow */
import type { Tab } from 'puppet-strings'
import * as http from 'http'
import { openChrome, openTab } from 'puppet-strings'
import { promisify } from 'util'
import { openChrome, openTab, closeBrowser } from 'puppet-strings'
import Bundler from 'parcel-bundler'
import tempy from 'tempy'
import getPort from 'get-port'

const sleep = promisify(setTimeout)

export default async function(appPath: string): Promise<Tab> {
const bundler = new Bundler(appPath, {
watch: false,
Expand All @@ -18,7 +20,16 @@ export default async function(appPath: string): Promise<Tab> {
const browser = await openChrome()
const tab = await openTab(browser, `http://localhost:${port}`)

server.close()
// Always true--to appease the type-checker
if (tab.puppeteer) {
tab.puppeteer.page.on('close', async () => {
// Allow enough time for Puppeteer to clean up before closing browser
await sleep(0)

closeBrowser(browser)
server.close()
})
}

return tab
}
4 changes: 2 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */
import test from 'ava'
import { closeBrowser, findElement } from 'puppet-strings'
import { closeTab, findElement } from 'puppet-strings'
import openApp from 'puppet-strings-open-app'

test('compiling and opening a web application', async t => {
Expand All @@ -9,5 +9,5 @@ test('compiling and opening a web application', async t => {

t.is(root.innerText, 'Hello World!')

await closeBrowser(app)
await closeTab(app)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"get-port": "^4.1.0",
"parcel-bundler": "^1.11.0",
"puppet-strings": "^2.3.1",
"puppet-strings": "^2.3.2",
"tempy": "^0.2.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8013,10 +8013,10 @@ punycode@^2.1.0:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==

puppet-strings@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/puppet-strings/-/puppet-strings-2.3.1.tgz#5c36a08529b3b447cf99232c8ede9f5008ced22a"
integrity sha512-Fzr4lUVrPZwgOCKIx+i6e4XNEX0TX0nfuoUHwB7SZVSfleqJYZdyJhEKdwBkX1aICoD4eE6IIP/qFahulg9EqQ==
puppet-strings@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/puppet-strings/-/puppet-strings-2.3.2.tgz#579e591d5dbd39d17c9b2807b8819890a09dacb7"
integrity sha512-8IeFD9lwgxHJm+T9QaYEczIXamg1p4I3o8qKyqMbuQDYGbNyydYUixZLujgmpyToLN26964ssymvMelhAiJTsw==
dependencies:
css-to-xpath "^0.1.0"
geckodriver "^1.14.1"
Expand Down

0 comments on commit e7f848b

Please sign in to comment.