Skip to content

Commit

Permalink
capricorn86#1004@patch: Fix missing css named colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisTessier committed Jul 30, 2023
1 parent e9038c7 commit 760fc94
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 9 deletions.
80 changes: 71 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/happy-dom/package.json
Expand Up @@ -89,6 +89,7 @@
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@vitest/ui": "^0.33.0",
"@webref/css": "6.6.2",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-filenames": "^1.3.2",
Expand Down
Expand Up @@ -15,6 +15,7 @@ const GRADIENT_REGEXP =
/^(repeating-linear|linear|radial|repeating-radial|conic|repeating-conic)-gradient\([^)]+\)$/;
const GLOBALS = ['inherit', 'initial', 'unset', 'revert'];
const COLORS = [
'none',
'currentcolor',
'transparent',
'silver',
Expand All @@ -31,12 +32,14 @@ const COLORS = [
'navy',
'blue',
'teal',
'aliceblue',
'aqua',
'antiquewhite',
'aquamarine',
'azure',
'beige',
'bisque',
'black',
'blanchedalmond',
'blueviolet',
'brown',
Expand All @@ -48,6 +51,7 @@ const COLORS = [
'cornflowerblue',
'cornsilk',
'crimson',
'cyan',
'darkblue',
'darkcyan',
'darkgoldenrod',
Expand Down Expand Up @@ -108,6 +112,7 @@ const COLORS = [
'lightyellow',
'limegreen',
'linen',
'magenta',
'mediumaquamarine',
'mediumblue',
'mediumorchid',
Expand All @@ -124,6 +129,7 @@ const COLORS = [
'navajowhite',
'oldlace',
'olivedrab',
'orange',
'orangered',
'orchid',
'palegoldenrod',
Expand All @@ -136,6 +142,7 @@ const COLORS = [
'pink',
'plum',
'powderblue',
'rebeccapurple',
'rosybrown',
'royalblue',
'saddlebrown',
Expand Down
24 changes: 24 additions & 0 deletions packages/happy-dom/test/css/css-named-colors.test.ts
@@ -0,0 +1,24 @@
import { test, expect } from 'vitest';
import parser from '../../src/css/declaration/property-manager/CSSStyleDeclarationValueParser';
import { values } from '@webref/css/css-color.json';

function isString(value: string | undefined): value is string {
return typeof value === 'string';
}

const namedColorsFromWebref = values
.filter((value) => value.name === '<color>')
.flatMap((value) => value.values)
.map((color) => color?.name)
.filter(isString);

test('named colors from webref are correctly selected', () => {
expect(namedColorsFromWebref).toContain('red');
expect(namedColorsFromWebref).toContain('green');
expect(namedColorsFromWebref).toContain('blue');
});

test.each(namedColorsFromWebref)('"%s" css named color must be defined', (expectedNamedColor) => {
const parsedColor = parser.getColor(expectedNamedColor);
expect(parsedColor).toStrictEqual(expectedNamedColor);
});

0 comments on commit 760fc94

Please sign in to comment.