@bsb/tests 0.0.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.
- package/README.md +7 -0
- package/bin/bsb-tests.cjs +376 -0
- package/docs/index.md +101 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/mocks.d.ts +39 -0
- package/lib/mocks.js +191 -0
- package/lib/mocks.js.map +1 -0
- package/lib/plugins/config-default/index.d.ts +27 -0
- package/lib/plugins/config-default/index.js +172 -0
- package/lib/plugins/config-default/index.js.map +1 -0
- package/lib/plugins/events-default/index.d.ts +27 -0
- package/lib/plugins/events-default/index.js +143 -0
- package/lib/plugins/events-default/index.js.map +1 -0
- package/lib/plugins/logging-default/index.d.ts +27 -0
- package/lib/plugins/logging-default/index.js +390 -0
- package/lib/plugins/logging-default/index.js.map +1 -0
- package/lib/plugins/observable-default/index.d.ts +27 -0
- package/lib/plugins/observable-default/index.js +166 -0
- package/lib/plugins/observable-default/index.js.map +1 -0
- package/lib/runner/plugin-custom.d.ts +1 -0
- package/lib/runner/plugin-custom.js +119 -0
- package/lib/runner/plugin-custom.js.map +1 -0
- package/lib/runner/plugin-events.d.ts +1 -0
- package/lib/runner/plugin-events.js +37 -0
- package/lib/runner/plugin-events.js.map +1 -0
- package/lib/runner/plugin-observable.d.ts +1 -0
- package/lib/runner/plugin-observable.js +22 -0
- package/lib/runner/plugin-observable.js.map +1 -0
- package/lib/runner/setup.d.ts +1 -0
- package/lib/runner/setup.js +19 -0
- package/lib/runner/setup.js.map +1 -0
- package/lib/sb/plugins/events/broadcast.d.ts +30 -0
- package/lib/sb/plugins/events/broadcast.js +390 -0
- package/lib/sb/plugins/events/broadcast.js.map +1 -0
- package/lib/sb/plugins/events/emit.d.ts +30 -0
- package/lib/sb/plugins/events/emit.js +386 -0
- package/lib/sb/plugins/events/emit.js.map +1 -0
- package/lib/sb/plugins/events/emitAndReturn.d.ts +30 -0
- package/lib/sb/plugins/events/emitAndReturn.js +415 -0
- package/lib/sb/plugins/events/emitAndReturn.js.map +1 -0
- package/lib/sb/plugins/events/emitStreamAndReceiveStream.d.ts +30 -0
- package/lib/sb/plugins/events/emitStreamAndReceiveStream.js +331 -0
- package/lib/sb/plugins/events/emitStreamAndReceiveStream.js.map +1 -0
- package/lib/sb/plugins/events/index.d.ts +28 -0
- package/lib/sb/plugins/events/index.js +69 -0
- package/lib/sb/plugins/events/index.js.map +1 -0
- package/lib/sb/plugins/events/plugin.d.ts +0 -0
- package/lib/sb/plugins/events/plugin.js +2 -0
- package/lib/sb/plugins/events/plugin.js.map +1 -0
- package/lib/sb/plugins/observable/index.d.ts +28 -0
- package/lib/sb/plugins/observable/index.js +141 -0
- package/lib/sb/plugins/observable/index.js.map +1 -0
- package/lib/trace.d.ts +40 -0
- package/lib/trace.js +85 -0
- package/lib/trace.js.map +1 -0
- package/package.json +51 -0
package/lib/trace.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { DTrace, Observable } from "@bsb/base";
|
|
28
|
+
/**
|
|
29
|
+
* @hidden
|
|
30
|
+
*/
|
|
31
|
+
export declare function createFakeDTrace(trace?: string, span?: string): DTrace;
|
|
32
|
+
/**
|
|
33
|
+
* Create a test Observable with minimal setup for testing
|
|
34
|
+
* @param trace - Optional trace ID (default: 'test-trace')
|
|
35
|
+
* @param span - Optional span ID (default: 'test-span')
|
|
36
|
+
* @param pluginName - Optional plugin name (default: 'test-plugin')
|
|
37
|
+
* @returns Observable for testing
|
|
38
|
+
* @hidden
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTestObservable(trace?: string, span?: string, pluginName?: string): Observable;
|
package/lib/trace.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.createFakeDTrace = createFakeDTrace;
|
|
30
|
+
exports.createTestObservable = createTestObservable;
|
|
31
|
+
const base_1 = require("@bsb/base");
|
|
32
|
+
/**
|
|
33
|
+
* @hidden
|
|
34
|
+
*/
|
|
35
|
+
function createFakeDTrace(trace, span) {
|
|
36
|
+
return {
|
|
37
|
+
t: trace ?? '',
|
|
38
|
+
s: span ?? '',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a test Observable with minimal setup for testing
|
|
43
|
+
* @param trace - Optional trace ID (default: 'test-trace')
|
|
44
|
+
* @param span - Optional span ID (default: 'test-span')
|
|
45
|
+
* @param pluginName - Optional plugin name (default: 'test-plugin')
|
|
46
|
+
* @returns Observable for testing
|
|
47
|
+
* @hidden
|
|
48
|
+
*/
|
|
49
|
+
function createTestObservable(trace, span, pluginName = 'test-plugin') {
|
|
50
|
+
const dTrace = createFakeDTrace(trace ?? 'test-trace', span ?? 'test-span');
|
|
51
|
+
// Create minimal resource context
|
|
52
|
+
const resource = {
|
|
53
|
+
'service.name': pluginName,
|
|
54
|
+
'service.version': '1.0.0-test',
|
|
55
|
+
'service.instance.id': 'test-instance',
|
|
56
|
+
'deployment.environment': 'test',
|
|
57
|
+
};
|
|
58
|
+
// Create stub unified backend - will be replaced by mocks in tests
|
|
59
|
+
const backend = {
|
|
60
|
+
// Logging methods
|
|
61
|
+
debug: () => { },
|
|
62
|
+
info: () => { },
|
|
63
|
+
warn: () => { },
|
|
64
|
+
error: () => { },
|
|
65
|
+
// Metrics methods
|
|
66
|
+
createCounter: () => ({ increment: () => { } }),
|
|
67
|
+
createGauge: () => ({ set: () => { }, increment: () => { }, decrement: () => { } }),
|
|
68
|
+
createHistogram: () => ({ record: () => { } }),
|
|
69
|
+
createTimer: () => ({ stop: () => 0 }),
|
|
70
|
+
createTrace: (name, attrs) => ({
|
|
71
|
+
id: 'test-trace-id',
|
|
72
|
+
trace: createFakeDTrace('test-trace', 'test-span'),
|
|
73
|
+
error: () => { },
|
|
74
|
+
end: () => { }
|
|
75
|
+
}),
|
|
76
|
+
createSpan: (parentTrace, name, attrs) => ({
|
|
77
|
+
id: 'child-span-' + name,
|
|
78
|
+
trace: createFakeDTrace(parentTrace.t, 'child-span-' + name), // Preserve parent trace ID
|
|
79
|
+
error: () => { },
|
|
80
|
+
end: () => { }
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
return new base_1.PluginObservable(dTrace, resource, backend, {});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=trace.js.map
|
package/lib/trace.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAOH,4CAKC;AAUD,oDA+CC;AAnED,oCAAqG;AAErG;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc,EAAE,IAAa;IAC5D,OAAO;QACL,CAAC,EAAE,KAAK,IAAI,EAAE;QACd,CAAC,EAAE,IAAI,IAAI,EAAE;KACd,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,KAAc,EACd,IAAa,EACb,aAAqB,aAAa;IAElC,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,IAAI,YAAY,EAAE,IAAI,IAAI,WA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AAI;YACxB,KAAK,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC,EAAE,2BAA2B;YACzF,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;YACf,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;SACd,CAAC;KACI,CAAC;IAET,OAAO,IAAI,uBAAgB,CACzB,MAAM,EACN,QAAQ,EACR,OAAO,EACP,EAAE,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bsb/tests",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Shared test suites for BSB Node.js core and plugins",
|
|
5
|
+
"license": "(AGPL-3.0-only OR Commercial)",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "BetterCorp (PTY) Ltd",
|
|
8
|
+
"email": "ninja@bettercorp.dev",
|
|
9
|
+
"url": "https://bettercorp.dev/"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/BetterCorp/better-service-base.git",
|
|
14
|
+
"directory": "tests/nodejs"
|
|
15
|
+
},
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"types": "lib/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/**/*",
|
|
20
|
+
"lib/**/*",
|
|
21
|
+
"README.md",
|
|
22
|
+
"docs/**/*"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "rimraf lib",
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"test": "mocha --config .mocharc.cjs",
|
|
28
|
+
"cli": "node ./bin/bsb-tests.cjs"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@bsb/base": "^9.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/mocha": "^10.0.6",
|
|
35
|
+
"@types/node": "^25.0.0",
|
|
36
|
+
"mocha": "^12.0.0-beta-9.6",
|
|
37
|
+
"rimraf": "^6.1.2",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=23.0.0",
|
|
43
|
+
"npm": ">=11.0.0"
|
|
44
|
+
},
|
|
45
|
+
"bin": {
|
|
46
|
+
"bsb-tests": "bin/bsb-tests.cjs"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|