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

fix: Flaky test #9947

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,33 @@
</script>

<form method="POST" action="?/form_submit" use:access_form_submit>
<button id="access-form-in-submit" type="submit"
>{form?.form_submit ? 'processed' : 'not processed'}</button
<button
id="access-form-in-submit"
type="submit"
data-processed={form?.form_submit ? 'true' : 'false'}>Access form in submit</button
>
</form>

<form method="POST" action="?/data_submit" use:access_data_submit>
<button id="access-data-in-submit" type="submit"
>{form?.data_submit ? 'processed' : 'not processed'}</button
<button
id="access-data-in-submit"
type="submit"
data-processed={form?.data_submit ? 'true' : 'false'}>Access data in submit</button
>
</form>

<form method="POST" action="?/form_callback" use:access_form_callback>
<button id="access-form-in-callback" type="submit"
>{form?.form_callback ? 'processed' : 'not processed'}</button
<button
id="access-form-in-callback"
type="submit"
data-processed={form?.form_callback ? 'true' : 'false'}>Access form in callback</button
>
</form>

<form method="POST" action="?/data_callback" use:access_data_callback>
<button id="access-data-in-callback" type="submit"
>{form?.data_callback ? 'processed' : 'not processed'}</button
<button
id="access-data-in-callback"
type="submit"
data-processed={form?.data_callback ? 'true' : 'false'}>Access data in callback</button
>
</form>
89 changes: 46 additions & 43 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,50 +828,53 @@ test.describe('Matchers', () => {
});

test.describe('Actions', () => {
for (const { id, old_name, new_name, call_location } of [
{
id: 'access-form-in-submit',
old_name: 'form',
new_name: 'formElement',
call_location: 'use:enhance submit function'
},
{
id: 'access-form-in-callback',
old_name: 'form',
new_name: 'formElement',
call_location: 'callback returned from use:enhance submit function'
},
{
id: 'access-data-in-submit',
old_name: 'data',
new_name: 'formData',
call_location: 'use:enhance submit function'
},
{
id: 'access-data-in-callback',
old_name: 'data',
new_name: 'formData',
call_location: 'callback returned from use:enhance submit function'
test(`Accessing v2 deprecated properties results in a warning log`, async ({
page,
javaScriptEnabled
}) => {
test.skip(!javaScriptEnabled, 'skip when js is disabled');
test.skip(!process.env.DEV, 'skip when not in dev mode');
await page.goto('/actions/enhance/old-property-access');

for (const { id, old_name, new_name, call_location } of [
{
id: 'access-form-in-submit',
old_name: 'form',
new_name: 'formElement',
call_location: 'use:enhance submit function'
},
{
id: 'access-form-in-callback',
old_name: 'form',
new_name: 'formElement',
call_location: 'callback returned from use:enhance submit function'
},
{
id: 'access-data-in-submit',
old_name: 'data',
new_name: 'formData',
call_location: 'use:enhance submit function'
},
{
id: 'access-data-in-callback',
old_name: 'data',
new_name: 'formData',
call_location: 'callback returned from use:enhance submit function'
}
]) {
await test.step(id, async () => {
const log_promise = page.waitForEvent('console');
const button = page.locator(`#${id}`);
await button.click();
await expect(button).toHaveAttribute('data-processed', 'true');
const log = await log_promise;
expect(log.text()).toBe(
`\`${old_name}\` has been deprecated in favor of \`${new_name}\`. \`${old_name}\` will be removed in a future version. (Called from ${call_location})`
);
expect(log.type()).toBe('warning');
});
}
]) {
test(`Accessing v2 deprecated properties results in a warning log, type: ${id}`, async ({
page,
javaScriptEnabled
}) => {
test.skip(!javaScriptEnabled, 'skip when js is disabled');
test.skip(!process.env.DEV, 'skip when not in dev mode');
await page.goto('/actions/enhance/old-property-access');
const log_promise = page.waitForEvent('console');
const button = page.locator(`#${id}`);
await button.click();
expect(await button.textContent()).toBe('processed'); // needed to make sure action completes
const log = await log_promise;
expect(log.text()).toBe(
`\`${old_name}\` has been deprecated in favor of \`${new_name}\`. \`${old_name}\` will be removed in a future version. (Called from ${call_location})`
);
expect(log.type()).toBe('warning');
});
}
});

test('Error props are returned', async ({ page, javaScriptEnabled }) => {
await page.goto('/actions/form-errors');
Expand Down