Skip to content

Commit 2961d2d

Browse files
committed
test for undocumented colors
1 parent 5b2e81d commit 2961d2d

6 files changed

Lines changed: 169 additions & 4 deletions

File tree

scripts/test-release.bat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@echo off
2+
setlocal
3+
4+
pushd %~dp0\..
5+
6+
:: Endgame tests in AMD
7+
call .\scripts\test.bat --runGlob **\*.releaseTest.js %*
8+
if %errorlevel% neq 0 exit /b %errorlevel%
9+
10+
11+
rmdir /s /q %VSCODEUSERDATADIR%
12+
13+
popd
14+
15+
endlocal

scripts/test-release.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [[ "$OSTYPE" == "darwin"* ]]; then
5+
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
6+
ROOT=$(dirname $(dirname $(realpath "$0")))
7+
VSCODEUSERDATADIR=`mktemp -d -t 'myuserdatadir'`
8+
else
9+
ROOT=$(dirname $(dirname $(readlink -f $0)))
10+
VSCODEUSERDATADIR=`mktemp -d 2>/dev/null`
11+
fi
12+
13+
cd $ROOT
14+
15+
# Tests in AMD
16+
./scripts/test.sh --runGlob **/*.releaseTest.js "$@"
17+
18+
19+
rm -r $VSCODEUSERDATADIR

src/vs/platform/theme/common/colorRegistry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface ColorContribution {
2020
readonly description: string;
2121
readonly defaults: ColorDefaults;
2222
readonly needsTransparency: boolean;
23+
readonly deprecationMessage: string;
2324
}
2425

2526

@@ -87,7 +88,7 @@ class ColorRegistry implements IColorRegistry {
8788
}
8889

8990
public registerColor(id: string, defaults: ColorDefaults, description: string, needsTransparency = false, deprecationMessage?: string): ColorIdentifier {
90-
let colorContribution = { id, description, defaults, needsTransparency };
91+
let colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage };
9192
this.colorsById[id] = colorContribution;
9293
let propertySchema: IJSONSchema = { type: 'string', description, format: 'color-hex', default: '#ff0000' };
9394
if (deprecationMessage) {
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { Registry } from 'vs/platform/registry/common/platform';
9+
import { IColorRegistry, Extensions, ColorContribution } from 'vs/platform/theme/common/colorRegistry';
10+
import { editorMarkerNavigationError } from 'vs/editor/contrib/gotoError/gotoErrorWidget';
11+
import { overviewRulerModifiedForeground } from 'vs/workbench/parts/scm/electron-browser/dirtydiffDecorator';
12+
import { STATUS_BAR_DEBUGGING_BACKGROUND } from 'vs/workbench/parts/debug/browser/statusbarColorProvider';
13+
import { debugExceptionWidgetBackground } from 'vs/workbench/parts/debug/browser/exceptionWidget';
14+
import { debugToolBarBackground } from 'vs/workbench/parts/debug/browser/debugActionsWidget';
15+
import { buttonBackground } from 'vs/workbench/parts/welcome/page/electron-browser/welcomePage';
16+
import { embeddedEditorBackground } from 'vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart';
17+
import { request, asText } from 'vs/base/node/request';
18+
import * as pfs from 'vs/base/node/pfs';
19+
import * as path from 'path';
20+
import * as assert from 'assert';
21+
22+
23+
interface ColorInfo {
24+
description: string;
25+
offset: number;
26+
length: number;
27+
}
28+
29+
interface DescriptionDiff {
30+
docDescription: string;
31+
specDescription: string;
32+
}
33+
34+
// add artificial dependencies to some files that are not loaded yet
35+
export const forceColorLoad = [editorMarkerNavigationError, overviewRulerModifiedForeground, STATUS_BAR_DEBUGGING_BACKGROUND,
36+
debugExceptionWidgetBackground, debugToolBarBackground, buttonBackground, embeddedEditorBackground];
37+
38+
export const experimental = []; // 'settings.modifiedItemForeground', 'editorUnnecessary.foreground' ];
39+
40+
suite('Color Registry', function () {
41+
42+
test('all colors documented', async function () {
43+
const reqContext = await request({ url: 'https://raw.githubusercontent.com/Microsoft/vscode-docs/vnext/docs/getstarted/theme-color-reference.md' });
44+
const content = await asText(reqContext);
45+
46+
const expression = /\-\s*\`([\w\.]+)\`: (.*)/g;
47+
48+
let m: RegExpExecArray;
49+
let colorsInDoc: { [id: string]: ColorInfo } = Object.create(null);
50+
while (m = expression.exec(content)) {
51+
colorsInDoc[m[1]] = { description: m[2], offset: m.index, length: m.length };
52+
}
53+
let missing = Object.create(null);
54+
let descriptionDiffs: { [id: string]: DescriptionDiff } = Object.create(null);
55+
56+
let themingRegistry = Registry.as<IColorRegistry>(Extensions.ColorContribution);
57+
for (let color of themingRegistry.getColors()) {
58+
if (!colorsInDoc[color.id]) {
59+
if (!color.deprecationMessage) {
60+
missing[color.id] = getDescription(color);
61+
}
62+
} else {
63+
let docDescription = colorsInDoc[color.id].description;
64+
let specDescription = getDescription(color);
65+
if (docDescription !== specDescription) {
66+
descriptionDiffs[color.id] = { docDescription, specDescription };
67+
}
68+
delete colorsInDoc[color.id];
69+
}
70+
}
71+
let colorsInExtensions = await getColorsFromExtension();
72+
for (let colorId in colorsInExtensions) {
73+
if (!colorsInDoc[colorId]) {
74+
missing[colorId] = colorsInExtensions[colorId];
75+
} else {
76+
delete colorsInDoc[colorId];
77+
}
78+
}
79+
for (let colorId of experimental) {
80+
if (missing[colorId]) {
81+
delete missing[colorId];
82+
}
83+
if (colorsInDoc[colorId]) {
84+
assert.fail(`Color ${colorId} found in doc but marked experimental. Please remove from experimental list.`);
85+
}
86+
}
87+
88+
let undocumentedKeys = Object.keys(missing).map(k => `${k}: ${missing[k]}`);
89+
assert.deepEqual(undocumentedKeys, [], 'Undocumented colors ids');
90+
91+
let superfluousKeys = Object.keys(colorsInDoc);
92+
assert.deepEqual(superfluousKeys, [], 'Colors ids in doc that do not exist');
93+
94+
});
95+
});
96+
97+
function getDescription(color: ColorContribution) {
98+
let specDescription = color.description;
99+
if (color.deprecationMessage) {
100+
specDescription = specDescription + ' ' + color.deprecationMessage;
101+
}
102+
return specDescription;
103+
}
104+
105+
async function getColorsFromExtension(): Promise<{ [id: string]: string }> {
106+
let extPath = require.toUrl('../../../../../../extensions');
107+
let extFolders = await pfs.readDirsInDir(extPath);
108+
let result: { [id: string]: string } = Object.create(null);
109+
for (let folder of extFolders) {
110+
try {
111+
let packageJSON = JSON.parse((await pfs.readFile(path.join(extPath, folder, 'package.json'))).toString());
112+
let contributes = packageJSON['contributes'];
113+
if (contributes) {
114+
let colors = contributes['colors'];
115+
if (colors) {
116+
for (let color of colors) {
117+
let colorId = color['id'];
118+
if (colorId) {
119+
result[colorId] = colorId['description'];
120+
}
121+
}
122+
}
123+
}
124+
} catch (e) {
125+
// ignore
126+
}
127+
128+
}
129+
return result;
130+
}

src/vs/workbench/parts/welcome/page/electron-browser/welcomePage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ export class WelcomeInputFactory implements IEditorInputFactory {
578578

579579
// theming
580580

581-
const buttonBackground = registerColor('welcomePage.buttonBackground', { dark: null, light: null, hc: null }, localize('welcomePage.buttonBackground', 'Background color for the buttons on the Welcome page.'));
582-
const buttonHoverBackground = registerColor('welcomePage.buttonHoverBackground', { dark: null, light: null, hc: null }, localize('welcomePage.buttonHoverBackground', 'Hover background color for the buttons on the Welcome page.'));
581+
export const buttonBackground = registerColor('welcomePage.buttonBackground', { dark: null, light: null, hc: null }, localize('welcomePage.buttonBackground', 'Background color for the buttons on the Welcome page.'));
582+
export const buttonHoverBackground = registerColor('welcomePage.buttonHoverBackground', { dark: null, light: null, hc: null }, localize('welcomePage.buttonHoverBackground', 'Hover background color for the buttons on the Welcome page.'));
583583

584584
registerThemingParticipant((theme, collector) => {
585585
const foregroundColor = theme.getColor(foreground);

src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ export class WalkThroughPart extends BaseEditor {
523523

524524
// theming
525525

526-
const embeddedEditorBackground = registerColor('walkThrough.embeddedEditorBackground', { dark: null, light: null, hc: null }, localize('walkThrough.embeddedEditorBackground', 'Background color for the embedded editors on the Interactive Playground.'));
526+
export const embeddedEditorBackground = registerColor('walkThrough.embeddedEditorBackground', { dark: null, light: null, hc: null }, localize('walkThrough.embeddedEditorBackground', 'Background color for the embedded editors on the Interactive Playground.'));
527527

528528
registerThemingParticipant((theme, collector) => {
529529
const color = getExtraColor(theme, embeddedEditorBackground, { dark: 'rgba(0, 0, 0, .4)', extra_dark: 'rgba(200, 235, 255, .064)', light: 'rgba(0,0,0,.08)', hc: null });

0 commit comments

Comments
 (0)