Skip to content

Commit 5e7652c

Browse files
committed
Better tests. Implement prettier.
- Refactor integration tests - use http for test server - implement prettier - remove https stuff from github workflow
1 parent 443a322 commit 5e7652c

16 files changed

+1639
-361
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ jobs:
2727
- name: Install dependencies
2828
run: npm ci
2929

30-
- name: Install mkcert
31-
run: |
32-
sudo apt-get update
33-
sudo apt-get install -y libnss3-tools
34-
wget https://dl.filippo.io/mkcert/latest?for=linux/amd64 -O mkcert
35-
chmod +x mkcert
36-
sudo mv mkcert /usr/local/bin/
37-
38-
- name: Set up local CA
39-
run: mkcert -install
40-
41-
- name: Generate certificates
42-
run: npm run makecerts
43-
44-
- name: Trust mkcert CA
45-
run: |
46-
sudo cp "$(mkcert -CAROOT)/rootCA.pem" /usr/local/share/ca-certificates/mkcert-ca.crt
47-
sudo update-ca-certificates
48-
49-
- name: Export NODE_EXTRA_CA_CERTS
50-
run: echo "NODE_EXTRA_CA_CERTS=$(mkcert -CAROOT)/rootCA.pem" >> $GITHUB_ENV
51-
5230
- name: Build project
5331
run: npm run build --if-present
5432

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
- Firefox 121+ (should be fine in many earlier versions, TBD)
2626
- If JS fails in an old browser, it will probably be fixable by updating `browserlist` in `package.json` then rebuilding
2727
- (Will be tested more definitively with browserstack at some point)
28+
- source styles use CSS Nesting which is explicitly processed out for compatibility
29+
- Integration test suite WIP
2830

2931
![screenshot of main UI](media/ui.webp)
3032

__tests__/integration.tests.js

Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,66 @@
1-
import puppeteer from 'puppeteer'
2-
import { testServer } from '../run'
3-
4-
let serverPort = 3003
5-
6-
describe("a fresh instance of biscuitman", () => {
7-
let server, browser, page
8-
let getConfig, getConsent, loadConsents
9-
10-
beforeAll(async () => {
11-
server = await testServer(serverPort)
12-
13-
browser = await puppeteer.launch({
14-
headless: true,
15-
// slowMo: showBrowser ? 100 : false,
16-
// devtools: showBrowser
17-
ignoreHTTPSErrors: true
18-
})
19-
20-
page = await context.newPage()
21-
22-
await page.setViewport({width: 1200, height: 600});
23-
24-
page.on('pageerror', (error) => {
25-
console.error('Page error:', error)
26-
})
27-
28-
page.on('console', (msg) => {
29-
let text = msg.text()
30-
if (msg.type() === 'error') {
31-
if (text.startsWith('Failed to load resource:')) return false
32-
console.log("Console error:", msg.text())
33-
}
34-
})
35-
36-
getConfig = () => page.evaluate(() => window.biscuitman)
37-
getConsent = () => page.evaluate(() => window.Consent)
38-
loadConsents = () => page.evaluate(() => JSON.parse(localStorage.getItem('myconsent')))
1+
describe('a fresh instance of biscuitman', () => {
2+
test('should load without without consents', async () => {
3+
expect(await utils.getConsent()).toBeEmpty()
4+
expect(await utils.loadConsents()).toBeNull()
395
})
406

41-
beforeEach(async () => {
42-
await page.goto(`https://localhost:${serverPort}`, {waitUntil: 'domcontentloaded'})
43-
})
44-
45-
afterEach(async () => {
46-
// Wipe storages
47-
const client = await page.target().createCDPSession()
48-
await client.send('Storage.clearDataForOrigin', {
49-
origin: `https://localhost:${serverPort}`,
50-
storageTypes: 'cookies, local_storage, session_storage, indexeddb, websql, cache_storage, service_workers'
51-
})
52-
})
53-
54-
afterAll(async () => {
55-
await browser.close()
56-
server.exit()
57-
})
58-
59-
test("should load without without consents", async () => {
60-
expect(await getConsent()).toBeEmpty()
61-
expect(await loadConsents()).toBeNull()
62-
})
63-
64-
test("should display a UI", async () => {
7+
test('should display a UI', async () => {
658
const ui = await page.$('.biscuitman')
669
expect(ui).not.toBeNull()
67-
10+
6811
const banner = await page.$('.biscuitman article')
6912
expect(await banner.isVisible()).toBe(true)
7013
})
7114

72-
test("should open settings modal after clicking settings", async () => {
15+
test('should open settings modal after clicking settings', async () => {
7316
await page.click('button[data-id=settings]')
7417
const dialog = await page.$('dialog')
7518
expect(await dialog.isVisible()).toBe(true)
7619
})
7720

78-
test("should close settings modal after clicking close", async () => {
21+
test('should close settings modal after clicking close', async () => {
7922
await page.click('button[data-id=settings]')
8023
const dialog = await page.$('dialog')
8124
await page.click('button[data-id=close]')
8225
expect(await dialog.isVisible()).toBe(false)
8326
})
8427

85-
test("should hide UI and save consents correctly after clicking accept", async () => {
28+
test('should hide UI and save consents correctly after clicking accept', async () => {
8629
await page.click('button[data-id=accept]')
8730

8831
const banner = await page.$('.biscuitman article')
8932
expect(await banner.isVisible()).toBe(false)
9033

9134
let entries = [
92-
['analytics',true],
93-
['functional',true],
94-
['advertisement',true],
95-
['performance',true],
96-
['uncategorized',true],
35+
['analytics', true],
36+
['functional', true],
37+
['advertisement', true],
38+
['performance', true],
39+
['uncategorized', true]
9740
]
9841

99-
expect(await getConsent()).toContainEntries(entries)
100-
expect(await loadConsents()).toContainEntries(entries)
42+
expect(await utils.getConsent()).toContainEntries(entries)
43+
expect(await utils.loadConsents()).toContainEntries(entries)
10144
})
10245

103-
test("should hide UI and save consents correctly after clicking reject", async () => {
46+
test('should hide UI and save consents correctly after clicking reject', async () => {
10447
await page.click('button[data-id=reject]')
10548

10649
const banner = await page.$('.biscuitman article')
10750
expect(await banner.isVisible()).toBe(false)
10851

10952
let entries = [
110-
['analytics',false],
111-
['functional',false],
112-
['advertisement',false],
113-
['performance',false],
114-
['uncategorized',false],
53+
['analytics', false],
54+
['functional', false],
55+
['advertisement', false],
56+
['performance', false],
57+
['uncategorized', false]
11558
]
116-
expect(await getConsent()).toContainEntries(entries)
117-
expect(await loadConsents()).toContainEntries(entries)
59+
expect(await utils.getConsent()).toContainEntries(entries)
60+
expect(await utils.loadConsents()).toContainEntries(entries)
11861
})
11962

120-
test("should hide UI and save consents correctly after selecting some sections", async () => {
121-
63+
test('should hide UI and save consents correctly after selecting some sections', async () => {
12264
await page.click('button[data-id=settings]')
12365
const dialog = await page.$('dialog')
12466
await page.click('[for=biscuitman_analytics]')
@@ -131,27 +73,26 @@ describe("a fresh instance of biscuitman", () => {
13173
expect(await banner.isVisible()).toBe(false)
13274

13375
let entries = [
134-
['analytics',true],
135-
['functional',true],
136-
['advertisement',false],
137-
['performance',true],
138-
['uncategorized',false]
76+
['analytics', true],
77+
['functional', true],
78+
['advertisement', false],
79+
['performance', true],
80+
['uncategorized', false]
13981
]
14082

141-
expect(await getConsent()).toContainEntries(entries)
142-
expect(await loadConsents()).toContainEntries(entries)
83+
expect(await utils.getConsent()).toContainEntries(entries)
84+
expect(await utils.loadConsents()).toContainEntries(entries)
14385
})
14486

145-
14687
test('should remove consent preferences when "bmInvalidate" is called', async () => {
14788
await page.evaluate(() => window.bmInvalidate())
148-
expect(await getConsent()).toEqual({})
149-
expect(await loadConsents()).toBeNull()
89+
expect(await utils.getConsent()).toEqual({})
90+
expect(await utils.loadConsents()).toBeNull()
15091
})
15192

15293
test('should update consent preferences when "bmUpdate" is called', async () => {
15394
await page.evaluate(() => window.bmUpdate())
154-
const dialog = await page.$("dialog")
95+
const dialog = await page.$('dialog')
15596
const dialogVisible = await page.evaluate(
15697
(dialog) => dialog.open,
15798
dialog

0 commit comments

Comments
 (0)