@@ -31,6 +31,13 @@ function convertObjectToESMExportString(obj) {
3131 return `export default ${ JSON . stringify ( obj ) } ` ;
3232}
3333
34+ function withPrecedingStatement ( code ) {
35+ return `
36+ import foo from "bar";
37+ ${ code }
38+ ` ;
39+ }
40+
3441ruleTester . run ( "required-properties-key-test" , rules [ "required-properties-key" ] , {
3542 valid : [
3643 {
@@ -349,3 +356,354 @@ ruleTester.run("ts-version-test", rules["no-ts-version"], {
349356 } ,
350357 ] ,
351358} ) ;
359+
360+ RuleTester . describe ( "On ESM export default with preceding statements" , ( ) => {
361+ ruleTester . run ( "required-properties-key-test" , rules [ "required-properties-key" ] , {
362+ valid : [
363+ {
364+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
365+ } ,
366+ ] ,
367+ invalid : [
368+ {
369+ code : withPrecedingStatement ( convertObjectToESMExportString ( requiredPropertyKeyMissing ) ) ,
370+ errors : [
371+ {
372+ message : "Components must export a key property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
373+ } ,
374+ ] ,
375+ } ,
376+ ] ,
377+ } ) ;
378+
379+ ruleTester . run ( "required-properties-key-test" , rules [ "required-properties-key" ] , {
380+ valid : [
381+ {
382+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
383+ } ,
384+ {
385+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
386+ } ,
387+ ] ,
388+ invalid : [
389+ {
390+ code : withPrecedingStatement ( convertObjectToCJSExportString ( requiredPropertyKeyMissing ) ) ,
391+ errors : [
392+ {
393+ message : "Components must export a key property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
394+ } ,
395+ ] ,
396+ } ,
397+ {
398+ code : withPrecedingStatement ( convertObjectToESMExportString ( requiredPropertyKeyMissing ) ) ,
399+ errors : [
400+ {
401+ message : "Components must export a key property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
402+ } ,
403+ ] ,
404+ } ,
405+ ] ,
406+ } ) ;
407+
408+ ruleTester . run ( "required-properties-name-test" , rules [ "required-properties-name" ] , {
409+ valid : [
410+ {
411+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
412+ } ,
413+ {
414+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
415+ } ,
416+ ] ,
417+ invalid : [
418+ {
419+ code : withPrecedingStatement ( convertObjectToCJSExportString ( requiredPropertyNameMissing ) ) ,
420+ errors : [
421+ {
422+ message : "Components must export a name property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
423+ } ,
424+ ] ,
425+ } ,
426+ {
427+ code : withPrecedingStatement ( convertObjectToESMExportString ( requiredPropertyNameMissing ) ) ,
428+ errors : [
429+ {
430+ message : "Components must export a name property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
431+ } ,
432+ ] ,
433+ } ,
434+ ] ,
435+ } ) ;
436+
437+ ruleTester . run ( "required-properties-description-test" , rules [ "required-properties-description" ] , {
438+ valid : [
439+ {
440+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
441+ } ,
442+ {
443+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
444+ } ,
445+ ] ,
446+ invalid : [
447+ {
448+ code : withPrecedingStatement (
449+ convertObjectToCJSExportString ( requiredPropertyDescriptionMissing ) ,
450+ ) ,
451+ errors : [
452+ {
453+ message : "Components must export a description property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
454+ } ,
455+ ] ,
456+ } ,
457+ {
458+ code : withPrecedingStatement (
459+ convertObjectToESMExportString ( requiredPropertyDescriptionMissing ) ,
460+ ) ,
461+ errors : [
462+ {
463+ message : "Components must export a description property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
464+ } ,
465+ ] ,
466+ } ,
467+ ] ,
468+ } ) ;
469+
470+ ruleTester . run ( "required-properties-version-test" , rules [ "required-properties-version" ] , {
471+ valid : [
472+ {
473+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
474+ } ,
475+ {
476+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
477+ } ,
478+ ] ,
479+ invalid : [
480+ {
481+ code : withPrecedingStatement (
482+ convertObjectToCJSExportString ( requiredPropertyVersionMissing ) ,
483+ ) ,
484+ errors : [
485+ {
486+ message : "Components must export a version property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
487+ } ,
488+ ] ,
489+ } ,
490+ {
491+ code : withPrecedingStatement (
492+ convertObjectToESMExportString ( requiredPropertyVersionMissing ) ,
493+ ) ,
494+ errors : [
495+ {
496+ message : "Components must export a version property. See https://pipedream.com/docs/components/guidelines/#required-metadata" ,
497+ } ,
498+ ] ,
499+ } ,
500+ ] ,
501+ } ) ;
502+
503+ ruleTester . run ( "required-properties-type-test" , rules [ "required-properties-type" ] , {
504+ valid : [
505+ {
506+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
507+ } ,
508+ {
509+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
510+ } ,
511+ ] ,
512+ invalid : [
513+ {
514+ code : withPrecedingStatement ( convertObjectToCJSExportString ( requiredPropertyTypeMissing ) ) ,
515+ errors : [
516+ {
517+ message : "Components must export a type property (\"source\" or \"action\")" ,
518+ } ,
519+ ] ,
520+ } ,
521+ {
522+ code : withPrecedingStatement ( convertObjectToESMExportString ( requiredPropertyTypeMissing ) ) ,
523+ errors : [
524+ {
525+ message : "Components must export a type property (\"source\" or \"action\")" ,
526+ } ,
527+ ] ,
528+ } ,
529+ ] ,
530+ } ) ;
531+
532+ ruleTester . run ( "default-value-required-for-optional-props-test" , rules [ "default-value-required-for-optional-props" ] , {
533+ valid : [
534+ {
535+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
536+ } ,
537+ {
538+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
539+ } ,
540+ ] ,
541+ invalid : [
542+ {
543+ code : withPrecedingStatement (
544+ convertObjectToCJSExportString ( optionalPropWithoutDefaultValue ) ,
545+ ) ,
546+ errors : [
547+ {
548+ message : "Component prop test is marked \"optional\", so it may need a \"default\" property. See https://pipedream.com/docs/components/guidelines/#default-values" ,
549+ } ,
550+ ] ,
551+ } ,
552+ {
553+ code : withPrecedingStatement (
554+ convertObjectToESMExportString ( optionalPropWithoutDefaultValue ) ,
555+ ) ,
556+ errors : [
557+ {
558+ message : "Component prop test is marked \"optional\", so it may need a \"default\" property. See https://pipedream.com/docs/components/guidelines/#default-values" ,
559+ } ,
560+ ] ,
561+ } ,
562+ ] ,
563+ } ) ;
564+
565+ ruleTester . run ( "props-label-test" , rules [ "props-label" ] , {
566+ valid : [
567+ {
568+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
569+ } ,
570+ {
571+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
572+ } ,
573+ ] ,
574+ invalid : [
575+ {
576+ code : withPrecedingStatement ( convertObjectToCJSExportString ( missingPropsLabel ) ) ,
577+ errors : [
578+ {
579+ message : "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props" ,
580+ } ,
581+ ] ,
582+ } ,
583+ {
584+ code : withPrecedingStatement ( convertObjectToESMExportString ( missingPropsLabel ) ) ,
585+ errors : [
586+ {
587+ message : "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props" ,
588+ } ,
589+ ] ,
590+ } ,
591+ ] ,
592+ } ) ;
593+
594+ ruleTester . run ( "props-description-test" , rules [ "props-description" ] , {
595+ valid : [
596+ {
597+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
598+ } ,
599+ {
600+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
601+ } ,
602+ ] ,
603+ invalid : [
604+ {
605+ code : withPrecedingStatement ( convertObjectToCJSExportString ( missingPropsDescription ) ) ,
606+ errors : [
607+ {
608+ message : "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props" ,
609+ } ,
610+ ] ,
611+ } ,
612+ {
613+ code : withPrecedingStatement ( convertObjectToESMExportString ( missingPropsDescription ) ) ,
614+ errors : [
615+ {
616+ message : "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props" ,
617+ } ,
618+ ] ,
619+ } ,
620+ ] ,
621+ } ) ;
622+
623+ ruleTester . run ( "source-name-test" , rules [ "source-name" ] , {
624+ valid : [
625+ {
626+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
627+ } ,
628+ {
629+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
630+ } ,
631+ ] ,
632+ invalid : [
633+ {
634+ code : withPrecedingStatement ( convertObjectToCJSExportString ( badSourceName ) ) ,
635+ errors : [
636+ {
637+ message : "Source names should start with \"New\". See https://pipedream.com/docs/components/guidelines/#source-name" ,
638+ } ,
639+ ] ,
640+ } ,
641+ {
642+ code : withPrecedingStatement ( convertObjectToESMExportString ( badSourceName ) ) ,
643+ errors : [
644+ {
645+ message : "Source names should start with \"New\". See https://pipedream.com/docs/components/guidelines/#source-name" ,
646+ } ,
647+ ] ,
648+ } ,
649+ ] ,
650+ } ) ;
651+
652+ ruleTester . run ( "source-description-test" , rules [ "source-description" ] , {
653+ valid : [
654+ {
655+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
656+ } ,
657+ {
658+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
659+ } ,
660+ ] ,
661+ invalid : [
662+ {
663+ code : withPrecedingStatement ( convertObjectToCJSExportString ( badSourceDescription ) ) ,
664+ errors : [
665+ {
666+ message : "Source descriptions should start with \"Emit new\". See https://pipedream.com/docs/components/guidelines/#source-description" ,
667+ } ,
668+ ] ,
669+ } ,
670+ {
671+ code : withPrecedingStatement ( convertObjectToESMExportString ( badSourceDescription ) ) ,
672+ errors : [
673+ {
674+ message : "Source descriptions should start with \"Emit new\". See https://pipedream.com/docs/components/guidelines/#source-description" ,
675+ } ,
676+ ] ,
677+ } ,
678+ ] ,
679+ } ) ;
680+
681+ ruleTester . run ( "ts-version-test" , rules [ "no-ts-version" ] , {
682+ valid : [
683+ {
684+ code : withPrecedingStatement ( convertObjectToCJSExportString ( valid ) ) ,
685+ } ,
686+ {
687+ code : withPrecedingStatement ( convertObjectToESMExportString ( valid ) ) ,
688+ } ,
689+ ] ,
690+ invalid : [
691+ {
692+ code : withPrecedingStatement ( convertObjectToCJSExportString ( tsVersion ) ) ,
693+ errors : [
694+ {
695+ message : "{{ts}} macro should be removed before committing" ,
696+ } ,
697+ ] ,
698+ } ,
699+ {
700+ code : withPrecedingStatement ( convertObjectToESMExportString ( tsVersion ) ) ,
701+ errors : [
702+ {
703+ message : "{{ts}} macro should be removed before committing" ,
704+ } ,
705+ ] ,
706+ } ,
707+ ] ,
708+ } ) ;
709+ } ) ;
0 commit comments