@@ -26,8 +26,6 @@ const parserOptions = {
26
26
// Tests
27
27
// ------------------------------------------------------------------------------
28
28
29
- const ASYNC_ERROR = { messageId : 'asyncServerAction' } ;
30
-
31
29
const ruleTester = new RuleTester ( { parserOptions } ) ;
32
30
33
31
ruleTester . run ( 'async-server-action' , rule , {
@@ -266,12 +264,20 @@ ruleTester.run('async-server-action', rule, {
266
264
'use server';
267
265
}
268
266
` ,
269
- output : `
267
+ errors : [
268
+ {
269
+ message : 'Server Actions must be async' ,
270
+ suggestions : [
271
+ {
272
+ output : `
270
273
async function addToCart(data) {
271
274
'use server';
272
275
}
273
276
` ,
274
- errors : [ ASYNC_ERROR ] ,
277
+ } ,
278
+ ] ,
279
+ } ,
280
+ ] ,
275
281
} ,
276
282
{
277
283
code : `
@@ -280,26 +286,42 @@ ruleTester.run('async-server-action', rule, {
280
286
const username = formData.get('username');
281
287
}
282
288
` ,
283
- output : `
289
+ errors : [
290
+ {
291
+ message : 'Server Actions must be async' ,
292
+ suggestions : [
293
+ {
294
+ output : `
284
295
async function requestUsername(formData) {
285
296
'use server';
286
297
const username = formData.get('username');
287
298
}
288
299
` ,
289
- errors : [ ASYNC_ERROR ] ,
300
+ } ,
301
+ ] ,
302
+ } ,
303
+ ] ,
290
304
} ,
291
305
{
292
306
code : `
293
307
function addToCart(data) {
294
308
"use server";
295
309
}
296
310
` ,
297
- output : `
311
+ errors : [
312
+ {
313
+ message : 'Server Actions must be async' ,
314
+ suggestions : [
315
+ {
316
+ output : `
298
317
async function addToCart(data) {
299
318
"use server";
300
319
}
301
320
` ,
302
- errors : [ ASYNC_ERROR ] ,
321
+ } ,
322
+ ] ,
323
+ } ,
324
+ ] ,
303
325
} ,
304
326
{
305
327
code : `
@@ -308,26 +330,42 @@ ruleTester.run('async-server-action', rule, {
308
330
const username = formData.get('username');
309
331
}
310
332
` ,
311
- output : `
333
+ errors : [
334
+ {
335
+ message : 'Server Actions must be async' ,
336
+ suggestions : [
337
+ {
338
+ output : `
312
339
async function requestUsername(formData) {
313
340
"use server";
314
341
const username = formData.get('username');
315
342
}
316
343
` ,
317
- errors : [ ASYNC_ERROR ] ,
344
+ } ,
345
+ ] ,
346
+ } ,
347
+ ] ,
318
348
} ,
319
349
{
320
350
code : `
321
351
const addToCart = (data) => {
322
352
'use server';
323
353
}
324
354
` ,
325
- output : `
355
+ errors : [
356
+ {
357
+ message : 'Server Actions must be async' ,
358
+ suggestions : [
359
+ {
360
+ output : `
326
361
const addToCart = async (data) => {
327
362
'use server';
328
363
}
329
364
` ,
330
- errors : [ ASYNC_ERROR ] ,
365
+ } ,
366
+ ] ,
367
+ } ,
368
+ ] ,
331
369
} ,
332
370
{
333
371
code : `
@@ -336,26 +374,42 @@ ruleTester.run('async-server-action', rule, {
336
374
const username = formData.get('username');
337
375
}
338
376
` ,
339
- output : `
377
+ errors : [
378
+ {
379
+ message : 'Server Actions must be async' ,
380
+ suggestions : [
381
+ {
382
+ output : `
340
383
const requestUsername = async (formData) => {
341
384
'use server';
342
385
const username = formData.get('username');
343
386
}
344
387
` ,
345
- errors : [ ASYNC_ERROR ] ,
388
+ } ,
389
+ ] ,
390
+ } ,
391
+ ] ,
346
392
} ,
347
393
{
348
394
code : `
349
395
const addToCart = (data) => {
350
396
"use server";
351
397
}
352
398
` ,
353
- output : `
399
+ errors : [
400
+ {
401
+ message : 'Server Actions must be async' ,
402
+ suggestions : [
403
+ {
404
+ output : `
354
405
const addToCart = async (data) => {
355
406
"use server";
356
407
}
357
408
` ,
358
- errors : [ ASYNC_ERROR ] ,
409
+ } ,
410
+ ] ,
411
+ } ,
412
+ ] ,
359
413
} ,
360
414
{
361
415
code : `
@@ -364,26 +418,42 @@ ruleTester.run('async-server-action', rule, {
364
418
const username = formData.get('username');
365
419
}
366
420
` ,
367
- output : `
421
+ errors : [
422
+ {
423
+ message : 'Server Actions must be async' ,
424
+ suggestions : [
425
+ {
426
+ output : `
368
427
const requestUsername = async (formData) => {
369
428
"use server";
370
429
const username = formData.get('username');
371
430
}
372
431
` ,
373
- errors : [ ASYNC_ERROR ] ,
432
+ } ,
433
+ ] ,
434
+ } ,
435
+ ] ,
374
436
} ,
375
437
{
376
438
code : `
377
439
const addToCart = function (data) {
378
440
'use server';
379
441
}
380
442
` ,
381
- output : `
443
+ errors : [
444
+ {
445
+ message : 'Server Actions must be async' ,
446
+ suggestions : [
447
+ {
448
+ output : `
382
449
const addToCart = async function (data) {
383
450
'use server';
384
451
}
385
452
` ,
386
- errors : [ ASYNC_ERROR ] ,
453
+ } ,
454
+ ] ,
455
+ } ,
456
+ ] ,
387
457
} ,
388
458
{
389
459
code : `
@@ -392,26 +462,42 @@ ruleTester.run('async-server-action', rule, {
392
462
const username = formData.get('username');
393
463
}
394
464
` ,
395
- output : `
465
+ errors : [
466
+ {
467
+ message : 'Server Actions must be async' ,
468
+ suggestions : [
469
+ {
470
+ output : `
396
471
const requestUsername = async function (formData) {
397
472
'use server';
398
473
const username = formData.get('username');
399
474
}
400
475
` ,
401
- errors : [ ASYNC_ERROR ] ,
476
+ } ,
477
+ ] ,
478
+ } ,
479
+ ] ,
402
480
} ,
403
481
{
404
482
code : `
405
483
const addToCart = function (data) {
406
484
"use server";
407
485
}
408
486
` ,
409
- output : `
487
+ errors : [
488
+ {
489
+ message : 'Server Actions must be async' ,
490
+ suggestions : [
491
+ {
492
+ output : `
410
493
const addToCart = async function (data) {
411
494
"use server";
412
495
}
413
496
` ,
414
- errors : [ ASYNC_ERROR ] ,
497
+ } ,
498
+ ] ,
499
+ } ,
500
+ ] ,
415
501
} ,
416
502
{
417
503
code : `
@@ -420,13 +506,21 @@ ruleTester.run('async-server-action', rule, {
420
506
const username = formData.get('username');
421
507
}
422
508
` ,
423
- output : `
509
+ errors : [
510
+ {
511
+ message : 'Server Actions must be async' ,
512
+ suggestions : [
513
+ {
514
+ output : `
424
515
const requestUsername = async function (formData) {
425
516
"use server";
426
517
const username = formData.get('username');
427
518
}
428
519
` ,
429
- errors : [ ASYNC_ERROR ] ,
520
+ } ,
521
+ ] ,
522
+ } ,
523
+ ] ,
430
524
} ,
431
525
] ) ,
432
526
} ) ;
0 commit comments