Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions docs/guide/running-the-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The server's dot shows its state, in the header and next to the site in the side

When the server is running, the details list **View site**, **wp-admin** and **Database** under **Server**, with the admin username and password. The header's server menu has **View site** and **wp-admin** too. Each opens in your default browser.

![The site view with the dev server running: in the details, under Server, a Stop button, the View site, wp-admin and Database links, and the admin credentials with the password hidden](/screenshots/dev-server-running.png)
![The site view with the dev server running: in the details, under Server, a Stop button, the View site, wp-admin and Database links, and the admin credentials](/screenshots/dev-server-running.png)

**Start** is disabled while a trunk update is running, and while `npm run build` is running, whether you typed it in the terminal or a patch, a pull request or a trunk update started it: the server would serve a `build/` that is still being written. A site set to start its server or watch when opened waits for that build to end. The reverse is no longer true: an update can run with the server up, because it pauses the build watch for the rebuild and leaves the server serving — see [Applying patches and PRs](./applying-patches) and [Staying up to date with trunk](./trunk-updates).

Expand All @@ -31,7 +31,7 @@ Every site uses the same credentials, shown under **Server** in the details:
- Username: `admin`
- Password: `password`

The **wp-admin** link opens the dashboard directly.
The **wp-admin** link opens the dashboard already logged in as `admin`. The site itself, and `wp-login.php`, stay logged out until you log in, so you can still test what a visitor sees.

## What the dev server actually runs

Expand Down
Binary file modified docs/public/screenshots/dev-server-running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/playground-plan.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,23 @@ function planPlaygroundLaunch(config) {
// The cost is real and deliberate: DISALLOW_FILE_MODS also blocks installing a
// second plugin or theme into the preview. Losing an afternoon of uncommitted
// work is worse than restarting a preview you can restart.
//
// Every strategy also turns on Playground's forced auto-login (#743), which
// the app's wp-admin link asks for (site-urls.cjs), so that link opens the
// dashboard logged in. It logs in whoever asks, but the server listens on the
// loopback only, and the admin password is `password` on every site anyway.
function planServeConstants(config) {
const cfg = config || {};
if (cfg.strategy === 'plugin-mount') {
return {
WP_ENVIRONMENT_TYPE: 'local',
WP_DEVELOPMENT_MODE: 'plugin',
PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true,
DISALLOW_FILE_MODS: true,
DISALLOW_FILE_EDIT: true
};
}
return { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'core' };
return { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'core', PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true };
}

module.exports = { planPlaygroundLaunch, planServeConstants, WORDPRESS_VFS_ROOT, PLUGINS_VFS_BASE };
17 changes: 3 additions & 14 deletions src/renderer/components/site-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { __, sprintf } from '@wordpress/i18n';
// given its final export yet, like the segmented control.
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- see above.
import { __experimentalTreeGrid as TreeGrid, __experimentalTreeGridCell as TreeGridCell, __experimentalTreeGridRow as TreeGridRow } from '@wordpress/components';
import { chevronDown, chevronRight, globe, offline, page, pencil, plus, seen, table, undo, unseen, wordpress } from '@wordpress/icons';
import { Button, EmptyState, Icon, IconButton, Link, Menu, Notice, Stack, Text, Tooltip, VisuallyHidden } from '@wordpress/ui';
import { chevronDown, chevronRight, globe, offline, page, pencil, plus, table, undo, wordpress } from '@wordpress/icons';
import { Button, EmptyState, Icon, Link, Menu, Notice, Stack, Text, Tooltip, VisuallyHidden } from '@wordpress/ui';
import { affectedFileTree, visibleAffectedRows } from '../affected-files.cjs';
import { siteDetailsRows } from '../site-details.cjs';
import { ProcessStatus } from './site-header-actions.jsx';
Expand Down Expand Up @@ -73,7 +73,6 @@ const LINK_ICONS = { site: globe, admin: wordpress, database: table };
// and what to log in with. Which of the three things it shows is decided in
// site-processes.cjs.
function ServerSection({ server }) {
const [showPassword, setShowPassword] = useState(false);
const { section } = server;
return (
<Stack direction="column" gap="md">
Expand All @@ -91,17 +90,7 @@ function ServerSection({ server }) {
<Text variant="body-md" className="muted-label">{__('Username')}</Text>
<Text variant="body-md">{section.credentials.username}</Text>
<Text variant="body-md" className="muted-label">{__('Password')}</Text>
<div className="credential-value">
<Text variant="body-md">{showPassword ? section.credentials.password : '••••••••'}</Text>
<IconButton
icon={showPassword ? unseen : seen}
label={showPassword ? __('Hide password') : __('Show password')}
variant="minimal"
tone="neutral"
size="small"
onClick={() => setShowPassword((current) => !current)}
/>
</div>
<Text variant="body-md">{section.credentials.password}</Text>
</div>
</Stack>
</Stack>
Expand Down
7 changes: 0 additions & 7 deletions src/renderer/shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,6 @@ body {
align-items: center;
}

.credential-value {
display: flex;
align-items: center;
gap: var(--wpds-dimension-gap-xs);
min-width: 0;
}

/* What a line of text is about, where a notice would be too much: said
quietly, something that went well, something to mind, something that went
wrong. One class each, for every card and dialog. */
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/site-processes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict';

const { __, sprintf } = require('@wordpress/i18n');
const { adminUrl, adminerUrl } = require('./site-urls.cjs');
const { adminUrl, adminerUrl, ADMIN_USERNAME } = require('./site-urls.cjs');
const { formatElapsed } = require('./dev-server-command.cjs');

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ function serverLinks({ url = '', running = false } = {}) {
}

// What the app's server is set up with. Fixed, and the same on every site.
const ADMIN_CREDENTIALS = Object.freeze({ username: 'admin', password: 'password' });
const ADMIN_CREDENTIALS = Object.freeze({ username: ADMIN_USERNAME, password: 'password' });

/**
* What the server's section of the details shows under its heading: where
Expand Down
19 changes: 16 additions & 3 deletions src/renderer/site-urls.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,29 @@ function siteUrl(serverUrl, relativePath) {
return `${base.replace(/\/+$/, '')}/${rel}`;
}

// The admin user every site is set up with. The credentials the details show
// are built from it (site-processes.cjs), so the user the wp-admin link logs
// in as is always the one they name.
const ADMIN_USERNAME = 'admin';

/**
* The admin dashboard.
* The admin dashboard, already logged in (#743).
*
* The trailing slash matters: WordPress redirects `/wp-admin` to `/wp-admin/`,
* and asking for the canonical form directly saves the round trip.
*
* The query is Playground's own: with PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED,
* which every site is served with (playground-plan.cjs), its auto-login
* mu-plugin logs the browser in as the named user on that request. Only this
* link does it: the site's front end and wp-login.php stay logged out until
* the contributor logs in, so a ticket about either can still be tested.
*
* @param {string} serverUrl
* @return {string}
*/
function adminUrl(serverUrl) {
return siteUrl(serverUrl, 'wp-admin/');
const url = siteUrl(serverUrl, 'wp-admin/');
return url ? `${url}?playground_force_auto_login_as_user=${ADMIN_USERNAME}` : '';
}

/**
Expand All @@ -62,5 +74,6 @@ function adminerUrl(serverUrl) {
module.exports = {
siteUrl,
adminUrl,
adminerUrl
adminerUrl,
ADMIN_USERNAME
};
8 changes: 4 additions & 4 deletions src/server-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ async function main() {
'WP_MAIL_SMTP_SECURE': process.env.WP_MAIL_SMTP_SECURE || '', // '', 'ssl', or 'tls'
'WP_MAIL_SMTP_USER': process.env.WP_MAIL_SMTP_USER || '',
'WP_MAIL_SMTP_PASS': process.env.WP_MAIL_SMTP_PASS || '',
// Last: the environment type and development mode every site
// gets, and, for a strategy that has to protect the host
// directory it mounted, the constants that do, which the shared
// sets above must not override.
// Last: the environment type, development mode and forced
// auto-login every site gets, and, for a strategy that has to
// protect the host directory it mounted, the constants that do,
// which the shared sets above must not override.
...serveConstants
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/e2e/journeys/dev-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se
// INVARIANT — the section says where the site, its admin and its
// database are.
await expect( link( 'View site' ) ).toHaveAttribute( 'href', URL );
await expect( link( 'wp-admin' ) ).toHaveAttribute( 'href', `${ URL }wp-admin/` );
await expect( link( 'wp-admin' ) ).toHaveAttribute( 'href', `${ URL }wp-admin/?playground_force_auto_login_as_user=admin` );
await expect( link( 'Database' ) ).toHaveAttribute( 'href', `${ URL }adminer.php` );

// INVARIANT — a link is opened in the browser, by the main process, and
Expand All @@ -621,7 +621,7 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se
const windowAddress = () => app.evaluate( ( { BrowserWindow } ) => BrowserWindow.getAllWindows()[ 0 ].webContents.getURL() );
const appAddress = await windowAddress();
await link( 'wp-admin' ).click();
await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/` ] );
await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/?playground_force_auto_login_as_user=admin` ] );
await server.heard();
await expect( ui.siteHeading( page, 'e2e-site' ) ).toBeVisible();
expect( await windowAddress() ).toBe( appAddress );
Expand All @@ -632,19 +632,15 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se
await headerMenu( 'Server running' ).click();
await expect( page.getByRole( 'menuitem' ) ).toHaveText( [ 'View site', 'wp-admin', 'Stop development server' ] );
await page.getByRole( 'menuitem', { name: 'View site', exact: true } ).click();
await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/`, URL ] );
await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/?playground_force_auto_login_as_user=admin`, URL ] );
await server.heard();
expect( await windowAddress() ).toBe( appAddress );

// INVARIANT — it says what to log in with, and shows the password only
// when asked to.
// INVARIANT — it says what to log in with, the password included: it is
// `password` on every site, so there is nothing to hide (#743).
const credentials = page.getByRole( 'complementary' ).filter( { visible: true } );
await expect( credentials.getByText( 'admin', { exact: true } ) ).toBeVisible();
await expect( credentials.getByText( 'password', { exact: true } ) ).toHaveCount( 0 );
await credentials.getByRole( 'button', { name: 'Show password', exact: true } ).click();
await expect( credentials.getByText( 'password', { exact: true } ) ).toBeVisible();
await credentials.getByRole( 'button', { name: 'Hide password', exact: true } ).click();
await expect( credentials.getByText( 'password', { exact: true } ) ).toHaveCount( 0 );

// INVARIANT — the header's menu stops it, and both places say so.
await headerMenu( 'Server running' ).click();
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/journeys/i18n.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ test( 'the open site\'s two processes are fully translatable, in the header and
await tell( 'playground:url', { sitePath: site.dir, url: URL } );
await expect( details.getByRole( 'link', { name: pseudoLocalize( 'Database' ), exact: true } ) ).toBeVisible();
await expect( menuButton( 'Build watching' ) ).toBeVisible();
await details.getByRole( 'button', { name: pseudoLocalize( 'Show password' ), exact: true } ).click();
await expect( details.getByRole( 'button', { name: pseudoLocalize( 'Hide password' ), exact: true } ) ).toBeVisible();
expect( ( await inDetails() ).filter( ( text ) => text !== 'password' ) ).toEqual( [] );
await menuButton( 'Server running' ).click();
await expect( item( 'Stop development server' ) ).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/journeys/site-links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test( 'a middle click on a link to the site opens it in the browser, and not in
// INVARIANT — a middle click goes to the browser, to the address the link
// names.
await admin.click( { button: 'middle' } );
await expect.poll( opened ).toEqual( [ SERVER_URL, `${ SERVER_URL }wp-admin/` ] );
await expect.poll( opened ).toEqual( [ SERVER_URL, `${ SERVER_URL }wp-admin/?playground_force_auto_login_as_user=admin` ] );

// INVARIANT — and the app opened no window of its own and went nowhere.
expect( await app.evaluate( ( { BrowserWindow } ) => BrowserWindow.getAllWindows().length ) ).toBe( 1 );
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/real-setup/create-site.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ for ( const target of TARGETS ) {
expect( html ).toContain( 'id="loginform"' );
expect( html ).toContain( 'name="log"' );
} ).toPass( { timeout: 60_000, intervals: [ 2_000, 5_000 ] } );
// INVARIANT: the wp-admin link opens the dashboard logged in (#743),
// which takes the constant the server sets and the query the link
// carries to both be the names Playground's auto-login reads. A
// rename on either side lands on the login form instead.
const dashboard = await request.get( adminUrl.href, { timeout: 15_000 } );
expect( dashboard.status() ).toBe( 200 );
const dashboardHtml = await dashboard.text();
expect( dashboardHtml ).toContain( 'id="wpadminbar"' );
expect( dashboardHtml ).not.toContain( 'id="loginform"' );
if ( target.servedAsPlugin ) {
// INVARIANT: the served WordPress runs the checkout as its active
// Gutenberg plugin, and cannot delete it. Read off the Plugins
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/playground-plan.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ test('a plugin-mount slug that is not a plain name is refused before it becomes
test('a Core site runs as a local environment in core development mode', () => {
assert.deepEqual(planServeConstants({ strategy: 'docroot', docroot: '/sites/wp/build' }), {
WP_ENVIRONMENT_TYPE: 'local',
WP_DEVELOPMENT_MODE: 'core'
WP_DEVELOPMENT_MODE: 'core',
PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true
});
// The default strategy is docroot, so it gets the same.
assert.deepEqual(planServeConstants({}), planServeConstants({ strategy: 'docroot' }));
Expand All @@ -93,6 +94,7 @@ test('a Gutenberg site runs as a local environment in plugin development mode, w
assert.deepEqual(planServeConstants({ strategy: 'plugin-mount', pluginDir: '/sites/gutenberg', pluginSlug: 'gutenberg' }), {
WP_ENVIRONMENT_TYPE: 'local',
WP_DEVELOPMENT_MODE: 'plugin',
PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true,
DISALLOW_FILE_MODS: true,
DISALLOW_FILE_EDIT: true
});
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/site-processes.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,19 @@ test('a server with no address has nowhere to send anyone', () => {
test('a server with an address offers the site and its admin, and its database once it is running', () => {
assert.deepEqual(serverLinks({ url: URL }), [
{ id: 'site', label: 'View site', href: URL },
{ id: 'admin', label: 'wp-admin', href: `${URL}wp-admin/` }
{ id: 'admin', label: 'wp-admin', href: `${URL}wp-admin/?playground_force_auto_login_as_user=admin` }
]);
assert.deepEqual(serverLinks({ url: URL, running: true }).at(-1), { id: 'database', label: 'Database', href: `${URL}adminer.php` });
assert.equal(serverLinks({ url: URL, running: true }).length, 3);
});

// The wp-admin link logs in as a user by name (#743): a link naming a user the
// credentials do not would land on the login screen without a word.
test('the wp-admin link logs in as the user the credentials name', () => {
const admin = serverLinks({ url: URL }).find((link) => link.id === 'admin');
assert.equal(new globalThis.URL(admin.href).searchParams.get('playground_force_auto_login_as_user'), serverSection({ url: URL }).credentials.username);
});

test('the section of a server with an address shows where the site is and what to log in with', () => {
assert.deepEqual(serverSection({ url: URL, running: true }), {
state: 'online',
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/site-urls.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const { siteUrl, adminUrl, adminerUrl } = require('../../src/renderer/site-urls.
// The shape server-runner.js actually produces: `http://127.0.0.1:${port}/`.
const RUNNING = 'http://127.0.0.1:8881/';

test('adminUrl: the admin of a running site (issue #248)', () => {
assert.strictEqual(adminUrl(RUNNING), 'http://127.0.0.1:8881/wp-admin/');
test('adminUrl: the admin of a running site, asking Playground to log the browser in (issues #248, #743)', () => {
assert.strictEqual(adminUrl(RUNNING), 'http://127.0.0.1:8881/wp-admin/?playground_force_auto_login_as_user=admin');
});

test('adminUrl: keeps the trailing slash WordPress would redirect to (issue #248)', () => {
assert.ok(adminUrl(RUNNING).endsWith('/wp-admin/'));
assert.strictEqual(new URL(adminUrl(RUNNING)).pathname, '/wp-admin/');
});

// The bug the old inline `.replace(/\/$/, '/')` could not catch: it swapped a
// trailing slash for a trailing slash.
test('adminUrl: a base without a trailing slash does not run the path together (issue #248)', () => {
assert.strictEqual(adminUrl('http://127.0.0.1:8881'), 'http://127.0.0.1:8881/wp-admin/');
assert.strictEqual(adminUrl('http://127.0.0.1:8881'), 'http://127.0.0.1:8881/wp-admin/?playground_force_auto_login_as_user=admin');
});

test('adminerUrl: matches what the Open Adminer button produced before (issue #248)', () => {
Expand Down
Loading