Skip to content

Commit

Permalink
refactor(detector): test cases structure
Browse files Browse the repository at this point in the history
  • Loading branch information
marabesi committed Dec 6, 2024
1 parent 00bd7b3 commit 776e005
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
10 changes: 10 additions & 0 deletions detector/test/smells-detector-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const IF_STATEMENT = 'if-statement';
export const FOR_OF = 'for-of-statement';
export const FOR_IN = 'for-in-statement';
export const FOR = 'for-statement';
export const TIMEOUT = 'timeout';
export const CONSOLE = 'console-statement';
export const MOCKERY = 'excessive-jest-mock';

export const JAVASCRIPT = 'javascript';
export const TYPESCRIPT = 'typescript';
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { describe, expect, test } from 'vitest';
import { SmellDetector } from '../src/index';
import { CONSOLE, FOR, FOR_IN, FOR_OF, IF_STATEMENT, JAVASCRIPT, MOCKERY, TIMEOUT, TYPESCRIPT } from './smells-detector-builder';

const IF_STATEMENT = 'if-statement';
const FOR_OF = 'for-of-statement';
const FOR_IN = 'for-in-statement';
const FOR = 'for-statement';
const TIMEOUT = 'timeout';
const CONSOLE = 'console-statement';
const MOCKERY = 'excessive-jest-mock';

const JAVASCRIPT = 'javascript';
const TYPESCRIPT = 'typescript';

describe('Smelly Test Smell Detection Suite', () => {
test.each([[{
Expand Down Expand Up @@ -383,16 +374,4 @@ jest.mock("../");`,
expect(result[index].description).toEqual(description);
expect(result[index].diagnostic).toEqual(diagnostic);
});

test.each([{
code: `
jest.mock("../");`,
language: TYPESCRIPT,
}
])(`detect code without smells`, ({ code, language }) => {
const smellDetector = new SmellDetector(code, language);
const result = smellDetector.findAll();

expect(result.length).toEqual(0);
});
});
17 changes: 17 additions & 0 deletions detector/test/smells-detector-without-smells.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from 'vitest';
import { SmellDetector } from '../src/index';
import { TYPESCRIPT } from './smells-detector-builder';

describe('Smelly Test Smell Detection Suite', () => {
test.each([{
code: `
jest.mock("../");`,
language: TYPESCRIPT,
}
])(`detect code without smells`, ({ code, language }) => {
const smellDetector = new SmellDetector(code, language);
const result = smellDetector.findAll();

expect(result.length).toEqual(0);
});
});

0 comments on commit 776e005

Please sign in to comment.