@gjsify/process 0.4.0 → 0.4.3

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/src/index.spec.ts DELETED
@@ -1,454 +0,0 @@
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
-
5
- import { describe, it, expect } from '@gjsify/unit'
6
-
7
- import process from 'node:process';
8
- import * as os from 'node:os';
9
-
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
- });
15
-
16
- await it("process.platform should be a string", async () => {
17
- expect(typeof process.platform).toBe("string");
18
- });
19
-
20
- await it("process.pid should be a number", async () => {
21
- expect(typeof process.pid).toBe("number");
22
- });
23
-
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
- });
28
-
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
- // Regression: process.nextTick must be deferred (not run synchronously).
199
- // On GJS, it should route through GLib idle (not microtask queue) so that
200
- // GTK input events (PRIORITY_DEFAULT = 0) can interleave between nextTick
201
- // callbacks (PRIORITY_HIGH_IDLE = 100), preventing window freezes.
202
- await it("process.nextTick is deferred, not synchronous", async () => {
203
- let ranSynchronously = false;
204
- let ranInNextTick = false;
205
- process.nextTick(() => { ranInNextTick = true; });
206
- // This line runs before the nextTick callback fires
207
- ranSynchronously = !ranInNextTick;
208
- // Wait for the nextTick callback
209
- await new Promise<void>(resolve => process.nextTick(resolve));
210
- expect(ranSynchronously).toBeTruthy();
211
- expect(ranInNextTick).toBeTruthy();
212
- });
213
-
214
- await it("process.exit should be a function", async () => {
215
- expect(typeof process.exit).toBe("function");
216
- });
217
-
218
- await it("process.kill should be a function", async () => {
219
- expect(typeof process.kill).toBe("function");
220
- });
221
-
222
- await it("process.abort should be a function", async () => {
223
- expect(typeof process.abort).toBe("function");
224
- });
225
-
226
- await it("process.umask should be a function", async () => {
227
- expect(typeof process.umask).toBe("function");
228
- });
229
-
230
- await it("process.cpuUsage should be a function", async () => {
231
- expect(typeof process.cpuUsage).toBe("function");
232
- });
233
-
234
- await it("process.cpuUsage() should return user and system", async () => {
235
- const usage = process.cpuUsage();
236
- expect(typeof usage.user).toBe("number");
237
- expect(typeof usage.system).toBe("number");
238
- });
239
- });
240
-
241
- // ==================== env ====================
242
-
243
- await describe("process: env manipulation", async () => {
244
- await it("should set and get env variables", async () => {
245
- process.env.TEST_GJSIFY_VAR = 'test_value';
246
- expect(process.env.TEST_GJSIFY_VAR).toBe('test_value');
247
- delete process.env.TEST_GJSIFY_VAR;
248
- });
249
-
250
- await it("should delete env variables", async () => {
251
- process.env.TEST_GJSIFY_DELETE = 'to_delete';
252
- delete process.env.TEST_GJSIFY_DELETE;
253
- expect(process.env.TEST_GJSIFY_DELETE).toBeUndefined();
254
- });
255
-
256
- await it("should coerce values to strings", async () => {
257
- process.env.TEST_GJSIFY_NUM = '42';
258
- expect(typeof process.env.TEST_GJSIFY_NUM).toBe('string');
259
- delete process.env.TEST_GJSIFY_NUM;
260
- });
261
-
262
- await it("PATH should be defined", async () => {
263
- expect(typeof process.env.PATH).toBe('string');
264
- expect(process.env.PATH!.length > 0).toBeTruthy();
265
- });
266
-
267
- await it("should enumerate keys with Object.keys()", async () => {
268
- const keys = Object.keys(process.env);
269
- expect(Array.isArray(keys)).toBeTruthy();
270
- expect(keys.length > 0).toBeTruthy();
271
- expect(keys).toContain('PATH');
272
- });
273
-
274
- await it("non-existent key should return undefined", async () => {
275
- expect(process.env.THIS_VAR_DOES_NOT_EXIST_GJSIFY_XYZ).toBeUndefined();
276
- });
277
-
278
- await it("should overwrite existing value", async () => {
279
- process.env.TEST_GJSIFY_OVERWRITE = 'first';
280
- expect(process.env.TEST_GJSIFY_OVERWRITE).toBe('first');
281
- process.env.TEST_GJSIFY_OVERWRITE = 'second';
282
- expect(process.env.TEST_GJSIFY_OVERWRITE).toBe('second');
283
- delete process.env.TEST_GJSIFY_OVERWRITE;
284
- });
285
-
286
- await it("HOME should match os.homedir()", async () => {
287
- const home = process.env.HOME;
288
- expect(home).toBeDefined();
289
- expect(home).toBe(os.homedir());
290
- });
291
- });
292
-
293
- // ==================== hrtime.bigint ====================
294
-
295
- await describe("process: hrtime.bigint", async () => {
296
- await it("should be a function", async () => {
297
- expect(typeof process.hrtime.bigint).toBe('function');
298
- });
299
-
300
- await it("should return a bigint", async () => {
301
- const result = process.hrtime.bigint();
302
- expect(typeof result).toBe('bigint');
303
- });
304
-
305
- await it("should be monotonically increasing", async () => {
306
- const a = process.hrtime.bigint();
307
- const b = process.hrtime.bigint();
308
- expect(b >= a).toBeTruthy();
309
- });
310
-
311
- await it("consecutive calls should increase", async () => {
312
- const first = process.hrtime.bigint();
313
- // Do a tiny bit of work
314
- let sum = 0;
315
- for (let i = 0; i < 1000; i++) sum += i;
316
- const second = process.hrtime.bigint();
317
- expect(second > first).toBeTruthy();
318
- });
319
- });
320
-
321
- // ==================== hrtime diff ====================
322
-
323
- await describe("process: hrtime diff", async () => {
324
- await it("should return diff when passed previous hrtime", async () => {
325
- const start = process.hrtime();
326
- const diff = process.hrtime(start);
327
- expect(Array.isArray(diff)).toBeTruthy();
328
- expect(diff.length).toBe(2);
329
- expect(diff[0] >= 0).toBeTruthy();
330
- expect(diff[1] >= 0).toBeTruthy();
331
- });
332
-
333
- await it("diff nanoseconds should be less than 1e9", async () => {
334
- const start = process.hrtime();
335
- const diff = process.hrtime(start);
336
- expect(diff[1] < 1e9).toBeTruthy();
337
- });
338
- });
339
-
340
- // ==================== additional properties ====================
341
-
342
- await describe("process: additional properties", async () => {
343
- await it("process.ppid should be a number", async () => {
344
- expect(typeof process.ppid).toBe("number");
345
- });
346
-
347
- await it("process.exitCode should be settable", async () => {
348
- const orig = process.exitCode;
349
- process.exitCode = 42;
350
- expect(process.exitCode).toBe(42);
351
- process.exitCode = orig as any;
352
- });
353
-
354
- await it("process.title should be a string", async () => {
355
- expect(typeof process.title).toBe("string");
356
- });
357
-
358
- await it("process.title should be non-empty", async () => {
359
- expect(process.title.length > 0).toBeTruthy();
360
- });
361
-
362
- await it("process.stdout should be defined", async () => {
363
- expect(process.stdout).toBeDefined();
364
- });
365
-
366
- await it("process.stderr should be defined", async () => {
367
- expect(process.stderr).toBeDefined();
368
- });
369
-
370
- await it("process.stdin should be defined", async () => {
371
- expect(process.stdin).toBeDefined();
372
- });
373
-
374
- await it("process.stdout should have write method", async () => {
375
- expect(typeof process.stdout.write).toBe("function");
376
- });
377
-
378
- await it("process.stderr should have write method", async () => {
379
- expect(typeof process.stderr.write).toBe("function");
380
- });
381
-
382
- await it("process.versions should contain a runtime version string", async () => {
383
- // On Node.js: process.versions.node, on GJS: process.versions.gjs
384
- const hasNodeVersion = typeof process.versions.node === 'string';
385
- const hasGjsVersion = typeof process.versions.gjs === 'string';
386
- expect(hasNodeVersion || hasGjsVersion).toBe(true);
387
- });
388
- });
389
-
390
- // ==================== chdir ====================
391
-
392
- await describe("process: chdir", async () => {
393
- await it("should change and restore directory", async () => {
394
- const original = process.cwd();
395
- process.chdir('/tmp');
396
- expect(process.cwd()).toBe('/tmp');
397
- process.chdir(original);
398
- expect(process.cwd()).toBe(original);
399
- });
400
-
401
- await it("chdir to non-existent dir should throw", async () => {
402
- const fn = () => process.chdir('/this/path/does/not/exist/gjsify');
403
- expect(fn).toThrow();
404
- });
405
- });
406
-
407
- // ==================== emitWarning ====================
408
-
409
- await describe("process: emitWarning", async () => {
410
- await it("should be a function", async () => {
411
- expect(typeof process.emitWarning).toBe("function");
412
- });
413
- });
414
-
415
- // ==================== EventEmitter interface ====================
416
-
417
- await describe("process: EventEmitter", async () => {
418
- await it("should have on method", async () => {
419
- expect(typeof process.on).toBe("function");
420
- });
421
-
422
- await it("should have emit method", async () => {
423
- expect(typeof process.emit).toBe("function");
424
- });
425
-
426
- await it("should have removeListener method", async () => {
427
- expect(typeof process.removeListener).toBe("function");
428
- });
429
-
430
- await it("should have once method", async () => {
431
- expect(typeof process.once).toBe("function");
432
- });
433
-
434
- await it("should have removeAllListeners method", async () => {
435
- expect(typeof process.removeAllListeners).toBe("function");
436
- });
437
-
438
- await it("should be able to register exit listener", async () => {
439
- const handler = () => {};
440
- process.on('exit', handler);
441
- // Should not throw — just register
442
- process.removeListener('exit', handler);
443
- });
444
-
445
- await it("should emit and receive custom events", async () => {
446
- let received = false;
447
- const handler = () => { received = true; };
448
- process.on('test-custom-event', handler);
449
- process.emit('test-custom-event');
450
- expect(received).toBeTruthy();
451
- process.removeListener('test-custom-event', handler);
452
- });
453
- });
454
- };