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

feat(e2e): Request Handling Tests #1272

Merged
merged 2 commits into from
Sep 9, 2023
Merged
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
63 changes: 51 additions & 12 deletions test/e2e/ipfs-companion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ async function getNumberOfConnectedPeers (browser, url) {
return parseInt(peers)
}

async function getFinalUrl (browser, initialUrl) {
await browser.get(initialUrl)
console.info('Checking the final url')
const finalUrl = await backOff(async () => {
const currentUrl = await browser.getCurrentUrl()
return currentUrl
}, {
delayFirstAttempt: true,
numOfAttempts: 5,
startingDelay: 500
})
return finalUrl
}

async function runBrowserTest (browserName, testFunc) {
const extension = getExtension(browserName)

Expand Down Expand Up @@ -175,21 +189,46 @@ async function runBrowserTest (browserName, testFunc) {
}
}

async function checkNumberOfConnectedPeers (browser, url) {
const peers = await getNumberOfConnectedPeers(browser, url)
expect(peers).not.to.equal(0)
}

describe('ipfs-companion', function () {
describe('ipfs-companion', () => {
before(function () {
if (process.env.TEST_E2E !== 'true') {
this.skip()
}
})
it('should be able to discover peers in Chromium', async function () {
await runBrowserTest('chromium', checkNumberOfConnectedPeers)
})
it('should be able to discover peers in Firefox', async function () {
await runBrowserTest('firefox', checkNumberOfConnectedPeers)
})

const browsersToTest = ['chromium', 'firefox']

for (const browserName of browsersToTest) {
describe(`ipfs-companion in ${browserName}`, () => {
it(`should be able to install the extension in ${browserName}`, async () => {
await runBrowserTest(browserName, async (browser, url) => {
const peers = await getNumberOfConnectedPeers(browser, url)
expect(peers).not.to.equal(0)
})
})

it(`should resolve urls in ${browserName}`, async () => {
await runBrowserTest(browserName, async (browser, url) => {
const urlsToTest = [{
initialUrl: 'https://ipfs.io/ipfs/QmTqZhR6f7jzdhLgPArDPnsbZpvvgxzCZycXK7ywkLxSyU?filename=ipfs-logo.3ea91a2f.svg',
finalUrl: 'http://bafybeicrwkoherkuzwp2zk3cd4jc3miwp7mrkz2blxrd5afbdibqv5ivo4.ipfs.localhost:8080/?filename=ipfs-logo.3ea91a2f.svg'
}, {
initialUrl: 'https://awesome.ipfs.io',
finalUrl: 'http://awesome.ipfs.io.ipns.localhost:8080/'
}, {
initialUrl: 'https://docs.ipfs.tech',
finalUrl: 'http://docs.ipfs.tech.ipns.localhost:8080/'
}, {
initialUrl: 'https://en.wikipedia-on-ipfs.org/wiki/InterPlanetary_File_System',
finalUrl: 'http://en.wikipedia-on-ipfs.org.ipns.localhost:8080/wiki/InterPlanetary_File_System'
}]

for (const { initialUrl, finalUrl } of urlsToTest) {
const resolvedUrl = await getFinalUrl(browser, initialUrl)
expect(resolvedUrl).to.equal(finalUrl)
}
})
})
})
}
})