@furystack/shades-mfe 1.0.27 → 1.0.28

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.28] - 2026-02-01
4
+
5
+ ### ⬆️ Dependencies
6
+
7
+ - Updated peer dependency `@furystack/shades` to include new CSS styling features
8
+
3
9
  ## [1.0.27] - 2026-01-26
4
10
 
5
11
  ### 🔧 Chores
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-shades-micro-frontend.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-shades-micro-frontend.spec.d.ts","sourceRoot":"","sources":["../src/create-shades-micro-frontend.spec.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,129 @@
1
+ import { Injector } from '@furystack/inject';
2
+ import { createComponent, Shade } from '@furystack/shades';
3
+ import { sleepAsync } from '@furystack/utils';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { CreateMicroFrontendService } from './create-microfrontend-service.js';
6
+ import { createShadesMicroFrontend } from './create-shades-micro-frontend.js';
7
+ describe('createShadesMicroFrontend', () => {
8
+ beforeEach(() => {
9
+ document.body.innerHTML = '<div id="root"></div>';
10
+ });
11
+ afterEach(() => {
12
+ document.body.innerHTML = '';
13
+ });
14
+ it('should return a CreateMicroFrontendService instance', () => {
15
+ const TestComponent = Shade({
16
+ shadowDomName: 'test-mfe-return-type',
17
+ render: ({ props }) => createComponent("div", null, props.value),
18
+ });
19
+ const result = createShadesMicroFrontend(TestComponent);
20
+ expect(result).toBeInstanceOf(CreateMicroFrontendService);
21
+ expect(result.create).toBeTypeOf('function');
22
+ expect(result.destroy).toBeUndefined();
23
+ });
24
+ it('should create a child injector when create is called', () => {
25
+ const TestComponent = Shade({
26
+ shadowDomName: 'test-mfe-child-injector',
27
+ render: ({ props }) => createComponent("div", null, props.value),
28
+ });
29
+ const parentInjector = new Injector();
30
+ const createChildSpy = vi.spyOn(parentInjector, 'createChild');
31
+ const mfeService = createShadesMicroFrontend(TestComponent);
32
+ const rootElement = document.getElementById('root');
33
+ mfeService.create({
34
+ api: { value: 'test' },
35
+ rootElement,
36
+ injector: parentInjector,
37
+ });
38
+ expect(createChildSpy).toHaveBeenCalledWith({
39
+ owner: createShadesMicroFrontend,
40
+ });
41
+ });
42
+ it('should render the component with the provided API props', async () => {
43
+ const testValue = crypto.randomUUID();
44
+ const TestComponent = Shade({
45
+ shadowDomName: 'test-mfe-render-props',
46
+ render: ({ props }) => createComponent("div", { "data-testid": "content" },
47
+ "Value: ",
48
+ props.value),
49
+ });
50
+ const injector = new Injector();
51
+ const rootElement = document.getElementById('root');
52
+ const mfeService = createShadesMicroFrontend(TestComponent);
53
+ mfeService.create({
54
+ api: { value: testValue },
55
+ rootElement,
56
+ injector,
57
+ });
58
+ await sleepAsync(10);
59
+ expect(rootElement.innerHTML).toContain(`Value: ${testValue}`);
60
+ });
61
+ it('should render the component into the provided root element', async () => {
62
+ const TestComponent = Shade({
63
+ shadowDomName: 'test-mfe-root-element',
64
+ render: () => createComponent("span", null, "MFE Content"),
65
+ });
66
+ const injector = new Injector();
67
+ const rootElement = document.getElementById('root');
68
+ const mfeService = createShadesMicroFrontend(TestComponent);
69
+ mfeService.create({
70
+ api: {},
71
+ rootElement,
72
+ injector,
73
+ });
74
+ await sleepAsync(10);
75
+ expect(rootElement.querySelector('test-mfe-root-element')).toBeTruthy();
76
+ expect(rootElement.innerHTML).toContain('MFE Content');
77
+ });
78
+ it('should work with complex API types', async () => {
79
+ const clickHandler = vi.fn();
80
+ const TestComponent = Shade({
81
+ shadowDomName: 'test-mfe-complex-api',
82
+ render: ({ props }) => (createComponent("div", null,
83
+ createComponent("span", { "data-testid": "user-name" }, props.user.name),
84
+ createComponent("span", { "data-testid": "item-count" }, props.items.length),
85
+ createComponent("button", { onclick: props.onClick }, "Click"))),
86
+ });
87
+ const injector = new Injector();
88
+ const rootElement = document.getElementById('root');
89
+ const mfeService = createShadesMicroFrontend(TestComponent);
90
+ mfeService.create({
91
+ api: {
92
+ user: { id: '123', name: 'John Doe' },
93
+ onClick: clickHandler,
94
+ items: ['a', 'b', 'c'],
95
+ },
96
+ rootElement,
97
+ injector,
98
+ });
99
+ await sleepAsync(10);
100
+ expect(rootElement.innerHTML).toContain('John Doe');
101
+ expect(rootElement.innerHTML).toContain('3');
102
+ const button = rootElement.querySelector('button');
103
+ button?.click();
104
+ expect(clickHandler).toHaveBeenCalled();
105
+ });
106
+ it('should use the child injector for the shade root', async () => {
107
+ let capturedInjector;
108
+ const TestComponent = Shade({
109
+ shadowDomName: 'test-mfe-injector-capture',
110
+ render: ({ injector }) => {
111
+ capturedInjector = injector;
112
+ return createComponent("div", null, "Test");
113
+ },
114
+ });
115
+ const parentInjector = new Injector();
116
+ const rootElement = document.getElementById('root');
117
+ const mfeService = createShadesMicroFrontend(TestComponent);
118
+ mfeService.create({
119
+ api: {},
120
+ rootElement,
121
+ injector: parentInjector,
122
+ });
123
+ await sleepAsync(10);
124
+ expect(capturedInjector).toBeDefined();
125
+ // The component should receive a child injector, not the parent
126
+ expect(capturedInjector).not.toBe(parentInjector);
127
+ });
128
+ });
129
+ //# sourceMappingURL=create-shades-micro-frontend.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-shades-micro-frontend.spec.js","sourceRoot":"","sources":["../src/create-shades-micro-frontend.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EAA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C,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAA;QACtC,gEAAgE;QAChE,MAAM,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@furystack/shades-mfe",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Micro-Frontend support for FuryStack Shades",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -38,7 +38,7 @@
38
38
  "homepage": "https://github.com/furystack/furystack",
39
39
  "dependencies": {
40
40
  "@furystack/inject": "^12.0.28",
41
- "@furystack/shades": "^11.0.35"
41
+ "@furystack/shades": "^11.1.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^25.0.10",
@@ -0,0 +1,170 @@
1
+ import { Injector } from '@furystack/inject'
2
+ import { createComponent, Shade } from '@furystack/shades'
3
+ import { sleepAsync } from '@furystack/utils'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import { CreateMicroFrontendService } from './create-microfrontend-service.js'
6
+ import { createShadesMicroFrontend } from './create-shades-micro-frontend.js'
7
+
8
+ describe('createShadesMicroFrontend', () => {
9
+ beforeEach(() => {
10
+ document.body.innerHTML = '<div id="root"></div>'
11
+ })
12
+
13
+ afterEach(() => {
14
+ document.body.innerHTML = ''
15
+ })
16
+
17
+ it('should return a CreateMicroFrontendService instance', () => {
18
+ const TestComponent = Shade<{ value: string }>({
19
+ shadowDomName: 'test-mfe-return-type',
20
+ render: ({ props }) => <div>{props.value}</div>,
21
+ })
22
+
23
+ const result = createShadesMicroFrontend(TestComponent)
24
+
25
+ expect(result).toBeInstanceOf(CreateMicroFrontendService)
26
+ expect(result.create).toBeTypeOf('function')
27
+ expect(result.destroy).toBeUndefined()
28
+ })
29
+
30
+ it('should create a child injector when create is called', () => {
31
+ const TestComponent = Shade<{ value: string }>({
32
+ shadowDomName: 'test-mfe-child-injector',
33
+ render: ({ props }) => <div>{props.value}</div>,
34
+ })
35
+
36
+ const parentInjector = new Injector()
37
+ const createChildSpy = vi.spyOn(parentInjector, 'createChild')
38
+
39
+ const mfeService = createShadesMicroFrontend(TestComponent)
40
+ const rootElement = document.getElementById('root') as HTMLDivElement
41
+
42
+ mfeService.create({
43
+ api: { value: 'test' },
44
+ rootElement,
45
+ injector: parentInjector,
46
+ })
47
+
48
+ expect(createChildSpy).toHaveBeenCalledWith({
49
+ owner: createShadesMicroFrontend,
50
+ })
51
+ })
52
+
53
+ it('should render the component with the provided API props', async () => {
54
+ const testValue = crypto.randomUUID()
55
+
56
+ const TestComponent = Shade<{ value: string }>({
57
+ shadowDomName: 'test-mfe-render-props',
58
+ render: ({ props }) => <div data-testid="content">Value: {props.value}</div>,
59
+ })
60
+
61
+ const injector = new Injector()
62
+ const rootElement = document.getElementById('root') as HTMLDivElement
63
+
64
+ const mfeService = createShadesMicroFrontend(TestComponent)
65
+ mfeService.create({
66
+ api: { value: testValue },
67
+ rootElement,
68
+ injector,
69
+ })
70
+
71
+ await sleepAsync(10)
72
+
73
+ expect(rootElement.innerHTML).toContain(`Value: ${testValue}`)
74
+ })
75
+
76
+ it('should render the component into the provided root element', async () => {
77
+ const TestComponent = Shade<object>({
78
+ shadowDomName: 'test-mfe-root-element',
79
+ render: () => <span>MFE Content</span>,
80
+ })
81
+
82
+ const injector = new Injector()
83
+ const rootElement = document.getElementById('root') as HTMLDivElement
84
+
85
+ const mfeService = createShadesMicroFrontend(TestComponent)
86
+ mfeService.create({
87
+ api: {},
88
+ rootElement,
89
+ injector,
90
+ })
91
+
92
+ await sleepAsync(10)
93
+
94
+ expect(rootElement.querySelector('test-mfe-root-element')).toBeTruthy()
95
+ expect(rootElement.innerHTML).toContain('MFE Content')
96
+ })
97
+
98
+ it('should work with complex API types', async () => {
99
+ type ComplexApi = {
100
+ user: { id: string; name: string }
101
+ onClick: () => void
102
+ items: string[]
103
+ }
104
+
105
+ const clickHandler = vi.fn()
106
+
107
+ const TestComponent = Shade<ComplexApi>({
108
+ shadowDomName: 'test-mfe-complex-api',
109
+ render: ({ props }) => (
110
+ <div>
111
+ <span data-testid="user-name">{props.user.name}</span>
112
+ <span data-testid="item-count">{props.items.length}</span>
113
+ <button onclick={props.onClick}>Click</button>
114
+ </div>
115
+ ),
116
+ })
117
+
118
+ const injector = new Injector()
119
+ const rootElement = document.getElementById('root') as HTMLDivElement
120
+
121
+ const mfeService = createShadesMicroFrontend(TestComponent)
122
+ mfeService.create({
123
+ api: {
124
+ user: { id: '123', name: 'John Doe' },
125
+ onClick: clickHandler,
126
+ items: ['a', 'b', 'c'],
127
+ },
128
+ rootElement,
129
+ injector,
130
+ })
131
+
132
+ await sleepAsync(10)
133
+
134
+ expect(rootElement.innerHTML).toContain('John Doe')
135
+ expect(rootElement.innerHTML).toContain('3')
136
+
137
+ const button = rootElement.querySelector('button')
138
+ button?.click()
139
+
140
+ expect(clickHandler).toHaveBeenCalled()
141
+ })
142
+
143
+ it('should use the child injector for the shade root', async () => {
144
+ let capturedInjector: Injector | undefined
145
+
146
+ const TestComponent = Shade<object>({
147
+ shadowDomName: 'test-mfe-injector-capture',
148
+ render: ({ injector }) => {
149
+ capturedInjector = injector
150
+ return <div>Test</div>
151
+ },
152
+ })
153
+
154
+ const parentInjector = new Injector()
155
+ const rootElement = document.getElementById('root') as HTMLDivElement
156
+
157
+ const mfeService = createShadesMicroFrontend(TestComponent)
158
+ mfeService.create({
159
+ api: {},
160
+ rootElement,
161
+ injector: parentInjector,
162
+ })
163
+
164
+ await sleepAsync(10)
165
+
166
+ expect(capturedInjector).toBeDefined()
167
+ // The component should receive a child injector, not the parent
168
+ expect(capturedInjector).not.toBe(parentInjector)
169
+ })
170
+ })