Skip to content

Commit af2cda9

Browse files
committed
Add ESM deliverables
- Add ESM test - improved run.js logging
1 parent a3e5629 commit af2cda9

19 files changed

Lines changed: 1317 additions & 59 deletions

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
- If JS fails in an old browser, it will probably be fixable by updating `browserlist` in `package.json` then rebuilding
2828
- (Will be tested more definitively with browserstack at some point)
2929
- source styles use CSS Nesting which is explicitly processed out for compatibility
30-
- Integration test suite WIP ![tests](https://github.com/replete/biscuitman/actions/workflows/node.js.yml/badge.svg)
30+
- Experimental ESM version `biscuitman.mjs` [ESM Module version demo](https://replete.github.io/biscuitman)
31+
- still uses globals
32+
- allows easier event setting with `.on('revoke', (sec) => { if (sec === 'analytics') window.reload() )})`
33+
- experimental stage, only worth maintaining if the codebase remains pretty much the same, consider this another packaging option
34+
- preliminary e2e tests ![tests](https://github.com/replete/biscuitman/actions/workflows/node.js.yml/badge.svg)
3135

3236
![screenshot of main UI](media/ui.webp)
3337

@@ -196,13 +200,13 @@ Visiting `https://localhost:3000` should now work without warnings.
196200

197201
### Building
198202
`npm run build` - creates project distributes.
199-
200-
Build script `runmjs` built with Node 20
203+
- Build script `run.js` built with Node 20
201204

202205
### Tests
203-
`npm run test` - Launches pupeeter integration tests in a browser
204-
`npm run coverage` - run jest tests with coverage
205-
Jest is set up with puppeteer to run some integration tests. We're using `@swc/jest`'s rust implementation of jest to speed things up.
206+
Jest is set up with puppeteer to run some integration tests. We're using `@swc/jest`'s rust implementation of jest to speed things up. This is only chromium for now, but at some point it would be good to implement browserStack selenium tests to automate browser compatibility checks.
207+
208+
`npm run test` - Launches pupeeter integration tests in a browser (in http mode only)
209+
`npm run coverage` - run jest tests with coverage saved to `/coverage/`
206210

207211

208212
## Support development

__tests__/e2e.tests.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
beforeEach(async () => {
2+
const client = await page.createCDPSession()
3+
await client.send('Storage.clearDataForOrigin', {
4+
origin: __SERVERURL__,
5+
storageTypes:
6+
'cookies, local_storage, session_storage, indexeddb, websql, cache_storage, service_workers'
7+
})
8+
await page.goto(`${__SERVERURL__}/index-esm.html`, { waitUntil: 'domcontentloaded' })
9+
})
10+
11+
describe('a fresh instance of biscuitman', () => {
12+
test('should load without without consents', async () => {
13+
expect(await utils.getConsent()).toBeEmpty()
14+
expect(await utils.loadConsents()).toBeNull()
15+
})
16+
17+
test('should display a UI', async () => {
18+
const ui = await page.$('.biscuitman')
19+
expect(ui).not.toBeNull()
20+
21+
const banner = await page.$('.biscuitman article')
22+
expect(await banner.isVisible()).toBe(true)
23+
})
24+
25+
test('should open settings modal after clicking settings', async () => {
26+
await page.click('button[data-id=settings]')
27+
const dialog = await page.$('dialog')
28+
expect(await dialog.isVisible()).toBe(true)
29+
})
30+
31+
test('should close settings modal after clicking close', async () => {
32+
await page.click('button[data-id=settings]')
33+
const dialog = await page.$('dialog')
34+
await page.click('button[data-id=close]')
35+
expect(await dialog.isVisible()).toBe(false)
36+
})
37+
38+
test('should hide UI and save consents correctly after clicking accept', async () => {
39+
await page.click('button[data-id=accept]')
40+
41+
const banner = await page.$('.biscuitman article')
42+
expect(await banner.isVisible()).toBe(false)
43+
44+
let entries = [
45+
['analytics', true],
46+
['functional', true],
47+
['advertisement', true],
48+
['performance', true],
49+
['uncategorized', true]
50+
]
51+
52+
expect(await utils.getConsent()).toContainEntries(entries)
53+
expect(await utils.loadConsents()).toContainEntries(entries)
54+
})
55+
56+
test('should hide UI and save consents correctly after clicking reject', async () => {
57+
await page.click('button[data-id=reject]')
58+
59+
const banner = await page.$('.biscuitman article')
60+
expect(await banner.isVisible()).toBe(false)
61+
62+
let entries = [
63+
['analytics', false],
64+
['functional', false],
65+
['advertisement', false],
66+
['performance', false],
67+
['uncategorized', false]
68+
]
69+
expect(await utils.getConsent()).toContainEntries(entries)
70+
expect(await utils.loadConsents()).toContainEntries(entries)
71+
})
72+
73+
test('should hide UI and save consents correctly after selecting some sections', async () => {
74+
await page.click('button[data-id=settings]')
75+
await page.click('[for=biscuitman_analytics]')
76+
await page.click('[for=biscuitman_functional]')
77+
await page.click('[for=biscuitman_performance]')
78+
79+
await page.click('button[data-id=save]')
80+
81+
const banner = await page.$('.biscuitman article')
82+
expect(await banner.isVisible()).toBe(false)
83+
84+
let entries = [
85+
['analytics', true],
86+
['functional', true],
87+
['advertisement', false],
88+
['performance', true],
89+
['uncategorized', false]
90+
]
91+
92+
expect(await utils.getConsent()).toContainEntries(entries)
93+
expect(await utils.loadConsents()).toContainEntries(entries)
94+
})
95+
96+
test('should remove consent preferences when "bmInvalidate" is called', async () => {
97+
await page.evaluate(() => window.bmInvalidate())
98+
expect(await utils.getConsent()).toEqual({})
99+
expect(await utils.loadConsents()).toBeNull()
100+
})
101+
102+
test('should update consent preferences when "bmUpdate" is called', async () => {
103+
await page.evaluate(() => window.bmUpdate())
104+
const dialog = await page.$('dialog')
105+
const dialogVisible = await page.evaluate(
106+
(dialog) => dialog.open,
107+
dialog
108+
)
109+
expect(dialogVisible).toBe(true)
110+
})
111+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
beforeEach(async () => {
2+
const client = await page.createCDPSession()
3+
await client.send('Storage.clearDataForOrigin', {
4+
origin: __SERVERURL__,
5+
storageTypes:
6+
'cookies, local_storage, session_storage, indexeddb, websql, cache_storage, service_workers'
7+
})
8+
await page.goto(__SERVERURL__, { waitUntil: 'domcontentloaded' })
9+
})
10+
111
describe('a fresh instance of biscuitman', () => {
212
test('should load without without consents', async () => {
313
expect(await utils.getConsent()).toBeEmpty()

cssreport.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/biscuitman.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! biscuitman.js 0.3.13 */
1+
/*! biscuitman.js 0.3.14 */
22
.biscuitman {
33
--t: #444;
44
--b: #fff;

dist/biscuitman.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! biscuitman.js 0.3.13 */
1+
/*! biscuitman.js 0.3.14 */
22
((d, w, Object1, h, bm)=>{
33
const defaults = {
44
key: 'myconsent',

dist/biscuitman.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)