• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockProcess() {
19  const process = {
20    runCmd: function (...args) {
21      console.warn("process.runCmd interface mocked in the Previewer. How this interface works on the Previewer" +
22        " may be different from that on a real device.")
23      return ChildProcessMock;
24    },
25    abort: function (...args) {
26      console.warn("process.abort interface mocked in the Previewer. How this interface works on the Previewer" +
27        " may be different from that on a real device.")
28    },
29    on: function (...args) {
30      console.warn("process.on interface mocked in the Previewer. How this interface works on the Previewer" +
31        " may be different from that on a real device.")
32    },
33    off: function (...args) {
34      console.warn("process.off interface mocked in the Previewer. How this interface works on the Previewer" +
35        " may be different from that on a real device.")
36      return paramMock.paramBooleanMock;
37    },
38    exit: function (...args) {
39      console.warn("process.exit interface mocked in the Previewer. How this interface works on the Previewer" +
40        " may be different from that on a real device.")
41    },
42    cwd: function (...args) {
43      console.warn("process.cwd interface mocked in the Previewer. How this interface works on the Previewer" +
44        " may be different from that on a real device.")
45      return paramMock.paramStringMock;
46    },
47    chdir: function (...args) {
48      console.warn("process.chdir interface mocked in the Previewer. How this interface works on the Previewer" +
49        " may be different from that on a real device.")
50    },
51    uptime: function (...args) {
52      console.warn("process.uptime interface mocked in the Previewer. How this interface works on the Previewer" +
53        " may be different from that on a real device.")
54      return paramMock.paramNumberMock;
55    },
56    kill: function (...args) {
57      console.warn("process.kill interface mocked in the Previewer. How this interface works on the Previewer" +
58        " may be different from that on a real device.")
59      return paramMock.paramBooleanMock;
60    },
61    getStartRealtime: function (...args) {
62      console.warn("process.getStartRealtime interface mocked in the Previewer. How this interface works on the Previewer" +
63        " may be different from that on a real device.")
64      return paramMock.paramNumberMock;
65    },
66    getPastCputime: function (...args) {
67      console.warn("process.getPastCputime interface mocked in the Previewer. How this interface works on the Previewer" +
68        " may be different from that on a real device.")
69      return paramMock.paramNumberMock;
70    },
71    getAvailableCores: function (...args) {
72      console.warn("process.getAvailableCores interface mocked in the Previewer. How this interface works on the Previewer" +
73        " may be different from that on a real device.")
74      return paramMock.paramArrayMock;
75    },
76    isIsolatedProcess: function (...args) {
77      console.warn("process.isIsolatedProcess interface mocked in the Previewer. How this interface works on the Previewer" +
78        " may be different from that on a real device.")
79      return paramMock.paramBooleanMock;
80    },
81    is64Bit: function (...args) {
82      console.warn("process.is64Bit interface mocked in the Previewer. How this interface works on the Previewer" +
83        " may be different from that on a real device.")
84      return paramMock.paramBooleanMock;
85    },
86    isAppUid: function (...args) {
87      console.warn("process.isAppUid interface mocked in the Previewer. How this interface works on the Previewer" +
88        " may be different from that on a real device.")
89      return paramMock.paramBooleanMock;
90    },
91    getUidForName: function (...args) {
92      console.warn("process.getUidForName interface mocked in the Previewer. How this interface works on the Previewer" +
93        " may be different from that on a real device.")
94      return paramMock.paramNumberMock;
95    },
96    getThreadPriority: function (...args) {
97      console.warn("process.getThreadPriority interface mocked in the Previewer. How this interface works on the Previewer" +
98        " may be different from that on a real device.")
99      return paramMock.paramNumberMock;
100    },
101    getSystemConfig: function (...args) {
102      console.warn("process.getSystemConfig interface mocked in the Previewer. How this interface works on the Previewer" +
103        " may be different from that on a real device.")
104      return paramMock.paramNumberMock;
105    },
106    getEnvironmentVar: function (...args) {
107      console.warn("process.getEnvironmentVar interface mocked in the Previewer. How this interface works on the Previewer" +
108        " may be different from that on a real device.")
109      return paramMock.paramStringMock;
110    },
111    egid: '[PC preview] unknow egid',
112    euid: '[PC preview] unknow euid',
113    gid: '[PC preview] unknow gid',
114    uid: '[PC preview] unknow uid',
115    groups: '[PC preview] unknow groups',
116    pid: '[PC preview] unknow pid',
117    ppid: '[PC preview] unknow ppid',
118    tid: '[PC preview] unknow tid',
119  }
120
121  const ChildProcessMock = {
122    pid: '[PC preview] unknow pid',
123    ppid: '[PC preview] unknow ppid',
124    exitCode: '[PC preview] unknow exitCode',
125    killed: '[PC preview] unknow killed',
126    wait: function (...args) {
127      console.warn("ChildProcess.wait interface mocked in the Previewer. How this interface works on the Previewer" +
128        " may be different from that on a real device.")
129      return new Promise((resolve, reject) => {
130        resolve(paramMock.paramNumberMock);
131      })
132    },
133    getOutput: function (...args) {
134      console.warn("ChildProcess.getOutput interface mocked in the Previewer. How this interface works on the Previewer" +
135        " may be different from that on a real device.")
136      const arr = new Uint8Array()
137      return new Promise((resolve, reject) => {
138        resolve(arr);
139      })
140    },
141    getErrorOutput: function (...args) {
142      console.warn("ChildProcess.getErrorOutput interface mocked in the Previewer. How this interface works on the Previewer" +
143        " may be different from that on a real device.")
144      const arr = new Uint8Array()
145      return new Promise((resolve, reject) => {
146        resolve(arr);
147      })
148    },
149    close: function (...args) {
150      console.warn("ChildProcess.close interface mocked in the Previewer. How this interface works on the Previewer" +
151        " may be different from that on a real device.")
152    },
153    kill: function (...args) {
154      console.warn("ChildProcess.kill interface mocked in the Previewer. How this interface works on the Previewer" +
155        " may be different from that on a real device.")
156    }
157  }
158  return process;
159}
160