Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local environment path #1547

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ tests/data/tmp/*
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
2 changes: 1 addition & 1 deletion classes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private function locate_plugin() {
$dir_url = trailingslashit( plugins_url( '', __DIR__ ) );
$dir_path = plugin_dir_path( __DIR__ );
$dir_basename = basename( $dir_path );
$plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
$plugin_basename = trailingslashit( $dir_basename ) . 'stream.php';

return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
}
Expand Down
8 changes: 6 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ module.exports = defineConfig( {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{ name: 'setup', testMatch: /setup\.js/ },
{
name: 'chromium',
use: { ...devices[ 'Desktop Chrome' ] },
use: {
...devices[ 'Desktop Chrome' ],
storageState: 'playwright/.auth/user.json',
},
dependencies: [ 'setup' ],
},
],
} );
Expand Down
5 changes: 1 addition & 4 deletions tests/e2e/editor-new-post.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ test.describe( 'Editor: saving a new post', () => {
console.log( `New post ${ postTitle }` );

// Even though we're using WP's npm package, it's more straightforward to do it this way, at least for me in this environment.
await page.goto( 'http://stream.wpenv.net/wp-login.php?redirect_to=http://stream.wpenv.net/wp-admin/post-new.php%2F&reauth=1' );
await page.getByLabel( 'Username or Email Address' ).fill( 'admin' );
await page.getByLabel( 'Password', { exact: true } ).fill( 'password' );
await page.getByRole( 'button', { name: 'Log In' } ).click();
await page.goto( 'http://stream.wpenv.net/wp-admin/post-new.php' );
await page.getByLabel( 'Add title' ).click();
await page.getByLabel( 'Add title' ).fill( postTitle );
await page.getByLabel( 'Add title' ).press( 'Tab' );
Expand Down
56 changes: 56 additions & 0 deletions tests/e2e/network-activated.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

let page;

test.describe.configure( { mode: 'serial' } );

test.beforeAll( async ( { browser } ) => {
page = await browser.newPage();
} );

test.afterAll( async () => {
await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' );
const isActive = await page
.getByLabel( 'Network Deactivate Stream' )
.isVisible();

if ( isActive ) {
// eslint-disable-next-line no-console
console.log( 'Deactivating Stream after Network tests.' );
await page.getByLabel( 'Network Deactivate Stream' ).click();
}
} );

test.describe( 'Network: shows network activated states', () => {
// Do we have a published row?
test( 'does not show stream in network admin when deactivated', async () => {
await page.goto( 'http://stream.wpenv.net/wp-admin/network/index.php' );
// Expects Stream log to not have the Network Settings.
await expect(
page.locator( '[href*="admin.php?page=wp_stream"]' ),
).not.toBeVisible();
} );

// We should not have an updated row. This times out which makes it fail.
test( 'does not have updated row', async () => {
await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' );
const isActive = await page
tharsheblows marked this conversation as resolved.
Show resolved Hide resolved
.getByLabel( 'Network Activate Stream' )
.isVisible();

if ( isActive ) {
tharsheblows marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-console
console.log( 'Activating Stream for next tests.' );
await page.getByLabel( 'Network Activate Stream' ).click();
}

await page.goto( 'http://stream.wpenv.net/wp-admin/network/index.php' );
// Expects Stream log to not have the Network Settings.
await expect(
page.locator( '[href*="admin.php?page=wp_stream_network_settings"]' ),
).toBeVisible();
} );
} );
41 changes: 41 additions & 0 deletions tests/e2e/setup/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { test as setup } from '@playwright/test';

const authFile = 'playwright/.auth/user.json';

/**
* Log in before all the tests.
* @see https://playwright.dev/docs/auth
*/
setup( 'authenticate', async ( { page } ) => {
// Log in.
await page.goto( 'http://stream.wpenv.net/wp-login.php' );
await page.getByLabel( 'Username or Email Address' ).fill( 'admin' );
await page.getByLabel( 'Password', { exact: true } ).fill( 'password' );
await page.getByRole( 'button', { name: 'Log In' } ).click();
// Wait until the page receives the cookies.

// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL( 'http://stream.wpenv.net/wp-admin/' );

await page.goto( 'http://stream.wpenv.net/wp-admin/network/plugins.php' );
const isActive = await page.getByLabel( 'Network Deactivate Stream' ).isVisible();

// eslint-disable-next-line no-console
console.log( `Stream is currently active: ${ isActive }` );

if ( isActive ) {
// eslint-disable-next-line no-console
console.log( 'Deactivating Stream before tests.' );
await page.getByLabel( 'Network Deactivate Stream' ).click();
}

// End of authentication steps.
await page.context().storageState( { path: authFile } );

// eslint-disable-next-line no-console
console.log( 'Done with network setup.' );
} );
Loading