@devscholar/node-ps1-dotnet 0.0.1 → 0.0.2

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 CHANGED
@@ -16,18 +16,9 @@ This is a project that mimics the [Node API for .NET](https://github.com/microso
16
16
 
17
17
  Please visit the [node-ps1-dotnet-examples](https://github.com/devscholar/node-ps1-dotnet-examples) repository for working examples.
18
18
 
19
- ## Quick Start with Examples
19
+ # Testing
20
20
 
21
- Clone the examples repository alongside this project:
22
-
23
- ```bash
24
- git clone https://github.com/devscholar/node-ps1-dotnet-examples.git
25
- cd node-ps1-dotnet-examples
26
- npm install
27
- npm run winforms-counter
28
- ```
29
-
30
- For more examples and details, see the [node-ps1-dotnet-examples README](https://github.com/devscholar/node-ps1-dotnet-examples).
21
+ Please visit the [testing.md](docs/testing.md) file for testing instructions.
31
22
 
32
23
  # License
33
24
 
@@ -0,0 +1,24 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ describe('node-ps1-dotnet', () => {
4
+ describe('utils', () => {
5
+ it('should export getPowerShellPath', async () => {
6
+ const { getPowerShellPath } = await import('../src/utils.js');
7
+ expect(typeof getPowerShellPath).toBe('function');
8
+ });
9
+ });
10
+
11
+ describe('ipc', () => {
12
+ it('should export IpcSync class', async () => {
13
+ const { IpcSync } = await import('../src/ipc.js');
14
+ expect(IpcSync).toBeDefined();
15
+ });
16
+ });
17
+
18
+ describe('types', () => {
19
+ it('should export ProtocolResponse type', async () => {
20
+ const types = await import('../src/types.js');
21
+ expect(types).toBeDefined();
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,30 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('Console Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+ let Console: any;
9
+
10
+ beforeAll(async () => {
11
+ try {
12
+ dotnet = await import('../src/index.js');
13
+ System = dotnet.System;
14
+ Console = System.Console;
15
+ } catch (e) {
16
+ console.log('Skipping console tests - load failed:', e);
17
+ }
18
+ });
19
+
20
+ afterAll(() => {
21
+ try {
22
+ dotnet?.node_ps1_dotnet?._close();
23
+ } catch {}
24
+ });
25
+
26
+ it('should access Console class', () => {
27
+ expect(Console).toBeDefined();
28
+ expect(Console.WriteLine).toBeDefined();
29
+ });
30
+ });
@@ -0,0 +1,55 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('Enum Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+
9
+ beforeAll(async () => {
10
+ try {
11
+ dotnet = await import('../src/index.js');
12
+ System = dotnet.System;
13
+ } catch (e) {
14
+ console.log('Skipping enum tests - load failed:', e);
15
+ }
16
+ });
17
+
18
+ afterAll(() => {
19
+ try {
20
+ dotnet?.node_ps1_dotnet?._close();
21
+ } catch {}
22
+ });
23
+
24
+ it('should load System namespace', () => {
25
+ expect(System).toBeDefined();
26
+ });
27
+
28
+ it('should access StringComparison enum', () => {
29
+ const StringComparison = System.StringComparison;
30
+ expect(StringComparison).toBeDefined();
31
+ expect(StringComparison.Ordinal).toBeDefined();
32
+ expect(StringComparison.OrdinalIgnoreCase).toBeDefined();
33
+ });
34
+
35
+ it('should access DateTimeKind enum', () => {
36
+ const DateTimeKind = System.DateTimeKind;
37
+ expect(DateTimeKind).toBeDefined();
38
+ expect(DateTimeKind.Unspecified).toBeDefined();
39
+ expect(DateTimeKind.Utc).toBeDefined();
40
+ expect(DateTimeKind.Local).toBeDefined();
41
+ });
42
+
43
+ it('should access DayOfWeek enum', () => {
44
+ const DayOfWeek = System.DayOfWeek;
45
+ expect(DayOfWeek).toBeDefined();
46
+ expect(DayOfWeek.Sunday).toBeDefined();
47
+ expect(DayOfWeek.Monday).toBeDefined();
48
+ });
49
+
50
+ it('should access StringComparison enum values', () => {
51
+ const StringComparison = System.StringComparison;
52
+ expect(StringComparison.Ordinal).toBeDefined();
53
+ expect(StringComparison.OrdinalIgnoreCase).toBeDefined();
54
+ });
55
+ });
@@ -0,0 +1,57 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('IO Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+ let IO: any;
9
+
10
+ beforeAll(async () => {
11
+ try {
12
+ dotnet = await import('../src/index.js');
13
+ System = dotnet.System;
14
+ IO = System.IO;
15
+ } catch (e) {
16
+ console.log('Skipping IO tests - load failed:', e);
17
+ }
18
+ });
19
+
20
+ afterAll(() => {
21
+ try {
22
+ dotnet?.node_ps1_dotnet?._close();
23
+ } catch {}
24
+ });
25
+
26
+ it('should access Path class', () => {
27
+ const Path = IO.Path;
28
+ expect(Path).toBeDefined();
29
+ expect(Path.Combine).toBeDefined();
30
+ });
31
+
32
+ it('should use Path.Combine', () => {
33
+ const Path = IO.Path;
34
+ const result = Path.Combine('folder', 'file.txt');
35
+ expect(result).toBeDefined();
36
+ expect(typeof result).toBe('string');
37
+ });
38
+
39
+ it('should access File class', () => {
40
+ const File = IO.File;
41
+ expect(File).toBeDefined();
42
+ expect(File.Exists).toBeDefined();
43
+ });
44
+
45
+ it('should access Directory class', () => {
46
+ const Directory = IO.Directory;
47
+ expect(Directory).toBeDefined();
48
+ expect(Directory.Exists).toBeDefined();
49
+ });
50
+
51
+ it('should get current directory', () => {
52
+ const Directory = IO.Directory;
53
+ const cwd = Directory.GetCurrentDirectory();
54
+ expect(cwd).toBeDefined();
55
+ expect(typeof cwd).toBe('string');
56
+ });
57
+ });
@@ -0,0 +1,95 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('String Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+
9
+ beforeAll(async () => {
10
+ try {
11
+ dotnet = await import('../src/index.js');
12
+ System = dotnet.System;
13
+ } catch (e) {
14
+ console.log('Skipping string tests - load failed:', e);
15
+ }
16
+ });
17
+
18
+ afterAll(() => {
19
+ try {
20
+ dotnet?.node_ps1_dotnet?._close();
21
+ } catch {}
22
+ });
23
+
24
+ it('should access String class', () => {
25
+ const String = System.String;
26
+ expect(String).toBeDefined();
27
+ });
28
+ });
29
+
30
+ (isWindows ? describe : describe.skip)('Array Tests', () => {
31
+ let dotnet: any;
32
+ let System: any;
33
+
34
+ beforeAll(async () => {
35
+ try {
36
+ dotnet = await import('../src/index.js');
37
+ System = dotnet.System;
38
+ } catch (e) {
39
+ console.log('Skipping array tests - load failed:', e);
40
+ }
41
+ });
42
+
43
+ afterAll(() => {
44
+ try {
45
+ dotnet?.node_ps1_dotnet?._close();
46
+ } catch {}
47
+ });
48
+
49
+ it('should access Array class', () => {
50
+ const Array = System.Array;
51
+ expect(Array).toBeDefined();
52
+ expect(Array.Reverse).toBeDefined();
53
+ });
54
+ });
55
+
56
+ (isWindows ? describe : describe.skip)('Environment Tests', () => {
57
+ let dotnet: any;
58
+ let System: any;
59
+
60
+ beforeAll(async () => {
61
+ try {
62
+ dotnet = await import('../src/index.js');
63
+ System = dotnet.System;
64
+ } catch (e) {
65
+ console.log('Skipping environment tests - load failed:', e);
66
+ }
67
+ });
68
+
69
+ afterAll(() => {
70
+ try {
71
+ dotnet?.node_ps1_dotnet?._close();
72
+ } catch {}
73
+ });
74
+
75
+ it('should access Environment class', () => {
76
+ const Environment = System.Environment;
77
+ expect(Environment).toBeDefined();
78
+ expect(Environment.ProcessorCount).toBeDefined();
79
+ expect(Environment.CurrentDirectory).toBeDefined();
80
+ });
81
+
82
+ it('should get processor count', () => {
83
+ const Environment = System.Environment;
84
+ const processorCount = Environment.ProcessorCount;
85
+ expect(processorCount).toBeDefined();
86
+ expect(processorCount).toBeGreaterThan(0);
87
+ });
88
+
89
+ it('should get current directory', () => {
90
+ const Environment = System.Environment;
91
+ const cwd = Environment.CurrentDirectory;
92
+ expect(cwd).toBeDefined();
93
+ expect(typeof cwd).toBe('string');
94
+ });
95
+ });
@@ -0,0 +1,99 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('Runtime Info Tests', () => {
6
+ let dotnet: any;
7
+
8
+ beforeAll(async () => {
9
+ try {
10
+ dotnet = await import('../src/index.js');
11
+ } catch (e) {
12
+ console.log('Skipping runtime info tests - load failed:', e);
13
+ }
14
+ });
15
+
16
+ afterAll(() => {
17
+ try {
18
+ dotnet?.node_ps1_dotnet?._close();
19
+ } catch {}
20
+ });
21
+
22
+ it('should get runtime version', () => {
23
+ const version = dotnet.default.runtimeVersion;
24
+ expect(version).toBeDefined();
25
+ expect(typeof version).toBe('string');
26
+ });
27
+
28
+ it('should get framework moniker', () => {
29
+ const moniker = dotnet.default.frameworkMoniker;
30
+ expect(moniker).toBeDefined();
31
+ expect(typeof moniker).toBe('string');
32
+ });
33
+
34
+ it('should access _getRuntimeInfo', () => {
35
+ const info = dotnet.node_ps1_dotnet._getRuntimeInfo();
36
+ expect(info).toBeDefined();
37
+ expect(info.frameworkMoniker).toBeDefined();
38
+ expect(info.runtimeVersion).toBeDefined();
39
+ });
40
+ });
41
+
42
+ (isWindows ? describe : describe.skip)('Type Loading Tests', () => {
43
+ let dotnet: any;
44
+ let System: any;
45
+
46
+ beforeAll(async () => {
47
+ try {
48
+ dotnet = await import('../src/index.js');
49
+ System = dotnet.System;
50
+ } catch (e) {
51
+ console.log('Skipping type loading tests - load failed:', e);
52
+ }
53
+ });
54
+
55
+ afterAll(() => {
56
+ try {
57
+ dotnet?.node_ps1_dotnet?._close();
58
+ } catch {}
59
+ });
60
+
61
+ it('should load System namespace', () => {
62
+ expect(System).toBeDefined();
63
+ });
64
+
65
+ it('should access basic types', () => {
66
+ expect(System.Int32).toBeDefined();
67
+ expect(System.String).toBeDefined();
68
+ expect(System.Boolean).toBeDefined();
69
+ expect(System.Object).toBeDefined();
70
+ });
71
+ });
72
+
73
+ (isWindows ? describe : describe.skip)('Assembly Tests', () => {
74
+ let dotnet: any;
75
+
76
+ beforeAll(async () => {
77
+ try {
78
+ dotnet = await import('../src/index.js');
79
+ } catch (e) {
80
+ console.log('Skipping assembly tests - load failed:', e);
81
+ }
82
+ });
83
+
84
+ afterAll(() => {
85
+ try {
86
+ dotnet?.node_ps1_dotnet?._close();
87
+ } catch {}
88
+ });
89
+
90
+ it('should have default export with load method', () => {
91
+ expect(dotnet.default).toBeDefined();
92
+ expect(typeof dotnet.default.load).toBe('function');
93
+ });
94
+
95
+ it('should have node_ps1_dotnet object', () => {
96
+ expect(dotnet.node_ps1_dotnet).toBeDefined();
97
+ expect(typeof dotnet.node_ps1_dotnet._load).toBe('function');
98
+ });
99
+ });
@@ -0,0 +1,35 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('Task Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+ let Task: any;
9
+
10
+ beforeAll(async () => {
11
+ try {
12
+ dotnet = await import('../src/index.js');
13
+ System = dotnet.System;
14
+ Task = System.Threading.Tasks.Task;
15
+ } catch (e) {
16
+ console.log('Skipping task tests - load failed:', e);
17
+ }
18
+ });
19
+
20
+ afterAll(() => {
21
+ try {
22
+ dotnet?.node_ps1_dotnet?._close();
23
+ } catch {}
24
+ });
25
+
26
+ it('should access Task class', () => {
27
+ expect(Task).toBeDefined();
28
+ expect(Task.Delay).toBeDefined();
29
+ });
30
+
31
+ it('should access Task.CompletedTask', () => {
32
+ const completedTask = Task.CompletedTask;
33
+ expect(completedTask).toBeDefined();
34
+ });
35
+ });
@@ -0,0 +1,147 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ const isWindows = process.platform === 'win32';
4
+
5
+ (isWindows ? describe : describe.skip)('GUI Event Handler Tests', () => {
6
+ let dotnet: any;
7
+ let System: any;
8
+ let Forms: any;
9
+ let Drawing: any;
10
+
11
+ beforeAll(async () => {
12
+ try {
13
+ dotnet = await import('../src/index.js');
14
+ dotnet.default.load('System.Windows.Forms');
15
+ dotnet.default.load('System.Drawing');
16
+ System = dotnet.System;
17
+ Forms = System.Windows.Forms;
18
+ Drawing = System.Drawing;
19
+ } catch (e) {
20
+ console.log('Skipping event handler tests - load failed:', e);
21
+ }
22
+ });
23
+
24
+ afterAll(() => {
25
+ try {
26
+ dotnet?.node_ps1_dotnet?._close();
27
+ } catch {}
28
+ });
29
+
30
+ it('should handle MouseDown event on Panel', () => {
31
+ const panel = new Forms.Panel();
32
+
33
+ let mouseDownTriggered = false;
34
+
35
+ panel.add_MouseDown((sender: any, e: any) => {
36
+ mouseDownTriggered = true;
37
+ });
38
+
39
+ expect(panel).toBeDefined();
40
+ });
41
+
42
+ it('should handle MouseUp event on Panel', () => {
43
+ const panel = new Forms.Panel();
44
+
45
+ panel.add_MouseUp((sender: any, e: any) => {
46
+ console.log('Mouse up');
47
+ });
48
+
49
+ expect(panel).toBeDefined();
50
+ });
51
+
52
+ it('should handle MouseMove event on Panel', () => {
53
+ const panel = new Forms.Panel();
54
+
55
+ panel.add_MouseMove((sender: any, e: any) => {
56
+ console.log('Mouse move');
57
+ });
58
+
59
+ expect(panel).toBeDefined();
60
+ });
61
+
62
+ it('should handle multiple events on same control', () => {
63
+ const button = new Forms.Button();
64
+
65
+ let clickCount = 0;
66
+
67
+ button.add_Click(() => {
68
+ clickCount++;
69
+ });
70
+
71
+ button.add_Click(() => {
72
+ clickCount++;
73
+ });
74
+
75
+ expect(button).toBeDefined();
76
+ });
77
+ });
78
+
79
+ (isWindows ? describe : describe.skip)('GUI Property Binding Tests', () => {
80
+ let dotnet: any;
81
+ let System: any;
82
+ let Forms: any;
83
+ let Drawing: any;
84
+
85
+ beforeAll(async () => {
86
+ try {
87
+ dotnet = await import('../src/index.js');
88
+ dotnet.default.load('System.Windows.Forms');
89
+ dotnet.default.load('System.Drawing');
90
+ System = dotnet.System;
91
+ Forms = System.Windows.Forms;
92
+ Drawing = System.Drawing;
93
+ } catch (e) {
94
+ console.log('Skipping property binding tests - load failed:', e);
95
+ }
96
+ });
97
+
98
+ afterAll(() => {
99
+ try {
100
+ dotnet?.node_ps1_dotnet?._close();
101
+ } catch {}
102
+ });
103
+
104
+ it('should update label text from button click', () => {
105
+ const label = new Forms.Label();
106
+ const button = new Forms.Button();
107
+
108
+ label.Text = 'Initial';
109
+ button.Text = 'Click';
110
+
111
+ button.add_Click(() => {
112
+ label.Text = 'Updated';
113
+ });
114
+
115
+ expect(label.Text).toBe('Initial');
116
+ });
117
+
118
+ it('should set location using Point', () => {
119
+ const label = new Forms.Label();
120
+ const location = new Drawing.Point(100, 50);
121
+
122
+ label.Location = location;
123
+
124
+ expect(label.Location.X).toBe(100);
125
+ expect(label.Location.Y).toBe(50);
126
+ });
127
+
128
+ it('should update control visibility', () => {
129
+ const button = new Forms.Button();
130
+
131
+ button.Visible = false;
132
+ expect(button.Visible).toBe(false);
133
+
134
+ button.Visible = true;
135
+ expect(button.Visible).toBe(true);
136
+ });
137
+
138
+ it('should update control enabled state', () => {
139
+ const button = new Forms.Button();
140
+
141
+ button.Enabled = false;
142
+ expect(button.Enabled).toBe(false);
143
+
144
+ button.Enabled = true;
145
+ expect(button.Enabled).toBe(true);
146
+ });
147
+ });
@@ -0,0 +1,43 @@
1
+ import { jest } from '@jest/globals';
2
+
3
+ describe('IpcSync', () => {
4
+ let IpcSync: any;
5
+ let mockFs: any;
6
+
7
+ beforeAll(async () => {
8
+ const ipcModule = await import('../src/ipc.js');
9
+ IpcSync = ipcModule.IpcSync;
10
+ });
11
+
12
+ beforeEach(() => {
13
+ mockFs = {
14
+ openSync: jest.fn(),
15
+ readSync: jest.fn(),
16
+ closeSync: jest.fn(),
17
+ };
18
+ });
19
+
20
+ it('should create an instance with pipe name and callback', () => {
21
+ const onEvent = jest.fn();
22
+ const ipc = new IpcSync('test_pipe', onEvent);
23
+
24
+ expect(ipc).toBeDefined();
25
+ expect(ipc).toHaveProperty('pipeName', 'test_pipe');
26
+ });
27
+
28
+ it('should have connect, send, and close methods', () => {
29
+ const onEvent = jest.fn();
30
+ const ipc = new IpcSync('test_pipe', onEvent);
31
+
32
+ expect(typeof ipc.connect).toBe('function');
33
+ expect(typeof ipc.send).toBe('function');
34
+ expect(typeof ipc.close).toBe('function');
35
+ });
36
+
37
+ it('should throw error when connecting to nonexistent pipe', () => {
38
+ const onEvent = jest.fn();
39
+ const ipc = new IpcSync('nonexistent_pipe_12345', onEvent);
40
+
41
+ expect(() => ipc.connect()).toThrow();
42
+ });
43
+ });