@thymian/core-testing 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.
Files changed (38) hide show
  1. package/README.md +285 -0
  2. package/dist/factories/http-request.factory.d.ts +40 -0
  3. package/dist/factories/http-request.factory.d.ts.map +1 -0
  4. package/dist/factories/http-request.factory.js +84 -0
  5. package/dist/factories/http-request.factory.js.map +1 -0
  6. package/dist/factories/http-response.factory.d.ts +51 -0
  7. package/dist/factories/http-response.factory.d.ts.map +1 -0
  8. package/dist/factories/http-response.factory.js +109 -0
  9. package/dist/factories/http-response.factory.js.map +1 -0
  10. package/dist/factories/parameter.factory.d.ts +28 -0
  11. package/dist/factories/parameter.factory.d.ts.map +1 -0
  12. package/dist/factories/parameter.factory.js +48 -0
  13. package/dist/factories/parameter.factory.js.map +1 -0
  14. package/dist/factories/schema.factory.d.ts +45 -0
  15. package/dist/factories/schema.factory.d.ts.map +1 -0
  16. package/dist/factories/schema.factory.js +81 -0
  17. package/dist/factories/schema.factory.js.map +1 -0
  18. package/dist/factories/thymian-format.factory.d.ts +46 -0
  19. package/dist/factories/thymian-format.factory.d.ts.map +1 -0
  20. package/dist/factories/thymian-format.factory.js +65 -0
  21. package/dist/factories/thymian-format.factory.js.map +1 -0
  22. package/dist/index.d.ts +40 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +46 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/mocks/emitter.mock.d.ts +71 -0
  27. package/dist/mocks/emitter.mock.d.ts.map +1 -0
  28. package/dist/mocks/emitter.mock.js +101 -0
  29. package/dist/mocks/emitter.mock.js.map +1 -0
  30. package/dist/mocks/logger.mock.d.ts +36 -0
  31. package/dist/mocks/logger.mock.d.ts.map +1 -0
  32. package/dist/mocks/logger.mock.js +74 -0
  33. package/dist/mocks/logger.mock.js.map +1 -0
  34. package/dist/mocks/plugin.mock.d.ts +85 -0
  35. package/dist/mocks/plugin.mock.d.ts.map +1 -0
  36. package/dist/mocks/plugin.mock.js +102 -0
  37. package/dist/mocks/plugin.mock.js.map +1 -0
  38. package/package.json +36 -0
@@ -0,0 +1,85 @@
1
+ import type { ThymianPlugin, ThymianPluginFn } from '@thymian/core';
2
+ /**
3
+ * Creates a mock ThymianPlugin with sensible defaults.
4
+ * All properties can be overridden.
5
+ *
6
+ * @param overrides - Partial plugin to override defaults
7
+ * @returns A complete ThymianPlugin object
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const plugin = createMockPlugin({
12
+ * name: 'test-plugin',
13
+ * plugin: async (emitter, logger, options) => {
14
+ * // Plugin logic
15
+ * }
16
+ * });
17
+ * ```
18
+ */
19
+ export declare function createMockPlugin<Options extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(overrides?: Partial<ThymianPlugin<Options>>): ThymianPlugin<Options>;
20
+ /**
21
+ * Creates a spy plugin function that can be used with createMockPlugin.
22
+ * Useful when you want to test what arguments are passed to the plugin.
23
+ *
24
+ * @param implementation - Optional plugin implementation
25
+ * @returns A spy function compatible with ThymianPluginFn
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const pluginFn = createSpyPluginFn(async (emitter, logger, options) => {
30
+ * logger.info('Plugin started');
31
+ * });
32
+ *
33
+ * const plugin = createMockPlugin({ plugin: pluginFn });
34
+ *
35
+ * await plugin.plugin(emitter, logger, options);
36
+ * expect(pluginFn).toHaveBeenCalledWith(emitter, logger, options);
37
+ * ```
38
+ */
39
+ export declare function createSpyPluginFn<Options extends Record<PropertyKey, unknown> & {
40
+ cwd: string;
41
+ } = {
42
+ cwd: string;
43
+ }>(implementation?: ThymianPluginFn<Options>): ThymianPluginFn<Options>;
44
+ /**
45
+ * Creates a plugin that emits a specific event when executed.
46
+ * Useful for testing event flow between plugins.
47
+ *
48
+ * @param eventName - The event name to emit
49
+ * @param eventData - The event data to emit
50
+ * @param overrides - Additional plugin overrides
51
+ * @returns A ThymianPlugin that emits the specified event
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const plugin = createPluginThatEmits('core.register', {
56
+ * plugin: somePlugin
57
+ * });
58
+ * ```
59
+ */
60
+ export declare function createPluginThatEmits<Options extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(eventName: string, eventData: any, overrides?: Partial<ThymianPlugin<Options>>): ThymianPlugin<Options>;
61
+ /**
62
+ * Creates a plugin with event and action metadata configured.
63
+ * Useful for testing plugin registration and capability declaration.
64
+ *
65
+ * @param config - Plugin configuration including events and actions
66
+ * @returns A ThymianPlugin with metadata
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const plugin = createPluginWithMetadata({
71
+ * name: 'my-plugin',
72
+ * events: {
73
+ * emits: ['core.register'],
74
+ * listensOn: ['core.ready']
75
+ * },
76
+ * actions: {
77
+ * provides: {
78
+ * 'core.load-format': { event: {}, response: {} }
79
+ * }
80
+ * }
81
+ * });
82
+ * ```
83
+ */
84
+ export declare function createPluginWithMetadata<Options extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(config: Partial<ThymianPlugin<Options>>): ThymianPlugin<Options>;
85
+ //# sourceMappingURL=plugin.mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mock.d.ts","sourceRoot":"","sources":["../../src/mocks/plugin.mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGpE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAC3E,SAAS,GAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAazE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAC/D,GAAG,EAAE,MAAM,CAAC;CACb,EACD,cAAc,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAErE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAE3E,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,GAAG,EACd,SAAS,GAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAM,GAC9C,aAAa,CAAC,OAAO,CAAC,CAOxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAC3E,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAEjE"}
@@ -0,0 +1,102 @@
1
+ import { vi } from 'vitest';
2
+ /**
3
+ * Creates a mock ThymianPlugin with sensible defaults.
4
+ * All properties can be overridden.
5
+ *
6
+ * @param overrides - Partial plugin to override defaults
7
+ * @returns A complete ThymianPlugin object
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const plugin = createMockPlugin({
12
+ * name: 'test-plugin',
13
+ * plugin: async (emitter, logger, options) => {
14
+ * // Plugin logic
15
+ * }
16
+ * });
17
+ * ```
18
+ */
19
+ export function createMockPlugin(overrides = {}) {
20
+ const defaultPlugin = vi.fn(async () => {
21
+ // Default no-op plugin
22
+ });
23
+ return {
24
+ name: 'mock-plugin',
25
+ version: '0.0.1',
26
+ plugin: defaultPlugin,
27
+ ...overrides,
28
+ };
29
+ }
30
+ /**
31
+ * Creates a spy plugin function that can be used with createMockPlugin.
32
+ * Useful when you want to test what arguments are passed to the plugin.
33
+ *
34
+ * @param implementation - Optional plugin implementation
35
+ * @returns A spy function compatible with ThymianPluginFn
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const pluginFn = createSpyPluginFn(async (emitter, logger, options) => {
40
+ * logger.info('Plugin started');
41
+ * });
42
+ *
43
+ * const plugin = createMockPlugin({ plugin: pluginFn });
44
+ *
45
+ * await plugin.plugin(emitter, logger, options);
46
+ * expect(pluginFn).toHaveBeenCalledWith(emitter, logger, options);
47
+ * ```
48
+ */
49
+ export function createSpyPluginFn(implementation) {
50
+ return vi.fn(implementation || (() => Promise.resolve()));
51
+ }
52
+ /**
53
+ * Creates a plugin that emits a specific event when executed.
54
+ * Useful for testing event flow between plugins.
55
+ *
56
+ * @param eventName - The event name to emit
57
+ * @param eventData - The event data to emit
58
+ * @param overrides - Additional plugin overrides
59
+ * @returns A ThymianPlugin that emits the specified event
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const plugin = createPluginThatEmits('core.register', {
64
+ * plugin: somePlugin
65
+ * });
66
+ * ```
67
+ */
68
+ export function createPluginThatEmits(eventName, eventData, overrides = {}) {
69
+ return createMockPlugin({
70
+ plugin: async (emitter, logger, options) => {
71
+ await emitter.emit(eventName, eventData);
72
+ },
73
+ ...overrides,
74
+ });
75
+ }
76
+ /**
77
+ * Creates a plugin with event and action metadata configured.
78
+ * Useful for testing plugin registration and capability declaration.
79
+ *
80
+ * @param config - Plugin configuration including events and actions
81
+ * @returns A ThymianPlugin with metadata
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const plugin = createPluginWithMetadata({
86
+ * name: 'my-plugin',
87
+ * events: {
88
+ * emits: ['core.register'],
89
+ * listensOn: ['core.ready']
90
+ * },
91
+ * actions: {
92
+ * provides: {
93
+ * 'core.load-format': { event: {}, response: {} }
94
+ * }
95
+ * }
96
+ * });
97
+ * ```
98
+ */
99
+ export function createPluginWithMetadata(config) {
100
+ return createMockPlugin(config);
101
+ }
102
+ //# sourceMappingURL=plugin.mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mock.js","sourceRoot":"","sources":["../../src/mocks/plugin.mock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAE9B,YAA6C,EAAE;IAC/C,MAAM,aAAa,GAA+C,EAAE,CAAC,EAAE,CACrE,KAAK,IAAI,EAAE;QACT,uBAAuB;IACzB,CAAC,CACF,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,OAAO;QAChB,MAAM,EAAE,aAAa;QACrB,GAAG,SAAS;KACa,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAI/B,cAAyC;IACzC,OAAO,EAAE,CAAC,EAAE,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CAGnC,SAAiB,EACjB,SAAc,EACd,YAA6C,EAAE;IAE/C,OAAO,gBAAgB,CAAU;QAC/B,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;YACzC,MAAM,OAAO,CAAC,IAAI,CAAC,SAAgB,EAAE,SAAS,CAAC,CAAC;QAClD,CAAC;QACD,GAAG,SAAS;KACb,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,wBAAwB,CAEtC,MAAuC;IACvC,OAAO,gBAAgB,CAAU,MAAM,CAAC,CAAC;AAC3C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@thymian/core-testing",
3
+ "version": "0.0.1",
4
+ "publishConfig": {
5
+ "access": "restricted"
6
+ },
7
+ "main": "./dist/index.js",
8
+ "type": "module",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "test": "vitest run",
21
+ "test:watch": "vitest"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "!**/*.tsbuildinfo"
26
+ ],
27
+ "dependencies": {
28
+ "tslib": "^2.3.0"
29
+ },
30
+ "devDependencies": {
31
+ "@thymian/core": "0.0.1"
32
+ },
33
+ "peerDependencies": {
34
+ "@thymian/core": "0.0.1"
35
+ }
36
+ }