Skip to content

Commit 1da3b55

Browse files
committed
Update test files with typescript
1 parent 4cf17d1 commit 1da3b55

File tree

11 files changed

+122
-264
lines changed

11 files changed

+122
-264
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ coverage/
99

1010
.DS_Store
1111
item.ts
12+
13+
*.js
14+
*.d.ts

index.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 101 deletions
This file was deleted.

index.test.js renamed to index.test.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
const postcss = require('postcss');
2-
3-
const variableCompress = require('./index');
4-
5-
async function run (input, output, opts) {
6-
let result = await postcss(
7-
[variableCompress(opts)]
8-
).process(input, { from: undefined });
1+
import postcss, { Root } from "postcss";
2+
import variableCompress, { variableCompressParameters } from "./index";
3+
4+
async function run(
5+
input: string | { toString(): string } | Root,
6+
output: string,
7+
opts?:
8+
| variableCompressParameters[]
9+
| (string | ((e: any) => any))[]
10+
| undefined
11+
) {
12+
let result = await postcss([variableCompress(opts)]).process(input, {
13+
from: undefined,
14+
});
915

1016
expect(result.css).toEqual(output);
1117
expect(result.warnings()).toHaveLength(0);
12-
1318
}
1419

15-
16-
it('Shorten css variables', async () => {
20+
it("Shorten css variables", async () => {
1721
await run(
1822
`:root {
1923
--first-color: #16f;
@@ -80,20 +84,27 @@ code {
8084
--5: #555;
8185
}`,
8286
[
83-
'--primary-color',
84-
'2',
85-
(e) => e.includes('special'),
86-
(e) => e === '--5'
87+
"--primary-color",
88+
"2",
89+
(e: string | string[]) => e.includes("special"),
90+
(e: string) => e === "--5",
8791
]
8892
);
8993
});
9094

91-
it('Support reloading. Now the plugin will reset mapped variables', async () => {
92-
await run(`:root{--first-color: #16f;--second-color: #ff7;}`, `:root{--0: #16f;--1: #ff7;}`, []);
93-
await run(`:root{--second-color: #ff7;--first-color: #16f;}`, `:root{--0: #ff7;--1: #16f;}`, []);
95+
it("Support reloading. Now the plugin will reset mapped variables", async () => {
96+
await run(
97+
`:root{--first-color: #16f;--second-color: #ff7;}`,
98+
`:root{--0: #16f;--1: #ff7;}`,
99+
[]
100+
);
101+
await run(
102+
`:root{--second-color: #ff7;--first-color: #16f;}`,
103+
`:root{--0: #ff7;--1: #16f;}`,
104+
[]
105+
);
94106
});
95107

96-
97-
it('Base array check or no array', async () => {
98-
await run(`:root{}`, `:root{}`);
108+
it("Base array check or no array", async () => {
109+
run(`:root{}`, `:root{}`);
99110
});

index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
export namespace variableCompress {
2-
export type skip = (variableName: string) => boolean | undefined;
1+
export type skipFunction = (variableName: string) => boolean | undefined;
2+
export type variableCompressParameters = skipFunction | string;
33

4-
export type parameters = skip | string;
5-
}
64
const postcssPlugin = "postcss-variable-compress";
75

86
let processed = Symbol("processed");
97
let renamedVariables: string[] = [];
108
let cssVariables = -1;
119
let pureSkips: string[] = [];
12-
let scriptBasedSkips: variableCompress.skip[] = [];
10+
let scriptBasedSkips: skipFunction[] = [];
1311
let cssVariablesMap = new Map();
1412

1513
function scriptCheck(val: string) {
@@ -83,7 +81,7 @@ function map(j: import("postcss").Declaration) {
8381
j[processed] = true;
8482
}
8583

86-
function variableCompress(opts?: variableCompress.parameters[]) {
84+
function variableCompress(opts?: variableCompressParameters[]) {
8785
processed = Symbol("processed");
8886

8987
renamedVariables = [];

package-lock.json

Lines changed: 72 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lint-staged": "^13.0.3",
3939
"postcss": "^8.2.8",
4040
"simple-git-hooks": "^2.0.2",
41+
"ts-jest": "^29.1.0",
4142
"typescript": "^4.3.5"
4243
},
4344
"simple-git-hooks": {
@@ -63,6 +64,7 @@
6364
}
6465
},
6566
"jest": {
67+
"preset": "ts-jest",
6668
"testEnvironment": "node",
6769
"coverageThreshold": {
6870
"global": {

splitFiles.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)