-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement e2e tests on analytics
- Loading branch information
Showing
13 changed files
with
193 additions
and
7 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
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
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,16 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const {getFixturesConfig} = require('../fixtures.testplane.conf'); | ||
|
||
module.exports = _.merge(getFixturesConfig(__dirname), { | ||
plugins: { | ||
'html-reporter-tester': { | ||
baseHost: 'https://example.com:123', | ||
yandexMetrika: { | ||
enabled: false | ||
} | ||
} | ||
} | ||
}); |
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,13 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const {getFixturesConfig} = require('../fixtures.testplane.conf'); | ||
|
||
module.exports = _.merge(getFixturesConfig(__dirname), { | ||
plugins: { | ||
'html-reporter-tester': { | ||
baseHost: 'https://example.com:123' | ||
} | ||
} | ||
}); |
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,11 @@ | ||
{ | ||
"name": "analytics", | ||
"description": "Test project that generates html-report for testing analytics", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"clean": "rm -rf report", | ||
"generate": "true # This report should be generated with different env vars during tests", | ||
"gui": "npx testplane gui --hostname 0.0.0.0 --port $(../../utils/get-port.js analytics gui)" | ||
} | ||
} |
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,3 @@ | ||
it('some test', async () => { | ||
throw new Error('Test should fail'); | ||
}); |
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,117 @@ | ||
const childProcess = require('child_process'); | ||
const path = require('path'); | ||
const {PORTS} = require('../../utils/constants'); | ||
|
||
const projectDir = path.resolve(__dirname, '../../fixtures/analytics'); | ||
|
||
const generateFixtureReport = async (args, env) => { | ||
await new Promise(resolve => { | ||
const proc = childProcess.spawn('npx', ['testplane', ...args], {cwd: projectDir, env: {...process.env, ...env}}); | ||
|
||
proc.on('exit', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
const launchStaticServer = () => { | ||
return new Promise((resolve) => { | ||
const proc = childProcess.spawn('node', [path.resolve(__dirname, '../static-server.js')], { | ||
stdio: ['pipe', 'pipe', 'pipe', 'ipc'], | ||
env: { | ||
...process.env, | ||
STATIC_DIR: path.resolve(__dirname, '../..'), | ||
PORT: PORTS.analytics.server | ||
} | ||
}); | ||
|
||
proc.on('message', () => { | ||
resolve(proc); | ||
}); | ||
}); | ||
}; | ||
|
||
describe('Analytics', () => { | ||
let server; | ||
|
||
afterEach(() => { | ||
server?.kill(); | ||
}); | ||
|
||
it('should include metrika script by default', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'enabled.testplane.conf.js']); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
const scriptElement = await browser.$('div[data-qa="metrika-script"] script'); | ||
|
||
await expect(scriptElement).toBeExisting(); | ||
}); | ||
|
||
it('should track feature usage when opening info panel', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'enabled.testplane.conf.js']); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
await browser.execute(() => { | ||
window.ym = (...args) => { | ||
if (!window.ym.calls) { | ||
window.ym.calls = []; | ||
} | ||
window.ym.calls.push(args); | ||
}; | ||
}); | ||
|
||
await browser.$('[data-qa="footer-item-info"]').click(); | ||
|
||
const [metrikaCall] = await browser.execute(() => { | ||
return window.ym.calls; | ||
}); | ||
|
||
expect(metrikaCall[1]).toEqual('reachGoal'); | ||
expect(metrikaCall[2]).toEqual('FEATURE_USAGE'); | ||
expect(metrikaCall[3]).toEqual({featureName: 'Open info panel'}); | ||
}); | ||
|
||
it('should not fail when opening info panel with analytics not available', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'disabled.testplane.conf.js']); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
await browser.$('[data-qa="footer-item-info"]').click(); | ||
|
||
const infoPanelElement = await browser.$('div*=Data sources'); | ||
|
||
await expect(infoPanelElement).toBeExisting(); | ||
}); | ||
|
||
it('should not include metrika script if analytics are disabled in config', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'disabled.testplane.conf.js']); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
const scriptElement = await browser.$('div[data-qa="metrika-script"] script'); | ||
|
||
await expect(scriptElement).not.toBeExisting(); | ||
}); | ||
|
||
it('should not include metrika script if analytics are disabled via gemini-configparser env var', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'enabled.testplane.conf.js'], {'html_reporter_yandex_metrika_enabled': false}); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
const scriptElement = await browser.$('div[data-qa="metrika-script"] script'); | ||
|
||
await expect(scriptElement).not.toBeExisting(); | ||
}); | ||
|
||
it('should not include metrika script if analytics are disabled via NO_ANALYTICS env var', async ({browser}) => { | ||
await generateFixtureReport(['-c', 'enabled.testplane.conf.js'], {'NO_ANALYTICS': true}); | ||
server = await launchStaticServer(); | ||
|
||
await browser.url(browser.options.baseUrl.replace('index.html', 'new-ui.html')); | ||
const scriptElement = await browser.$('div[data-qa="metrika-script"] script'); | ||
|
||
await expect(scriptElement).not.toBeExisting(); | ||
}); | ||
}); |
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,17 @@ | ||
const express = require('express'); | ||
|
||
const dir = process.env.STATIC_DIR; | ||
const port = process.env.PORT; | ||
const host = process.env.HOST ?? 'localhost'; | ||
|
||
const app = express(); | ||
app.use(express.static(dir)); | ||
app.listen(port, (err) => { | ||
if (err) { | ||
console.error('Failed to start test server:'); | ||
throw new Error(err); | ||
} | ||
|
||
process.send('Ready'); | ||
console.info(`Server is listening on ${host}:${port}`); | ||
}); |
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 |
---|---|---|
|
@@ -17,6 +17,10 @@ module.exports = { | |
plugins: { | ||
server: 8084, | ||
gui: 8074 | ||
}, | ||
analytics: { | ||
server: 8085, | ||
gui: 8075 | ||
} | ||
} | ||
}; |