mirror of
https://github.com/elementor/hello-theme.git
synced 2026-07-29 15:07:33 +08:00
Some checks failed
Build / Build theme (push) Failing after 1s
Lint / ESLint (push) Failing after 0s
PHPUnit / File Diff (push) Failing after 1s
Lint / PHPCS (push) Failing after 41s
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - Test Results (push) Successful in 2s
* Setup prettier * Fix lint/format issues
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { request, test as baseTest } from '@playwright/test';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fetchNonce, login } from './wp-authentication.ts';
|
|
import ApiRequests from './assets/api-requests.ts';
|
|
|
|
export const parallelTest = baseTest.extend<
|
|
NonNullable<unknown>,
|
|
{
|
|
workerStorageState: string;
|
|
workerBaseURL: string;
|
|
apiRequests: ApiRequests;
|
|
}
|
|
>({
|
|
// Use the same storage state for all tests in this worker.
|
|
baseURL: ({ workerBaseURL }, use) => use(workerBaseURL),
|
|
workerBaseURL: [
|
|
async ({}, use) => {
|
|
await use(
|
|
process.env.BASE_URL ||
|
|
(1 === Number(process.env.TEST_PARALLEL_INDEX)
|
|
? process.env.TEST_SERVER
|
|
: process.env.DEV_SERVER),
|
|
);
|
|
},
|
|
{ scope: 'worker' },
|
|
],
|
|
|
|
// Use the same storage state for all tests in this worker.
|
|
storageState: ({ workerStorageState }, use) => use(workerStorageState),
|
|
|
|
// Authenticate once per worker with a worker-scoped fixture.
|
|
workerStorageState: [
|
|
async ({ workerBaseURL }, use, testInfo) => {
|
|
// Use parallelIndex as a unique identifier for each worker.
|
|
const id = testInfo.workerIndex;
|
|
const fileName = path.resolve(
|
|
testInfo.project.outputDir,
|
|
`.storageState-${id}.json`,
|
|
);
|
|
|
|
if (fs.existsSync(fileName)) {
|
|
// Reuse existing authentication state if any.
|
|
await use(fileName);
|
|
return;
|
|
}
|
|
|
|
// Send authentication request.
|
|
const context = await login(
|
|
request,
|
|
process.env.USERNAME || 'admin',
|
|
process.env.PASSWORD || 'password',
|
|
workerBaseURL,
|
|
);
|
|
await context.storageState({ path: fileName });
|
|
await context.dispose();
|
|
|
|
await use(fileName);
|
|
},
|
|
{ scope: 'worker' },
|
|
],
|
|
|
|
// Use the same storage state for all tests in this worker.
|
|
apiRequests: [
|
|
async ({ workerStorageState, workerBaseURL }, use) => {
|
|
const context = await request.newContext({
|
|
storageState: workerStorageState,
|
|
});
|
|
try {
|
|
const nonce = await fetchNonce(context, workerBaseURL);
|
|
const apiRequests = new ApiRequests(workerBaseURL, nonce);
|
|
await use(apiRequests);
|
|
} catch (e) {
|
|
throw new Error(
|
|
`Failed to fetch Nonce. Base URL: ${workerBaseURL}, Storage State: ${workerStorageState} `,
|
|
{ cause: e },
|
|
);
|
|
}
|
|
},
|
|
{ scope: 'worker' },
|
|
],
|
|
});
|