@equinor/fusion-framework 8.0.14 → 8.1.0-next.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +198 -0
  2. package/README.md +30 -0
  3. package/dist/esm/__tests__/mock/application-module.test.js +53 -0
  4. package/dist/esm/__tests__/mock/application-module.test.js.map +1 -0
  5. package/dist/esm/__tests__/mock/documented-usage.test.js +73 -0
  6. package/dist/esm/__tests__/mock/documented-usage.test.js.map +1 -0
  7. package/dist/esm/__tests__/mock/mock-framework.test.js +212 -0
  8. package/dist/esm/__tests__/mock/mock-framework.test.js.map +1 -0
  9. package/dist/esm/init.js +7 -2
  10. package/dist/esm/init.js.map +1 -1
  11. package/dist/esm/mock/FrameworkMockConfigurator.js +233 -0
  12. package/dist/esm/mock/FrameworkMockConfigurator.js.map +1 -0
  13. package/dist/esm/mock/index.js +32 -0
  14. package/dist/esm/mock/index.js.map +1 -0
  15. package/dist/esm/mock/mock-framework.js +55 -0
  16. package/dist/esm/mock/mock-framework.js.map +1 -0
  17. package/dist/esm/version.js +1 -1
  18. package/dist/esm/version.js.map +1 -1
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/dist/types/__tests__/mock/application-module.test.d.ts +1 -0
  21. package/dist/types/__tests__/mock/documented-usage.test.d.ts +1 -0
  22. package/dist/types/__tests__/mock/mock-framework.test.d.ts +1 -0
  23. package/dist/types/mock/FrameworkMockConfigurator.d.ts +185 -0
  24. package/dist/types/mock/index.d.ts +29 -0
  25. package/dist/types/mock/mock-framework.d.ts +58 -0
  26. package/dist/types/version.d.ts +1 -1
  27. package/docs/testing-api.md +25 -0
  28. package/docs/testing-choosing-a-layer.md +90 -0
  29. package/docs/testing-design.md +63 -0
  30. package/docs/testing-extending.md +102 -0
  31. package/docs/testing.md +178 -0
  32. package/package.json +17 -11
  33. package/src/__tests__/mock/application-module.test.ts +87 -0
  34. package/src/__tests__/mock/documented-usage.test.ts +98 -0
  35. package/src/__tests__/mock/mock-framework.test.ts +278 -0
  36. package/src/init.ts +7 -2
  37. package/src/mock/FrameworkMockConfigurator.ts +270 -0
  38. package/src/mock/index.ts +62 -0
  39. package/src/mock/mock-framework.ts +72 -0
  40. package/src/version.ts +1 -1
  41. package/vitest.config.ts +1 -1
@@ -0,0 +1,72 @@
1
+ import type { AnyModule } from '@equinor/fusion-framework-module';
2
+
3
+ import { init } from '../init.js';
4
+ import type { Fusion } from '../types.js';
5
+
6
+ import { FrameworkMockConfigurator } from './FrameworkMockConfigurator.js';
7
+
8
+ /**
9
+ * Configures a mocked framework before it is initialized.
10
+ *
11
+ * @typeParam TModules - Module descriptors beyond the built-in set.
12
+ * @param configurator - The configurator to configure.
13
+ */
14
+ export type FrameworkMockConfigureFn<TModules extends Array<AnyModule> = []> = (
15
+ configurator: FrameworkMockConfigurator<TModules>,
16
+ ) => void | Promise<void>;
17
+
18
+ /**
19
+ * Starts a Fusion framework instance that needs no credentials and no network.
20
+ *
21
+ * @remarks
22
+ * The real framework is started: the real module set, the real configuration
23
+ * pipeline and the real lifecycle. Only the boundaries that would need
24
+ * credentials or network access are substituted, so a test exercises the wiring
25
+ * an application actually depends on rather than a reimplementation of it.
26
+ *
27
+ * The configurator passed to `configure` is a {@link FrameworkMockConfigurator},
28
+ * which *is* a `FrameworkConfigurator`. Every `enableX` helper therefore accepts
29
+ * it unchanged — including the ones an application team writes for their own
30
+ * modules.
31
+ *
32
+ * Spying on individual calls is left to the test runner. The framework makes the
33
+ * runtime substitutable; `vi.spyOn`, `bun:test` `spyOn` and `t.mock.method` all
34
+ * work against the resulting instance with no framework support.
35
+ *
36
+ * @typeParam TModules - Module descriptors beyond the built-in set. Supply this
37
+ * when a test registers application modules, so they are typed on the result.
38
+ * @template TModules - Module descriptors beyond the built-in set.
39
+ * @param configure - Callback that configures the framework before it starts.
40
+ * @returns The initialized framework instance.
41
+ *
42
+ * @example Zero configuration
43
+ * ```typescript
44
+ * const fusion = await mockFramework();
45
+ * ```
46
+ *
47
+ * @example Configure the built-in mocks
48
+ * ```typescript
49
+ * const fusion = await mockFramework((configurator) => {
50
+ * configurator.msal.setAccount({ name: 'Ada Lovelace' });
51
+ * configurator.serviceDiscovery.setBaseUri('http://localhost:6669');
52
+ * });
53
+ * ```
54
+ *
55
+ * @example Register an application module
56
+ * ```typescript
57
+ * const fusion = await mockFramework<[InvoiceModule]>((configurator) => {
58
+ * enableInvoicesMock(configurator, { total: 42 });
59
+ * });
60
+ *
61
+ * await fusion.modules.invoices.getInvoice('1');
62
+ * ```
63
+ */
64
+ export async function mockFramework<TModules extends Array<AnyModule> = []>(
65
+ configure?: FrameworkMockConfigureFn<TModules>,
66
+ ): Promise<Fusion<TModules>> {
67
+ const configurator = new FrameworkMockConfigurator<TModules>();
68
+ await configure?.(configurator);
69
+ return await init(configurator);
70
+ }
71
+
72
+ export default mockFramework;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '8.0.14';
2
+ export const version = '8.1.0-next.0';
package/vitest.config.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineProject } from 'vitest/config';
2
2
 
3
- import { name, version } from './package.json';
3
+ import { name, version } from './package.json' with { type: 'json' };
4
4
 
5
5
  export default defineProject({
6
6
  test: {