greybel-mock-environment 2.3.4 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,7 @@ export declare class Device {
54
54
  createUserFolder(userName: string): boolean;
55
55
  isAnyProcessActive(): boolean;
56
56
  isRootProcessActive(): boolean;
57
- addProcess(options: Omit<ProcessOptions, 'pid'>): Device;
57
+ addProcess(options: Omit<ProcessOptions, 'pid'>): number;
58
58
  removeProcess(pid: number): boolean;
59
59
  addGroup(userName: string, groupName: string): boolean;
60
60
  removeGroup(userName: string, groupName: string): boolean;
@@ -67,7 +67,8 @@ var Device = /** @class */ (function () {
67
67
  owner: this.users.get('root'),
68
68
  command: 'kernel_task',
69
69
  protected: true
70
- }).addProcess({
70
+ });
71
+ this.addProcess({
71
72
  owner: this.users.get('root'),
72
73
  command: 'Xorg',
73
74
  protected: true
@@ -252,15 +253,17 @@ var Device = /** @class */ (function () {
252
253
  owner: options.owner,
253
254
  pid: pid,
254
255
  command: options.command,
255
- protected: options.protected
256
+ protected: options.protected,
257
+ ref: options.ref
256
258
  });
257
259
  this.processes.set(pid, process);
258
- return this;
260
+ return pid;
259
261
  };
260
262
  Device.prototype.removeProcess = function (pid) {
261
263
  if (this.processes.has(pid)) {
262
264
  var process_4 = this.processes.get(pid);
263
265
  if (!process_4.protected) {
266
+ process_4.kill();
264
267
  this.processes.delete(pid);
265
268
  return true;
266
269
  }
@@ -1,16 +1,22 @@
1
1
  import { User } from './user';
2
- export declare class ProcessOptions {
2
+ export interface ProcessRef {
3
+ exit(): void;
4
+ }
5
+ export interface ProcessOptions {
3
6
  owner: User;
4
7
  pid: number;
5
8
  command: string;
6
9
  protected?: boolean;
10
+ ref?: ProcessRef;
7
11
  }
8
12
  export declare class Process {
9
- owner: User;
10
- pid: number;
11
- cpu: number;
12
- mem: number;
13
- command: string;
14
- protected: boolean;
13
+ readonly owner: User;
14
+ readonly pid: number;
15
+ readonly cpu: number;
16
+ readonly mem: number;
17
+ readonly command: string;
18
+ readonly protected: boolean;
19
+ readonly ref: ProcessRef | null;
15
20
  constructor(options: ProcessOptions);
21
+ kill(): void;
16
22
  }
@@ -1,22 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Process = exports.ProcessOptions = void 0;
3
+ exports.Process = void 0;
4
4
  var utils_1 = require("../utils");
5
- var ProcessOptions = /** @class */ (function () {
6
- function ProcessOptions() {
7
- }
8
- return ProcessOptions;
9
- }());
10
- exports.ProcessOptions = ProcessOptions;
11
5
  var Process = /** @class */ (function () {
12
6
  function Process(options) {
7
+ var _a;
13
8
  this.owner = options.owner;
14
9
  this.pid = options.pid;
15
10
  this.cpu = (0, utils_1.getRandom)(2, 15);
16
11
  this.mem = (0, utils_1.getRandom)(5, 33);
17
12
  this.command = options.command;
18
13
  this.protected = options.protected;
14
+ this.ref = (_a = options.ref) !== null && _a !== void 0 ? _a : null;
19
15
  }
16
+ Process.prototype.kill = function () {
17
+ if (this.ref !== null) {
18
+ this.ref.exit();
19
+ }
20
+ };
20
21
  return Process;
21
22
  }());
22
23
  exports.Process = Process;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-mock-environment",
3
- "version": "2.3.4",
3
+ "version": "2.4.1",
4
4
  "description": "Mock environment",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",