-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement testing system that uses build folder (#39)
Co-authored-by: Beanes <sikyserver@gmail.com>
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.next_build_id.txt | ||
build/ | ||
node_modules | ||
package-lock.json |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"https://cutt.ly/9WBfIgT": { | ||
"destination": "www.google.com", | ||
"timeout": 5000 | ||
} | ||
} |
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 |
---|---|---|
@@ -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) | ||
|
||
|
||
})() |
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 |
---|---|---|
@@ -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" | ||
} | ||
} |