Skip to content

Commit

Permalink
fix: improve error checking in new flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost91- committed Nov 5, 2023
1 parent ec19577 commit 1ea67b8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
47 changes: 46 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"typescript": "5.2.2"
},
"dependencies": {
"@playwright/test": "^1.39.0",
"chalk": "^5.3.0",
"commander": "^11.0.0",
"fp-ts": "^2.12.2",
Expand Down
20 changes: 17 additions & 3 deletions src/publish/publish-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// SPDX-License-Identifier: MIT

import path from 'node:path';

import { expect } from '@playwright/test';
import { chromium, type Dialog, type Page } from 'playwright-chromium';

import type { Options } from '../options';

const foundryBaseURL = 'https://foundryvtt.com/';
Expand Down Expand Up @@ -34,7 +37,7 @@ async function login(page: Page, { username, password }: Options) {
await page.getByPlaceholder('Username').fill(username);
await page.getByPlaceholder('Password').fill(password);
await page.getByRole('button', { name: 'Log In' }).click();
await page.getByText(`You are now logged in as ${username}!`).isVisible();
await expect(page.getByText(`You are now logged in as ${username}!`)).toBeVisible();
console.log('Login successful.');
}

Expand Down Expand Up @@ -68,8 +71,17 @@ async function publishPackage(page: Page, options: Options) {
await page.locator('#save').click();
await page.waitForURL(getPackageURL(options));

const savePackageErrorText = 'Could not save package. Please correct errors below.';
if (!options.dryRun) {
await expect(
page.getByText(/Package .+ was saved successfully/).or(page.getByText(savePackageErrorText)),
).toBeVisible();
}
const failedToSave = await page.getByText(savePackageErrorText).isVisible();

const errors = await page.locator('ul.errorlist li').evaluateAll((li) => li.map((element) => element.textContent));
if (errors.length > 0) {

if (failedToSave || errors.length > 0) {
throw new Error(`Errors while publishing package:\n${errors.join('\n')}`);
}

Expand All @@ -93,13 +105,15 @@ async function deleteObsoleteVersions(page: Page, options: Options) {
.map((e) => e.id),
options,
);
console.log(versionsToDelete);

const accept = (dialog: Dialog) => dialog.accept();
page.on('dialog', accept);
for (const version of versionsToDelete) {
console.log(`Deleting version ${version}…`);
await page.locator(`[id="${version}"]`).locator('button[name=delete-version]').click();
if (!options.dryRun) {
await expect(page.getByText(/Package .+ was saved successfully/)).toBeVisible();
}
}
page.off('dialog', accept);
console.log('Obsolete versions deleted successfully.');
Expand Down

0 comments on commit 1ea67b8

Please sign in to comment.