Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
- fix: tests
  • Loading branch information
phoenisx committed Mar 12, 2022
1 parent 7d30965 commit 4a1b9e4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ This extension helps to autocomplete globally shared CSS Variables and a lot mor
* If your project uses **SASS/LESS**, and you are facing issues to setup this extension, please
read [Customization](./customize-extension.md) Doc.
* [Theme Support](./theming.md)
* *CSS Level 4 color spec support is limited*, to keep the bundle size small
* Except `color()` api, every other CSS color is supported. Please find
details for CSS colors [here in MDN Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)

## Supported Configs:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"intellisense"
],
"description": "Intellisense support for CSS Variables",
"version": "1.1.0",
"version": "1.2.0",
"publisher": "phoenisx",
"license": "MIT",
"homepage": "https://github.com/willofindie/vscode-cssvar",
Expand Down
23 changes: 11 additions & 12 deletions src/test/color-provider/color-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EndOfLine, TextDocument } from "vscode";
import { parseToRgb } from "polished";
import { RgbaColor } from "polished/lib/types/color";
import { parseToRgb } from "../../color-parser";

import { CssColorProvider } from "../../color-provider";
import { CSSVarDeclarations } from "../../main";
Expand Down Expand Up @@ -74,8 +73,8 @@ const getDocumentFromText = (text: string) => {

describe("Test Color Provider", () => {
let provider: CssColorProvider;
const red300 = parseToRgb("#fc8181") as RgbaColor;
const red500 = parseToRgb("#e53e3e") as RgbaColor;
const red300 = parseToRgb("#fc8181");
const red500 = parseToRgb("#e53e3e");

beforeAll(() => {
provider = new CssColorProvider();
Expand All @@ -87,10 +86,10 @@ describe("Test Color Provider", () => {
);
expect(colorInfos.length).toBe(1);
expect(colorInfos[0].color).toMatchObject({
red: red300.red / 255,
green: red300.green / 255,
blue: red300.blue / 255,
alpha: red300.alpha ?? 1,
red: red300!.r,
green: red300!.g,
blue: red300!.b,
alpha: red300!.alpha ?? 1,
});
expect(colorInfos[0].range.start.character).toBe(7);
expect(colorInfos[0].range.end.character).toBe(27);
Expand All @@ -101,10 +100,10 @@ describe("Test Color Provider", () => {
);
expect(colorInfos.length).toBe(3);
expect(colorInfos[1].color).toMatchObject({
red: red500.red / 255,
green: red500.green / 255,
blue: red500.blue / 255,
alpha: red500.alpha ?? 1,
red: red500!.r,
green: red500!.g,
blue: red500!.b,
alpha: red500!.alpha ?? 1,
});
expect(colorInfos[1].range).toEqual(
expect.objectContaining({
Expand Down
4 changes: 2 additions & 2 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Test Parser", () => {
const oldVariable: CSSVarDeclarations = {
type: "css",
property: "--red",
value: "#f00",
value: "rgb(255, 0, 0)",
theme: "",
};
CACHE.cssVars = {
Expand All @@ -94,7 +94,7 @@ describe("Test Parser", () => {
type: "css",
property: "--red500",
value: "#f24455",
color: "#f24455",
color: "rgb(242, 68, 85)",
theme: "",
location: expect.objectContaining({
uri: RENAMED_FILE,
Expand Down
9 changes: 7 additions & 2 deletions src/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,45 @@ describe("Utility Function Tests", () => {
it("should return proper Hex string for unknown Color Names", () => {
const cssVars: CSSVarDeclarations[] = [
{
type: "css",
property: "--red500",
value: "red",
theme: "",
},
];
const result = getColor(cssVars[0].value, cssVars);
expect(result.success).toBeTruthy();
expect(result.color).toEqual("#f00");
expect(result.color).toEqual("rgb(255, 0, 0)");
});
it("should return proper Hex string recursively", () => {
const cssVars: CSSVarDeclarations[] = [
{
type: "css",
property: "--red500",
value: "red",
theme: "",
},
{
type: "css",
property: "--bg01",
value: "var(--red500)",
theme: "",
},
];
const result = getColor(cssVars[1].value, cssVars);
expect(result.success).toBeTruthy();
expect(result.color).toEqual("#f00");
expect(result.color).toEqual("rgb(255, 0, 0)");
});
it("should not return color if value is not a color", () => {
const cssVars: CSSVarDeclarations[] = [
{
type: "css",
property: "--pad-1",
value: "16px",
theme: "",
},
{
type: "css",
property: "--spacing-x",
value: "var(--pad-1)",
theme: "",
Expand Down

0 comments on commit 4a1b9e4

Please sign in to comment.