Skip to content

Commit f7322cd

Browse files
Update dependency pleasantest to v3 (#2038)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Caleb Eby <[email protected]>
1 parent a3f82c0 commit f7322cd

File tree

11 files changed

+4311
-11406
lines changed

11 files changed

+4311
-11406
lines changed

package-lock.json

Lines changed: 4260 additions & 11329 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"ltx": "3.0.0",
8585
"mini-css-extract-plugin": "1.6.2",
8686
"npm-run-all": "4.1.5",
87-
"pleasantest": "2.2.0",
87+
"pleasantest": "3.1.0",
8888
"postcss": "8.4.20",
8989
"postcss-inline-svg": "4.1.0",
9090
"postcss-loader": "4.3.0",

src/components/alert/alert.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path';
22

3-
import type { ElementHandle } from 'pleasantest';
43
import { getAccessibilityTree, withBrowser } from 'pleasantest';
54

65
import { loadTwigTemplate } from '../../../test-utils.js';
@@ -18,9 +17,7 @@ describe('Alert component', () => {
1817
})
1918
);
2019

21-
const body = await page.evaluateHandle<ElementHandle>(
22-
() => document.body
23-
);
20+
const body = await page.evaluateHandle(() => document.body);
2421
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(
2522
`text "¡Hola!"`
2623
);
@@ -36,9 +33,7 @@ describe('Alert component', () => {
3633
})
3734
);
3835

39-
const body = await page.evaluateHandle<ElementHandle>(
40-
() => document.body
41-
);
36+
const body = await page.evaluateHandle(() => document.body);
4237
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
4338
status
4439
text "Hello world!"
@@ -55,9 +50,7 @@ describe('Alert component', () => {
5550
})
5651
);
5752

58-
const body = await page.evaluateHandle<ElementHandle>(
59-
() => document.body
60-
);
53+
const body = await page.evaluateHandle(() => document.body);
6154
// Nothing to see if the `hidden` attribute is added to the alert
6255
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(``);
6356
})

src/components/author/author.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path';
22

3-
import type { ElementHandle } from 'pleasantest';
43
import { getAccessibilityTree, withBrowser } from 'pleasantest';
54

65
import { loadTwigTemplate } from '../../../test-utils.js';
@@ -27,7 +26,7 @@ test(
2726
})
2827
);
2928

30-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
29+
const body = await page.evaluateHandle(() => document.body);
3130
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
3231
text "By"
3332
link "Shakira Isabel Mebarak Ripoll"
@@ -81,7 +80,7 @@ test(
8180
})
8281
);
8382

84-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
83+
const body = await page.evaluateHandle(() => document.body);
8584

8685
// Confirm the meta value is rendered and the date is not rendered
8786
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
@@ -109,7 +108,7 @@ test(
109108
})
110109
);
111110

112-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
111+
const body = await page.evaluateHandle(() => document.body);
113112

114113
// Confirm the author name is "text" and not a link
115114
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
@@ -137,7 +136,7 @@ test(
137136
})
138137
);
139138

140-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
139+
const body = await page.evaluateHandle(() => document.body);
141140

142141
// Confirm the author name is "text" and not a link
143142
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`

src/components/button-swap/button-swap.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path';
22

3-
import type { ElementHandle } from 'pleasantest';
43
import { getAccessibilityTree, withBrowser } from 'pleasantest';
54

65
import { loadGlobalCSS, loadTwigTemplate } from '../../../test-utils.js';
@@ -17,7 +16,7 @@ test(
1716
await loadGlobalCSS(utils);
1817

1918
// Before JS initializes
20-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
19+
const body = await page.evaluateHandle(() => document.body);
2120
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
2221
status
2322
text "Currently unsubscribed from notifications"
@@ -54,7 +53,7 @@ test(
5453
);
5554
await loadGlobalCSS(utils);
5655

57-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
56+
const body = await page.evaluateHandle(() => document.body);
5857
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
5958
status
6059
text "Unsubscribed"

src/components/card/card.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'path';
22

3-
import type { ElementHandle } from 'pleasantest';
43
import { getAccessibilityTree, withBrowser } from 'pleasantest';
54

65
import { loadTwigTemplate } from '../../../test-utils.js';
@@ -20,9 +19,7 @@ describe('Card component', () => {
2019
})
2120
);
2221

23-
const body = await page.evaluateHandle<ElementHandle>(
24-
() => document.body
25-
);
22+
const body = await page.evaluateHandle(() => document.body);
2623
expect(await getAccessibilityTree(body, { includeText: false }))
2724
.toMatchInlineSnapshot(`
2825
article
@@ -43,9 +40,7 @@ describe('Card component', () => {
4340
})
4441
);
4542

46-
const body = await page.evaluateHandle<ElementHandle>(
47-
() => document.body
48-
);
43+
const body = await page.evaluateHandle(() => document.body);
4944
expect(
5045
await getAccessibilityTree(body, { includeText: false })
5146
).toMatchInlineSnapshot(`heading "Lorem ipsum dolor sit amet" (level=2)`);

src/components/comment/comment.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
import type { ElementHandle, PleasantestUtils } from 'pleasantest';
3+
import type { PleasantestUtils } from 'pleasantest';
44
import { getAccessibilityTree, withBrowser } from 'pleasantest';
55

66
import { loadGlobalCSS, loadTwigTemplate } from '../../../test-utils.js';
@@ -36,7 +36,7 @@ test(
3636

3737
await initCommentsJS(utils);
3838

39-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
39+
const body = await page.evaluateHandle(() => document.body);
4040
expect(await getAccessibilityTree(body, { includeText: false }))
4141
.toMatchInlineSnapshot(`
4242
article "Test author name said:"

src/components/input/elastic-textarea.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const initTextareaJS = (utils: PleasantestUtils, textarea: ElementHandle) =>
1010
utils.runJS(
1111
`
1212
import { createElasticTextArea } from './elastic-textarea'
13-
export default (textarea) => createElasticTextArea(textarea);
13+
const [textarea] = import.meta.pleasantestArgs
14+
createElasticTextArea(textarea);
1415
`,
1516
[textarea]
1617
);

src/components/sky-nav/sky-nav.test.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,21 @@ const initSkyNavJS = (utils: PleasantestUtils, navButton: ElementHandle) =>
1313
utils.runJS(
1414
`
1515
import { initSkyNav } from './sky-nav'
16-
export default (navButton) => initSkyNav(navButton)
16+
const [navButton] = import.meta.pleasantestArgs;
17+
initSkyNav(navButton)
1718
`,
1819
[navButton]
1920
);
2021

2122
test(
2223
'can be opened on small screens',
2324
withBrowser({ device: iPhone }, async ({ utils, screen, user, page }) => {
24-
// The rendered markup needs to be captured so we can pass it into the
25-
// `page.evaluate` function below
26-
const renderedMarkup = await skyNavMarkup({
27-
includeMainDemo: true,
28-
menu,
29-
});
30-
// Pleasantest uses `document.innerHTML` to inject the markup into the DOM,
31-
// but that means inline scripts are not executed.
32-
// @see https://github.com/cloudfour/pleasantest/issues/526
33-
//
34-
// > HTML5 specifies that a <script> tag inserted with innerHTML should not execute.
35-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations
36-
//
37-
// This causes this test to fail because the Sky Nav template has an inline
38-
// script. To get around that, the code below uses `document.write` instead
39-
// which _will_ execute the inline script.
40-
//
41-
// Using `document.write` is discouraged. For the purposes of this test,
42-
// though, it is okay.
43-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Document/write
44-
await page.evaluate((renderedMarkup) => {
45-
document.body.innerHTML = '';
46-
document.write(renderedMarkup);
47-
}, renderedMarkup);
25+
await utils.injectHTML(
26+
await skyNavMarkup({
27+
includeMainDemo: true,
28+
menu,
29+
})
30+
);
4831

4932
await loadGlobalCSS(utils);
5033
const navButton = await screen.getByRole('button', {
@@ -55,7 +38,7 @@ test(
5538
// Initial state: menu is closed
5639
await expect(navButton).toHaveAttribute('aria-expanded', 'false');
5740
expect(await screen.queryByRole('list')).toBeNull();
58-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
41+
const body = await page.evaluateHandle(() => document.body);
5942
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
6043
link "Skip to main content"
6144
text "Skip to main content"
@@ -121,7 +104,7 @@ test(
121104
// Initial state: list is visible, button is hidden
122105
expect(navButton).not.toBeVisible();
123106
await expect(await screen.queryByRole('list')).toBeVisible();
124-
const body = await page.evaluateHandle<ElementHandle>(() => document.body);
107+
const body = await page.evaluateHandle(() => document.body);
125108
expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(`
126109
link "Skip to main content"
127110
text "Skip to main content"

src/components/subscribe/subscribe.test.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import path from 'path';
22

33
import type { ElementHandle, PleasantestUtils } from 'pleasantest';
4-
import { getAccessibilityTree, withBrowser } from 'pleasantest';
4+
import {
5+
getAccessibilityTree,
6+
makeCallableJSHandle,
7+
withBrowser,
8+
} from 'pleasantest';
59

610
import { loadGlobalCSS, loadTwigTemplate } from '../../../test-utils.js';
711

12+
import type { createSubscribe } from './subscribe.js';
13+
814
// Helper to load the Twig template file
915
const componentMarkup = (args = {}) =>
1016
loadTwigTemplate(path.join(__dirname, './subscribe.twig'))({
@@ -25,7 +31,7 @@ const demoDestroyInitMarkup = loadTwigTemplate(
2531
const expectElementToBeVisuallyHidden = async (
2632
element: ElementHandle<HTMLElement>
2733
) => {
28-
const { elHeight, elWidth } = await element.evaluate((el: HTMLElement) => ({
34+
const { elHeight, elWidth } = await element.evaluate((el) => ({
2935
elHeight: el.clientHeight,
3036
elWidth: el.clientWidth,
3137
}));
@@ -41,7 +47,7 @@ const expectElementToBeVisuallyHidden = async (
4147
const expectElementNotToBeVisuallyHidden = async (
4248
form: ElementHandle<HTMLElement>
4349
) => {
44-
const { elHeight, elWidth } = await form.evaluate((el: HTMLElement) => ({
50+
const { elHeight, elWidth } = await form.evaluate((el) => ({
4551
elHeight: el.clientHeight,
4652
elWidth: el.clientWidth,
4753
}));
@@ -277,17 +283,24 @@ describe('Subscription component', () => {
277283
await loadGlobalCSS(utils);
278284
await utils.loadCSS('./subscribe.scss');
279285
await utils.injectHTML(await demoDestroyInitMarkup());
280-
await utils.runJS(`
286+
const { subscribeComponent } = await utils.runJS<{
287+
subscribeComponent: NonNullable<ReturnType<typeof createSubscribe>>;
288+
}>(`
281289
import { createSubscribe } from './subscribe';
282-
// We attach it to the window object as a workaround to have access to
283-
// the subscribeComponent later in this test.
284-
window.subscribeComponent = createSubscribe(
290+
export const subscribeComponent = createSubscribe(
285291
document.querySelector('.js-subscribe')
286292
);
287293
// Set it to the "destroyed" state
288-
window.subscribeComponent.destroy();
294+
subscribeComponent.destroy();
289295
`);
290296

297+
const initSubscribe = makeCallableJSHandle(
298+
await subscribeComponent.getProperty('init')
299+
);
300+
const destroySubscribe = makeCallableJSHandle(
301+
await subscribeComponent.getProperty('destroy')
302+
);
303+
291304
// The form should be active/visible when `destroy()` is called
292305
const form = await screen.getByRole('form', {
293306
name: 'Get Weekly Digests',
@@ -312,9 +325,7 @@ describe('Subscription component', () => {
312325
await expectElementNotToBeVisuallyHidden(form);
313326

314327
// Initialize the Subscribe component
315-
await utils.runJS(`
316-
window.subscribeComponent.init();
317-
`);
328+
await initSubscribe();
318329

319330
// The form should be visually hidden after `init()` is called
320331
await expectElementToBeVisuallyHidden(form);
@@ -355,9 +366,7 @@ describe('Subscription component', () => {
355366
// Then blur the focus
356367
await formSubmitBtn.evaluate((btn) => btn.blur());
357368
// And immediately run the `destroy()`
358-
await utils.runJS(`
359-
window.subscribeComponent.destroy();
360-
`);
369+
await destroySubscribe();
361370
// Wait out the Subscribe component timeout
362371
await new Promise((resolve) => {
363372
setTimeout(resolve, 2000);

0 commit comments

Comments
 (0)