diff --git a/src/index.test.ts b/src/index.test.ts index 3833ac8..11676cc 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -7,7 +7,37 @@ if (!global.crypto) { } describe('custom-html', () => { - it('executes html injection', () => { + it('executes simple html injection', () => { + const executedJS: string[] = [] + const fakeEvent = new Event('pageview', {}) as MCEvent + fakeEvent.payload = { + htmlCode: `

some text

+ + `, + } + fakeEvent.client = { + emitter: 'browser', + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', + language: 'en-US', + referer: '', + ip: '127.0.0.1', + url: new URL('http://127.0.0.1:1337'), + execute: jsString => { + executedJS.push(jsString) + return true + }, + } + handler(fakeEvent) + expect(executedJS).toHaveLength(3) + expect(executedJS[0]).toEqual( + "const d = document.createElement('div');d.innerHTML = `

some text

`;document.body.appendChild(d);" + ) + expect(executedJS[1]).toEqual(`console.log('Log from MC')`) + expect(executedJS[2]).toEqual(`console.log('Log 2 from MC')`) + }) + + it('executes html injection with scripts that wait for other scripts', () => { const executedJS: string[] = [] const fakeEvent = new Event('pageview', {}) as MCEvent fakeEvent.payload = {