From d6072ea0e8dac1b733317448faa1b2afa35efc6f Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Wed, 7 Dec 2022 10:59:45 +0000 Subject: [PATCH] Record tests using same setup as the test runner no issue --- ghost/core/core/cli/record-test.js | 33 +++++-------------- .../test/e2e-browser/utils/global-setup.js | 1 - ghost/core/test/e2e-browser/utils/index.js | 5 ++- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/ghost/core/core/cli/record-test.js b/ghost/core/core/cli/record-test.js index 217fd6c4f8..17d6fc8598 100644 --- a/ghost/core/core/cli/record-test.js +++ b/ghost/core/core/cli/record-test.js @@ -1,46 +1,29 @@ const {chromium} = require('@playwright/test'); const Command = require('./command'); -const testUtils = require('../../test/utils'); +const playwrightConfig = require('../../playwright.config'); +const {globalSetup} = require('../../test/e2e-browser/utils'); module.exports = class RecordTest extends Command { setup() { this.help('Use PlayWright to record a browser-based test'); - this.argument('--admin', {type: 'boolean', defaultValue: false, desc: 'Start browser-based test in Ghost admin'}); - this.argument('--no-setup', {type: 'boolean', defaultValue: false, desc: 'Disable the default setup, for testing Ghost admin setup'}); - this.argument('--fixtures', {type: 'array', defaultValue: [], delimiter: ',', desc: 'A list of comma-separated fixtures to include'}); } permittedEnvironments() { return ['testing-browser']; } - async handle(argv) { - const app = await testUtils.startGhost(); - - if (argv.fixtures.length > 0) { - await testUtils.initFixtures(...argv.fixtures); - } + async handle() { + await globalSetup({ + projects: [playwrightConfig] + }); const browser = await chromium.launch({headless: false}); - const baseURL = argv.admin ? `${app.url}ghost/` : app.url; - const context = await browser.newContext({ - baseURL - }); + const context = await browser.newContext(playwrightConfig.use); // Pause the page, and start recording manually. const page = await context.newPage(); - await page.goto(''); - - if (argv.admin && !argv['no-setup']) { - await page.getByPlaceholder('The Daily Awesome').click(); - await page.getByPlaceholder('The Daily Awesome').fill('The Local Test'); - await page.getByPlaceholder('Jamie Larson').fill('Testy McTesterson'); - await page.getByPlaceholder('jamie@example.com').fill('testy@example.com'); - await page.getByPlaceholder('At least 10 characters').fill('Mc.T3ster$0n'); - await page.getByPlaceholder('At least 10 characters').press('Enter'); - await page.locator('.gh-done-pink').click(); - } + await page.goto('/ghost'); await page.pause(); } diff --git a/ghost/core/test/e2e-browser/utils/global-setup.js b/ghost/core/test/e2e-browser/utils/global-setup.js index 7bdd784c0a..be59f3fae1 100644 --- a/ghost/core/test/e2e-browser/utils/global-setup.js +++ b/ghost/core/test/e2e-browser/utils/global-setup.js @@ -4,7 +4,6 @@ const {spawn, exec} = require('child_process'); const {knex} = require('../../../core/server/data/db'); const {setupGhost, setupStripe} = require('./e2e-browser-utils'); const {chromium} = require('@playwright/test'); -const models = require('../../../core/server/models'); const {startGhost} = require('../../utils/e2e-framework'); const {stopGhost} = require('../../utils/e2e-utils'); diff --git a/ghost/core/test/e2e-browser/utils/index.js b/ghost/core/test/e2e-browser/utils/index.js index ae1503fc1c..59e6e066ed 100644 --- a/ghost/core/test/e2e-browser/utils/index.js +++ b/ghost/core/test/e2e-browser/utils/index.js @@ -1 +1,4 @@ -module.exports = require('./e2e-browser-utils'); +module.exports = { + ...require('./e2e-browser-utils'), + globalSetup: require('./global-setup') +};