From 33cd07164658f726f3b6006bf3f1ba03bcabfe07 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 10:58:12 -0500 Subject: [PATCH 1/9] Framework: Run Travis JS Unit Test tasks concurrently Include check-licenses --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a464d766d9739..39df464ff0e801 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,9 +34,11 @@ jobs: install: - npm ci script: - - npm run lint - - npm run check-local-changes - - npm run test-unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" + - $( npm bin )/concurrently --kill-others-on-fail \ + "npm run lint" \ + "npm run check-local-changes" \ + "npm run check-licenses" \ + "npm run test-unit -- --ci --maxWorkers=2 --cacheDirectory=\"$HOME/.jest-cache\"" - name: PHP unit tests (Docker) env: WP_VERSION=latest DOCKER=true From ef23f7b89426822163d23592e41aef56540a7df4 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 10:58:21 -0500 Subject: [PATCH 2/9] Framework: Remove postinstall script --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 0700d64f3141b9..1f0e798ff37f1d 100644 --- a/package.json +++ b/package.json @@ -175,7 +175,6 @@ "lint-css": "wp-scripts lint-style '**/*.scss'", "lint-css:fix": "npm run lint-css -- --fix", "package-plugin": "./bin/build-plugin-zip.sh", - "postinstall": "npm run check-licenses && npm run build:packages", "pot-to-php": "./bin/pot-to-php.js", "precommit": "lint-staged", "publish:check": "npm run build:packages && lerna updated", From f4c926aba23ba82569b99f4c3cf2fd268a5bcb0b Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 10:58:43 -0500 Subject: [PATCH 3/9] Framework: Avoid npm install / build in PHP unit tests --- bin/run-wp-unit-tests.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/run-wp-unit-tests.sh b/bin/run-wp-unit-tests.sh index 8e1ee81db79e3d..ab7f9ce2319ad9 100755 --- a/bin/run-wp-unit-tests.sh +++ b/bin/run-wp-unit-tests.sh @@ -16,11 +16,8 @@ else # Run the build because otherwise there will be a bunch of warnings about # failed `stat` calls from `filemtime()`. composer install || exit 1 - npm install || exit 1 fi -npm run build || exit 1 - echo Running with the following versions: if [[ $DOCKER = "true" ]]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit php -v @@ -32,8 +29,9 @@ fi # Run PHPUnit tests if [[ $DOCKER = "true" ]]; then - npm run test-php || exit 1 - npm run test-unit-php-multisite || exit 1 + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer run-script lint + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit phpunit + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit -e WP_MULTISITE=1 phpunit else phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1 From d69d0565893e3dc7a6fdb1def5eeb7b090a88ac6 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 11:25:27 -0500 Subject: [PATCH 4/9] Framework: Run build for JS unit tests Assumed previously relied on postinstall --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 39df464ff0e801..211b8b331281a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ jobs: install: - npm ci script: + - npm run build - $( npm bin )/concurrently --kill-others-on-fail \ "npm run lint" \ "npm run check-local-changes" \ From 732f50091182812f89bdb9aa033d7b605103e747 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 11:36:36 -0500 Subject: [PATCH 5/9] Testing: Ensure directory exists before writing in ensure_editor_styles --- phpunit/class-extend-styles-test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit/class-extend-styles-test.php b/phpunit/class-extend-styles-test.php index 6ae12ada227973..7d7c48fe7c1320 100644 --- a/phpunit/class-extend-styles-test.php +++ b/phpunit/class-extend-styles-test.php @@ -65,6 +65,10 @@ protected function ensure_editor_styles( $should_exist = true ) { $this->original_file = $path . '.bak'; } } elseif ( $should_exist ) { + if ( ! is_dir( dirname( $path ) ) ) { + mkdir( $path ); + } + $this->style_contents = ''; file_put_contents( $path, $this->style_contents ); $this->original_file = null; From 651d56207a718a06fb5ef6742e04dbe11259ec80 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 11:39:16 -0500 Subject: [PATCH 6/9] Testing: Remove core-block-theme-test.php Slated for removal as of #13569 --- phpunit/class-core-block-theme-test.php | 106 ------------------------ 1 file changed, 106 deletions(-) delete mode 100644 phpunit/class-core-block-theme-test.php diff --git a/phpunit/class-core-block-theme-test.php b/phpunit/class-core-block-theme-test.php deleted file mode 100644 index dc378dd85a4eaa..00000000000000 --- a/phpunit/class-core-block-theme-test.php +++ /dev/null @@ -1,106 +0,0 @@ -old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null; - remove_action( 'wp_default_scripts', 'wp_default_scripts' ); - - $GLOBALS['wp_scripts'] = new WP_Scripts(); - $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); - - $this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null; - remove_action( 'wp_default_styles', 'wp_default_styles' ); - - $GLOBALS['wp_styles'] = new WP_Styles(); - $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' ); - } - - function tearDown() { - $GLOBALS['wp_scripts'] = $this->old_wp_scripts; - add_action( 'wp_default_scripts', 'wp_default_scripts' ); - - $GLOBALS['wp_styles'] = $this->old_wp_styles; - add_action( 'wp_default_styles', 'wp_default_styles' ); - - if ( current_theme_supports( 'wp-block-styles' ) ) { - remove_theme_support( 'wp-block-styles' ); - } - - parent::tearDown(); - } - - /** - * Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'. - * - * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. - */ - function test_block_styles_for_editing_without_theme_support() { - // Confirm we are without theme support by default. - $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); - - gutenberg_register_scripts_and_styles(); - - $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); - wp_enqueue_style( 'wp-edit-blocks' ); - $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); - } - - /** - * Tests that visual block styles are enqueued when there is theme support for 'wp-block-styles'. - * - * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. - */ - function test_block_styles_for_editing_with_theme_support() { - add_theme_support( 'wp-block-styles' ); - gutenberg_register_scripts_and_styles(); - - $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); - wp_enqueue_style( 'wp-edit-blocks' ); - $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); - } - - /** - * Tests that visual block styles are not enqueued for viewing when there is no theme support for 'wp-block-styles'. - * - * Visual block styles should not be enqueued unless a theme opts in. - * This way we avoid style conflicts with existing themes. - */ - function test_no_block_styles_for_viewing_without_theme_support() { - // Confirm we are without theme support by default. - $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); - - gutenberg_register_scripts_and_styles(); - - $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); - wp_enqueue_style( 'wp-block-library' ); - $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); - } - - /** - * Tests that visual block styles are enqueued for viewing when there is theme support for 'wp-block-styles'. - * - * Visual block styles should be enqueued when a theme opts in. - */ - function test_block_styles_for_viewing_with_theme_support() { - add_theme_support( 'wp-block-styles' ); - - gutenberg_register_scripts_and_styles(); - - $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); - wp_enqueue_style( 'wp-block-library' ); - $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); - } -} From 7f31ee4ca5dae8b21c6e026a3e6d4de16c062cf6 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 11:49:46 -0500 Subject: [PATCH 7/9] Testing: mkdir recursive --- phpunit/class-extend-styles-test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpunit/class-extend-styles-test.php b/phpunit/class-extend-styles-test.php index 7d7c48fe7c1320..ed717cf838431c 100644 --- a/phpunit/class-extend-styles-test.php +++ b/phpunit/class-extend-styles-test.php @@ -65,8 +65,10 @@ protected function ensure_editor_styles( $should_exist = true ) { $this->original_file = $path . '.bak'; } } elseif ( $should_exist ) { + // Ensure directory exists before writing style contents, since + // it's likely if this is reached there's no build directory. if ( ! is_dir( dirname( $path ) ) ) { - mkdir( $path ); + mkdir( $path, 0777, true ); } $this->style_contents = ''; From da4088527e9e87574641cfbdbc9ca26d898ff0a5 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 12:31:00 -0500 Subject: [PATCH 8/9] Testing: mkdir the dir, not the path --- phpunit/class-extend-styles-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/class-extend-styles-test.php b/phpunit/class-extend-styles-test.php index ed717cf838431c..027366a77ef197 100644 --- a/phpunit/class-extend-styles-test.php +++ b/phpunit/class-extend-styles-test.php @@ -68,7 +68,7 @@ protected function ensure_editor_styles( $should_exist = true ) { // Ensure directory exists before writing style contents, since // it's likely if this is reached there's no build directory. if ( ! is_dir( dirname( $path ) ) ) { - mkdir( $path, 0777, true ); + mkdir( dirname( $path ), 0777, true ); } $this->style_contents = ''; From 63797564ba7ce542a89133b5f3465efc346d438f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 6 Mar 2019 13:36:46 -0500 Subject: [PATCH 9/9] Testing: Fix docker-compose run arg order --- bin/run-wp-unit-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run-wp-unit-tests.sh b/bin/run-wp-unit-tests.sh index ab7f9ce2319ad9..cc75f3d866adf0 100755 --- a/bin/run-wp-unit-tests.sh +++ b/bin/run-wp-unit-tests.sh @@ -31,7 +31,7 @@ fi if [[ $DOCKER = "true" ]]; then docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm composer run-script lint docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit phpunit - docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm wordpress_phpunit -e WP_MULTISITE=1 phpunit + docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -e WP_MULTISITE=1 wordpress_phpunit phpunit else phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1