Skip to content

Commit

Permalink
test: add test cases to cover other export variations
Browse files Browse the repository at this point in the history
  • Loading branch information
kazushisan committed Sep 10, 2024
1 parent 76b18ec commit 2457bc8
Showing 1 changed file with 101 additions and 1 deletion.
102 changes: 101 additions & 1 deletion lib/util/removeUnusedExport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export { remain };`,
});

describe('locally used declaration but not used in any other file', () => {
it('should remove export keyword if its not used in any other file', () => {
it('should remove export keyword of variable if its not used in any other file', () => {
const { languageService, fileService } = setup();
fileService.set('/app/main.ts', `import { a } from './a';`);

Expand All @@ -639,6 +639,106 @@ const b = 'b';
console.log(b);`,
);
});

it('should remove export keyword of class declaration if its not used in any other file', () => {
const { languageService, fileService } = setup();
fileService.set('/app/main.ts', `import { a } from './a';`);

fileService.set(
'/app/a.ts',
`export const a = 'a';
export class B {}
console.log(B);`,
);

removeUnusedExport({
languageService,
fileService,
targetFile: '/app/a.ts',
});

assert.equal(
fileService.get('/app/a.ts').trim(),
`export const a = 'a';
class B {}
console.log(B);`,
);
});

it('should remove export keyword of interface declaration if its not used in any other file', () => {
const { languageService, fileService } = setup();
fileService.set('/app/main.ts', `import { a } from './a';`);

fileService.set(
'/app/a.ts',
`export const a = 'a';
export interface B {}
const b: B = {};`,
);

removeUnusedExport({
languageService,
fileService,
targetFile: '/app/a.ts',
});

assert.equal(
fileService.get('/app/a.ts').trim(),
`export const a = 'a';
interface B {}
const b: B = {};`,
);
});
});

it('should remove export keyword of type alias declaration if its not used in any other file', () => {
const { languageService, fileService } = setup();
fileService.set('/app/main.ts', `import { a } from './a';`);

fileService.set(
'/app/a.ts',
`export const a = 'a';
export type B = 'b';
const b: B = 'b';`,
);

removeUnusedExport({
languageService,
fileService,
targetFile: '/app/a.ts',
});

assert.equal(
fileService.get('/app/a.ts').trim(),
`export const a = 'a';
type B = 'b';
const b: B = 'b';`,
);
});

it('should remove export keyword of interface declaration if its not used in any other file', () => {
const { languageService, fileService } = setup();
fileService.set('/app/main.ts', `import { a } from './a';`);

fileService.set(
'/app/a.ts',
`export const a = 'a';
export interface B {}
const b: B = {};`,
);

removeUnusedExport({
languageService,
fileService,
targetFile: '/app/a.ts',
});

assert.equal(
fileService.get('/app/a.ts').trim(),
`export const a = 'a';
interface B {}
const b: B = {};`,
);
});

describe('deleteUnusedFile', () => {
Expand Down

0 comments on commit 2457bc8

Please sign in to comment.