-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds jest + puppeteer and adds a series of tests that goes through customizing a game, exporting, and testing that the hacked game works. note that the tests are all done in a single run, not isolated, and primarily use image snapshots (this isn't best practice, but is quicker/easier and should be good enough for the coverage we'd care about)
- Loading branch information
Showing
17 changed files
with
8,120 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
Binary file added
BIN
+48.7 KB
...ts__/index-test-js-borksy-should-allow-custom-javascript-to-be-added-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.8 KB
..._snapshots__/index-test-js-borksy-should-allow-game-to-be-customized-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.5 KB
..._snapshots__/index-test-js-borksy-should-allow-game-to-be-customized-2-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.8 KB
..._snapshots__/index-test-js-borksy-should-allow-game-to-be-customized-3-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.8 KB
..._snapshots__/index-test-js-borksy-should-allow-game-to-be-customized-4-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.9 KB
...apshots__/index-test-js-borksy-should-collapse-sections-when-clicked-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.9 KB
...pshots__/index-test-js-borksy-should-include-customized-hack-options-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50.5 KB
..._image_snapshots__/index-test-js-borksy-should-include-hack-readm-es-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+64.9 KB
src/test/__image_snapshots__/index-test-js-borksy-should-load-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.91 KB
...hots__/index-test-js-borksy-should-produce-a-game-with-hacks-applied-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.11 KB
...mage_snapshots__/index-test-js-borksy-should-produce-a-playable-game-1-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.84 KB
...mage_snapshots__/index-test-js-borksy-should-produce-a-playable-game-2-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,157 @@ | ||
const path = require('path'); | ||
const puppeteer = require('puppeteer'); | ||
const fs = require('fs'); | ||
|
||
describe('Borksy', () => { | ||
/** @type puppeteer.Browser */ | ||
let browser; | ||
/** @type puppeteer.Page */ | ||
let page; | ||
|
||
const download = path.resolve(__dirname, 'myBORKSYgameCustomFilename.html'); | ||
|
||
beforeAll(async () => { | ||
browser = await puppeteer.launch({ | ||
headless: false, | ||
args: ['--disable-web-security', '--disable-features=IsolateOrigins', ' --disable-site-isolation-trials'], | ||
}); | ||
page = await browser.newPage(); | ||
|
||
await page._client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: path.resolve(__dirname) }); | ||
await page.goto(`file:///${path.resolve(__dirname, '../../docs/index.html').replace(/\\/g, '/')}`, { | ||
waitUntil: 'networkidle2', | ||
}); | ||
|
||
// hide mascot to avoid noise in snapshots | ||
await page.evaluate(() => { | ||
document.querySelector('#mascot').style.visibility = 'hidden'; | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await browser.close(); | ||
}); | ||
|
||
it('should load', async () => { | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should collapse sections when clicked', async () => { | ||
await page.click('#about .collapsible_header'); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should allow game to be customized', async () => { | ||
// fill out game data | ||
await page.click('form > .collapsible:first-of-type > .collapsible_header'); // open title | ||
await page.type('#title', 'Custom Title'); | ||
await page.type('#filename', 'Custom Filename'); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
|
||
// remove collision on walls | ||
await page.click('form > .collapsible:nth-of-type(3) > .collapsible_header'); // open gamedata | ||
await page.focus('#gamedata'); | ||
await page.keyboard.down('Control'); | ||
await page.keyboard.press('Home'); | ||
await page.keyboard.up('Control'); | ||
for (let i = 0; i < 39; ++i) { | ||
await page.keyboard.press('ArrowDown'); | ||
} | ||
await page.keyboard.down('Shift'); | ||
await page.keyboard.press('ArrowDown'); | ||
await page.keyboard.up('Shift'); | ||
await page.keyboard.press('Backspace'); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
|
||
// enable transparent sprites hack | ||
await page.click('#hacks-section > .collapsible_header'); // open hacks | ||
await page.click('.collapsible[data-associated-hack="transparent-sprites"] > .collapsible_header'); // open transparent sprites | ||
await page.click('.collapsible[data-associated-hack="transparent-sprites"] input[type="checkbox"]'); // click checkbox | ||
await page.click('.collapsible[data-associated-hack="transparent-sprites"] .collapsible:first-of-type > .collapsible_header'); // open hack options | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
|
||
// customize `isTransparent` check in `gameOptions` | ||
await page.focus('.collapsible[data-associated-hack="transparent-sprites"] [data-default-type="hackOptions"]'); | ||
await page.keyboard.down('Control'); | ||
await page.keyboard.press('Home'); | ||
await page.keyboard.up('Control'); | ||
await page.keyboard.press('End'); | ||
await page.keyboard.type('\n\treturn drawing === player();'); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should include hack READMEs', async () => { | ||
await page.click('.collapsible[data-associated-hack="transparent-sprites"] .collapsible:last-of-type > .collapsible_header'); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should allow custom javascript to be added', async () => { | ||
await page.click('form > .collapsible:last-of-type > .collapsible_header'); // open additional js | ||
await page.focus('#additionalJS'); | ||
await page.keyboard.type(` | ||
requestAnimationFrame(() => { | ||
var el = document.createElement('div'); | ||
el.textContent = 'test'; | ||
el.style.position = 'fixed'; | ||
el.style.top = '0'; | ||
el.style.left = '0'; | ||
el.style.color='white'; | ||
document.body.appendChild(el); | ||
}); | ||
`); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should allow game to be downloaded', async () => { | ||
// remove download if we already have one | ||
if (fs.existsSync(download)) { | ||
await fs.promises.unlink(download); | ||
} | ||
|
||
await page.click('#download-button'); // start download | ||
await page.waitForTimeout(2000); // wait for download to finish | ||
expect(fs.existsSync(download)).toBe(true); | ||
}); | ||
|
||
it('should produce a playable game', async () => { | ||
await page.goto(`file:///${download.replace(/\\/g, '/')}`, { | ||
waitUntil: 'networkidle2', | ||
}); | ||
await page.keyboard.down('ArrowRight'); // complete title dialog | ||
await page.waitForTimeout(100); | ||
await page.keyboard.up('ArrowRight'); // complete title dialog | ||
await page.waitForTimeout(100); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
await page.keyboard.down('ArrowRight'); // end title dialog | ||
await page.waitForTimeout(100); | ||
await page.keyboard.up('ArrowRight'); // end title dialog | ||
await page.waitForTimeout(100); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should produce a game with hacks applied', async () => { | ||
// walk on top of wall to demonstrate transparent sprites | ||
await page.keyboard.down('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
await page.keyboard.up('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
await page.keyboard.down('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
await page.keyboard.up('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
await page.keyboard.down('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
await page.keyboard.up('ArrowLeft'); | ||
await page.waitForTimeout(100); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
|
||
it('should include customized hackOptions', async () => { | ||
// move dog onto wall to demonstrate `isTransparent` check | ||
await page.evaluate(() => { | ||
window.sprite.a.x = 1; | ||
}); | ||
await page.waitForTimeout(100); | ||
expect(await page.screenshot()).toMatchImageSnapshot(); | ||
}); | ||
}); |
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 @@ | ||
const { toMatchImageSnapshot } = require('jest-image-snapshot'); | ||
|
||
expect.extend({ | ||
toMatchImageSnapshot, | ||
}); | ||
jest.setTimeout(20000); |