diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit index 618c2bf..30c869e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,5 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +npm run lint:fix diff --git a/package-lock.json b/package-lock.json index 933d0e1..2d7f15a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1426,7 +1426,7 @@ "version": "22.8.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.1.tgz", "integrity": "sha512-k6Gi8Yyo8EtrNtkHXutUu2corfDf9su95VYVP10aGYMMROM6SAItZi0w1XszA6RtWTHSVp5OeFof37w0IEqCQg==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.19.8" @@ -6531,7 +6531,7 @@ "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", - "devOptional": true, + "dev": true, "license": "MIT" }, "node_modules/unicorn-magic": { diff --git a/package.json b/package.json index eef7912..a725634 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "start": "ts-node src/launch.ts", "lint": "ts-standard src/**/*.ts", "lint:fix": "ts-standard --fix src/**/*.ts", - "prebuild": "npm run clean && ts-standard --fix src/**/*.ts", + "prebuild": "npm run clean && ts-standard --fix src/**/*.ts tests/**/*.ts", "prepare": "npm run build && husky install", "test": "vitest run" }, diff --git a/tests/lib/mediaQuery.test.ts b/tests/lib/mediaQuery.test.ts index a34dd9c..7dab108 100644 --- a/tests/lib/mediaQuery.test.ts +++ b/tests/lib/mediaQuery.test.ts @@ -1,8 +1,8 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest' import { findIndexOfMediaQueries, - getMediaQueries, -} from "../../src/lib/mediaQuery"; + getMediaQueries +} from '../../src/lib/mediaQuery' const simpleCssWithMediaQuery = ` /* On screens that are 992px or less, set the background color to blue */ @media screen and (max-width: 992px) { @@ -17,7 +17,7 @@ const simpleCssWithMediaQuery = ` background-color: olive; } } -`; +` const complexCssWithMediaQuery = ` /* Small screens (phones) */ @@ -89,27 +89,27 @@ const complexCssWithMediaQuery = ` section { flex-direction: column; } -}`; - -describe("findIndexOfMediaQueries", () => { - it("return position of media query if present", () => { - expect(findIndexOfMediaQueries(simpleCssWithMediaQuery)).toEqual([75, 233]); - }); - - it("return empty array if no media query", () => { - expect(findIndexOfMediaQueries("")).toEqual([]); - }); -}); - -describe("getMediaQueries", () => { - it("return media queries", () => { - const rules = getMediaQueries(simpleCssWithMediaQuery); - expect(rules.length).toEqual(2); - }); - - it("return media queries with complex css", () => { - const rules = getMediaQueries(complexCssWithMediaQuery); - - expect(rules.length).toEqual(6); - }); -}); +}` + +describe('findIndexOfMediaQueries', () => { + it('return position of media query if present', () => { + expect(findIndexOfMediaQueries(simpleCssWithMediaQuery)).toEqual([75, 233]) + }) + + it('return empty array if no media query', () => { + expect(findIndexOfMediaQueries('')).toEqual([]) + }) +}) + +describe('getMediaQueries', () => { + it('return media queries', () => { + const rules = getMediaQueries(simpleCssWithMediaQuery) + expect(rules.length).toEqual(2) + }) + + it('return media queries with complex css', () => { + const rules = getMediaQueries(complexCssWithMediaQuery) + + expect(rules.length).toEqual(6) + }) +}) diff --git a/tests/lib/removeComments.test.ts b/tests/lib/removeComments.test.ts index 8cd08fc..a3ef73e 100644 --- a/tests/lib/removeComments.test.ts +++ b/tests/lib/removeComments.test.ts @@ -1,14 +1,14 @@ -import { describe, it, expect } from "vitest"; -import { removeComments } from "../../src/lib/removeComments"; +import { describe, it, expect } from 'vitest' +import { removeComments } from '../../src/lib/removeComments' -describe("removeComments", () => { - it("should remove single-line comments", () => { - expect(removeComments("color: black; // background-color: white")).toBe( - "color: black;" - ); - }); +describe('removeComments', () => { + it('should remove single-line comments', () => { + expect(removeComments('color: black; // background-color: white')).toBe( + 'color: black;' + ) + }) - it("should remove comments and duplicate characters", () => { + it('should remove comments and duplicate characters', () => { const input = ` /* Multi-line Comment @@ -27,7 +27,7 @@ describe("removeComments", () => { // this is the closing comment - `; + ` const expected = ` body { color: black; @@ -36,9 +36,9 @@ describe("removeComments", () => { div { border: 1px solid black; } - `; - const result = removeComments(input); - + ` + const result = removeComments(input) + expect(result.replace(/[\s\t]*/g, '')).toEqual(expected.replace(/[\s\t]*/g, '')) }) }) diff --git a/tests/lib/removeDuplicates.test.ts b/tests/lib/removeDuplicates.test.ts index ffa4883..14df78b 100644 --- a/tests/lib/removeDuplicates.test.ts +++ b/tests/lib/removeDuplicates.test.ts @@ -1,28 +1,28 @@ -import { describe, it, expect } from "vitest"; -import { removeDuplicates } from "../../src/lib/removeDuplicates"; +import { describe, it, expect } from 'vitest' +import { removeDuplicates } from '../../src/lib/removeDuplicates' -describe("removeDuplicates", () => { - it("should remove duplicate semicolons", () => { - expect(removeDuplicates("color: black;;", [";"])).toBe("color: black;"); - }); +describe('removeDuplicates', () => { + it('should remove duplicate semicolons', () => { + expect(removeDuplicates('color: black;;', [';'])).toBe('color: black;') + }) - it("should remove duplicate periods", () => { - expect(removeDuplicates("..className", ["."])).toBe(".className"); - }); + it('should remove duplicate periods', () => { + expect(removeDuplicates('..className', ['.'])).toBe('.className') + }) - it("should remove duplicate comma", () => { - expect(removeDuplicates(".className,, .bar", [","])).toBe( - ".className, .bar" - ); - }); + it('should remove duplicate comma', () => { + expect(removeDuplicates('.className,, .bar', [','])).toBe( + '.className, .bar' + ) + }) - it("should remove duplicate spaces", () => { - expect(removeDuplicates("color: black", [" "])).toBe("color: black"); - }); + it('should remove duplicate spaces', () => { + expect(removeDuplicates('color: black', [' '])).toBe('color: black') + }) - it("should remove multiple duplicate characters", () => { - expect(removeDuplicates("color: black;; 1..0", [";", ".", " "])).toBe( - "color: black; 1.0" - ); - }); -}); + it('should remove multiple duplicate characters', () => { + expect(removeDuplicates('color: black;; 1..0', [';', '.', ' '])).toBe( + 'color: black; 1.0' + ) + }) +}) diff --git a/tests/lib/tokenize.test.ts b/tests/lib/tokenize.test.ts index a40caed..fc8e3ba 100644 --- a/tests/lib/tokenize.test.ts +++ b/tests/lib/tokenize.test.ts @@ -1,8 +1,8 @@ -import { describe, test, expect } from "vitest"; -import { tokenize } from "../../src/lib/tokenize"; +import { describe, test, expect } from 'vitest' +import { tokenize } from '../../src/lib/tokenize' -describe("tokenize", () => { - test("tokenize", () => { +describe('tokenize', () => { + test('tokenize', () => { const css = ` a { color: purple;} div { border: none; } @@ -10,8 +10,8 @@ describe("tokenize", () => { .mickey { color: purple;} .don { color: purple; background: red; } .goofy { background: red; } - .goofy { color: purple; }`; - const res = tokenize(css); - expect(res).toBeDefined(); - }); -}); + .goofy { color: purple; }` + const res = tokenize(css) + expect(res).toBeDefined() + }) +})