UNPKG

2.04 kBPlain TextView Raw
1// *****************************************************************************
2// Copyright (C) 2018 Ericsson and others.
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License v. 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0.
7//
8// This Source Code may also be made available under the following Secondary
9// Licenses when the conditions for such availability set forth in the Eclipse
10// Public License v. 2.0 are satisfied: GNU General Public License, version 2
11// with the GNU Classpath Exception which is available at
12// https://www.gnu.org/software/classpath/license.html.
13//
14// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15// *****************************************************************************
16
17import { Emitter } from '../../../common';
18import { PreferenceChange } from '../preference-service';
19
20/* eslint-disable @typescript-eslint/no-explicit-any */
21export function createMockPreferenceProxy(preferences: { [p: string]: any }): any {
22 const unsupportedOperation = (_: any, __: string) => {
23 throw new Error('Unsupported operation');
24 };
25 return new Proxy({}, {
26 get: (_, property: string) => {
27 if (property === 'onPreferenceChanged') {
28 return new Emitter<PreferenceChange>().event;
29 }
30 if (property === 'dispose') {
31 return () => { };
32 }
33 if (property === 'ready') {
34 return Promise.resolve();
35 }
36 // eslint-disable-next-line no-null/no-null
37 if (preferences[property] !== undefined && preferences[property] !== null) {
38 return preferences[property];
39 }
40 return undefined;
41 },
42 ownKeys: () => [],
43 getOwnPropertyDescriptor: (_, property: string) => ({}),
44 set: unsupportedOperation,
45 deleteProperty: unsupportedOperation,
46 defineProperty: unsupportedOperation
47 });
48}