@mfeflow/testing 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/package.json +69 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sanjeev Sharma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mfeflow/testing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test helpers for mfeflow micro-frontends. `renderWithPlatform` renders a component inside the same providers the shell uses; `resetPlatform` clears storage, the i18n instance, the theme on `<html>` and remote error reports between tests.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @mfeflow/testing @testing-library/react @testing-library/dom react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`@testing-library/react` (^16), `react` and `react-dom` (^19) are peer dependencies; Testing Library also needs `@testing-library/dom`. `renderWithPlatform` imports only `@mfeflow/runtime/providers`, so Module Federation is not loaded in your tests. Run tests in a DOM environment such as jsdom.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { afterEach, expect, test } from 'vitest';
|
|
17
|
+
import { withProps } from '@mfeflow/runtime';
|
|
18
|
+
import { ThemeProvider } from '@mfeflow/theme/react';
|
|
19
|
+
import { renderWithPlatform, resetPlatform } from '@mfeflow/testing';
|
|
20
|
+
import { themes } from './themes';
|
|
21
|
+
|
|
22
|
+
afterEach(resetPlatform);
|
|
23
|
+
|
|
24
|
+
test('renders with the shell providers', () => {
|
|
25
|
+
const { getByText } = renderWithPlatform(<Cart />, {
|
|
26
|
+
providers: [withProps(ThemeProvider, { themes, defaultTheme: 'light' })],
|
|
27
|
+
});
|
|
28
|
+
expect(getByText('Cart')).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Module Federation sharing
|
|
33
|
+
|
|
34
|
+
Bucket: **config**. Used at build, lint or test time only, never shipped to the browser, so it is not shared through Module Federation.
|
|
35
|
+
|
|
36
|
+
## Links
|
|
37
|
+
|
|
38
|
+
- [mfeflow repository](https://github.com/mfeflow/mfeflow) and its README
|
|
39
|
+
- [Documentation](https://mfeflow.github.io/mfeflow/)
|
|
40
|
+
|
|
41
|
+
MIT licensed.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RenderOptions, type RenderResult } from '@testing-library/react';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import { type ProviderComponent } from '@mfeflow/runtime/providers';
|
|
4
|
+
export interface PlatformRenderOptions extends Omit<RenderOptions, 'wrapper'> {
|
|
5
|
+
/** The same list the shell passes to `composeProviders`, e.g. `[withProps(ThemeProvider, {...})]`. */
|
|
6
|
+
providers?: readonly ProviderComponent[];
|
|
7
|
+
}
|
|
8
|
+
/** `render` from Testing Library, wrapped in the shell's providers. */
|
|
9
|
+
export declare function renderWithPlatform(ui: ReactElement, options?: PlatformRenderOptions): RenderResult;
|
|
10
|
+
/**
|
|
11
|
+
* Clears page-wide platform state between tests: web storage, the i18n
|
|
12
|
+
* instance, the theme on `<html>`, and remote error reports.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resetPlatform(): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { composeProviders } from "@mfeflow/runtime/providers";
|
|
3
|
+
function renderWithPlatform(ui, options = {}) {
|
|
4
|
+
const { providers = [], ...rest } = options;
|
|
5
|
+
return render(ui, {
|
|
6
|
+
...rest,
|
|
7
|
+
wrapper: composeProviders(providers)
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function resetPlatform() {
|
|
11
|
+
if ("u" > typeof localStorage) localStorage.clear();
|
|
12
|
+
if ("u" > typeof sessionStorage) sessionStorage.clear();
|
|
13
|
+
Reflect.deleteProperty(globalThis, 'mfeflowI18n');
|
|
14
|
+
Reflect.deleteProperty(globalThis, 'mfeflowReports');
|
|
15
|
+
if ("u" > typeof document) {
|
|
16
|
+
const root = document.documentElement;
|
|
17
|
+
root.removeAttribute('style');
|
|
18
|
+
root.removeAttribute('data-theme');
|
|
19
|
+
root.removeAttribute('lang');
|
|
20
|
+
root.removeAttribute('dir');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { renderWithPlatform, resetPlatform };
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mfeflow/testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Test helpers for mfeflow micro-frontends: renderWithPlatform wraps components in the same providers the shell uses; resetPlatform clears storage, i18n, theme and reports between tests.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"micro-frontend",
|
|
7
|
+
"mfe",
|
|
8
|
+
"testing",
|
|
9
|
+
"testing-library",
|
|
10
|
+
"react",
|
|
11
|
+
"vitest",
|
|
12
|
+
"module-federation",
|
|
13
|
+
"rsbuild"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://mfeflow.github.io/mfeflow/",
|
|
16
|
+
"bugs": "https://github.com/mfeflow/mfeflow/issues",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/mfeflow/mfeflow.git",
|
|
20
|
+
"directory": "packages/testing"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Sanjeev Sharma <speedsharma.ai@gmail.com>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22.12"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@mfeflow/runtime": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@testing-library/react": "^16.0.0",
|
|
48
|
+
"react": "^19.0.0",
|
|
49
|
+
"react-dom": "^19.0.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@module-federation/enhanced": "2.9.2",
|
|
53
|
+
"@rsbuild/plugin-react": "2.1.1",
|
|
54
|
+
"@rslib/core": "1.0.5",
|
|
55
|
+
"@testing-library/dom": "10.4.2",
|
|
56
|
+
"@testing-library/react": "16.3.3",
|
|
57
|
+
"@types/node": "26.6.6",
|
|
58
|
+
"@types/react": "19.3.0",
|
|
59
|
+
"@types/react-dom": "19.3.0",
|
|
60
|
+
"jsdom": "30.1.3",
|
|
61
|
+
"react": "19.3.1",
|
|
62
|
+
"react-dom": "19.3.1",
|
|
63
|
+
"typescript": "7.0.2"
|
|
64
|
+
},
|
|
65
|
+
"mfeflow": {
|
|
66
|
+
"bucket": "config"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "rslib build",
|
|
70
|
+
"typecheck": "tsc --noEmit"
|
|
71
|
+
}
|
|
6
72
|
}
|