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

Upgrade outdated packages; Bump React to v18 #7548

Merged
merged 32 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6154f24
Update Gutenberg package dependencies
ampprojectbot Jan 5, 2023
5dbd5c4
Bump React and ReactDOM to 18.2.0
thelovekesh May 6, 2023
2cc3288
Bump react-test-renderer to 18.2.0
thelovekesh May 6, 2023
a3981ad
Add @testing-library/react
thelovekesh May 6, 2023
39cae75
Refactor test cases to implement `@testing-library/react`
thelovekesh Dec 15, 2022
f40dfa6
Update jest snapshots
thelovekesh Dec 16, 2022
3cc6522
Use mocked DOM events from testing-library
thelovekesh Dec 16, 2022
e9d7684
Update lockfile
thelovekesh May 6, 2023
8dd9f2c
Update Gutenberg package dependencies
thelovekesh May 6, 2023
9a94fff
Update jest snapshots
thelovekesh May 6, 2023
18c09e8
Fix bug due to improper effect unmount in useDelayedFlag hook
thelovekesh Jan 10, 2023
1fdf6eb
Upgrade to React 18
thelovekesh May 6, 2023
46616f8
Update Gutenberg package dependencies
thelovekesh May 6, 2023
5bfd951
Add custom jest resolver to fix export statement syntax errors
thelovekesh May 6, 2023
8c0ece9
Update jest snapshots after upgrading @wordpress/components package
thelovekesh May 6, 2023
f484f1a
Update store registration as `registerStore` is deprecated
thelovekesh May 15, 2023
bcb0232
Remove block validation store registration
thelovekesh May 15, 2023
1412b5a
Update usage of block-validation store
thelovekesh May 15, 2023
d1df79c
Update usage of block-validation store in test cases
thelovekesh May 15, 2023
f302dc2
Update store registration for block editor as `registerStore` is depr…
thelovekesh May 15, 2023
6a5aa7a
Update packages
thelovekesh May 15, 2023
42874b0
Update jest snapshots after upgrading @wordpress/components package
thelovekesh May 15, 2023
b4faf01
Update e2e-tests workflow to run e2e tests with Node 16
thelovekesh May 16, 2023
494d78a
Fix state batch updates in Options context provider
thelovekesh May 23, 2023
895be5e
Bump deps to latest version
thelovekesh May 23, 2023
6cd4845
Update `AfterActivationSiteScan` service to work with React 18 only
thelovekesh May 23, 2023
9f7014a
Update PHPUnit tests workflow to run multisite in existing job
thelovekesh May 23, 2023
cd2ae21
Remove commented code from block-validation tests
thelovekesh May 24, 2023
53630f1
Revert package.json engines
thelovekesh May 24, 2023
d09a12a
Update gallery handler test cases to remove lazy loading attribute
thelovekesh May 24, 2023
e565be2
Update gallery handler test cases to remove extra whitespaces with lo…
thelovekesh May 24, 2023
eeebbd9
Update gallery handler test cases to remove lazy loading attribute
thelovekesh May 24, 2023
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
88 changes: 18 additions & 70 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ jobs:
env:
COMPOSE_INTERACTIVE_NO_CLI: true


# TODO: Remove it once node version in .nvmrc is updated to >=16.
Copy link
Member

Choose a reason for hiding this comment

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

Wait, why isn't .nvmrc updated to node 18 if the engines.node was updated in package.json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aah, I missed reverting the changes in engines. Since many deps in @wordpress/* are outdated, let's keep node to 14.

- name: Setup Node
uses: actions/setup-node@v3.6.0
with:
node-version: 16
cache: npm

- name: Run E2E tests
run: npm run test:e2e:ci

Expand Down Expand Up @@ -372,6 +380,7 @@ jobs:
include:
- php: '8.0'
wp: 'trunk'
multisite: true
experimental: true

- php: '8.1'
Expand All @@ -391,6 +400,7 @@ jobs:
external-http: true

- php: '7.4'
multisite: true
wp: 'latest'

- php: '7.4'
Expand Down Expand Up @@ -553,6 +563,14 @@ jobs:
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib

- name: Run multisite tests
if: ${{ matrix.multisite == true && needs.pre-run.outputs.changed-php-count > 0 }}
run: vendor/bin/phpunit --verbose
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp
env:
WP_TESTS_DIR: /tmp/wordpress-tests-lib
WP_MULTISITE: 1

- name: Run tests with coverage
if: ${{ matrix.coverage == true && needs.pre-run.outputs.changed-php-count > 0 }}
run: vendor/bin/phpunit --verbose --coverage-clover ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/amp/build/logs/clover.xml
Expand All @@ -575,76 +593,6 @@ jobs:
flags: php,unit
fail_ci_if_error: true

#-----------------------------------------------------------------------------------------------------------------------

unit-test-multisite-php:
name: 'Unit Tests Multisite: PHP 7.4, WP Latest'
needs: pre-run
runs-on: ubuntu-latest
if: needs.pre-run.outputs.changed-php-count > 0
continue-on-error: true
strategy:
matrix:
testsuite: ['default', 'external-http']

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3.6.0
with:
node-version-file: '.nvmrc'
cache: npm

- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Configure Composer cache
uses: actions/cache@v3.3.1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Node dependencies
run: npm ci
env:
CI: true

- name: Install Composer dependencies
run: |
# phpdocumentor/reflection has to be removed as it makes use of an outdated dependency.
composer remove --dev phpdocumentor/reflection
composer install --prefer-dist --ignore-platform-reqs --no-progress --no-interaction

# See https://github.com/wp-cli/wp-cli/issues/5484
- name: Remove conflicting Requests library
run: composer remove --dev --ignore-platform-reqs --no-interaction --no-scripts roave/security-advisories wp-cli/export-command wp-cli/extension-command wp-cli/wp-cli wp-cli/wp-cli-tests

- name: Update PHPUnit
if: needs.pre-run.outputs.changed-php-count > 0
run: |
# We are using PHP 7.4 and WP Latest.
echo "Installing PHPUnit 9.3"
composer require --dev --ignore-platform-reqs phpunit/phpunit:"9.3.*" --with-dependencies

- name: Build plugin
run: npm run build:js

- name: Move amp-wp to amp
run: cp -r "$PWD" "/tmp/amp"

- name: Start wp-env
working-directory: /tmp/amp
run: npm run wp-env start

- name: Run multisite unit tests
working-directory: /tmp/amp
run: npm run test:php:multisite ${{ matrix.testsuite == 'external-http' && '-- --testsuite external-http' || '' }}

#-----------------------------------------------------------------------------------------------------------------------

feature-test-php:
Expand Down
9 changes: 4 additions & 5 deletions assets/src/admin/site-scan-notice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';
import { render } from '@wordpress/element';
import { createRoot } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -94,16 +94,15 @@ domReady(() => {
event.filename &&
/amp-site-scan-notice(\.min)?\.js/.test(event.filename)
) {
render(<ErrorScreen error={event.error} />, root);
createRoot(root).render(<ErrorScreen error={event.error} />);
}
};

global.addEventListener('error', errorHandler);

render(
createRoot(root).render(
<Providers>
<SiteScanNotice />
</Providers>,
root
</Providers>
);
});
18 changes: 10 additions & 8 deletions assets/src/block-editor/store/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { registerStore } from '@wordpress/data';
import { createReduxStore, register } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -13,10 +13,12 @@ import * as selectors from './selectors';
*/
const MODULE_KEY = 'amp/block-editor';

export default registerStore(MODULE_KEY, {
reducer: (state) => state,
selectors,
initialState: {
...window.ampBlockEditor,
},
});
export default register(
createReduxStore(MODULE_KEY, {
reducer: (state) => state,
selectors,
initialState: {
...window.ampBlockEditor,
},
})
);
27 changes: 13 additions & 14 deletions assets/src/block-validation/components/amp-document-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
*/
import AMPValidationErrorsKeptIcon from '../../../../images/amp-validation-errors-kept.svg';
import BellIcon from '../../../../images/bell-icon.svg';
import { BLOCK_VALIDATION_STORE_KEY } from '../../store';
import { store as blockValidationStore } from '../../store';
import { StatusIcon } from '../icon';
import { SidebarNotification } from '../sidebar-notification';
import { useAMPDocumentToggle } from '../../hooks/use-amp-document-toggle';
Expand All @@ -37,19 +37,18 @@ export default function AMPDocumentStatusNotification() {
unreviewedValidationErrorCount,
} = useSelect(
(select) => ({
isPostDirty: select(BLOCK_VALIDATION_STORE_KEY).getIsPostDirty(),
maybeIsPostDirty: select(
BLOCK_VALIDATION_STORE_KEY
).getMaybeIsPostDirty(),
keptMarkupValidationErrorCount: select(
BLOCK_VALIDATION_STORE_KEY
).getKeptMarkupValidationErrors().length,
reviewedValidationErrorCount: select(
BLOCK_VALIDATION_STORE_KEY
).getReviewedValidationErrors().length,
unreviewedValidationErrorCount: select(
BLOCK_VALIDATION_STORE_KEY
).getUnreviewedValidationErrors().length,
isPostDirty: select(blockValidationStore).getIsPostDirty(),
maybeIsPostDirty:
select(blockValidationStore).getMaybeIsPostDirty(),
keptMarkupValidationErrorCount:
select(blockValidationStore).getKeptMarkupValidationErrors()
.length,
reviewedValidationErrorCount:
select(blockValidationStore).getReviewedValidationErrors()
.length,
unreviewedValidationErrorCount:
select(blockValidationStore).getUnreviewedValidationErrors()
.length,
}),
[]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/**
* External dependencies
*/
import { act } from 'react-dom/test-utils';
import { render, fireEvent } from '@testing-library/react';

/**
* WordPress dependencies
*/
import { render, unmountComponentAtNode } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';

/**
Expand All @@ -28,8 +27,6 @@ jest.mock('../../../hooks/use-errors-fetching-state-changes', () => ({
}));

describe('AMPDocumentStatusNotification', () => {
let container;

const openGeneralSidebar = jest.fn();
const closePublishSidebar = jest.fn();

Expand Down Expand Up @@ -65,18 +62,6 @@ describe('AMPDocumentStatusNotification', () => {
}));
});

beforeEach(() => {
// jest.clearAllMocks();
container = document.createElement('div');
document.body.appendChild(container);
});

afterEach(() => {
unmountComponentAtNode(container);
container.remove();
container = null;
});

it('renders only a toggle if AMP is disabled', () => {
setupHooks(
{},
Expand All @@ -86,9 +71,7 @@ describe('AMPDocumentStatusNotification', () => {
}
);

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
const { container } = render(<AMPDocumentStatusNotification />);

expect(container.children).toHaveLength(1);
expect(container.innerHTML).toContain('Enable AMP');
Expand All @@ -103,9 +86,7 @@ describe('AMPDocumentStatusNotification', () => {
}
);

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
const { container } = render(<AMPDocumentStatusNotification />);

expect(container.innerHTML).toContain('Enable AMP');
expect(
Expand All @@ -119,9 +100,7 @@ describe('AMPDocumentStatusNotification', () => {
isPostDirty: true,
});

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
let { container } = render(<AMPDocumentStatusNotification />);

expect(container.innerHTML).toContain('Enable AMP');
expect(container.innerHTML).toContain('Content has changed.');
Expand All @@ -133,14 +112,13 @@ describe('AMPDocumentStatusNotification', () => {
maybeIsPostDirty: true,
});

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
({ container } = render(<AMPDocumentStatusNotification />));

expect(container.innerHTML).toContain('Content may have changed.');

// Simulate button click.
container.querySelector('button').click();
fireEvent.click(container.querySelector('button'));

expect(openGeneralSidebar).toHaveBeenCalledTimes(1);
expect(closePublishSidebar).toHaveBeenCalledTimes(1);
});
Expand All @@ -150,9 +128,7 @@ describe('AMPDocumentStatusNotification', () => {
keptMarkupValidationErrorCount: 3,
});

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
const { container } = render(<AMPDocumentStatusNotification />);

expect(container.innerHTML).toContain('Enable AMP');
expect(container.innerHTML).toContain(
Expand All @@ -169,9 +145,7 @@ describe('AMPDocumentStatusNotification', () => {
unreviewedValidationErrorCount: 1,
});

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
const { container } = render(<AMPDocumentStatusNotification />);

expect(container.innerHTML).toContain('Enable AMP');
expect(container.innerHTML).toContain(
Expand All @@ -186,9 +160,7 @@ describe('AMPDocumentStatusNotification', () => {
it('renders a correct message if there are no errors', () => {
setupHooks();

act(() => {
render(<AMPDocumentStatusNotification />, container);
});
const { container } = render(<AMPDocumentStatusNotification />);

expect(container.innerHTML).toContain('Enable AMP');
expect(container.innerHTML).toContain(
Expand Down
Loading