@@ -739,6 +739,198 @@ ruleTester.run('global aliases', rule, {
739739 ] ,
740740} ) ;
741741
742+ ruleTester . run ( 'global package source' , rule , {
743+ valid : [
744+ {
745+ code : dedent `
746+ import { expect } from 'bun:test'
747+
748+ expect(x).toBe(y);
749+ ` ,
750+ parserOptions : { sourceType : 'module' } ,
751+ settings : { jest : { globalPackage : '@jest/globals' } } ,
752+ } ,
753+ {
754+ code : dedent `
755+ const { it } = require('@jest/globals');
756+
757+ it('is not considered a test function', () => {});
758+ ` ,
759+ parserOptions : { sourceType : 'script' } ,
760+ settings : { jest : { globalPackage : 'bun:test' } } ,
761+ } ,
762+ {
763+ code : dedent `
764+ const { fn: it } = require('bun:test');
765+
766+ it('is not considered a test function', () => {});
767+ ` ,
768+ parserOptions : { sourceType : 'script' } ,
769+ settings : { jest : { globalPackage : 'bun:test' } } ,
770+ } ,
771+ {
772+ code : dedent `
773+ import { it } from '@jest/globals';
774+
775+ it('is not considered a test function', () => {});
776+ ` ,
777+ parserOptions : { sourceType : 'module' } ,
778+ settings : { jest : { globalPackage : 'bun:test' } } ,
779+ } ,
780+ {
781+ code : dedent `
782+ import { fn as it } from 'bun:test';
783+
784+ it('is not considered a test function', () => {});
785+ ` ,
786+ parserOptions : { sourceType : 'module' } ,
787+ settings : { jest : { globalPackage : 'bun:test' } } ,
788+ } ,
789+ ] ,
790+ invalid : [
791+ {
792+ code : 'expect(x).toBe(y);' ,
793+ parserOptions : { sourceType : 'script' } ,
794+ errors : [
795+ {
796+ messageId : 'details' as const ,
797+ data : expectedParsedJestFnCallResultData ( {
798+ name : 'expect' ,
799+ type : 'expect' ,
800+ head : {
801+ original : null ,
802+ local : 'expect' ,
803+ type : 'global' ,
804+ node : 'expect' ,
805+ } ,
806+ members : [ 'toBe' ] ,
807+ } ) ,
808+ column : 1 ,
809+ line : 1 ,
810+ } ,
811+ ] ,
812+ settings : { jest : { globalPackage : 'bun:test' } } ,
813+ } ,
814+ {
815+ code : dedent `
816+ import { describe, expect, it } from 'bun:test'
817+
818+ describe('some tests', () => {
819+ it('ensures something', () => {
820+ expect.assertions();
821+ });
822+ });
823+ ` ,
824+ parserOptions : { sourceType : 'module' } ,
825+ errors : [
826+ {
827+ messageId : 'details' as const ,
828+ data : expectedParsedJestFnCallResultData ( {
829+ name : 'describe' ,
830+ type : 'describe' ,
831+ head : {
832+ original : 'describe' ,
833+ local : 'describe' ,
834+ type : 'import' ,
835+ node : 'describe' ,
836+ } ,
837+ members : [ ] ,
838+ } ) ,
839+ column : 1 ,
840+ line : 3 ,
841+ } ,
842+ {
843+ messageId : 'details' as const ,
844+ data : expectedParsedJestFnCallResultData ( {
845+ name : 'it' ,
846+ type : 'test' ,
847+ head : {
848+ original : 'it' ,
849+ local : 'it' ,
850+ type : 'import' ,
851+ node : 'it' ,
852+ } ,
853+ members : [ ] ,
854+ } ) ,
855+ column : 3 ,
856+ line : 4 ,
857+ } ,
858+ {
859+ messageId : 'details' as const ,
860+ data : expectedParsedJestFnCallResultData ( {
861+ name : 'expect' ,
862+ type : 'expect' ,
863+ head : {
864+ original : 'expect' ,
865+ local : 'expect' ,
866+ type : 'import' ,
867+ node : 'expect' ,
868+ } ,
869+ members : [ 'assertions' ] ,
870+ } ) ,
871+ column : 5 ,
872+ line : 5 ,
873+ } ,
874+ ] ,
875+ settings : { jest : { globalPackage : 'bun:test' } } ,
876+ } ,
877+ {
878+ code : dedent `
879+ import { expect } from 'bun:test'
880+
881+ expect(x).not.toBe(y);
882+ ` ,
883+ parserOptions : { sourceType : 'module' } ,
884+ errors : [
885+ {
886+ messageId : 'details' as const ,
887+ data : expectedParsedJestFnCallResultData ( {
888+ name : 'expect' ,
889+ type : 'expect' ,
890+ head : {
891+ original : 'expect' ,
892+ local : 'expect' ,
893+ type : 'import' ,
894+ node : 'expect' ,
895+ } ,
896+ members : [ 'not' , 'toBe' ] ,
897+ } ) ,
898+ column : 1 ,
899+ line : 3 ,
900+ } ,
901+ ] ,
902+ settings : { jest : { globalPackage : 'bun:test' } } ,
903+ } ,
904+ {
905+ code : 'context("when there is an error", () => {})' ,
906+ errors : [
907+ {
908+ messageId : 'details' as const ,
909+ data : expectedParsedJestFnCallResultData ( {
910+ name : 'describe' ,
911+ type : 'describe' ,
912+ head : {
913+ original : 'describe' ,
914+ local : 'context' ,
915+ type : 'global' ,
916+ node : 'context' ,
917+ } ,
918+ members : [ ] ,
919+ } ) ,
920+ column : 1 ,
921+ line : 1 ,
922+ } ,
923+ ] ,
924+ settings : {
925+ jest : {
926+ globalPackage : 'bun:test' ,
927+ globalAliases : { describe : [ 'context' ] } ,
928+ } ,
929+ } ,
930+ } ,
931+ ] ,
932+ } ) ;
933+
742934ruleTester . run ( 'typescript' , rule , {
743935 valid : [
744936 {
0 commit comments