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