Skip to content

Commit cca25dc

Browse files
ciampoMamaduka
authored andcommitted
Tests: Reset deprecation history in shared Vitest setup (WordPress#83849)
Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent cd313b5 commit cca25dc

25 files changed

Lines changed: 31 additions & 155 deletions

File tree

‎docs/contributors/code/testing-overview.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Vitest resets mock implementations and call history, restores spies, resets stub
190190

191191
### Expected console calls
192192

193+
Gutenberg's internal Vitest setup clears `@wordpress/deprecated`'s logged-message history before each test. A message still logs only once within a test. Suites do not need their own deprecation-history cleanup. To suppress a known deprecation in behavior tests, set its `logged` entry in `beforeEach` and delete that entry in the test that asserts the warning.
194+
193195
Gutenberg's internal Vitest setup fails a test when `console.error`, `console.warn`, `console.info`, or `console.log` has calls that the test did not explicitly expect. Use `toHaveErroredWith`, `toHaveWarnedWith`, `toHaveInformedWith`, or `toHaveLoggedWith` with specific arguments. Asymmetric matchers such as `expect.objectContaining` are supported.
194196

195197
```js

‎package-lock.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/block-editor/src/store/test/selectors.jsdom.test.jsx‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@wordpress/blocks';
2020
import { RawHTML } from '@wordpress/element';
2121
import { symbol } from '@wordpress/icons';
22-
import { logged } from '@wordpress/deprecated';
2322
import { select, dispatch } from '@wordpress/data';
2423
import * as selectors from '../selectors';
2524
import { store } from '../';
@@ -5371,14 +5370,6 @@ describe( '__unstableGetClientIdWithClientIdsTree', () => {
53715370
const DEPRECATION_MESSAGE =
53725371
"wp.data.select( 'core/block-editor' ).__unstableGetClientIdWithClientIdsTree is deprecated since version 6.3 and will be removed in version 6.5.";
53735372

5374-
beforeEach( () => {
5375-
delete logged[ DEPRECATION_MESSAGE ];
5376-
} );
5377-
5378-
afterEach( () => {
5379-
delete logged[ DEPRECATION_MESSAGE ];
5380-
} );
5381-
53825373
it( "should return a stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
53835374
const state = {
53845375
blocks: {
@@ -5411,14 +5402,6 @@ describe( '__unstableGetClientIdsTree', () => {
54115402
const DEPRECATION_MESSAGE =
54125403
"wp.data.select( 'core/block-editor' ).__unstableGetClientIdsTree is deprecated since version 6.3 and will be removed in version 6.5.";
54135404

5414-
beforeEach( () => {
5415-
delete logged[ DEPRECATION_MESSAGE ];
5416-
} );
5417-
5418-
afterEach( () => {
5419-
delete logged[ DEPRECATION_MESSAGE ];
5420-
} );
5421-
54225405
it( "should return the full content tree starting from the given root, consisting of stripped down block object containing only its client ID and its inner blocks' client IDs", () => {
54235406
const state = {
54245407
blocks: {

‎packages/blocks/src/api/test/children.jsdom.test.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { afterEach, describe, expect, it } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22
import { renderToString } from '@wordpress/element';
3-
import { logged } from '@wordpress/deprecated';
43
import {
54
getSerializeCapableElement,
65
concat,
@@ -9,10 +8,6 @@ import {
98
} from '../children';
109
/* eslint-disable testing-library/render-result-naming-convention */
1110

12-
afterEach( () => {
13-
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
14-
} );
15-
1611
describe( 'getSerializeCapableElement', () => {
1712
it( 'returns a serialize capable element', () => {
1813
const blockNode = [

‎packages/blocks/src/api/test/matchers.jsdom.test.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import { afterEach, describe, expect, it } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22
import { parse } from 'hpq';
33
import { renderToString } from '@wordpress/element';
4-
import { logged } from '@wordpress/deprecated';
54
import * as sources from '../matchers';
65

7-
afterEach( () => {
8-
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
9-
} );
10-
116
describe( 'matchers', () => {
127
describe( 'children()', () => {
138
it( 'should return a source function', () => {

‎packages/blocks/src/api/test/node.jsdom.test.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { afterEach, describe, expect, it } from 'vitest';
2-
import { logged } from '@wordpress/deprecated';
1+
import { describe, expect, it } from 'vitest';
32
import { getNamedNodeMapAsObject, toHTML, fromDOM } from '../node';
43

5-
afterEach( () => {
6-
Object.keys( logged ).forEach( ( key ) => delete logged[ key ] );
7-
} );
8-
94
describe( 'getNamedNodeMapAsObject', () => {
105
it( 'should return an object of node attributes', () => {
116
const node = document.createElement( 'img' );

‎packages/components/src/badge/test/index.jsdom.test.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
1+
import { beforeEach, describe, expect, it } from 'vitest';
22
import { render, screen } from '@testing-library/react';
33
import { logged } from '@wordpress/deprecated';
44
import _Badge from '..';
@@ -15,10 +15,6 @@ beforeEach( () => {
1515
logged[ DEPRECATION_MESSAGE ] = true;
1616
} );
1717

18-
afterEach( () => {
19-
delete logged[ DEPRECATION_MESSAGE ];
20-
} );
21-
2218
describe( 'Shows a deprecation warning', () => {
2319
it( 'Badge', () => {
2420
delete logged[ DEPRECATION_MESSAGE ];

‎packages/components/src/circular-option-picker/test/index.browser.test.tsx‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22
import { userEvent } from 'vitest/browser';
33
import { screen } from '@testing-library/react';
44
import { render } from 'vitest-browser-react';
5-
import { logged } from '@wordpress/deprecated';
65
import CircularOptionPicker from '..';
76

87
const SINGLE_OPTION = [ <CircularOptionPicker.Option key="option" /> ];
@@ -24,14 +23,6 @@ function getOption( name: string ) {
2423
}
2524

2625
describe( 'CircularOptionPicker', () => {
27-
beforeEach( () => {
28-
delete logged[ AS_BUTTONS_DEPRECATION ];
29-
} );
30-
31-
afterEach( () => {
32-
delete logged[ AS_BUTTONS_DEPRECATION ];
33-
} );
34-
3526
it( 'should preserve toggle-button semantics when an option is rendered without a picker', async () => {
3627
await render(
3728
<CircularOptionPicker.Option

‎packages/components/src/color-palette/test/index.browser.test.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import { screen, waitFor } from '@testing-library/react';
33
import { userEvent } from 'vitest/browser';
44
import { render } from 'vitest-browser-react';
@@ -24,10 +24,6 @@ beforeEach( () => {
2424
logged[ DEPRECATION_MESSAGE ] = true;
2525
} );
2626

27-
afterEach( () => {
28-
delete logged[ DEPRECATION_MESSAGE ];
29-
} );
30-
3127
const ControlledColorPalette = ( {
3228
onChange,
3329
}: {

‎packages/components/src/composite/legacy/test/index.browser.test.tsx‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, test } from 'vitest';
1+
import { beforeEach, describe, expect, it, test } from 'vitest';
22
import { userEvent } from 'vitest/browser';
33
import { queryByAttribute, screen, waitFor } from '@testing-library/react';
44
import { render, renderHook } from 'vitest-browser-react';
@@ -29,12 +29,6 @@ beforeEach( () => {
2929
}
3030
} );
3131

32-
afterEach( () => {
33-
for ( const message of Object.values( DEPRECATION_MESSAGES ) ) {
34-
delete logged[ message ];
35-
}
36-
} );
37-
3832
type InitialState = Parameters< typeof useCompositeState >[ 0 ];
3933
type CompositeState = ReturnType< typeof useCompositeState >;
4034
type CompositeStateProps = CompositeState | { state: CompositeState };

0 commit comments

Comments
 (0)