@@ -91,23 +91,21 @@ describe('addFile', () => {
9191 // - The check stage cache for files that indirectly import the added file should also be invalidated.
9292 const iff = await createIFF ( {
9393 'tsconfig.json' : '{ "cmkOptions": { "enabled": true } }' ,
94- 'src/a.module.css' : '' ,
95- 'src/b.module.css' : '@value a_1 from "./a.module.css";' , // directly
96- 'src/re-export.module.css' : '@import "./a.module.css";' ,
97- 'src/c.module.css' : '@value a_1 from "./re-export.module.css";' , // indirectly
94+ 'src/b.module.css' : '@import "./a.module.css";' , // directly
95+ 'src/c.module.css' : '@value a_1 from "./b.module.css";' , // indirectly
9896 } ) ;
9997 const project = createProject ( { project : iff . rootDir } ) ;
10098 expect ( formatDiagnostics ( project . getDiagnostics ( ) , iff . rootDir ) ) . toMatchInlineSnapshot ( `
10199 [
102100 {
103101 "category": "error",
104102 "fileName": "<rootDir>/src/b.module.css",
105- "length": 3 ,
103+ "length": 14 ,
106104 "start": {
107- "column": 8 ,
105+ "column": 10 ,
108106 "line": 1,
109107 },
110- "text": "Module './a.module.css' has no exported token 'a_1'. ",
108+ "text": "Cannot import module './a.module.css'",
111109 },
112110 {
113111 "category": "error",
@@ -117,12 +115,12 @@ describe('addFile', () => {
117115 "column": 8,
118116 "line": 1,
119117 },
120- "text": "Module './re-export .module.css' has no exported token 'a_1'.",
118+ "text": "Module './b .module.css' has no exported token 'a_1'.",
121119 },
122120 ]
123121 ` ) ;
124122 await writeFile ( iff . join ( 'src/a.module.css' ) , '@value a_1: red;' ) ;
125- project . updateFile ( iff . join ( 'src/a.module.css' ) ) ;
123+ project . addFile ( iff . join ( 'src/a.module.css' ) ) ;
126124 expect ( formatDiagnostics ( project . getDiagnostics ( ) , iff . rootDir ) ) . toMatchInlineSnapshot ( `[]` ) ;
127125 } ) ;
128126 test ( 'changes the resolution results of import specifiers in other files' , async ( ) => {
@@ -206,19 +204,19 @@ describe('updateFile', () => {
206204 ` ) ;
207205
208206 // New semantic diagnostics are reported
209- await writeFile ( iff . join ( 'src/a.module.css' ) , `.a-1 {} ` ) ;
207+ await writeFile ( iff . join ( 'src/a.module.css' ) , `@import './non-existent.module.css'; ` ) ;
210208 project . updateFile ( iff . join ( 'src/a.module.css' ) ) ;
211209 expect ( formatDiagnostics ( project . getDiagnostics ( ) , iff . rootDir ) ) . toMatchInlineSnapshot ( `
212210 [
213211 {
214212 "category": "error",
215213 "fileName": "<rootDir>/src/a.module.css",
216- "length": 3 ,
214+ "length": 25 ,
217215 "start": {
218- "column": 2 ,
216+ "column": 10 ,
219217 "line": 1,
220218 },
221- "text": "css-modules-kit does not support invalid names as JavaScript identifiers. ",
219+ "text": "Cannot import module './non-existent.module.css' ",
222220 },
223221 ]
224222 ` ) ;
@@ -313,16 +311,25 @@ describe('removeFile', () => {
313311 const iff = await createIFF ( {
314312 'tsconfig.json' : '{ "cmkOptions": { "enabled": true } }' ,
315313 'src/a.module.css' : '@value a_1: red;' ,
316- 'src/b.module.css' : '@value a_1 from "./a.module.css";' , // directly
317- 'src/re-export.module.css' : '@import "./a.module.css";' ,
318- 'src/c.module.css' : '@value a_1 from "./re-export.module.css";' , // indirectly
314+ 'src/b.module.css' : '@import "./a.module.css";' , // directly
315+ 'src/c.module.css' : '@value a_1 from "./b.module.css";' , // indirectly
319316 } ) ;
320317 const project = createProject ( { project : iff . rootDir } ) ;
321318 expect ( formatDiagnostics ( project . getDiagnostics ( ) , iff . rootDir ) ) . toMatchInlineSnapshot ( `[]` ) ;
322319 await rm ( iff . join ( 'src/a.module.css' ) ) ;
323320 project . removeFile ( iff . join ( 'src/a.module.css' ) ) ;
324321 expect ( formatDiagnostics ( project . getDiagnostics ( ) , iff . rootDir ) ) . toMatchInlineSnapshot ( `
325322 [
323+ {
324+ "category": "error",
325+ "fileName": "<rootDir>/src/b.module.css",
326+ "length": 14,
327+ "start": {
328+ "column": 10,
329+ "line": 1,
330+ },
331+ "text": "Cannot import module './a.module.css'",
332+ },
326333 {
327334 "category": "error",
328335 "fileName": "<rootDir>/src/c.module.css",
@@ -331,7 +338,7 @@ describe('removeFile', () => {
331338 "column": 8,
332339 "line": 1,
333340 },
334- "text": "Module './re-export .module.css' has no exported token 'a_1'.",
341+ "text": "Module './b .module.css' has no exported token 'a_1'.",
335342 },
336343 ]
337344 ` ) ;
@@ -459,8 +466,8 @@ describe('getDiagnostics', () => {
459466 test ( 'returns semantic diagnostics' , async ( ) => {
460467 const iff = await createIFF ( {
461468 'tsconfig.json' : '{ "cmkOptions": { "enabled": true } }' ,
462- 'src/a.module.css' : `.a-1 {} ` ,
463- 'src/b.module.css' : `.b-1 {} ` ,
469+ 'src/a.module.css' : `@import './non-existent-1.module.css'; ` ,
470+ 'src/b.module.css' : `@import './non-existent-2.module.css'; ` ,
464471 } ) ;
465472 const project = createProject ( { project : iff . rootDir } ) ;
466473 const diagnostics = project . getDiagnostics ( ) ;
@@ -469,22 +476,22 @@ describe('getDiagnostics', () => {
469476 {
470477 "category": "error",
471478 "fileName": "<rootDir>/src/a.module.css",
472- "length": 3 ,
479+ "length": 27 ,
473480 "start": {
474- "column": 2 ,
481+ "column": 10 ,
475482 "line": 1,
476483 },
477- "text": "css-modules-kit does not support invalid names as JavaScript identifiers. ",
484+ "text": "Cannot import module './non-existent-1.module.css' ",
478485 },
479486 {
480487 "category": "error",
481488 "fileName": "<rootDir>/src/b.module.css",
482- "length": 3 ,
489+ "length": 27 ,
483490 "start": {
484- "column": 2 ,
491+ "column": 10 ,
485492 "line": 1,
486493 },
487- "text": "css-modules-kit does not support invalid names as JavaScript identifiers. ",
494+ "text": "Cannot import module './non-existent-2.module.css' ",
488495 },
489496 ]
490497 ` ) ;
0 commit comments