From 4d6c01aa917c8f3152f4935135796b4b3615943b Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 9 Oct 2019 11:25:23 -0700 Subject: [PATCH 1/4] Framework: Replace all usage of `wp-scripts env` with `@wordpress/env`. --- .travis.yml | 42 +----- package.json | 13 +- packages/env/README.md | 33 +++-- packages/env/lib/cli.js | 15 +++ .../env/lib/create-docker-compose-config.js | 18 ++- packages/env/lib/env.js | 42 +++++- .../install-tests-wordpress-phpunit.sh | 126 ++++++++++++++++++ packages/env/lib/scripts/phpunit-multisite.sh | 2 + 8 files changed, 236 insertions(+), 55 deletions(-) create mode 100755 packages/env/lib/scripts/install-tests-wordpress-phpunit.sh create mode 100755 packages/env/lib/scripts/phpunit-multisite.sh diff --git a/.travis.yml b/.travis.yml index 27b1e7383e85ff..dc0b302fc92fd2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,6 @@ branches: env: global: - PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true - - WP_DEVELOP_DIR: ./wordpress - LOCAL_SCRIPT_DEBUG: false - INSTALL_COMPOSER: false - INSTALL_WORDPRESS: true @@ -45,51 +44,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: diff --git a/package.json b/package.json index 84f28a49d0d870..60dc29a3d4ebcd 100644 --- a/package.json +++ b/package.json @@ -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'", "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", @@ -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", @@ -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": { diff --git a/packages/env/README.md b/packages/env/README.md index 45736ee1fa29bb..a100ae1dd5b0bc 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -14,15 +14,18 @@ $ wp-env --help wp-env 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 [command..] Runs an arbitrary command in one of the + underlying Docker containers. Options: --help Show help [boolean] @@ -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 [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: []] +``` diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js index 6f134afd9ae421..d8115674cfb7fb 100644 --- a/packages/env/lib/cli.js +++ b/packages/env/lib/cli.js @@ -82,6 +82,21 @@ module.exports = function cli() { }, withSpinner( env.clean ) ); + yargs.command( + 'run [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; }; diff --git a/packages/env/lib/create-docker-compose-config.js b/packages/env/lib/create-docker-compose-config.js index 7a3dfc7d33b6aa..bda9d7ad6fe8fd 100644 --- a/packages/env/lib/create-docker-compose-config.js +++ b/packages/env/lib/create-docker-compose-config.js @@ -1,7 +1,8 @@ module.exports = function createDockerComposeConfig( pluginPath, pluginName, - pluginTestsPath + pluginTestsPath, + scriptsPath ) { const commonVolumes = ` - ${ pluginPath }/:/var/www/html/wp-content/plugins/${ pluginName }/ @@ -14,6 +15,7 @@ module.exports = function createDockerComposeConfig( return `version: '2' volumes: tests-wordpress: + tests-wordpress-phpunit: services: mysql: environment: @@ -51,5 +53,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/ `; }; diff --git a/packages/env/lib/env.js b/packages/env/lib/env.js index 159bb2ac2fc45f..459eec540602d6 100644 --- a/packages/env/lib/env.js +++ b/packages/env/lib/env.js @@ -17,6 +17,7 @@ const createDockerComposeConfig = require( './create-docker-compose-config' ); const pluginPath = process.cwd(); const pluginName = path.basename( pluginPath ); const pluginTestsPath = fs.existsSync( './packages' ) ? '/packages' : ''; +const scriptsPath = path.join( __dirname, './scripts' ); const dockerComposeOptions = { config: path.join( __dirname, 'docker-compose.yml' ), }; @@ -95,7 +96,12 @@ module.exports = { spinner.text = `Installing WordPress@${ ref }.`; fs.writeFileSync( dockerComposeOptions.config, - createDockerComposeConfig( pluginPath, pluginName, pluginTestsPath ) + createDockerComposeConfig( + pluginPath, + pluginName, + pluginTestsPath, + scriptsPath + ) ); // These will bring up the database container, @@ -162,4 +168,38 @@ module.exports = { await dockerCompose.rm( dockerComposeOptions ); spinner.text = `Cleaned ${ description }.`; }, + + async run( { container, command, spinner } ) { + command = command.join( ' ' ); + spinner.text = `Running \`${ command }\` in "${ container }".`; + + if ( container === 'tests-wordpress-phpunit' ) { + // Run this "on-demand" to avoid making `start` slower. + await dockerCompose + .run( + 'tests-wordpress-phpunit', + '/scripts/install-tests-wordpress-phpunit.sh tests-wordpress-phpunit root password mysql', + dockerComposeOptions + ) + .catch( () => {} ); + } + + const result = await dockerCompose.run( + container, + command, + dockerComposeOptions + ); + if ( result.out ) { + // eslint-disable-next-line no-console + console.log( `\n\n${ result.out }\n\n` ); + } else if ( result.err ) { + // eslint-disable-next-line no-console + console.error( `\n\n${ result.err }\n\n` ); + throw result.err; + } + + // Remove dangling containers and finish. + await dockerCompose.rm( dockerComposeOptions ); + spinner.text = `Ran \`${ command }\` in "${ container }".`; + }, }; diff --git a/packages/env/lib/scripts/install-tests-wordpress-phpunit.sh b/packages/env/lib/scripts/install-tests-wordpress-phpunit.sh new file mode 100755 index 00000000000000..04bd02508f892c --- /dev/null +++ b/packages/env/lib/scripts/install-tests-wordpress-phpunit.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 +fi + +DB_NAME=$1 +DB_USER=$2 +DB_PASS=$3 +DB_HOST=${4-localhost} +WP_VERSION=${5-latest} +SKIP_DB_CREATE=${6-false} + +WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} + +download() { + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + fi +} + +if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then + WP_TESTS_TAG="tags/$WP_VERSION" +elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + WP_TESTS_TAG="trunk" +else + # http serves a single offer, whereas https serves multiple. we only want one + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + if [[ -z "$LATEST_VERSION" ]]; then + echo "Latest WordPress version could not be found" + exit 1 + fi + WP_TESTS_TAG="tags/$LATEST_VERSION" +fi + +set -ex + +install_wp() { + + if [ -d $WP_CORE_DIR ]; then + return; + fi + + mkdir -p $WP_CORE_DIR + + if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p /tmp/wordpress-nightly + download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip + unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/ + mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + else + local ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz + tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR + fi + + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php +} + +install_test_suite() { + # portable in-place argument for both GNU sed and Mac OSX sed + if [[ $(uname -s) == 'Darwin' ]]; then + local ioption='-i .bak' + else + local ioption='-i' + fi + + # set up testing suite if it doesn't yet exist + if [ ! -d $WP_TESTS_DIR ]; then + # set up testing suite + mkdir -p $WP_TESTS_DIR + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + fi + + if [ ! -f wp-tests-config.php ]; then + download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + # remove all forward slashes in the end + WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + fi + +} + +install_db() { + + if [ ${SKIP_DB_CREATE} = "true" ]; then + return 0 + fi + + # parse DB_HOST for port or socket references + local PARTS=(${DB_HOST//\:/ }) + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + + # create database + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + +install_wp +install_test_suite +install_db diff --git a/packages/env/lib/scripts/phpunit-multisite.sh b/packages/env/lib/scripts/phpunit-multisite.sh new file mode 100755 index 00000000000000..5dccff05d79cc3 --- /dev/null +++ b/packages/env/lib/scripts/phpunit-multisite.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +export WP_MULTISITE=1 && phpunit From 2b23a47dd4c0dae19c48b4e8990249293c2a8843 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 9 Oct 2019 12:53:30 -0700 Subject: [PATCH 2/4] Travis: Fix nodegit Linux install. --- .travis.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc0b302fc92fd2..622d052f06c763 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -dist: trusty - language: generic services: @@ -30,6 +28,13 @@ env: - INSTALL_COMPOSER: false - INSTALL_WORDPRESS: true +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - libstdc++-4.9-dev + before_install: - nvm install --latest-npm - | @@ -106,12 +111,12 @@ jobs: - npm run test-unit:native -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" - name: PHP unit tests - env: INSTALL_COMPOSER=true + env: INSTALL_COMPOSER=true INSTALL_WORDPRESS=false script: - npm run test-php && npm run test-unit-php-multisite - name: PHP unit tests (PHP 5.6) - env: INSTALL_COMPOSER=true LOCAL_PHP=5.6-fpm + env: INSTALL_COMPOSER=true INSTALL_WORDPRESS=false LOCAL_PHP=5.6-fpm script: - npm run test-php && npm run test-unit-php-multisite From 6b782e09ef3fd6c76d0ec73f8941bba707fc3ad2 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 9 Oct 2019 13:40:13 -0700 Subject: [PATCH 3/4] Env: Make sure errors exit with the correct code. --- packages/env/lib/cli.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js index d8115674cfb7fb..85b9825887b083 100644 --- a/packages/env/lib/cli.js +++ b/packages/env/lib/cli.js @@ -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 ); + } ); }; From 0caa67e4929648d23a3d537da209f2fcbec8423a Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 9 Oct 2019 16:00:02 -0700 Subject: [PATCH 4/4] Env: Use latest WP for tests. --- .travis.yml | 6 +- .../env/lib/create-docker-compose-config.js | 3 +- packages/env/lib/env.js | 67 ++++++++++--------- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 622d052f06c763..5021dd2b38a635 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ cache: - $HOME/.jest-cache - $HOME/.npm - $HOME/.nvm/.cache + - ../gutenberg-wordpress + - ../gutenberg-tests-wordpress branches: only: @@ -111,12 +113,12 @@ jobs: - npm run test-unit:native -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" - name: PHP unit tests - env: INSTALL_COMPOSER=true INSTALL_WORDPRESS=false + env: INSTALL_COMPOSER=true script: - npm run test-php && npm run test-unit-php-multisite - name: PHP unit tests (PHP 5.6) - env: INSTALL_COMPOSER=true INSTALL_WORDPRESS=false LOCAL_PHP=5.6-fpm + env: INSTALL_COMPOSER=true LOCAL_PHP=5.6-fpm script: - npm run test-php && npm run test-unit-php-multisite diff --git a/packages/env/lib/create-docker-compose-config.js b/packages/env/lib/create-docker-compose-config.js index bda9d7ad6fe8fd..0a22fb0f956465 100644 --- a/packages/env/lib/create-docker-compose-config.js +++ b/packages/env/lib/create-docker-compose-config.js @@ -11,10 +11,9 @@ 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: diff --git a/packages/env/lib/env.js b/packages/env/lib/env.js index 459eec540602d6..b91f8703ea2587 100644 --- a/packages/env/lib/env.js +++ b/packages/env/lib/env.js @@ -44,6 +44,7 @@ const resetDatabase = ( isTests = false ) => module.exports = { async start( { ref, spinner = {} } ) { spinner.text = `Downloading WordPress@${ ref } 0/100%.`; + let percent = 0; const gitFetchOptions = { fetchOpts: { callbacks: { @@ -51,10 +52,11 @@ module.exports = { // Fetches are finished when all objects are received and indexed, // so received objects plus indexed objects should equal twice // the total number of objects when done. - const percent = ( + percent = Math.max( + percent, ( ( progress.receivedObjects() + progress.indexedObjects() ) / ( progress.totalObjects() * 2 ) ) * - 100 + 100 ).toFixed( 0 ); spinner.text = `Downloading WordPress@${ ref } ${ percent }/100%.`; }, @@ -63,34 +65,39 @@ module.exports = { }; // Clone or get the repo. - const repoPath = `../${ pluginName }-wordpress/`; - const repo = await NodeGit.Clone( - 'https://github.com/WordPress/WordPress.git', - repoPath, - gitFetchOptions - ) - // Repo already exists, get it. - .catch( () => NodeGit.Repository.open( repoPath ) ); - - // Checkout the specified ref. - const remote = await repo.getRemote( 'origin' ); - await remote.fetch( ref, gitFetchOptions.fetchOpts ); - await remote.disconnect(); - try { - await repo.checkoutRef( - await repo - .getReference( 'FETCH_HEAD' ) - // Sometimes git doesn't update FETCH_HEAD for things - // like tags so we try another method here. - .catch( repo.getReference.bind( repo, ref ) ), - { - checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE, - } - ); - } catch ( err ) { - // Some commit refs need to be set as detached. - await repo.setHeadDetached( ref ); - } + const cloneOrGetRepo = async ( repoPath ) => { + const repo = await NodeGit.Clone( + 'https://github.com/WordPress/WordPress.git', + repoPath, + gitFetchOptions + ) + // Repo already exists, get it. + .catch( () => NodeGit.Repository.open( repoPath ) ); + + // Checkout the specified ref. + const remote = await repo.getRemote( 'origin' ); + await remote.fetch( ref, gitFetchOptions.fetchOpts ); + await remote.disconnect(); + try { + await repo.checkoutRef( + await repo + .getReference( 'FETCH_HEAD' ) + // Sometimes git doesn't update FETCH_HEAD for things + // like tags so we try another method here. + .catch( repo.getReference.bind( repo, ref ) ), + { + checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE, + } + ); + } catch ( err ) { + // Some commit refs need to be set as detached. + await repo.setHeadDetached( ref ); + } + }; + await Promise.all( [ + cloneOrGetRepo( `../${ pluginName }-wordpress/` ), + cloneOrGetRepo( `../${ pluginName }-tests-wordpress/` ), + ] ); spinner.text = `Downloading WordPress@${ ref } 100/100%.`; spinner.text = `Installing WordPress@${ ref }.`;