From 776e0057842128a89eedf29fe4323d0c94e3babc Mon Sep 17 00:00:00 2001 From: marabesi Date: Fri, 6 Dec 2024 14:12:13 +0100 Subject: [PATCH] refactor(detector): test cases structure --- detector/test/smells-detector-builder.ts | 10 ++++++++ ...ts => smells-detector-with-smells.test.ts} | 23 +------------------ .../smells-detector-without-smells.test.ts | 17 ++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 detector/test/smells-detector-builder.ts rename detector/test/{smells-detector.test.ts => smells-detector-with-smells.test.ts} (95%) create mode 100644 detector/test/smells-detector-without-smells.test.ts diff --git a/detector/test/smells-detector-builder.ts b/detector/test/smells-detector-builder.ts new file mode 100644 index 0000000..faecc71 --- /dev/null +++ b/detector/test/smells-detector-builder.ts @@ -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'; \ No newline at end of file diff --git a/detector/test/smells-detector.test.ts b/detector/test/smells-detector-with-smells.test.ts similarity index 95% rename from detector/test/smells-detector.test.ts rename to detector/test/smells-detector-with-smells.test.ts index a0bd42b..b50d599 100644 --- a/detector/test/smells-detector.test.ts +++ b/detector/test/smells-detector-with-smells.test.ts @@ -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([[{ @@ -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); - }); }); diff --git a/detector/test/smells-detector-without-smells.test.ts b/detector/test/smells-detector-without-smells.test.ts new file mode 100644 index 0000000..7f84488 --- /dev/null +++ b/detector/test/smells-detector-without-smells.test.ts @@ -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); + }); +});