@gjsify/process 0.0.3 → 0.1.0
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.
- package/README.md +27 -2
- package/lib/esm/index.js +430 -4
- package/lib/types/index.d.ts +91 -2
- package/package.json +13 -20
- package/src/extended.spec.ts +214 -0
- package/src/index.spec.ts +429 -19
- package/src/index.ts +481 -3
- package/src/test.mts +2 -1
- package/tsconfig.json +21 -9
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/index.js +0 -6
- package/test.gjs.mjs +0 -34721
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.mjs +0 -308
- package/tsconfig.types.json +0 -8
- package/tsconfig.types.tsbuildinfo +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Ported from refs/node-test/parallel/test-process-*.js
|
|
2
|
+
// Original: MIT license, Node.js contributors
|
|
3
|
+
|
|
4
|
+
import { describe, it, expect } from '@gjsify/unit';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
|
|
7
|
+
export default async () => {
|
|
8
|
+
|
|
9
|
+
// ===================== Signal handling =====================
|
|
10
|
+
await describe('process signal handling', async () => {
|
|
11
|
+
await it('should support registering SIGTERM handler', async () => {
|
|
12
|
+
let handlerCalled = false;
|
|
13
|
+
const handler = () => { handlerCalled = true; };
|
|
14
|
+
process.on('SIGTERM', handler);
|
|
15
|
+
expect(process.listenerCount('SIGTERM')).toBeGreaterThan(0);
|
|
16
|
+
process.removeListener('SIGTERM', handler);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await it('should support registering SIGINT handler', async () => {
|
|
20
|
+
const handler = () => {};
|
|
21
|
+
process.on('SIGINT', handler);
|
|
22
|
+
expect(process.listenerCount('SIGINT')).toBeGreaterThan(0);
|
|
23
|
+
process.removeListener('SIGINT', handler);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// ===================== process.stdout/stderr =====================
|
|
28
|
+
await describe('process.stdout and process.stderr', async () => {
|
|
29
|
+
await it('process.stdout should exist', async () => {
|
|
30
|
+
expect(process.stdout).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await it('process.stderr should exist', async () => {
|
|
34
|
+
expect(process.stderr).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await it('process.stdout should have write method', async () => {
|
|
38
|
+
expect(typeof process.stdout.write).toBe('function');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await it('process.stderr should have write method', async () => {
|
|
42
|
+
expect(typeof process.stderr.write).toBe('function');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ===================== process.stdin =====================
|
|
47
|
+
await describe('process.stdin', async () => {
|
|
48
|
+
await it('should exist', async () => {
|
|
49
|
+
expect(process.stdin).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ===================== process.nextTick ordering =====================
|
|
54
|
+
await describe('process.nextTick ordering', async () => {
|
|
55
|
+
await it('should execute callbacks in FIFO order', async () => {
|
|
56
|
+
const order: number[] = [];
|
|
57
|
+
await new Promise<void>((resolve) => {
|
|
58
|
+
process.nextTick(() => { order.push(1); });
|
|
59
|
+
process.nextTick(() => { order.push(2); });
|
|
60
|
+
process.nextTick(() => {
|
|
61
|
+
order.push(3);
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
expect(order[0]).toBe(1);
|
|
66
|
+
expect(order[1]).toBe(2);
|
|
67
|
+
expect(order[2]).toBe(3);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await it('should pass arguments to callback', async () => {
|
|
71
|
+
const result = await new Promise<string>((resolve) => {
|
|
72
|
+
process.nextTick((a: string, b: string) => {
|
|
73
|
+
resolve(a + b);
|
|
74
|
+
}, 'hello', ' world');
|
|
75
|
+
});
|
|
76
|
+
expect(result).toBe('hello world');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// ===================== process.env deep =====================
|
|
81
|
+
await describe('process.env deep', async () => {
|
|
82
|
+
await it('should support setting and deleting env vars', async () => {
|
|
83
|
+
process.env.TEST_GJSIFY_VAR = 'test_value';
|
|
84
|
+
expect(process.env.TEST_GJSIFY_VAR).toBe('test_value');
|
|
85
|
+
delete process.env.TEST_GJSIFY_VAR;
|
|
86
|
+
expect(process.env.TEST_GJSIFY_VAR).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await it('should coerce non-string values to strings', async () => {
|
|
90
|
+
(process.env as any).TEST_NUM = 42;
|
|
91
|
+
expect(typeof process.env.TEST_NUM).toBe('string');
|
|
92
|
+
expect(process.env.TEST_NUM).toBe('42');
|
|
93
|
+
delete process.env.TEST_NUM;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await it('should enumerate env vars with Object.keys', async () => {
|
|
97
|
+
const keys = Object.keys(process.env);
|
|
98
|
+
expect(keys.length).toBeGreaterThan(0);
|
|
99
|
+
// PATH or HOME should be present
|
|
100
|
+
const hasCommon = keys.includes('PATH') || keys.includes('HOME') || keys.includes('USER');
|
|
101
|
+
expect(hasCommon).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ===================== process.hrtime =====================
|
|
106
|
+
await describe('process.hrtime deep', async () => {
|
|
107
|
+
await it('hrtime should return [seconds, nanoseconds]', async () => {
|
|
108
|
+
const hr = process.hrtime();
|
|
109
|
+
expect(Array.isArray(hr)).toBe(true);
|
|
110
|
+
expect(hr.length).toBe(2);
|
|
111
|
+
expect(typeof hr[0]).toBe('number');
|
|
112
|
+
expect(typeof hr[1]).toBe('number');
|
|
113
|
+
expect(hr[0]).toBeGreaterThan(-1);
|
|
114
|
+
expect(hr[1]).toBeGreaterThan(-1);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await it('hrtime diff should measure elapsed time', async () => {
|
|
118
|
+
const start = process.hrtime();
|
|
119
|
+
// Small busy wait
|
|
120
|
+
let sum = 0;
|
|
121
|
+
for (let i = 0; i < 100000; i++) sum += i;
|
|
122
|
+
const diff = process.hrtime(start);
|
|
123
|
+
expect(diff[0]).toBeGreaterThan(-1);
|
|
124
|
+
// Total nanoseconds should be positive
|
|
125
|
+
const totalNs = diff[0] * 1e9 + diff[1];
|
|
126
|
+
expect(totalNs).toBeGreaterThan(0);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await it('hrtime.bigint should return bigint', async () => {
|
|
130
|
+
const t = process.hrtime.bigint();
|
|
131
|
+
expect(typeof t).toBe('bigint');
|
|
132
|
+
expect(t > 0n).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await it('hrtime.bigint should be monotonic', async () => {
|
|
136
|
+
const a = process.hrtime.bigint();
|
|
137
|
+
const b = process.hrtime.bigint();
|
|
138
|
+
expect(b >= a).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// ===================== process.memoryUsage =====================
|
|
143
|
+
await describe('process.memoryUsage deep', async () => {
|
|
144
|
+
await it('should return object with expected fields', async () => {
|
|
145
|
+
const mem = process.memoryUsage();
|
|
146
|
+
expect(typeof mem).toBe('object');
|
|
147
|
+
expect(typeof mem.rss).toBe('number');
|
|
148
|
+
expect(typeof mem.heapTotal).toBe('number');
|
|
149
|
+
expect(typeof mem.heapUsed).toBe('number');
|
|
150
|
+
expect(typeof mem.external).toBe('number');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
await it('rss should be positive', async () => {
|
|
154
|
+
const mem = process.memoryUsage();
|
|
155
|
+
expect(mem.rss).toBeGreaterThan(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
await it('heapUsed should be less than or equal to heapTotal', async () => {
|
|
159
|
+
const mem = process.memoryUsage();
|
|
160
|
+
expect(mem.heapUsed <= mem.heapTotal).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ===================== process.cpuUsage =====================
|
|
165
|
+
await describe('process.cpuUsage deep', async () => {
|
|
166
|
+
await it('should return user and system times', async () => {
|
|
167
|
+
const usage = process.cpuUsage();
|
|
168
|
+
expect(typeof usage.user).toBe('number');
|
|
169
|
+
expect(typeof usage.system).toBe('number');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await it('should accept previous value for delta', async () => {
|
|
173
|
+
const prev = process.cpuUsage();
|
|
174
|
+
// Do some work
|
|
175
|
+
let sum = 0;
|
|
176
|
+
for (let i = 0; i < 100000; i++) sum += i;
|
|
177
|
+
const delta = process.cpuUsage(prev);
|
|
178
|
+
expect(typeof delta.user).toBe('number');
|
|
179
|
+
expect(typeof delta.system).toBe('number');
|
|
180
|
+
// Delta user time should be non-negative
|
|
181
|
+
expect(delta.user >= 0).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// ===================== process.emitWarning =====================
|
|
186
|
+
await describe('process.emitWarning', async () => {
|
|
187
|
+
await it('should be a function', async () => {
|
|
188
|
+
expect(typeof process.emitWarning).toBe('function');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// ===================== process.versions =====================
|
|
193
|
+
await describe('process.versions deep', async () => {
|
|
194
|
+
await it('should have versions object', async () => {
|
|
195
|
+
expect(typeof process.versions).toBe('object');
|
|
196
|
+
expect(process.versions !== null).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
await it('should have v8 or gjs version', async () => {
|
|
200
|
+
// On Node.js: v8 exists. On GJS: may have gjs or modules
|
|
201
|
+
const hasEngine = process.versions.v8 !== undefined ||
|
|
202
|
+
(process.versions as any).gjs !== undefined ||
|
|
203
|
+
process.versions.modules !== undefined;
|
|
204
|
+
expect(hasEngine).toBe(true);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// ===================== process.config =====================
|
|
209
|
+
await describe('process.config', async () => {
|
|
210
|
+
await it('should be an object', async () => {
|
|
211
|
+
expect(typeof process.config).toBe('object');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
};
|
package/src/index.spec.ts
CHANGED
|
@@ -1,28 +1,438 @@
|
|
|
1
|
+
// Ported from refs/node-test/parallel/ and refs/node/test/parallel/test-process-*.js
|
|
2
|
+
// Original: MIT license, Node.js contributors
|
|
3
|
+
// Additional tests inspired by refs/bun/test/js/node/ and refs/deno/ext/node/polyfills/
|
|
4
|
+
|
|
1
5
|
import { describe, it, expect } from '@gjsify/unit'
|
|
2
6
|
|
|
3
|
-
import process from 'process';
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
import * as os from 'node:os';
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
export default async () => {
|
|
11
|
+
await describe("process: properties", async () => {
|
|
12
|
+
await it("process.arch should be a string", async () => {
|
|
13
|
+
expect(typeof process.arch).toBe("string");
|
|
14
|
+
});
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// case 'env':
|
|
11
|
-
// case 'exit':
|
|
12
|
-
// case 'nextTick':
|
|
13
|
-
// return;
|
|
14
|
-
// }
|
|
15
|
-
// console.log(key, typeof process[key] === 'function' ? process[key]() : process[key]);
|
|
16
|
-
// });
|
|
16
|
+
await it("process.platform should be a string", async () => {
|
|
17
|
+
expect(typeof process.platform).toBe("string");
|
|
18
|
+
});
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
await it("process.pid should be a number", async () => {
|
|
21
|
+
expect(typeof process.pid).toBe("number");
|
|
22
|
+
});
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
await it("process.pid should be a positive integer", async () => {
|
|
25
|
+
expect(process.pid > 0).toBeTruthy();
|
|
26
|
+
expect(Number.isInteger(process.pid)).toBeTruthy();
|
|
27
|
+
});
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
await it("process.ppid should be a positive integer", async () => {
|
|
30
|
+
expect(process.ppid > 0).toBeTruthy();
|
|
31
|
+
expect(Number.isInteger(process.ppid)).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await it("process.version should be a string starting with v", async () => {
|
|
35
|
+
expect(typeof process.version).toBe("string");
|
|
36
|
+
expect(process.version[0]).toBe("v");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await it("process.version should match semver pattern", async () => {
|
|
40
|
+
expect(process.version).toMatch(/^v\d+/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await it("process.versions should be an object", async () => {
|
|
44
|
+
expect(typeof process.versions).toBe("object");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
await it("process.argv should be an array", async () => {
|
|
48
|
+
expect(Array.isArray(process.argv)).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await it("process.argv should have at least 1 element", async () => {
|
|
52
|
+
expect(process.argv.length >= 1).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await it("process.argv first element should be a string", async () => {
|
|
56
|
+
expect(typeof process.argv[0]).toBe("string");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await it("process.env should be an object", async () => {
|
|
60
|
+
expect(typeof process.env).toBe("object");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await it("process.execPath should be a string", async () => {
|
|
64
|
+
expect(typeof process.execPath).toBe("string");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await it("process.execPath should be a non-empty string", async () => {
|
|
68
|
+
expect(process.execPath.length > 0).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await it("process.platform should be a known platform", async () => {
|
|
72
|
+
const knownPlatforms = ['aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', 'win32'];
|
|
73
|
+
expect(knownPlatforms).toContain(process.platform);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await it("process.arch should be a known architecture", async () => {
|
|
77
|
+
const knownArchs = ['arm', 'arm64', 'ia32', 'loong64', 'mips', 'mipsel', 'ppc', 'ppc64', 'riscv64', 's390', 's390x', 'x64'];
|
|
78
|
+
expect(knownArchs).toContain(process.arch);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await it("process.config should be an object", async () => {
|
|
82
|
+
expect(typeof process.config).toBe("object");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await it("process.execArgv should be an array", async () => {
|
|
86
|
+
expect(Array.isArray(process.execArgv)).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await it("process.argv0 should be a string", async () => {
|
|
90
|
+
expect(typeof process.argv0).toBe("string");
|
|
91
|
+
expect(process.argv0.length > 0).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await describe("process: methods", async () => {
|
|
96
|
+
await it("process.cwd() should return a string", async () => {
|
|
97
|
+
expect(typeof process.cwd()).toBe("string");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await it("process.cwd() should return an absolute path", async () => {
|
|
101
|
+
const cwd = process.cwd();
|
|
102
|
+
expect(cwd[0]).toBe("/");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await it("process.cwd() should return a path containing /", async () => {
|
|
106
|
+
const cwd = process.cwd();
|
|
107
|
+
expect(cwd).toContain("/");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await it("process.uptime() should return a number", async () => {
|
|
111
|
+
expect(typeof process.uptime()).toBe("number");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
await it("process.uptime() should be >= 0", async () => {
|
|
115
|
+
expect(process.uptime() >= 0).toBeTruthy();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
await it("process.uptime() should increase over time", async () => {
|
|
119
|
+
const a = process.uptime();
|
|
120
|
+
const b = process.uptime();
|
|
121
|
+
expect(b >= a).toBeTruthy();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await it("process.hrtime() should return an array of 2 numbers", async () => {
|
|
125
|
+
const hr = process.hrtime();
|
|
126
|
+
expect(Array.isArray(hr)).toBeTruthy();
|
|
127
|
+
expect(hr.length).toBe(2);
|
|
128
|
+
expect(typeof hr[0]).toBe("number");
|
|
129
|
+
expect(typeof hr[1]).toBe("number");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await it("process.hrtime() should return non-negative values", async () => {
|
|
133
|
+
const hr = process.hrtime();
|
|
134
|
+
expect(hr[0] >= 0).toBeTruthy();
|
|
135
|
+
expect(hr[1] >= 0).toBeTruthy();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
await it("process.hrtime() nanoseconds should be less than 1e9", async () => {
|
|
139
|
+
const hr = process.hrtime();
|
|
140
|
+
expect(hr[1] < 1e9).toBeTruthy();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
await it("process.memoryUsage() should return an object", async () => {
|
|
144
|
+
const mem = process.memoryUsage();
|
|
145
|
+
expect(typeof mem).toBe("object");
|
|
146
|
+
expect(typeof mem.rss).toBe("number");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
await it("process.memoryUsage() should have heapTotal and heapUsed", async () => {
|
|
150
|
+
const mem = process.memoryUsage();
|
|
151
|
+
expect(typeof mem.heapTotal).toBe("number");
|
|
152
|
+
expect(typeof mem.heapUsed).toBe("number");
|
|
153
|
+
expect(typeof mem.external).toBe("number");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
await it("process.memoryUsage() rss should be positive", async () => {
|
|
157
|
+
const mem = process.memoryUsage();
|
|
158
|
+
expect(mem.rss > 0).toBeTruthy();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await it("process.nextTick should be a function", async () => {
|
|
162
|
+
expect(typeof process.nextTick).toBe("function");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await it("process.nextTick should execute callback", async () => {
|
|
166
|
+
let called = false;
|
|
167
|
+
process.nextTick(() => { called = true; });
|
|
168
|
+
// Wait for microtask
|
|
169
|
+
await new Promise<void>(resolve => {
|
|
170
|
+
process.nextTick(resolve);
|
|
171
|
+
});
|
|
172
|
+
expect(called).toBeTruthy();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await it("process.nextTick should pass arguments", async () => {
|
|
176
|
+
const result = await new Promise<string>(resolve => {
|
|
177
|
+
process.nextTick((a: string, b: string) => resolve(a + b), 'hello', ' world');
|
|
178
|
+
});
|
|
179
|
+
expect(result).toBe('hello world');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await it("process.nextTick ordering: first scheduled runs first", async () => {
|
|
183
|
+
const order: number[] = [];
|
|
184
|
+
await new Promise<void>(resolve => {
|
|
185
|
+
process.nextTick(() => { order.push(1); });
|
|
186
|
+
process.nextTick(() => { order.push(2); });
|
|
187
|
+
process.nextTick(() => {
|
|
188
|
+
order.push(3);
|
|
189
|
+
resolve();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
expect(order.length).toBe(3);
|
|
193
|
+
expect(order[0]).toBe(1);
|
|
194
|
+
expect(order[1]).toBe(2);
|
|
195
|
+
expect(order[2]).toBe(3);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
await it("process.exit should be a function", async () => {
|
|
199
|
+
expect(typeof process.exit).toBe("function");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await it("process.kill should be a function", async () => {
|
|
203
|
+
expect(typeof process.kill).toBe("function");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await it("process.abort should be a function", async () => {
|
|
207
|
+
expect(typeof process.abort).toBe("function");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await it("process.umask should be a function", async () => {
|
|
211
|
+
expect(typeof process.umask).toBe("function");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
await it("process.cpuUsage should be a function", async () => {
|
|
215
|
+
expect(typeof process.cpuUsage).toBe("function");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await it("process.cpuUsage() should return user and system", async () => {
|
|
219
|
+
const usage = process.cpuUsage();
|
|
220
|
+
expect(typeof usage.user).toBe("number");
|
|
221
|
+
expect(typeof usage.system).toBe("number");
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ==================== env ====================
|
|
226
|
+
|
|
227
|
+
await describe("process: env manipulation", async () => {
|
|
228
|
+
await it("should set and get env variables", async () => {
|
|
229
|
+
process.env.TEST_GJSIFY_VAR = 'test_value';
|
|
230
|
+
expect(process.env.TEST_GJSIFY_VAR).toBe('test_value');
|
|
231
|
+
delete process.env.TEST_GJSIFY_VAR;
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
await it("should delete env variables", async () => {
|
|
235
|
+
process.env.TEST_GJSIFY_DELETE = 'to_delete';
|
|
236
|
+
delete process.env.TEST_GJSIFY_DELETE;
|
|
237
|
+
expect(process.env.TEST_GJSIFY_DELETE).toBeUndefined();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await it("should coerce values to strings", async () => {
|
|
241
|
+
process.env.TEST_GJSIFY_NUM = '42';
|
|
242
|
+
expect(typeof process.env.TEST_GJSIFY_NUM).toBe('string');
|
|
243
|
+
delete process.env.TEST_GJSIFY_NUM;
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
await it("PATH should be defined", async () => {
|
|
247
|
+
expect(typeof process.env.PATH).toBe('string');
|
|
248
|
+
expect(process.env.PATH!.length > 0).toBeTruthy();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
await it("should enumerate keys with Object.keys()", async () => {
|
|
252
|
+
const keys = Object.keys(process.env);
|
|
253
|
+
expect(Array.isArray(keys)).toBeTruthy();
|
|
254
|
+
expect(keys.length > 0).toBeTruthy();
|
|
255
|
+
expect(keys).toContain('PATH');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
await it("non-existent key should return undefined", async () => {
|
|
259
|
+
expect(process.env.THIS_VAR_DOES_NOT_EXIST_GJSIFY_XYZ).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
await it("should overwrite existing value", async () => {
|
|
263
|
+
process.env.TEST_GJSIFY_OVERWRITE = 'first';
|
|
264
|
+
expect(process.env.TEST_GJSIFY_OVERWRITE).toBe('first');
|
|
265
|
+
process.env.TEST_GJSIFY_OVERWRITE = 'second';
|
|
266
|
+
expect(process.env.TEST_GJSIFY_OVERWRITE).toBe('second');
|
|
267
|
+
delete process.env.TEST_GJSIFY_OVERWRITE;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
await it("HOME should match os.homedir()", async () => {
|
|
271
|
+
const home = process.env.HOME;
|
|
272
|
+
expect(home).toBeDefined();
|
|
273
|
+
expect(home).toBe(os.homedir());
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// ==================== hrtime.bigint ====================
|
|
278
|
+
|
|
279
|
+
await describe("process: hrtime.bigint", async () => {
|
|
280
|
+
await it("should be a function", async () => {
|
|
281
|
+
expect(typeof process.hrtime.bigint).toBe('function');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
await it("should return a bigint", async () => {
|
|
285
|
+
const result = process.hrtime.bigint();
|
|
286
|
+
expect(typeof result).toBe('bigint');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
await it("should be monotonically increasing", async () => {
|
|
290
|
+
const a = process.hrtime.bigint();
|
|
291
|
+
const b = process.hrtime.bigint();
|
|
292
|
+
expect(b >= a).toBeTruthy();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
await it("consecutive calls should increase", async () => {
|
|
296
|
+
const first = process.hrtime.bigint();
|
|
297
|
+
// Do a tiny bit of work
|
|
298
|
+
let sum = 0;
|
|
299
|
+
for (let i = 0; i < 1000; i++) sum += i;
|
|
300
|
+
const second = process.hrtime.bigint();
|
|
301
|
+
expect(second > first).toBeTruthy();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// ==================== hrtime diff ====================
|
|
306
|
+
|
|
307
|
+
await describe("process: hrtime diff", async () => {
|
|
308
|
+
await it("should return diff when passed previous hrtime", async () => {
|
|
309
|
+
const start = process.hrtime();
|
|
310
|
+
const diff = process.hrtime(start);
|
|
311
|
+
expect(Array.isArray(diff)).toBeTruthy();
|
|
312
|
+
expect(diff.length).toBe(2);
|
|
313
|
+
expect(diff[0] >= 0).toBeTruthy();
|
|
314
|
+
expect(diff[1] >= 0).toBeTruthy();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await it("diff nanoseconds should be less than 1e9", async () => {
|
|
318
|
+
const start = process.hrtime();
|
|
319
|
+
const diff = process.hrtime(start);
|
|
320
|
+
expect(diff[1] < 1e9).toBeTruthy();
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// ==================== additional properties ====================
|
|
325
|
+
|
|
326
|
+
await describe("process: additional properties", async () => {
|
|
327
|
+
await it("process.ppid should be a number", async () => {
|
|
328
|
+
expect(typeof process.ppid).toBe("number");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
await it("process.exitCode should be settable", async () => {
|
|
332
|
+
const orig = process.exitCode;
|
|
333
|
+
process.exitCode = 42;
|
|
334
|
+
expect(process.exitCode).toBe(42);
|
|
335
|
+
process.exitCode = orig as any;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
await it("process.title should be a string", async () => {
|
|
339
|
+
expect(typeof process.title).toBe("string");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
await it("process.title should be non-empty", async () => {
|
|
343
|
+
expect(process.title.length > 0).toBeTruthy();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
await it("process.stdout should be defined", async () => {
|
|
347
|
+
expect(process.stdout).toBeDefined();
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
await it("process.stderr should be defined", async () => {
|
|
351
|
+
expect(process.stderr).toBeDefined();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
await it("process.stdin should be defined", async () => {
|
|
355
|
+
expect(process.stdin).toBeDefined();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
await it("process.stdout should have write method", async () => {
|
|
359
|
+
expect(typeof process.stdout.write).toBe("function");
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
await it("process.stderr should have write method", async () => {
|
|
363
|
+
expect(typeof process.stderr.write).toBe("function");
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
await it("process.versions should contain a runtime version string", async () => {
|
|
367
|
+
// On Node.js: process.versions.node, on GJS: process.versions.gjs
|
|
368
|
+
const hasNodeVersion = typeof process.versions.node === 'string';
|
|
369
|
+
const hasGjsVersion = typeof process.versions.gjs === 'string';
|
|
370
|
+
expect(hasNodeVersion || hasGjsVersion).toBe(true);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// ==================== chdir ====================
|
|
375
|
+
|
|
376
|
+
await describe("process: chdir", async () => {
|
|
377
|
+
await it("should change and restore directory", async () => {
|
|
378
|
+
const original = process.cwd();
|
|
379
|
+
process.chdir('/tmp');
|
|
380
|
+
expect(process.cwd()).toBe('/tmp');
|
|
381
|
+
process.chdir(original);
|
|
382
|
+
expect(process.cwd()).toBe(original);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
await it("chdir to non-existent dir should throw", async () => {
|
|
386
|
+
const fn = () => process.chdir('/this/path/does/not/exist/gjsify');
|
|
387
|
+
expect(fn).toThrow();
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// ==================== emitWarning ====================
|
|
392
|
+
|
|
393
|
+
await describe("process: emitWarning", async () => {
|
|
394
|
+
await it("should be a function", async () => {
|
|
395
|
+
expect(typeof process.emitWarning).toBe("function");
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// ==================== EventEmitter interface ====================
|
|
400
|
+
|
|
401
|
+
await describe("process: EventEmitter", async () => {
|
|
402
|
+
await it("should have on method", async () => {
|
|
403
|
+
expect(typeof process.on).toBe("function");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
await it("should have emit method", async () => {
|
|
407
|
+
expect(typeof process.emit).toBe("function");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
await it("should have removeListener method", async () => {
|
|
411
|
+
expect(typeof process.removeListener).toBe("function");
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
await it("should have once method", async () => {
|
|
415
|
+
expect(typeof process.once).toBe("function");
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
await it("should have removeAllListeners method", async () => {
|
|
419
|
+
expect(typeof process.removeAllListeners).toBe("function");
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
await it("should be able to register exit listener", async () => {
|
|
423
|
+
const handler = () => {};
|
|
424
|
+
process.on('exit', handler);
|
|
425
|
+
// Should not throw — just register
|
|
426
|
+
process.removeListener('exit', handler);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
await it("should emit and receive custom events", async () => {
|
|
430
|
+
let received = false;
|
|
431
|
+
const handler = () => { received = true; };
|
|
432
|
+
process.on('test-custom-event', handler);
|
|
433
|
+
process.emit('test-custom-event');
|
|
434
|
+
expect(received).toBeTruthy();
|
|
435
|
+
process.removeListener('test-custom-event', handler);
|
|
26
436
|
});
|
|
27
437
|
});
|
|
28
|
-
};
|
|
438
|
+
};
|