1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const jsdom_1 = require("../test/jsdom");
|
19 | let disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
20 | const assert = require("assert");
|
21 | const inversify_1 = require("inversify");
|
22 | const frontend_application_bindings_1 = require("../frontend-application-bindings");
|
23 | const preference_contribution_1 = require("./preference-contribution");
|
24 | const frontend_application_config_provider_1 = require("../frontend-application-config-provider");
|
25 | disableJSDOM();
|
26 | process.on('unhandledRejection', (reason, promise) => {
|
27 | console.error(reason);
|
28 | throw reason;
|
29 | });
|
30 |
|
31 | let testContainer;
|
32 | function createTestContainer() {
|
33 | const result = new inversify_1.Container();
|
34 | (0, frontend_application_bindings_1.bindPreferenceService)(result.bind.bind(result));
|
35 | return result;
|
36 | }
|
37 | const EDITOR_FONT_SIZE_PROPERTIES = {
|
38 | 'editor.fontSize': {
|
39 | type: 'number',
|
40 | default: 14,
|
41 | overridable: true
|
42 | },
|
43 | };
|
44 | const EDITOR_INSERT_SPACES_PROPERTIES = {
|
45 | 'editor.insertSpaces': {
|
46 | type: 'boolean',
|
47 | default: true,
|
48 | overridable: true
|
49 | },
|
50 | };
|
51 | describe('Preference Schema Provider', () => {
|
52 | let prefSchema;
|
53 | before(() => {
|
54 | disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
55 | frontend_application_config_provider_1.FrontendApplicationConfigProvider.set({
|
56 | preferences: {
|
57 | 'editor.fontSize': 20,
|
58 | '[typescript]': { 'editor.fontSize': 24 }
|
59 | }
|
60 | });
|
61 | });
|
62 | after(() => {
|
63 | disableJSDOM();
|
64 | });
|
65 | beforeEach(async () => {
|
66 | testContainer = createTestContainer();
|
67 | prefSchema = testContainer.get(preference_contribution_1.PreferenceSchemaProvider);
|
68 | });
|
69 | it('Should load all preferences specified in the frontend config.', () => {
|
70 | assert.strictEqual(prefSchema.get('editor.fontSize'), 20);
|
71 | assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
|
72 | });
|
73 | it('Should favor the default specified in the package.json over a default registered by a schema', () => {
|
74 | prefSchema.setSchema({
|
75 | properties: {
|
76 | ...EDITOR_FONT_SIZE_PROPERTIES
|
77 | }
|
78 | });
|
79 | assert.strictEqual(prefSchema.get('editor.fontSize'), 20);
|
80 | });
|
81 | it('Should merge language-specific overrides from schemas and the package.json', () => {
|
82 | prefSchema.setSchema({
|
83 | properties: {
|
84 | ...EDITOR_FONT_SIZE_PROPERTIES,
|
85 | ...EDITOR_INSERT_SPACES_PROPERTIES,
|
86 | '[typescript]': {
|
87 | type: 'object',
|
88 | default: {
|
89 | 'editor.insertSpaces': false
|
90 | }
|
91 | }
|
92 | }
|
93 | });
|
94 | assert.strictEqual(prefSchema.get('editor.insertSpaces'), true);
|
95 | assert.strictEqual(prefSchema.get('[typescript].editor.insertSpaces'), false);
|
96 | assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
|
97 | });
|
98 | it('Should favor package.json specifications in the merge process', () => {
|
99 | prefSchema.setSchema({
|
100 | properties: {
|
101 | ...EDITOR_FONT_SIZE_PROPERTIES,
|
102 | ...EDITOR_INSERT_SPACES_PROPERTIES,
|
103 | '[typescript]': {
|
104 | type: 'object',
|
105 | default: {
|
106 | 'editor.insertSpaces': false,
|
107 | 'editor.fontSize': 36,
|
108 | }
|
109 | }
|
110 | }
|
111 | });
|
112 | assert.strictEqual(prefSchema.get('[typescript].editor.insertSpaces'), false);
|
113 | assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
|
114 | });
|
115 | });
|
116 |
|
\ | No newline at end of file |