-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e83dc7d
commit bdf7f4d
Showing
6 changed files
with
52 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,52 @@ | ||
'use strict' | ||
|
||
const pkg = require('./package.json') | ||
const execa = require('execa') | ||
const { chromium } = require('playwright'); | ||
|
||
module.exports = { | ||
[pkg.name]: function (browser) { | ||
browser | ||
.url(process.env.LIBP2P_EXAMPLE_TEST_URL) | ||
.waitForElementVisible('#status') | ||
.waitForElementVisible('#output') | ||
.pause(5000) | ||
async function run() { | ||
let url = '' | ||
const proc = execa('parcel', ['./index.html'], { | ||
preferLocal: true, | ||
localDir: __dirname, | ||
cwd: __dirname, | ||
all: true | ||
}) | ||
|
||
browser.expect.element('#status').text.to.contain('libp2p started!') | ||
browser.expect.element('#output').text.to.contain('libp2p id is') | ||
proc.all.on('data', async (chunk) => { | ||
/**@type {string} */ | ||
const out = chunk.toString() | ||
|
||
browser.expect.element('#output').text.to.contain('Found peer') | ||
browser.expect.element('#output').text.to.contain('Connected to') | ||
if (out.includes('Server running at')) { | ||
url = out.replace('Server running at ', '') | ||
} | ||
|
||
if (out.includes('✨ Built in ')) { | ||
try { | ||
const browser = await chromium.launch(); | ||
const page = await browser.newPage(); | ||
await page.goto(url); | ||
await page.waitForFunction(selector => document.querySelector(selector).innerText === 'libp2p started!', '#status') | ||
await page.waitForFunction( | ||
selector => { | ||
const text = document.querySelector(selector).innerText | ||
return text.includes('libp2p id is') && | ||
text.includes('Found peer') && | ||
text.includes('Connected to') | ||
}, | ||
'#output', | ||
{ timeout: 5000 } | ||
) | ||
await browser.close(); | ||
|
||
} catch (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} finally { | ||
proc.cancel() | ||
} | ||
} | ||
}) | ||
|
||
browser.end() | ||
} | ||
} | ||
|
||
module.exports = run |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters