|
| 1 | +const childProcess = require('child_process'); |
| 2 | +const {existsSync} = require('fs'); |
| 3 | +const fs = require('fs/promises'); |
| 4 | +const path = require('path'); |
| 5 | +const {promisify} = require('util'); |
| 6 | + |
| 7 | +const treeKill = promisify(require('tree-kill')); |
| 8 | + |
| 9 | +const {PORTS} = require('../../utils/constants'); |
| 10 | +const {runGui} = require('../utils'); |
| 11 | + |
| 12 | +const serverHost = process.env.SERVER_HOST ?? 'host.docker.internal'; |
| 13 | + |
| 14 | +const projectName = process.env.PROJECT_UNDER_TEST; |
| 15 | +const projectDir = path.resolve(__dirname, '../../fixtures', projectName); |
| 16 | +const guiUrl = `http://${serverHost}:${PORTS[projectName].gui}`; |
| 17 | + |
| 18 | +const reportDir = path.join(projectDir, 'report'); |
| 19 | +const reportBackupDir = path.join(projectDir, 'report-backup'); |
| 20 | +const screensDir = path.join(projectDir, 'screens'); |
| 21 | + |
| 22 | +describe('GUI mode', () => { |
| 23 | + describe('Auto-run with -a option', () => { |
| 24 | + let guiProcess; |
| 25 | + |
| 26 | + afterEach(async () => { |
| 27 | + if (guiProcess) { |
| 28 | + await treeKill(guiProcess.pid); |
| 29 | + } |
| 30 | + |
| 31 | + childProcess.execSync('git restore .', {cwd: screensDir}); |
| 32 | + childProcess.execSync('git clean -dfx .', {cwd: screensDir}); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('New UI', () => { |
| 36 | + beforeEach(async ({browser}) => { |
| 37 | + if (existsSync(reportBackupDir)) { |
| 38 | + await fs.rm(reportDir, {recursive: true, force: true, maxRetries: 3}); |
| 39 | + await fs.cp(reportBackupDir, reportDir, {recursive: true, force: true}); |
| 40 | + } else { |
| 41 | + await fs.cp(reportDir, reportBackupDir, {recursive: true}); |
| 42 | + } |
| 43 | + |
| 44 | + guiProcess = await runGui(projectDir, {autoRun: true, grep: 'successful test'}); |
| 45 | + |
| 46 | + await browser.url(guiUrl + '/new-ui'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should automatically run tests when started with -a option', async ({browser}) => { |
| 50 | + const testItem = await browser.$('[data-list-item*="chrome"]'); |
| 51 | + await testItem.click(); |
| 52 | + |
| 53 | + await browser.$('[data-qa="suite-status-bar-status"]*=Success').waitForDisplayed({timeout: 5000}); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments