-
Notifications
You must be signed in to change notification settings - Fork 445
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
chore: add browser example test #846
Conversation
09a5f24
to
46c197d
Compare
'use strict'
const execa = require('execa')
const assert = require('assert')
const { chromium } = require('playwright');
async function run () {
let url = ''
const proc = execa('parcel', ['./index.html'], {
preferLocal: true,
localDir: __dirname,
cwd: __dirname,
all: true
})
proc.all.on('data', async (chunk) => {
/**@type {string} */
const out = chunk.toString()
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()
}
}
})
}
module.exports = run With the above snippet in the test.js there no need for changes in the others files. What do you think ? |
46c197d
to
2b6fece
Compare
@@ -8,6 +8,7 @@ | |||
], | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1", | |||
"build": "parcel build index.html", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not needed with the new setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried this out, but we need it otherwise the tests do not run.
2b6fece
to
bdf7f4d
Compare
bdf7f4d
to
03173f3
Compare
Thanks for the suggestions @hugomrdias . This should now be good. Just waiting on CI |
This PR adds a test for the libp2p in the browser example. It also includes the browser setup for testing examples based on ipfs/js-ipfs#2528