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

Framework: Replace all usage of wp-scripts env with @wordpress/env. #17871

Closed
wants to merge 4 commits into from
Closed
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
53 changes: 14 additions & 39 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
dist: trusty

language: generic

services:
Expand All @@ -16,6 +14,8 @@ cache:
- $HOME/.jest-cache
- $HOME/.npm
- $HOME/.nvm/.cache
- ../gutenberg-wordpress
- ../gutenberg-tests-wordpress

branches:
only:
Expand All @@ -26,11 +26,17 @@ branches:
env:
global:
- PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- WP_DEVELOP_DIR: ./wordpress
- LOCAL_SCRIPT_DEBUG: false
- INSTALL_COMPOSER: false
- INSTALL_WORDPRESS: true

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++-4.9-dev

before_install:
- nvm install --latest-npm
- |
Expand All @@ -45,51 +51,20 @@ before_install:
install:
# Build Gutenberg.
- npm ci
- npm run check-engines
- npm run build
- |
if [[ "$INSTALL_WORDPRESS" = "true" ]]; then
# Download and unpack WordPress.
curl -sL https://wordpress.org/nightly-builds/wordpress-latest.zip -o /tmp/wordpress-latest.zip
unzip -q /tmp/wordpress-latest.zip -d /tmp
mkdir -p wordpress/src
mv /tmp/wordpress/* wordpress/src

# Create the upload directory with permissions that Travis can handle.
mkdir -p wordpress/src/wp-content/uploads
chmod 767 wordpress/src/wp-content/uploads

# Grab the tools we need for WordPress' local-env.
curl -sL https://github.com/WordPress/wordpress-develop/archive/master.zip -o /tmp/wordpress-develop.zip
unzip -q /tmp/wordpress-develop.zip -d /tmp
mv \
/tmp/wordpress-develop-master/tools \
/tmp/wordpress-develop-master/tests \
/tmp/wordpress-develop-master/.env \
/tmp/wordpress-develop-master/docker-compose.yml \
/tmp/wordpress-develop-master/wp-cli.yml \
/tmp/wordpress-develop-master/*config-sample.php \
/tmp/wordpress-develop-master/package.json wordpress

# Install WordPress.
cd wordpress
npm install dotenv wait-on
npm run env:start
sleep 10
npm run env:install
cd ..

# Connect Gutenberg to WordPress.
npm run env connect
npm run env cli plugin activate gutenberg
npm run env start
fi
- |
if [[ "$INSTALL_COMPOSER" = "true" ]]; then
npm run env docker-run -- php composer install
npm run env run composer install
fi
- |
if [[ "$E2E_ROLE" = "author" ]]; then
npm run env cli -- user create author author@example.com --role=author --user_pass=authpass
npm run env cli -- post update 1 --post_author=2
npm run env run tests-wordpress-cli 'user create author author@example.com --role=author --user_pass=authpass'
npm run env run tests-wordpress-cli 'post update 1 --post_author=2'
fi

jobs:
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@
"dev:packages": "node ./bin/packages/watch.js",
"docs:build": "node ./docs/tool/index.js && node ./bin/update-readmes.js",
"fixtures:clean": "rimraf \"packages/e2e-tests/fixtures/blocks/*.+(json|serialized.html)\"",
"fixtures:server-registered": "wp-scripts env docker-run php ./bin/get-server-blocks.php > test/integration/full-content/server-registered.json",
"fixtures:server-registered": "npm run env run tests-wordpress-phpunit './bin/get-server-blocks.php > test/integration/full-content/server-registered.json'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should run this script with PHP, it doesn't use PHPUnit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but tests-wordpress-phpunit has php and we already use it.

"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate",
"lint": "concurrently \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\" \"npm run lint-types\"",
"lint-js": "wp-scripts lint-js",
"lint-js:fix": "npm run lint-js -- --fix",
"lint-php": "wp-scripts env lint-php",
"lint-php": "npm run env run composer run-script lint",
"lint-pkg-json": "wp-scripts lint-pkg-json ./packages",
"lint-css": "wp-scripts lint-style '**/*.scss'",
"lint-css:fix": "npm run lint-css -- --fix",
Expand All @@ -212,7 +212,7 @@
"publish:dev": "npm run build:packages && lerna publish --npm-tag next",
"publish:prod": "npm run build:packages && lerna publish",
"test": "npm run lint && npm run test-unit",
"pretest-e2e": "npm run env reinstall",
"pretest-e2e": "npm run env clean",
"test-e2e": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js",
"test-e2e:local": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js",
"test-e2e:watch": "npm run test-e2e:local -- --watch",
Expand All @@ -221,16 +221,15 @@
"test-unit": "wp-scripts test-unit-js --config test/unit/jest.config.js",
"test-unit:update": "npm run test-unit -- --updateSnapshot",
"test-unit:watch": "npm run test-unit -- --watch",
"test-unit-php": "wp-scripts env test-php",
"test-unit-php-multisite": "cross-env WP_MULTISITE=1 wp-scripts env test-php",
"test-unit-php": "npm run env run tests-wordpress-phpunit phpunit",
"test-unit-php-multisite": "npm run env run tests-wordpress-phpunit /scripts/phpunit-multisite.sh",
"test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js",
"test-unit:native:debug": "cd test/native/ && node --inspect ../../node_modules/.bin/jest --runInBand --config ./jest.config.js",
"design-system:build": "npm run build:packages && build-storybook -c ./packages/components/storybook -o ./playground/dist/design-system/components",
"design-system:dev": "concurrently \"npm run dev:packages\" \"start-storybook -c ./packages/components/storybook\"",
"playground:build": "npm run build:packages && parcel build playground/src/index.html -d playground/dist",
"playground:dev": "concurrently \"npm run dev:packages\" \"parcel playground/src/index.html -d playground/dist\"",
"preenv": "npm run check-engines",
"env": "wp-scripts env"
"env": "packages/env/bin/wp-env"
},
"husky": {
"hooks": {
Expand Down
33 changes: 24 additions & 9 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ $ wp-env --help
wp-env <command>

Commands:
wp-env start [ref] Starts WordPress for development on port 8888
(​http://localhost:8888​) and tests on port 8889
(​http://localhost:8889​). If the current working
directory is a plugin and/or has e2e-tests with
plugins and/or mu-plugins, they will be mounted
appropiately.
wp-env stop Stops running WordPress for development and tests
and frees the ports.
wp-env clean [environment] Cleans the WordPress databases.
wp-env start [ref] Starts WordPress for development on port
8888 (​http://localhost:8888​) and tests
on port 8889 (​http://localhost:8889​). If
the current working directory is a plugin
and/or has e2e-tests with plugins and/or
mu-plugins, they will be mounted
appropiately.
wp-env stop Stops running WordPress for development
and tests and frees the ports.
wp-env clean [environment] Cleans the WordPress databases.
wp-env run <container> [command..] Runs an arbitrary command in one of the
underlying Docker containers.

Options:
--help Show help [boolean]
Expand Down Expand Up @@ -63,3 +66,15 @@ Positionals:
environment Which environments' databases to clean.
[string] [choices: "all", "development", "tests"] [default: "tests"]
```

### `$ wp-env run --help`

```sh
wp-env run <container> [command..]

Runs an arbitrary command in one of the underlying Docker containers.

Positionals:
container The container to run the command on. [string] [required]
command The command to run. [array] [default: []]
```
22 changes: 21 additions & 1 deletion packages/env/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ const withSpinner = ( command ) => ( ...args ) => {
) }ms)`
);
},
( err ) => spinner.fail( err.message || err.err )
( err ) => {
spinner.fail( err.message );
// eslint-disable-next-line no-console
console.error( `\n\n${ err.out || err.err }\n\n` );
process.exit( err.exitCode || 1 );
}
);
};

Expand Down Expand Up @@ -82,6 +87,21 @@ module.exports = function cli() {
},
withSpinner( env.clean )
);
yargs.command(
'run <container> [command..]',
'Runs an arbitrary command in one of the underlying Docker containers.',
( args ) => {
args.positional( 'container', {
type: 'string',
describe: 'The container to run the command on.',
} );
args.positional( 'command', {
type: 'string',
describe: 'The command to run.',
} );
},
withSpinner( env.run )
);

return yargs;
};
21 changes: 18 additions & 3 deletions packages/env/lib/create-docker-compose-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = function createDockerComposeConfig(
pluginPath,
pluginName,
pluginTestsPath
pluginTestsPath,
scriptsPath
) {
const commonVolumes = `
- ${ pluginPath }/:/var/www/html/wp-content/plugins/${ pluginName }/
Expand All @@ -10,10 +11,10 @@ module.exports = function createDockerComposeConfig(
const volumes = `
- ${ pluginPath }/../${ pluginName }-wordpress/:/var/www/html/${ commonVolumes }`;
const testsVolumes = `
- tests-wordpress:/var/www/html/${ commonVolumes }`;
- ${ pluginPath }/../${ pluginName }-tests-wordpress/:/var/www/html/${ commonVolumes }`;
return `version: '2'
volumes:
tests-wordpress:
tests-wordpress-phpunit:
services:
mysql:
environment:
Expand Down Expand Up @@ -51,5 +52,19 @@ services:
- tests-wordpress
image: wordpress:cli
volumes:${ testsVolumes }
tests-wordpress-phpunit:
depends_on:
- mysql
environment:
PHPUNIT_DB_HOST: mysql
image: chriszarate/wordpress-phpunit
volumes:
- ${ pluginPath }/:/app/
- ${ scriptsPath }/:/scripts/
- tests-wordpress-phpunit/:/tmp/
composer:
image: composer
volumes:
- ${ pluginPath }/:/app/
`;
};
Loading