Skip to content

Commit 8eadd6d

Browse files
committed
Fix code style issues with ESLint
1 parent b9d8aa8 commit 8eadd6d

File tree

4 files changed

+202
-202
lines changed

4 files changed

+202
-202
lines changed

tests/e2e/config/users.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const admin = {
2-
username: 'admin',
3-
password: 'password',
4-
store: {
5-
firstname: 'John',
6-
lastname: 'Doe',
7-
company: 'Automattic',
8-
country: 'US:CA',
9-
addressfirstline: 'addr 1',
10-
addresssecondline: 'addr 2',
11-
city: 'San Francisco',
12-
state: 'CA',
13-
postcode: '94107',
14-
},
2+
username: 'admin',
3+
password: 'password',
4+
store: {
5+
firstname: 'John',
6+
lastname: 'Doe',
7+
company: 'Automattic',
8+
country: 'US:CA',
9+
addressfirstline: 'addr 1',
10+
addresssecondline: 'addr 2',
11+
city: 'San Francisco',
12+
state: 'CA',
13+
postcode: '94107',
14+
},
1515
};
1616

1717
export { admin };

tests/e2e/global-setup.js

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,90 @@
22
/**
33
* External dependencies
44
*/
5-
const { chromium, expect } = require( '@playwright/test' );
5+
const { chromium, expect } = require('@playwright/test');
66

77
/**
88
* Internal dependencies
99
*/
10-
const fs = require( 'fs' );
11-
const { admin } = require( './config/users' );
12-
13-
module.exports = async ( config ) => {
14-
const { stateDir, baseURL, userAgent } = config.projects[ 0 ].use;
15-
16-
console.log( `State Dir: ${ stateDir }` );
17-
console.log( `Base URL: ${ baseURL }` );
18-
19-
// used throughout tests for authentication
20-
process.env.ADMINSTATE = `${ stateDir }adminState.json`;
21-
process.env.baseURL = baseURL;
22-
23-
// Clear out the previous save states
24-
try {
25-
fs.unlinkSync( process.env.ADMINSTATE );
26-
console.log( 'Admin state file deleted successfully.' );
27-
} catch ( err ) {
28-
if ( err.code === 'ENOENT' ) {
29-
console.log( 'Admin state file does not exist.' );
30-
} else {
31-
console.log( 'Admin state file could not be deleted: ' + err );
32-
}
33-
}
34-
35-
// Pre-requisites
36-
let adminLoggedIn = false;
37-
38-
// Specify user agent when running against an external test site to avoid getting HTTP 406 NOT ACCEPTABLE errors.
39-
const contextOptions = { baseURL, userAgent };
40-
41-
// Create browser, browserContext, and page for customer and admin users
42-
const browser = await chromium.launch();
43-
const adminContext = await browser.newContext( contextOptions );
44-
const adminPage = await adminContext.newPage();
45-
46-
// Sign in as admin user and save state
47-
const adminRetries = 5;
48-
for ( let i = 0; i < adminRetries; i++ ) {
49-
try {
50-
console.log( 'Trying to log-in as admin...' );
51-
52-
// Login to admin.
53-
const waitForNavigationPromise = adminPage.waitForURL( '**/wp-admin/' );
54-
await adminPage.goto( '/wp-login.php', {
55-
waitUntil: 'networkidle',
56-
} );
57-
const usernameLocator = await adminPage.locator( 'input[name="log"]' );
58-
await usernameLocator.fill( admin.username );
59-
const passwordLocator = await adminPage.locator( 'input[name="pwd"]' );
60-
await passwordLocator.fill( admin.password );
61-
const submitButtonLocator = await adminPage.getByRole( 'button', { name: 'Log In' } );
62-
await submitButtonLocator.click();
63-
await waitForNavigationPromise;
64-
65-
// Check if logged in successfully.
66-
const mainHeadingLocator = await adminPage.locator( '.wrap > h1' );
67-
await expect( await mainHeadingLocator.evaluate( ( el ) => el.textContent ) ).toBe( 'Dashboard' );
68-
69-
// Save state.
70-
await adminPage.context().storageState( { path: process.env.ADMINSTATE } );
71-
72-
console.log( 'Logged-in as admin successfully.' );
73-
adminLoggedIn = true;
74-
75-
break;
76-
} catch ( e ) {
77-
console.log( `Admin log-in failed, Retrying... ${ i }/${ adminRetries }` );
78-
console.log( e );
79-
}
80-
}
81-
82-
if ( ! adminLoggedIn ) {
83-
console.error(
84-
'Cannot proceed e2e test, as admin login failed. Please check if the test site has been setup correctly.'
85-
);
86-
process.exit( 1 );
87-
}
88-
89-
await adminContext.close();
90-
await browser.close();
10+
const fs = require('fs');
11+
const { admin } = require('./config/users');
12+
13+
module.exports = async (config) => {
14+
const { stateDir, baseURL, userAgent } = config.projects[0].use;
15+
16+
console.log(`State Dir: ${stateDir}`);
17+
console.log(`Base URL: ${baseURL}`);
18+
19+
// used throughout tests for authentication
20+
process.env.ADMINSTATE = `${stateDir}adminState.json`;
21+
process.env.baseURL = baseURL;
22+
23+
// Clear out the previous save states
24+
try {
25+
fs.unlinkSync(process.env.ADMINSTATE);
26+
console.log('Admin state file deleted successfully.');
27+
} catch (err) {
28+
if (err.code === 'ENOENT') {
29+
console.log('Admin state file does not exist.');
30+
} else {
31+
console.log('Admin state file could not be deleted: ' + err);
32+
}
33+
}
34+
35+
// Pre-requisites
36+
let adminLoggedIn = false;
37+
38+
// Specify user agent when running against an external test site to avoid getting HTTP 406 NOT ACCEPTABLE errors.
39+
const contextOptions = { baseURL, userAgent };
40+
41+
// Create browser, browserContext, and page for customer and admin users
42+
const browser = await chromium.launch();
43+
const adminContext = await browser.newContext(contextOptions);
44+
const adminPage = await adminContext.newPage();
45+
46+
// Sign in as admin user and save state
47+
const adminRetries = 5;
48+
for (let i = 0; i < adminRetries; i++) {
49+
try {
50+
console.log('Trying to log-in as admin...');
51+
52+
// Login to admin.
53+
const waitForNavigationPromise = adminPage.waitForURL('**/wp-admin/');
54+
await adminPage.goto('/wp-login.php', {
55+
waitUntil: 'networkidle',
56+
});
57+
const usernameLocator = await adminPage.locator('input[name="log"]');
58+
await usernameLocator.fill(admin.username);
59+
const passwordLocator = await adminPage.locator('input[name="pwd"]');
60+
await passwordLocator.fill(admin.password);
61+
const submitButtonLocator = await adminPage.getByRole('button', { name: 'Log In' });
62+
await submitButtonLocator.click();
63+
await waitForNavigationPromise;
64+
65+
// Check if logged in successfully.
66+
const mainHeadingLocator = await adminPage.locator('.wrap > h1');
67+
await expect(await mainHeadingLocator.evaluate((el) => el.textContent)).toBe('Dashboard');
68+
69+
// Save state.
70+
await adminPage.context().storageState({ path: process.env.ADMINSTATE });
71+
72+
console.log('Logged-in as admin successfully.');
73+
adminLoggedIn = true;
74+
75+
break;
76+
} catch (e) {
77+
console.log(`Admin log-in failed, Retrying... ${i}/${adminRetries}`);
78+
console.log(e);
79+
}
80+
}
81+
82+
if (!adminLoggedIn) {
83+
console.error(
84+
'Cannot proceed e2e test, as admin login failed. Please check if the test site has been setup correctly.'
85+
);
86+
process.exit(1);
87+
}
88+
89+
await adminContext.close();
90+
await browser.close();
9191
};

tests/e2e/playwright.config.js

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
const { loadConfig } = require( '@wordpress/env/lib/config' );
2-
const { defineConfig, devices } = require( '@playwright/test' );
1+
const { loadConfig } = require('@wordpress/env/lib/config');
2+
const { defineConfig, devices } = require('@playwright/test');
33

44
/**
55
* @see https://playwright.dev/docs/test-configuration
66
*/
7-
module.exports = ( async () => {
8-
// Get Base URL from wp-env.
9-
const wpEnvConfig = await loadConfig( './' );
10-
let baseUrl = 'http://localhost';
11-
if ( wpEnvConfig ) {
12-
const port = wpEnvConfig.env.tests.port || null;
13-
14-
if ( port ) {
15-
baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL;
16-
}
17-
}
18-
19-
return defineConfig( {
20-
testDir: '../../tests',
21-
22-
/* Maximum time one test can run for. */
23-
timeout: 90 * 1000,
24-
25-
expect: {
26-
/**
27-
* Maximum time expect() should wait for the condition to be met.
28-
* For example in `await expect(locator).toHaveText();`
29-
*/
30-
timeout: 20 * 1000,
31-
},
32-
33-
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
34-
outputDir: './test-results/report',
35-
36-
/* Run tests in files in parallel */
37-
fullyParallel: false,
38-
39-
/* Fail the build on CI if you accidentally left test.only in the source code. */
40-
forbidOnly: !! process.env.CI,
41-
42-
/* Retry on CI only */
43-
retries: process.env.CI ? 2 : 0,
44-
45-
/* Opt out of parallel tests on CI. */
46-
workers: process.env.CI ? 1 : 1,
47-
48-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
49-
reporter: [
50-
[ 'list' ],
51-
[
52-
'html',
53-
{
54-
outputFolder: './test-results/playwright-report',
55-
open: 'never',
56-
},
57-
],
58-
],
59-
60-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
61-
use: {
62-
/* Base URL to use in actions like `await page.goto('/')`. */
63-
baseURL: baseUrl,
64-
65-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
66-
trace: 'retain-on-failure',
67-
68-
// Capture screenshot after each test failure.
69-
screenshot: 'only-on-failure',
70-
71-
stateDir: './tests/e2e/test-results/storage/',
72-
73-
// Record video only when retrying a test for the first time.
74-
video: 'on-first-retry',
75-
76-
// Viewport used for all pages in the context.
77-
viewport: { width: 1280, height: 720 },
78-
},
79-
80-
/* Configure projects for major browsers */
81-
projects: [
82-
{
83-
name: 'chromium',
84-
use: { ...devices[ 'Desktop Chrome' ] },
85-
},
86-
],
87-
88-
// path to the global setup files.
89-
globalSetup: require.resolve( './global-setup' ),
90-
} );
91-
} )();
7+
module.exports = (async () => {
8+
// Get Base URL from wp-env.
9+
const wpEnvConfig = await loadConfig('./');
10+
let baseUrl = 'http://localhost';
11+
if (wpEnvConfig) {
12+
const port = wpEnvConfig.env.tests.port || null;
13+
14+
if (port) {
15+
baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL;
16+
}
17+
}
18+
19+
return defineConfig({
20+
testDir: '../../tests',
21+
22+
/* Maximum time one test can run for. */
23+
timeout: 90 * 1000,
24+
25+
expect: {
26+
/**
27+
* Maximum time expect() should wait for the condition to be met.
28+
* For example in `await expect(locator).toHaveText();`
29+
*/
30+
timeout: 20 * 1000,
31+
},
32+
33+
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
34+
outputDir: './test-results/report',
35+
36+
/* Run tests in files in parallel */
37+
fullyParallel: false,
38+
39+
/* Fail the build on CI if you accidentally left test.only in the source code. */
40+
forbidOnly: !!process.env.CI,
41+
42+
/* Retry on CI only */
43+
retries: process.env.CI ? 2 : 0,
44+
45+
/* Opt out of parallel tests on CI. */
46+
workers: process.env.CI ? 1 : 1,
47+
48+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
49+
reporter: [
50+
['list'],
51+
[
52+
'html',
53+
{
54+
outputFolder: './test-results/playwright-report',
55+
open: 'never',
56+
},
57+
],
58+
],
59+
60+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
61+
use: {
62+
/* Base URL to use in actions like `await page.goto('/')`. */
63+
baseURL: baseUrl,
64+
65+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
66+
trace: 'retain-on-failure',
67+
68+
// Capture screenshot after each test failure.
69+
screenshot: 'only-on-failure',
70+
71+
stateDir: './tests/e2e/test-results/storage/',
72+
73+
// Record video only when retrying a test for the first time.
74+
video: 'on-first-retry',
75+
76+
// Viewport used for all pages in the context.
77+
viewport: { width: 1280, height: 720 },
78+
},
79+
80+
/* Configure projects for major browsers */
81+
projects: [
82+
{
83+
name: 'chromium',
84+
use: { ...devices['Desktop Chrome'] },
85+
},
86+
],
87+
88+
// path to the global setup files.
89+
globalSetup: require.resolve('./global-setup'),
90+
});
91+
})();

0 commit comments

Comments
 (0)