Skip to content

Commit c862982

Browse files
committed
add tests for edge cases
1 parent ca2bbbf commit c862982

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

packages/ts-plugin/e2e/named-exports.test.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ describe('supports completions', async () => {
211211
'a.module.css': dedent`
212212
.a_1 { color: red; }
213213
`,
214+
// The tokens exported from following definition file should be ignored.
215+
'generated/a.module.css.d.ts': dedent`
216+
export const a_1: string;
217+
`,
214218
});
215219
describe('default behavior', async () => {
216220
const iff = await baseIff.fork({
@@ -318,9 +322,17 @@ describe('supports code fixes', async () => {
318322
'a.module.css': dedent`
319323
.a_1 { color: red; }
320324
`,
325+
// The tokens exported from following definition file should be ignored.
326+
'generated/a.module.css.d.ts': dedent`
327+
export const a_1: string;
328+
`,
321329
});
322330
describe('default behavior', async () => {
323331
const iff = await baseIff.fork({
332+
'import-statement-already-exists.ts': dedent`
333+
import { a_1 } from './a.module.css';
334+
styles;
335+
`,
324336
'tsconfig.json': dedent`
325337
{
326338
"cmkOptions": {
@@ -335,7 +347,7 @@ describe('supports code fixes', async () => {
335347
});
336348
test.each([
337349
{
338-
name: 'styles',
350+
name: 'styles in index.ts',
339351
file: iff.paths['index.ts'],
340352
startLine: 1,
341353
startOffset: 1,
@@ -360,14 +372,40 @@ describe('supports code fixes', async () => {
360372
],
361373
},
362374
{
363-
name: 'a_1',
375+
name: 'a_1 in index.ts',
364376
file: iff.paths['index.ts'],
365377
startLine: 2,
366378
startOffset: 1,
367379
endLine: 2,
368380
endOffset: 4,
369381
expected: [],
370382
},
383+
// MEMO: css-modules-kit does not support the following case to simplify the implementation.
384+
// {
385+
// name: 'styles in import-statement-already-exists.ts',
386+
// file: iff.paths['import-statement-already-exists.ts'],
387+
// startLine: 2,
388+
// startOffset: 1,
389+
// endLine: 2,
390+
// endOffset: 7,
391+
// expected: [
392+
// {
393+
// fixName: 'import',
394+
// changes: [
395+
// {
396+
// fileName: formatPath(iff.paths['import-statement-already-exists.ts']),
397+
// textChanges: [
398+
// {
399+
// start: { line: 1, offset: 1 },
400+
// end: { line: 1, offset: 1 },
401+
// newText: `import * as styles from "./a.module.css";${ts.sys.newLine}${ts.sys.newLine}`,
402+
// },
403+
// ],
404+
// },
405+
// ],
406+
// },
407+
// ],
408+
// },
371409
])('$name', async ({ file, startLine, startOffset, endLine, endOffset, expected }) => {
372410
const res = await tsserver.sendGetCodeFixes({
373411
errorCodes: [2304],

0 commit comments

Comments
 (0)