Skip to content

Commit

Permalink
Implement testing system that uses build folder (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Beanes <sikyserver@gmail.com>
  • Loading branch information
Beaness and Beaness authored Sep 19, 2021
1 parent 3ed9e5f commit 823c6af
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.next_build_id.txt
build/
node_modules
package-lock.json
6 changes: 6 additions & 0 deletions tests/bypasses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"https://cutt.ly/9WBfIgT": {
"destination": "www.google.com",
"timeout": 5000
}
}
83 changes: 83 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const puppeteer = require('puppeteer')
const path = require('path')

const { EventEmitter } = require('events');
const { URL } = require('url');

const bypasses = require('./bypasses.json');



class TimeoutError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}


(async() => {
const browser = await puppeteer.launch({
headless: false,
args: [
'--no-sandbox',
`--load-extension=${path.join(__dirname, '../build/FastForward.chromium')}`
],
ignoreDefaultArgs: ['--disable-extensions', '--enable-automation']
});

// We do not need to view the FastForward site
browser.on('targetcreated', async target => {
if (target.url() === 'https://universal-bypass.org/firstrun') {
const targetPage = await target.page()
targetPage.close()
return;
}
})
const page = await browser.newPage()
await page.setRequestInterception(true);
// A custom EventEmitter to emit url changes
const urlEmitter = new EventEmitter()
page.on('request', request => {
const url = new URL(request.url())
urlEmitter.emit('change', url.host)
request.continue();
})

const waitForDomain = (domain, timeoutms) => {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new TimeoutError(`Timeout limit of ${timeoutms}ms has been exceeded`))
}, timeoutms)
const listener = urlEmitter.on('change', changedURL => {
if (domain === changedURL) {
clearTimeout(timeout)
resolve();
urlEmitter.removeListener('change', listener);
}
})
})
}

// Wait 3 seconds for FastForward to load
setTimeout(async () => {
for (const url in bypasses) {
const destination = bypasses[url].destination
const timeout = bypasses[url].timeout || 5000
console.log(`⌛ Testing "${url}" with expected destination "${destination}"`)
await page.goto(url)
await waitForDomain(destination, timeout)
.then(() => {
console.log(`✔️ Success`)
})
.catch(err => {
console.log(`❌ Failed at ${url}. ${err.message}`)
process.exit(1)
})
}
console.log('✓ All bypasses have passed the test!')
}, 3000)


})()
17 changes: 17 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "autotest",
"version": "1.0.0",
"description": "A tool to automatically test FastForward extension",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/FastForwardTeam/FastForward.git",
"directory": "tests"
}
}
"license" : "Unlicense",
"author": "Beaness",
"dependencies": {
"puppeteer": "^10.2.0"
}
}

0 comments on commit 823c6af

Please sign in to comment.