Skip to content

Commit 81fb74f

Browse files
authored
chore: add test (#80)
1 parent 4bee864 commit 81fb74f

File tree

6 files changed

+287
-333
lines changed

6 files changed

+287
-333
lines changed

.vscodeignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ demo.gif
1717
.cssrem
1818
.yarnrc.yml
1919
scripts/**
20+
.nvmrc

package.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,20 @@
260260
]
261261
},
262262
"devDependencies": {
263-
"@types/mocha": "^10.0.9",
264263
"@types/node": "20.x",
265264
"@types/vscode": "^1.90.0",
266-
"@typescript-eslint/eslint-plugin": "^8.10.0",
267-
"@typescript-eslint/parser": "^8.7.0",
268-
"@vscode/l10n-dev": "^0.0.18",
265+
"@typescript-eslint/eslint-plugin": "^8.20.0",
266+
"@typescript-eslint/parser": "^8.20.0",
269267
"@vscode/test-cli": "^0.0.10",
270268
"@vscode/test-electron": "^2.4.1",
271269
"conventional-changelog-cli": "^5.0.0",
272-
"esbuild": "^0.24.0",
273-
"eslint": "^9.13.0",
270+
"esbuild": "^0.24.2",
271+
"eslint": "^9.18.0",
274272
"tsx": "^4.19.2",
275273
"typescript": "^5.6.3"
276274
},
277275
"dependencies": {
278-
"@vscode/l10n": "^0.0.10",
276+
"@vscode/l10n": "^0.0.18",
279277
"jsonc-parser": "^3.0.0",
280278
"minimatch": "^10.0.1"
281279
},

src/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ export async function loadConfig(): Promise<void> {
7979
export function isIngore(uri: Uri) {
8080
return cog.ignores.some((p) => minimatch(uri.path, p));
8181
}
82+
83+
export function testConfig(c: Partial<Config>) {
84+
cog = { ...c } as unknown as Config;
85+
fixIngores();
86+
fixLanguages();
87+
resetRules();
88+
}

src/test/rules.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as assert from 'assert';
2+
import { RULES } from '../rules';
3+
import { testConfig } from '../config';
4+
5+
suite('rules', () => {
6+
suite('pxToRem', () => {
7+
testConfig({
8+
rootFontSize: 16,
9+
fixedDigits: 2,
10+
autoRemovePrefixZero: true,
11+
});
12+
const rule = RULES.find((w) => w.type === 'pxToRem');
13+
14+
test('should be working', () => {
15+
const res = rule?.fn(`12px`);
16+
assert.equal(res?.value, `.75rem`);
17+
});
18+
19+
test(`should be return null when character can't be parsed as a number`, () => {
20+
const res = rule?.fn(`&.px`);
21+
assert.equal(res, null);
22+
});
23+
});
24+
});

tsconfig.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "ES2020",
4+
"target": "es2020",
55
"lib": [
6-
"ES2020"
6+
"es2020"
77
],
8+
"outDir": "out",
89
"sourceMap": true,
910
"rootDir": "src",
10-
"outDir": "out",
11-
"strict": true,
12-
"noEmit": true
11+
"strict": true
1312
},
14-
"include": [
15-
"src/**/*.ts"
13+
"exclude": [
14+
"node_modules",
15+
".vscode-test",
16+
"examples",
17+
"scripts"
1618
]
1719
}

0 commit comments

Comments
 (0)