1- import * as core from "@actions/core" ;
2- import { findRuffVersionInSpec } from "./pyproject" ;
1+ import { beforeEach , describe , expect , it , jest } from "@jest/globals" ;
32
4- jest . mock ( "@actions/core" , ( ) => ( {
5- info : jest . fn ( ) ,
6- warning : jest . fn ( ) ,
3+ const info = jest . fn ( ) ;
4+ const warning = jest . fn ( ) ;
5+
6+ jest . unstable_mockModule ( "@actions/core" , ( ) => ( {
7+ info,
8+ warning,
79} ) ) ;
810
11+ const { findRuffVersionInSpec } = await import ( "../../src/utils/pyproject" ) ;
12+
913describe ( "findRuffVersionInSpec" , ( ) => {
1014 beforeEach ( ( ) => {
11- jest . clearAllMocks ( ) ;
15+ info . mockReset ( ) ;
16+ warning . mockReset ( ) ;
1217 } ) ;
1318
1419 describe ( "ruff dependency strings" , ( ) => {
1520 it ( "should extract version from 'ruff==0.9.3'" , ( ) => {
1621 const result = findRuffVersionInSpec ( "ruff==0.9.3" ) ;
1722 expect ( result ) . toBe ( "0.9.3" ) ;
18- expect ( core . info ) . toHaveBeenCalledWith (
23+ expect ( info ) . toHaveBeenCalledWith (
1924 "Found ruff version in requirements file: 0.9.3" ,
2025 ) ;
21- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
26+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
2227 } ) ;
2328
2429 it ( "should extract version from 'ruff>=0.14'" , ( ) => {
2530 const result = findRuffVersionInSpec ( "ruff>=0.14" ) ;
2631 expect ( result ) . toBe ( ">=0.14" ) ;
27- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
32+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
2833 } ) ;
2934
3035 it ( "should extract version from 'ruff ~=1.0.0'" , ( ) => {
3136 const result = findRuffVersionInSpec ( "ruff ~=1.0.0" ) ;
3237 expect ( result ) . toBe ( "~=1.0.0" ) ;
33- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
38+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
3439 } ) ;
3540
3641 it ( "should extract version from 'ruff>=0.14,<1.0'" , ( ) => {
3742 const result = findRuffVersionInSpec ( "ruff>=0.14,<1.0" ) ;
3843 expect ( result ) . toBe ( ">=0.14,<1.0" ) ;
39- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
44+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
4045 } ) ;
4146
4247 it ( "should extract version from 'ruff>=0.14,<2.0,!=1.5.0'" , ( ) => {
4348 const result = findRuffVersionInSpec ( "ruff>=0.14,<2.0,!=1.5.0" ) ;
4449 expect ( result ) . toBe ( ">=0.14,<2.0,!=1.5.0" ) ;
45- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
50+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
4651 } ) ;
4752
4853 it ( "should return undefined for non-ruff dependency 'another-dep 0.1.6'" , ( ) => {
4954 const result = findRuffVersionInSpec ( "another-dep 0.1.6" ) ;
5055 expect ( result ) . toBeUndefined ( ) ;
51- expect ( core . info ) . not . toHaveBeenCalled ( ) ;
52- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
56+ expect ( info ) . not . toHaveBeenCalled ( ) ;
57+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
5358 } ) ;
5459
5560 it ( "should return undefined for non-ruff dependency 'another-dep==0.1.6'" , ( ) => {
5661 const result = findRuffVersionInSpec ( "another-dep==0.1.6" ) ;
5762 expect ( result ) . toBeUndefined ( ) ;
58- expect ( core . info ) . not . toHaveBeenCalled ( ) ;
59- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
63+ expect ( info ) . not . toHaveBeenCalled ( ) ;
64+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
6065 } ) ;
6166
6267 it ( "should strip trailing backslash" , ( ) => {
6368 const result = findRuffVersionInSpec ( "ruff==0.9.3 \\" ) ;
6469 expect ( result ) . toBe ( "0.9.3" ) ;
65- expect ( core . info ) . toHaveBeenCalledWith (
70+ expect ( info ) . toHaveBeenCalledWith (
6671 "Found ruff version in requirements file: 0.9.3" ,
6772 ) ;
68- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
73+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
6974 } ) ;
7075
7176 it ( "should strip trailing backslash with whitespace" , ( ) => {
7277 const result = findRuffVersionInSpec ( " ruff==0.9.3 \\ " ) ;
7378 expect ( result ) . toBe ( "0.9.3" ) ;
74- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
79+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
7580 } ) ;
7681 } ) ;
7782
@@ -81,10 +86,10 @@ describe("findRuffVersionInSpec", () => {
8186 'ruff>=0.14 ; python_version >= "3.11"' ,
8287 ) ;
8388 expect ( result ) . toBe ( ">=0.14" ) ;
84- expect ( core . info ) . toHaveBeenCalledWith (
89+ expect ( info ) . toHaveBeenCalledWith (
8590 "Found ruff version in requirements file: >=0.14" ,
8691 ) ;
87- expect ( core . warning ) . toHaveBeenCalledWith (
92+ expect ( warning ) . toHaveBeenCalledWith (
8893 "Environment markers are ignored. ruff is a standalone tool that works independently of Python version." ,
8994 ) ;
9095 } ) ;
@@ -94,7 +99,7 @@ describe("findRuffVersionInSpec", () => {
9499 "ruff==0.9.3 ; sys_platform == 'linux'" ,
95100 ) ;
96101 expect ( result ) . toBe ( "0.9.3" ) ;
97- expect ( core . warning ) . toHaveBeenCalledWith (
102+ expect ( warning ) . toHaveBeenCalledWith (
98103 "Environment markers are ignored. ruff is a standalone tool that works independently of Python version." ,
99104 ) ;
100105 } ) ;
@@ -104,7 +109,7 @@ describe("findRuffVersionInSpec", () => {
104109 'ruff>=0.14 ; python_version >= "3.11" and sys_platform == "linux"' ,
105110 ) ;
106111 expect ( result ) . toBe ( ">=0.14" ) ;
107- expect ( core . warning ) . toHaveBeenCalledWith (
112+ expect ( warning ) . toHaveBeenCalledWith (
108113 "Environment markers are ignored. ruff is a standalone tool that works independently of Python version." ,
109114 ) ;
110115 } ) ;
@@ -114,7 +119,7 @@ describe("findRuffVersionInSpec", () => {
114119 'ruff>=0.14,<1.0 ; python_version >= "3.11"' ,
115120 ) ;
116121 expect ( result ) . toBe ( ">=0.14,<1.0" ) ;
117- expect ( core . warning ) . toHaveBeenCalledWith (
122+ expect ( warning ) . toHaveBeenCalledWith (
118123 "Environment markers are ignored. ruff is a standalone tool that works independently of Python version." ,
119124 ) ;
120125 } ) ;
@@ -124,47 +129,47 @@ describe("findRuffVersionInSpec", () => {
124129 it ( "should handle whitespace" , ( ) => {
125130 const result = findRuffVersionInSpec ( " ruff >=0.14 " ) ;
126131 expect ( result ) . toBe ( ">=0.14" ) ;
127- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
132+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
128133 } ) ;
129134
130135 it ( "should handle whitespace with environment markers" , ( ) => {
131136 const result = findRuffVersionInSpec (
132137 " ruff >=0.14 ; python_version >= '3.11' " ,
133138 ) ;
134139 expect ( result ) . toBe ( ">=0.14" ) ;
135- expect ( core . warning ) . toHaveBeenCalled ( ) ;
140+ expect ( warning ) . toHaveBeenCalled ( ) ;
136141 } ) ;
137142
138143 it ( "should return undefined for empty string" , ( ) => {
139144 const result = findRuffVersionInSpec ( "" ) ;
140145 expect ( result ) . toBeUndefined ( ) ;
141- expect ( core . info ) . not . toHaveBeenCalled ( ) ;
142- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
146+ expect ( info ) . not . toHaveBeenCalled ( ) ;
147+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
143148 } ) ;
144149
145150 it ( "should return undefined for whitespace only" , ( ) => {
146151 const result = findRuffVersionInSpec ( " " ) ;
147152 expect ( result ) . toBeUndefined ( ) ;
148- expect ( core . info ) . not . toHaveBeenCalled ( ) ;
149- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
153+ expect ( info ) . not . toHaveBeenCalled ( ) ;
154+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
150155 } ) ;
151156
152157 it ( "should return undefined for just semicolon" , ( ) => {
153158 const result = findRuffVersionInSpec ( ";" ) ;
154159 expect ( result ) . toBeUndefined ( ) ;
155- expect ( core . info ) . not . toHaveBeenCalled ( ) ;
156- expect ( core . warning ) . not . toHaveBeenCalled ( ) ;
160+ expect ( info ) . not . toHaveBeenCalled ( ) ;
161+ expect ( warning ) . not . toHaveBeenCalled ( ) ;
157162 } ) ;
158163
159164 it ( "should handle exact example from issue #256" , ( ) => {
160165 const result = findRuffVersionInSpec (
161166 'ruff>=0.14 ; python_version >= "3.11"' ,
162167 ) ;
163168 expect ( result ) . toBe ( ">=0.14" ) ;
164- expect ( core . info ) . toHaveBeenCalledWith (
169+ expect ( info ) . toHaveBeenCalledWith (
165170 "Found ruff version in requirements file: >=0.14" ,
166171 ) ;
167- expect ( core . warning ) . toHaveBeenCalledWith (
172+ expect ( warning ) . toHaveBeenCalledWith (
168173 "Environment markers are ignored. ruff is a standalone tool that works independently of Python version." ,
169174 ) ;
170175 } ) ;
@@ -174,15 +179,15 @@ describe("findRuffVersionInSpec", () => {
174179 "ruff>=0.14 ; python_version >= '3.11'" ,
175180 ) ;
176181 expect ( result ) . toBe ( ">=0.14" ) ;
177- expect ( core . warning ) . toHaveBeenCalled ( ) ;
182+ expect ( warning ) . toHaveBeenCalled ( ) ;
178183 } ) ;
179184
180185 it ( "should handle double-quoted environment markers" , ( ) => {
181186 const result = findRuffVersionInSpec (
182187 'ruff>=0.14 ; python_version >= "3.11"' ,
183188 ) ;
184189 expect ( result ) . toBe ( ">=0.14" ) ;
185- expect ( core . warning ) . toHaveBeenCalled ( ) ;
190+ expect ( warning ) . toHaveBeenCalled ( ) ;
186191 } ) ;
187192 } ) ;
188193} ) ;
0 commit comments