@flancer32/teq-web 0.3.0 → 0.4.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.
@@ -1,112 +0,0 @@
1
- import {describe, it, beforeEach} from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import {buildTestContainer} from '../common.js';
4
-
5
- describe('Fl32_Web_Back_Server (mocked)', () => {
6
-
7
- /** @type {import('@teqfw/di').Container} */
8
- let container;
9
- /** @type {Array<*>} */
10
- const log = [];
11
-
12
- // Mocks for HTTP/1 and HTTP/2 servers
13
- const mockHttp = {
14
- createServer: () => ({
15
- listen: () => { log.push('http.listen'); },
16
- on: () => { log.push('http.on'); },
17
- close: (cb) => { log.push('http.close'); cb && cb(); },
18
- }),
19
- };
20
-
21
- const mockHttp2 = {
22
- createServer: () => ({
23
- listen: () => { log.push('http2.listen'); },
24
- on: () => { log.push('http2.on'); },
25
- close: (cb) => { log.push('http2.close'); cb && cb(); },
26
- }),
27
- createSecureServer: (tlsOpts) => ({
28
- listen: () => { log.push('http2s.listen'); },
29
- on: () => { log.push('http2s.on'); },
30
- close: (cb) => { log.push('http2s.close'); cb && cb(); },
31
- })
32
- };
33
-
34
- beforeEach(() => {
35
- log.length = 0;
36
- container = buildTestContainer();
37
-
38
- container.register('node:http', mockHttp);
39
- container.register('node:http2', mockHttp2);
40
-
41
- container.register('Fl32_Web_Back_Logger$', {
42
- info: (...args) => log.push(['info', ...args]),
43
- error: (...args) => log.push(['error', ...args]),
44
- });
45
-
46
- container.register('Fl32_Web_Back_Dispatcher$', {
47
- orderHandlers: () => log.push('dispatcher.orderHandlers'),
48
- onEventRequest: () => {},
49
- });
50
- });
51
-
52
- it('should start in HTTP/1 mode by default', async () => {
53
- const server = await container.get('Fl32_Web_Back_Server$');
54
- await server.start(); // default mode is HTTP/1
55
- assert.deepStrictEqual(log, [
56
- 'dispatcher.orderHandlers',
57
- ['info', 'Starting server in HTTP/1 mode on port 3000...'],
58
- 'http.on',
59
- 'http.listen',
60
- ]);
61
- });
62
-
63
- it('should start in HTTP/2 mode if specified', async () => {
64
- const server = await container.get('Fl32_Web_Back_Server$');
65
- await server.start({type: 'http2', port: 8080});
66
- assert.deepStrictEqual(log, [
67
- 'dispatcher.orderHandlers',
68
- ['info', 'Starting server in HTTP/2 mode on port 8080...'],
69
- 'http2.on',
70
- 'http2.listen',
71
- ]);
72
- });
73
-
74
- it('should start in HTTPS/2 mode with TLS config', async () => {
75
- const server = await container.get('Fl32_Web_Back_Server$');
76
- await server.start({type: 'https', port: 8443, tls: {key: 'a', cert: 'b'}});
77
- assert.deepStrictEqual(log, [
78
- 'dispatcher.orderHandlers',
79
- ['info', 'Starting server in HTTPS (HTTP/2 + TLS) mode on port 8443...'],
80
- 'http2s.on',
81
- 'http2s.listen',
82
- ]);
83
- });
84
-
85
- it('should throw error if TLS config is missing in HTTPS mode', async () => {
86
- const server = await container.get('Fl32_Web_Back_Server$');
87
- await assert.rejects(
88
- () => server.start({type: 'https', port: 1234}),
89
- /TLS key and certificate are required/
90
- );
91
- assert.deepStrictEqual(log.at(-1), ['error', 'HTTPS server requires TLS key and certificate']);
92
- });
93
-
94
- it('should throw error on unsupported server type', async () => {
95
- const server = await container.get('Fl32_Web_Back_Server$');
96
- await assert.rejects(
97
- () => server.start({type: 'ftp', port: 21}),
98
- /not supported/
99
- );
100
- assert.deepStrictEqual(log.at(-1), ['error', 'Unsupported server type: ftp']);
101
- });
102
-
103
- it('should stop the server', async () => {
104
- const server = await container.get('Fl32_Web_Back_Server$');
105
- await server.start();
106
- await server.stop();
107
- assert.deepStrictEqual(log.slice(-2), [
108
- 'http.close',
109
- ['info', 'Server stopped'],
110
- ]);
111
- });
112
- });
@@ -1,22 +0,0 @@
1
- /**
2
- * Provides a utility to create a configured TeqFW DI container for unit testing.
3
- */
4
- import path from 'node:path';
5
- import Container from '@teqfw/di';
6
-
7
- // Resolve the plugin source path relative to this script
8
- const SRC = path.resolve(import.meta.dirname, '../../src');
9
-
10
- /**
11
- * Builds a test DI container for unit tests.
12
- * Registers plugin namespace and enables test mode.
13
- *
14
- * @returns {TeqFw_Di_Container} Test container instance.
15
- */
16
- export function buildTestContainer() {
17
- const container = new Container();
18
- const resolver = container.getResolver();
19
- resolver.addNamespaceRoot('Fl32_Web_', SRC);
20
- container.enableTestMode();
21
- return container;
22
- }