@sima-land/isomorph 11.0.0-alpha.0 → 11.0.0-alpha.3
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/{dist/cache → cache}/types.d.ts +0 -0
- package/{dist/utils/webpack/module-federation → cache}/types.js +0 -0
- package/{dist/cache → cache}/types.js.map +0 -0
- package/{dist/config → config}/browser.d.ts +0 -0
- package/{dist/config → config}/browser.js +0 -0
- package/{dist/config → config}/browser.js.map +0 -0
- package/{dist/config → config}/index.d.ts +0 -0
- package/{dist/config → config}/index.js +0 -0
- package/{dist/config → config}/index.js.map +0 -0
- package/{dist/config → config}/node.d.ts +0 -0
- package/{dist/config → config}/node.js +0 -0
- package/{dist/config → config}/node.js.map +0 -0
- package/{dist/config → config}/types.d.ts +0 -0
- package/{dist/tracer → config}/types.js +0 -0
- package/{dist/config → config}/types.js.map +0 -0
- package/{dist/config → config}/utils.d.ts +0 -0
- package/{dist/config → config}/utils.js +0 -0
- package/{dist/config → config}/utils.js.map +0 -0
- package/{dist/container → container}/application.d.ts +0 -0
- package/{dist/container → container}/application.js +0 -0
- package/{dist/container → container}/application.js.map +0 -0
- package/{dist/container → container}/index.d.ts +0 -0
- package/{dist/container → container}/index.js +0 -0
- package/{dist/container → container}/index.js.map +0 -0
- package/{dist/container → container}/types.d.ts +0 -0
- package/{dist/saga-runner → container}/types.js +0 -0
- package/{dist/container → container}/types.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/browser.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/browser.js +0 -0
- package/{dist/error-tracker → error-tracker}/browser.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/node.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/node.js +0 -0
- package/{dist/error-tracker → error-tracker}/node.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/types.d.ts +0 -0
- package/{dist/preset → error-tracker}/types.js +0 -0
- package/{dist/error-tracker → error-tracker}/types.js.map +0 -0
- package/{dist/error-tracker → error-tracker}/utils.d.ts +0 -0
- package/{dist/error-tracker → error-tracker}/utils.js +0 -0
- package/{dist/error-tracker → error-tracker}/utils.js.map +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js +0 -0
- package/{dist/http-client → http-client}/middleware/cookie.js.map +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.d.ts +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js +0 -0
- package/{dist/http-client → http-client}/middleware/tracing.js.map +0 -0
- package/{dist/http-client/utils.d.ts → http-client/sauce/index.d.ts} +0 -9
- package/{dist/http-client/utils.js → http-client/sauce/index.js} +2 -18
- package/http-client/sauce/index.js.map +1 -0
- package/{dist/http-client → http-client}/types.d.ts +0 -0
- package/{dist/logger → http-client}/types.js +0 -0
- package/{dist/http-client → http-client}/types.js.map +0 -0
- package/http-client/utils.d.ts +9 -0
- package/http-client/utils.js +20 -0
- package/http-client/utils.js.map +1 -0
- package/{dist/http-server → http-server}/constants.d.ts +0 -0
- package/{dist/http-server → http-server}/constants.js +0 -0
- package/{dist/http-server → http-server}/constants.js.map +0 -0
- package/{dist/http-server → http-server}/handler/health-check.d.ts +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js +0 -0
- package/{dist/http-server → http-server}/handler/health-check.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/logging.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js +0 -0
- package/{dist/http-server → http-server}/middleware/logging.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.d.ts +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js +0 -0
- package/{dist/http-server → http-server}/middleware/metrics.js.map +0 -0
- package/{dist/http-server → http-server}/middleware/tracing.d.ts +1 -1
- package/{dist/http-server → http-server}/middleware/tracing.js +3 -2
- package/http-server/middleware/tracing.js.map +1 -0
- package/http-server/template/index.d.ts +1 -0
- package/http-server/template/index.js +36 -0
- package/http-server/template/index.js.map +1 -0
- package/{dist/http-server → http-server}/types.d.ts +8 -0
- package/{dist/http-server → http-server}/types.js +0 -0
- package/{dist/http-server → http-server}/types.js.map +0 -0
- package/{dist/http-server → http-server}/utils.d.ts +5 -1
- package/{dist/http-server → http-server}/utils.js +16 -4
- package/http-server/utils.js.map +1 -0
- package/{dist/logger → logger}/handler/console.d.ts +0 -0
- package/{dist/logger → logger}/handler/console.js +0 -0
- package/{dist/logger → logger}/handler/console.js.map +0 -0
- package/{dist/logger → logger}/handler/sentry.d.ts +0 -0
- package/{dist/logger → logger}/handler/sentry.js +0 -0
- package/{dist/logger → logger}/handler/sentry.js.map +0 -0
- package/{dist/logger → logger}/index.d.ts +0 -0
- package/{dist/logger → logger}/index.js +0 -0
- package/{dist/logger → logger}/index.js.map +0 -0
- package/{dist/logger → logger}/types.d.ts +0 -0
- package/{dist/http-client → logger}/types.js +0 -0
- package/{dist/logger → logger}/types.js.map +0 -0
- package/{dist/metrics → metrics}/constants.d.ts +0 -0
- package/{dist/metrics → metrics}/constants.js +0 -0
- package/{dist/metrics → metrics}/constants.js.map +0 -0
- package/{dist/metrics → metrics}/node.d.ts +0 -0
- package/{dist/metrics → metrics}/node.js +0 -0
- package/{dist/metrics → metrics}/node.js.map +0 -0
- package/package.json +6 -11
- package/{dist/preset → preset}/index.d.ts +0 -0
- package/{dist/preset → preset}/index.js +5 -3
- package/preset/index.js.map +1 -0
- package/{dist/preset → preset}/node/index.d.ts +3 -0
- package/{dist/preset → preset}/node/index.js +47 -17
- package/preset/node/index.js.map +1 -0
- package/{dist/preset → preset}/node/response.d.ts +6 -1
- package/{dist/preset → preset}/node/response.js +28 -2
- package/preset/node/response.js.map +1 -0
- package/{dist/preset → preset}/types.d.ts +2 -2
- package/{dist/error-tracker → preset}/types.js +0 -0
- package/{dist/preset → preset}/types.js.map +0 -0
- package/{dist/saga-runner → saga-runner}/index.d.ts +0 -0
- package/{dist/saga-runner → saga-runner}/index.js +3 -1
- package/saga-runner/index.js.map +1 -0
- package/{dist/saga-runner → saga-runner}/types.d.ts +0 -0
- package/{dist/container → saga-runner}/types.js +0 -0
- package/{dist/saga-runner → saga-runner}/types.js.map +0 -0
- package/{dist/tokens.d.ts → tokens.d.ts} +9 -3
- package/{dist/tokens.js → tokens.js} +6 -1
- package/tokens.js.map +1 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js +0 -0
- package/{dist/utils → utils}/browser/analytics/data-layer.js.map +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.d.ts +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js +0 -0
- package/{dist/utils → utils}/browser/analytics/oko.js.map +0 -0
- package/{dist/utils → utils}/browser/storage/index.d.ts +0 -0
- package/{dist/utils → utils}/browser/storage/index.js +0 -0
- package/{dist/utils → utils}/browser/storage/index.js.map +0 -0
- package/{dist/utils → utils}/number.d.ts +0 -0
- package/{dist/utils → utils}/number.js +0 -0
- package/{dist/utils → utils}/number.js.map +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.d.ts +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.js +0 -0
- package/{dist/utils → utils}/react/error-handlers/index.js.map +0 -0
- package/{dist/utils → utils}/redux/remote-data.d.ts +0 -0
- package/{dist/utils → utils}/redux/remote-data.js +0 -0
- package/{dist/utils → utils}/redux/remote-data.js.map +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.d.ts +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js +0 -0
- package/{dist/utils → utils}/redux-saga/take-chain.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/index.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.d.ts +0 -0
- package/{dist/config → utils/webpack/module-federation}/types.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/types.js.map +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.d.ts +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js +0 -0
- package/{dist/utils → utils}/webpack/module-federation/utils.js.map +0 -0
- package/LICENSE +0 -201
- package/dist/cache/types.js +0 -3
- package/dist/http-client/utils.js.map +0 -1
- package/dist/http-server/middleware/tracing.js.map +0 -1
- package/dist/http-server/utils.js.map +0 -1
- package/dist/preset/index.js.map +0 -1
- package/dist/preset/node/index.js.map +0 -1
- package/dist/preset/node/response.js.map +0 -1
- package/dist/saga-runner/index.js.map +0 -1
- package/dist/tokens.js.map +0 -1
- package/dist/tracer/node.d.ts +0 -10
- package/dist/tracer/node.js +0 -38
- package/dist/tracer/node.js.map +0 -1
- package/dist/tracer/types.d.ts +0 -2
- package/dist/tracer/types.js.map +0 -1
- package/readme.md +0 -23
- package/src/cache/types.ts +0 -7
- package/src/config/browser.ts +0 -10
- package/src/config/index.ts +0 -18
- package/src/config/node.ts +0 -18
- package/src/config/types.ts +0 -9
- package/src/config/utils.ts +0 -7
- package/src/container/application.ts +0 -91
- package/src/container/index.ts +0 -79
- package/src/container/types.ts +0 -17
- package/src/error-tracker/browser.ts +0 -14
- package/src/error-tracker/node.ts +0 -14
- package/src/error-tracker/types.ts +0 -22
- package/src/error-tracker/utils.ts +0 -18
- package/src/http-client/middleware/cookie.ts +0 -73
- package/src/http-client/middleware/tracing.ts +0 -79
- package/src/http-client/types.ts +0 -8
- package/src/http-client/utils.ts +0 -76
- package/src/http-server/constants.ts +0 -4
- package/src/http-server/handler/health-check.ts +0 -13
- package/src/http-server/middleware/logging.ts +0 -34
- package/src/http-server/middleware/metrics.ts +0 -87
- package/src/http-server/middleware/tracing.ts +0 -35
- package/src/http-server/types.ts +0 -29
- package/src/http-server/utils.ts +0 -105
- package/src/logger/handler/console.ts +0 -35
- package/src/logger/handler/sentry.ts +0 -38
- package/src/logger/index.ts +0 -31
- package/src/logger/types.ts +0 -28
- package/src/metrics/constants.ts +0 -4
- package/src/metrics/node.ts +0 -54
- package/src/preset/index.ts +0 -24
- package/src/preset/node/index.ts +0 -101
- package/src/preset/node/response.ts +0 -57
- package/src/preset/types.ts +0 -9
- package/src/saga-runner/index.ts +0 -59
- package/src/saga-runner/types.ts +0 -13
- package/src/tokens.ts +0 -54
- package/src/tracer/node.ts +0 -40
- package/src/tracer/types.ts +0 -3
- package/src/utils/browser/analytics/__test__/data-layer.test.ts +0 -50
- package/src/utils/browser/analytics/__test__/oko.test.tsx +0 -143
- package/src/utils/browser/analytics/data-layer.ts +0 -12
- package/src/utils/browser/analytics/oko.ts +0 -44
- package/src/utils/browser/storage/index.ts +0 -75
- package/src/utils/number.ts +0 -8
- package/src/utils/react/error-handlers/__test__/__snapshots__/index.test.tsx.snap +0 -27
- package/src/utils/react/error-handlers/__test__/index.test.tsx +0 -64
- package/src/utils/react/error-handlers/index.tsx +0 -62
- package/src/utils/redux/__test__/remote-data.test.ts +0 -50
- package/src/utils/redux/remote-data.ts +0 -34
- package/src/utils/redux-saga/__test__/take-chain.test.ts +0 -141
- package/src/utils/redux-saga/take-chain.ts +0 -65
- package/src/utils/webpack/module-federation/__test__/index.test.ts +0 -246
- package/src/utils/webpack/module-federation/index.ts +0 -92
- package/src/utils/webpack/module-federation/types.ts +0 -44
- package/src/utils/webpack/module-federation/utils.ts +0 -43
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`ErrorBoundary should call captureException 1`] = `<div />`;
|
|
4
|
-
|
|
5
|
-
exports[`ErrorBoundary should render children component 1`] = `
|
|
6
|
-
<div>
|
|
7
|
-
<div>
|
|
8
|
-
Normal component
|
|
9
|
-
</div>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
exports[`ErrorBoundary should render fallback component 1`] = `
|
|
14
|
-
<div>
|
|
15
|
-
<div>
|
|
16
|
-
Fallback
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
exports[`SafeSuspense should render with props 1`] = `
|
|
22
|
-
<div>
|
|
23
|
-
<div>
|
|
24
|
-
Normal component
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
`;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { ErrorBoundary, SafeSuspense } from '..';
|
|
4
|
-
|
|
5
|
-
describe('ErrorBoundary', () => {
|
|
6
|
-
const error = new Error('Test error');
|
|
7
|
-
|
|
8
|
-
const FailedComponent = () => {
|
|
9
|
-
throw error;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
it('should render children component', () => {
|
|
13
|
-
const { container } = render(
|
|
14
|
-
<ErrorBoundary fallback={null}>
|
|
15
|
-
<div>Normal component</div>
|
|
16
|
-
</ErrorBoundary>,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
expect(container.textContent).toContain('Normal component');
|
|
20
|
-
expect(container).toMatchSnapshot();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should render fallback component', () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
<ErrorBoundary fallback={<div>Fallback</div>}>
|
|
26
|
-
<>
|
|
27
|
-
<div>Normal component</div>
|
|
28
|
-
<FailedComponent />
|
|
29
|
-
</>
|
|
30
|
-
</ErrorBoundary>,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(container.textContent).toContain('Fallback');
|
|
34
|
-
expect(container).toMatchSnapshot();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should call captureException', () => {
|
|
38
|
-
const handlerException = jest.fn();
|
|
39
|
-
|
|
40
|
-
const { container } = render(
|
|
41
|
-
<ErrorBoundary fallback={null} onError={handlerException}>
|
|
42
|
-
<>
|
|
43
|
-
<div>Normal component</div>
|
|
44
|
-
<FailedComponent />
|
|
45
|
-
</>
|
|
46
|
-
</ErrorBoundary>,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(handlerException).toBeCalledWith(error, { componentStack: expect.any(String) });
|
|
50
|
-
expect(container).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('SafeSuspense', () => {
|
|
55
|
-
it('should render with props', () => {
|
|
56
|
-
const { container } = render(
|
|
57
|
-
<SafeSuspense fallback={<div>Fallback</div>} onError={jest.fn()}>
|
|
58
|
-
<div>Normal component</div>
|
|
59
|
-
</SafeSuspense>,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
expect(container).toMatchSnapshot();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface Props {
|
|
4
|
-
/** Дочерний компонент. */
|
|
5
|
-
children: NonNullable<React.ReactNode> | null;
|
|
6
|
-
|
|
7
|
-
/** Запасной элемент, если возникла ошибка. */
|
|
8
|
-
fallback: NonNullable<React.ReactNode> | null;
|
|
9
|
-
|
|
10
|
-
/** Функция для логирования ошибки. */
|
|
11
|
-
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Обработчик ошибок в React-компонентах.
|
|
16
|
-
*/
|
|
17
|
-
export class ErrorBoundary extends React.Component<Props, { hasError: boolean }> {
|
|
18
|
-
/**
|
|
19
|
-
* @param props Свойства.
|
|
20
|
-
*/
|
|
21
|
-
constructor(props: Props) {
|
|
22
|
-
super(props);
|
|
23
|
-
|
|
24
|
-
this.state = { hasError: false };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @inheritdoc */
|
|
28
|
-
static getDerivedStateFromError() {
|
|
29
|
-
return { hasError: true };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @inheritdoc */
|
|
33
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
34
|
-
const { onError } = this.props;
|
|
35
|
-
|
|
36
|
-
onError?.(error, errorInfo);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Рендер.
|
|
41
|
-
* @return Дочерний элемент либо запасное значение.
|
|
42
|
-
*/
|
|
43
|
-
render() {
|
|
44
|
-
const { children, fallback } = this.props;
|
|
45
|
-
|
|
46
|
-
return this.state.hasError ? fallback : children;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Обертка над Suspense c перехватом ошибок.
|
|
52
|
-
* @todo Возможно этот компонент не нужен...
|
|
53
|
-
* @param props Свойства.
|
|
54
|
-
* @return Элемент.
|
|
55
|
-
*/
|
|
56
|
-
export const SafeSuspense = ({ children, fallback, onError }: Props) => (
|
|
57
|
-
<React.Suspense fallback={fallback}>
|
|
58
|
-
<ErrorBoundary fallback={fallback} onError={onError}>
|
|
59
|
-
{children}
|
|
60
|
-
</ErrorBoundary>
|
|
61
|
-
</React.Suspense>
|
|
62
|
-
);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
-
import { createRemoteDataReducers, RemoteDataState, STATUS } from '../remote-data';
|
|
3
|
-
|
|
4
|
-
interface TestState extends RemoteDataState<number, string> {
|
|
5
|
-
foo: 'bar';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('createGenericSlice', () => {
|
|
9
|
-
const initialState: TestState = {
|
|
10
|
-
data: 0,
|
|
11
|
-
error: '',
|
|
12
|
-
status: STATUS.initial,
|
|
13
|
-
foo: 'bar',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const { reducer, actions } = createSlice({
|
|
17
|
-
name: 'user',
|
|
18
|
-
initialState,
|
|
19
|
-
reducers: createRemoteDataReducers<TestState>(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should handle request action', () => {
|
|
23
|
-
const actual = reducer(initialState, actions.request());
|
|
24
|
-
|
|
25
|
-
expect(actual).toEqual({
|
|
26
|
-
...initialState,
|
|
27
|
-
status: STATUS.fetching,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should handle success action', () => {
|
|
32
|
-
const actual = reducer(initialState, actions.success(234));
|
|
33
|
-
|
|
34
|
-
expect(actual).toEqual({
|
|
35
|
-
...initialState,
|
|
36
|
-
data: 234,
|
|
37
|
-
status: STATUS.success,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should handle failure action', () => {
|
|
42
|
-
const actual = reducer(initialState, actions.failure('error message here'));
|
|
43
|
-
|
|
44
|
-
expect(actual).toEqual({
|
|
45
|
-
...initialState,
|
|
46
|
-
error: 'error message here',
|
|
47
|
-
status: STATUS.failure,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { PayloadAction, Draft } from '@reduxjs/toolkit';
|
|
2
|
-
|
|
3
|
-
export type Status = 'initial' | 'fetching' | 'success' | 'failure';
|
|
4
|
-
|
|
5
|
-
export interface RemoteDataState<TData, TError> {
|
|
6
|
-
data: TData;
|
|
7
|
-
error: TError;
|
|
8
|
-
status: Status;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const STATUS: Record<Status, Status> = {
|
|
12
|
-
initial: 'initial',
|
|
13
|
-
fetching: 'fetching',
|
|
14
|
-
success: 'success',
|
|
15
|
-
failure: 'failure',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Возвращает набор обработчиков для работы с удаленными данными.
|
|
20
|
-
* @return Набор.
|
|
21
|
-
*/
|
|
22
|
-
export const createRemoteDataReducers = <S extends RemoteDataState<any, any>>() => ({
|
|
23
|
-
request: (state: Draft<S>) => {
|
|
24
|
-
state.status = STATUS.fetching;
|
|
25
|
-
},
|
|
26
|
-
success: (state: Draft<S>, action: PayloadAction<S['data']>) => {
|
|
27
|
-
state.data = action.payload;
|
|
28
|
-
state.status = STATUS.success;
|
|
29
|
-
},
|
|
30
|
-
failure: (state: Draft<S>, action: PayloadAction<S['error']>) => {
|
|
31
|
-
state.error = action.payload;
|
|
32
|
-
state.status = STATUS.failure;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { delay, fork, put, race, take } from 'redux-saga/effects';
|
|
2
|
-
import { generateTakeChain, putDelayed, takeChain } from '../take-chain';
|
|
3
|
-
|
|
4
|
-
const SettlementTypes = {
|
|
5
|
-
UPDATE: 'settlement',
|
|
6
|
-
REMOVE: 'settlement',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('takeChain', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
jest.spyOn(Date, 'now').mockImplementation(() => 123);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const testTypes = [SettlementTypes.UPDATE, SettlementTypes.REMOVE];
|
|
15
|
-
const timeout = 100;
|
|
16
|
-
const testTask = jest.fn();
|
|
17
|
-
const deps: [string, number] = ['John', 23];
|
|
18
|
-
|
|
19
|
-
it('generateTakeChain few actions', () => {
|
|
20
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
21
|
-
|
|
22
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
23
|
-
|
|
24
|
-
expect(gen.next({ type: SettlementTypes.REMOVE.toString() }).value).toEqual(
|
|
25
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
expect(gen.next().value).toEqual(
|
|
29
|
-
race({
|
|
30
|
-
action: take(testTypes),
|
|
31
|
-
canceled: take('BREAK_123'),
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
expect(
|
|
35
|
-
gen.next({
|
|
36
|
-
action: { type: SettlementTypes.UPDATE.toString() },
|
|
37
|
-
canceled: { type: 'BREAK_123' },
|
|
38
|
-
}).value,
|
|
39
|
-
).toEqual(
|
|
40
|
-
fork(testTask, ...deps, [
|
|
41
|
-
{ type: SettlementTypes.REMOVE.toString() },
|
|
42
|
-
{ type: SettlementTypes.UPDATE.toString() },
|
|
43
|
-
]),
|
|
44
|
-
);
|
|
45
|
-
expect(gen.next()).toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('generateTakeChain one action', () => {
|
|
49
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
50
|
-
|
|
51
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
52
|
-
|
|
53
|
-
expect(gen.next({ type: 'settlement/REMOVE' }).value).toEqual(
|
|
54
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(gen.next().value).toEqual(
|
|
58
|
-
race({
|
|
59
|
-
action: take(testTypes),
|
|
60
|
-
canceled: take('BREAK_123'),
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
expect(
|
|
64
|
-
gen.next({
|
|
65
|
-
action: undefined,
|
|
66
|
-
canceled: { type: 'BREAK_123' },
|
|
67
|
-
}).value,
|
|
68
|
-
).toEqual(fork(testTask, ...deps, [{ type: 'settlement/REMOVE' }]));
|
|
69
|
-
expect(gen.next()).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('generateTakeChain without canceled', () => {
|
|
73
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
74
|
-
|
|
75
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
76
|
-
|
|
77
|
-
expect(gen.next({ type: 'settlement/REMOVE' }).value).toEqual(
|
|
78
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(gen.next().value).toEqual(
|
|
82
|
-
race({
|
|
83
|
-
action: take(testTypes),
|
|
84
|
-
canceled: take('BREAK_123'),
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
expect(
|
|
88
|
-
gen.next({
|
|
89
|
-
action: undefined,
|
|
90
|
-
canceled: undefined,
|
|
91
|
-
}).value,
|
|
92
|
-
).toBeTruthy();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('generateTakeChain when puts all actions and have not canceled', () => {
|
|
96
|
-
const gen = generateTakeChain(timeout, testTypes, testTask, deps);
|
|
97
|
-
|
|
98
|
-
expect(gen.next().value).toEqual(take(testTypes));
|
|
99
|
-
|
|
100
|
-
expect(gen.next({ type: SettlementTypes.REMOVE.toString() }).value).toEqual(
|
|
101
|
-
fork(putDelayed, timeout, { type: 'BREAK_123' }),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(gen.next().value).toEqual(
|
|
105
|
-
race({
|
|
106
|
-
action: take(testTypes),
|
|
107
|
-
canceled: take('BREAK_123'),
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
expect(
|
|
112
|
-
gen.next({
|
|
113
|
-
action: { type: SettlementTypes.UPDATE.toString() },
|
|
114
|
-
canceled: undefined,
|
|
115
|
-
}).value,
|
|
116
|
-
).toEqual(
|
|
117
|
-
fork(testTask, ...deps, [
|
|
118
|
-
{ type: SettlementTypes.REMOVE.toString() },
|
|
119
|
-
{ type: SettlementTypes.UPDATE.toString() },
|
|
120
|
-
]),
|
|
121
|
-
);
|
|
122
|
-
expect(gen.next()).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should fork generateTakeChain', () => {
|
|
126
|
-
const fakeTakeChain = takeChain(timeout, testTypes, testTask, ...deps);
|
|
127
|
-
|
|
128
|
-
expect(fakeTakeChain).toEqual(fork(generateTakeChain, timeout, testTypes, testTask, deps));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('putDelayed', () => {
|
|
133
|
-
it('should works properly', () => {
|
|
134
|
-
const gen = putDelayed(10, { type: 'test' });
|
|
135
|
-
|
|
136
|
-
expect(gen.next().value).toEqual(delay(10));
|
|
137
|
-
expect(gen.next().value).toEqual(put({ type: 'test' }));
|
|
138
|
-
|
|
139
|
-
expect(gen.next()).toBeTruthy();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Action } from '@reduxjs/toolkit';
|
|
2
|
-
import { delay, fork, put, race, take } from 'redux-saga/effects';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Накапливает экшены и генерирует эффект по таймауту.
|
|
6
|
-
* @param timeout Время задержки в мс.
|
|
7
|
-
* @param types Массив с типами ожидаемых экшенов.
|
|
8
|
-
* @param task Генератор.
|
|
9
|
-
* @param deps Аргументы для генератора.
|
|
10
|
-
* @return Эффект.
|
|
11
|
-
*/
|
|
12
|
-
export function takeChain<
|
|
13
|
-
Deps extends any[],
|
|
14
|
-
Task extends (...someArgs: [...Deps, Action[]]) => any,
|
|
15
|
-
>(timeout: number, types: string[], task: Task, ...deps: Deps) {
|
|
16
|
-
return fork(generateTakeChain as any, timeout, types, task, deps);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Генерирует эффект по таймауту.
|
|
21
|
-
* @param timeout Время задержки в мс.
|
|
22
|
-
* @param types Массив с типами ожидаемых экшенов.
|
|
23
|
-
* @param task Генератор.
|
|
24
|
-
* @param deps Аргументы для генератора.
|
|
25
|
-
*/
|
|
26
|
-
export function* generateTakeChain<
|
|
27
|
-
Deps extends any[],
|
|
28
|
-
Task extends (...someArgs: [...Deps, Action[]]) => any,
|
|
29
|
-
>(timeout: number, types: string[], task: Task, deps: Deps): Generator<any, void, any> {
|
|
30
|
-
while (true) {
|
|
31
|
-
const breakAction: Action = { type: `BREAK_${Date.now()}` };
|
|
32
|
-
const firstAction: Action = yield take(types);
|
|
33
|
-
const collectedActions = [firstAction];
|
|
34
|
-
|
|
35
|
-
yield fork(putDelayed, timeout, breakAction);
|
|
36
|
-
|
|
37
|
-
while (true) {
|
|
38
|
-
const { action, canceled } = yield race({
|
|
39
|
-
action: take(types),
|
|
40
|
-
canceled: take(breakAction.type),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
action && collectedActions.push(action);
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
canceled ||
|
|
47
|
-
types.every(type => collectedActions.some(someAction => someAction.type === type))
|
|
48
|
-
) {
|
|
49
|
-
// @todo убрать "as any"
|
|
50
|
-
yield fork(task as any, ...deps, collectedActions);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Вызывает экшен с заданной задержкой.
|
|
59
|
-
* @param timeout Время задержки в мс.
|
|
60
|
-
* @param action Тип экшена.
|
|
61
|
-
*/
|
|
62
|
-
export function* putDelayed(timeout: number, action: Action) {
|
|
63
|
-
yield delay(timeout);
|
|
64
|
-
yield put(action);
|
|
65
|
-
}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { container, Compiler } from 'webpack';
|
|
2
|
-
import { LIBRARY_ERROR_TEXT, ModuleFederationPlugin, REMOTE_ERROR_TEXT } from '..';
|
|
3
|
-
|
|
4
|
-
jest.mock('../utils', () => ({
|
|
5
|
-
createExternalConfig: jest.fn(arg => arg),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
jest.mock('webpack', () => {
|
|
9
|
-
class ModuleFederationPluginMock {
|
|
10
|
-
static __spy__ = { constructor: jest.fn(), apply: jest.fn() };
|
|
11
|
-
|
|
12
|
-
constructor(...args: any[]) {
|
|
13
|
-
ModuleFederationPluginMock.__spy__.constructor(...args);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
apply(...args: any[]) {
|
|
17
|
-
ModuleFederationPluginMock.__spy__.apply(...args);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
container: {
|
|
23
|
-
ModuleFederationPlugin: ModuleFederationPluginMock,
|
|
24
|
-
},
|
|
25
|
-
WebpackError: class extends Error {},
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
function getSpy(value: any): { constructor: jest.Mock; apply: jest.Mock } {
|
|
30
|
-
return value.__spy__;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
getSpy(container.ModuleFederationPlugin).constructor.mockClear();
|
|
35
|
-
getSpy(container.ModuleFederationPlugin).apply.mockClear();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('ModuleFederationPlugin', () => {
|
|
39
|
-
function createCompilerMock(): Compiler {
|
|
40
|
-
return {
|
|
41
|
-
hooks: {
|
|
42
|
-
environment: {
|
|
43
|
-
tap: jest.fn((name, cb) => cb()),
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
} as any;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe('ModuleFederationPlugin instance', () => {
|
|
50
|
-
it('should apply original plugin', () => {
|
|
51
|
-
const compiler = createCompilerMock();
|
|
52
|
-
const instance = new ModuleFederationPlugin({ name: 'test-module' });
|
|
53
|
-
|
|
54
|
-
expect(getSpy(container.ModuleFederationPlugin).apply).toBeCalledTimes(0);
|
|
55
|
-
|
|
56
|
-
instance.apply(compiler);
|
|
57
|
-
|
|
58
|
-
expect(getSpy(container.ModuleFederationPlugin).apply).toBeCalledTimes(1);
|
|
59
|
-
expect(getSpy(container.ModuleFederationPlugin).apply).toBeCalledWith(compiler);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should not creat and throw error, if library property pass to plugin', () => {
|
|
63
|
-
expect(() => {
|
|
64
|
-
new ModuleFederationPlugin({ library: 'test' } as any);
|
|
65
|
-
}).toThrowError(LIBRARY_ERROR_TEXT);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should not creat and throw error, if remotes property incorrect', () => {
|
|
69
|
-
expect(() => {
|
|
70
|
-
new ModuleFederationPlugin({ remotes: { remoteOne: {} } } as any);
|
|
71
|
-
}).toThrowError(REMOTE_ERROR_TEXT);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('ModuleFederationPlugin instance should create with correct arguments', () => {
|
|
76
|
-
it('for remotes', () => {
|
|
77
|
-
const compiler = createCompilerMock();
|
|
78
|
-
const instance = new ModuleFederationPlugin({
|
|
79
|
-
name: 'service-name',
|
|
80
|
-
remotes: {
|
|
81
|
-
firstRemote: 'first-remote-service',
|
|
82
|
-
secondRemote: 'second-remote-service',
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
instance.apply(compiler);
|
|
87
|
-
|
|
88
|
-
expect(getSpy(container.ModuleFederationPlugin).constructor).toBeCalledWith({
|
|
89
|
-
name: 'service-name',
|
|
90
|
-
library: {
|
|
91
|
-
type: 'global',
|
|
92
|
-
name: ['__FederationContainers__', 'service-name'],
|
|
93
|
-
},
|
|
94
|
-
remotes: {
|
|
95
|
-
firstRemote: {
|
|
96
|
-
external: {
|
|
97
|
-
serviceName: 'first-remote-service',
|
|
98
|
-
remoteEntriesGlobalKey: '__RemoteEntriesList__',
|
|
99
|
-
containersGlobalKey: '__FederationContainers__',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
secondRemote: {
|
|
103
|
-
external: {
|
|
104
|
-
serviceName: 'second-remote-service',
|
|
105
|
-
remoteEntriesGlobalKey: '__RemoteEntriesList__',
|
|
106
|
-
containersGlobalKey: '__FederationContainers__',
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('for remotes with custom global variables name', () => {
|
|
114
|
-
const compiler = createCompilerMock();
|
|
115
|
-
const instance = new ModuleFederationPlugin({
|
|
116
|
-
name: 'service-name',
|
|
117
|
-
remotes: {
|
|
118
|
-
firstRemote: 'first-remote-service',
|
|
119
|
-
secondRemote: 'second-remote-service',
|
|
120
|
-
},
|
|
121
|
-
remoteEntriesGlobalKey: 'remotes-entry-key',
|
|
122
|
-
containersGlobalKey: 'containers-key',
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
instance.apply(compiler);
|
|
126
|
-
expect(getSpy(container.ModuleFederationPlugin).constructor).toBeCalledWith({
|
|
127
|
-
name: 'service-name',
|
|
128
|
-
library: {
|
|
129
|
-
type: 'global',
|
|
130
|
-
name: ['containers-key', 'service-name'],
|
|
131
|
-
},
|
|
132
|
-
remotes: {
|
|
133
|
-
firstRemote: {
|
|
134
|
-
external: {
|
|
135
|
-
serviceName: 'first-remote-service',
|
|
136
|
-
remoteEntriesGlobalKey: 'remotes-entry-key',
|
|
137
|
-
containersGlobalKey: 'containers-key',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
secondRemote: {
|
|
141
|
-
external: {
|
|
142
|
-
serviceName: 'second-remote-service',
|
|
143
|
-
remoteEntriesGlobalKey: 'remotes-entry-key',
|
|
144
|
-
containersGlobalKey: 'containers-key',
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('for various remote type', () => {
|
|
152
|
-
const compiler = createCompilerMock();
|
|
153
|
-
|
|
154
|
-
const instance = new ModuleFederationPlugin({
|
|
155
|
-
name: 'service-name',
|
|
156
|
-
remotes: {
|
|
157
|
-
firstRemote: 'first-remote-service',
|
|
158
|
-
secondRemote: {
|
|
159
|
-
name: 'second-remote-service',
|
|
160
|
-
},
|
|
161
|
-
thirdRemote: {
|
|
162
|
-
name: 'third-remote-service',
|
|
163
|
-
remoteEntryPath: '//example.com/path/to/RemoteEntry.js',
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
instance.apply(compiler);
|
|
169
|
-
expect(getSpy(container.ModuleFederationPlugin).constructor).toBeCalledWith({
|
|
170
|
-
name: 'service-name',
|
|
171
|
-
library: {
|
|
172
|
-
type: 'global',
|
|
173
|
-
name: ['__FederationContainers__', 'service-name'],
|
|
174
|
-
},
|
|
175
|
-
remotes: {
|
|
176
|
-
firstRemote: {
|
|
177
|
-
external: {
|
|
178
|
-
serviceName: 'first-remote-service',
|
|
179
|
-
remoteEntriesGlobalKey: '__RemoteEntriesList__',
|
|
180
|
-
containersGlobalKey: '__FederationContainers__',
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
secondRemote: {
|
|
184
|
-
external: {
|
|
185
|
-
serviceName: 'second-remote-service',
|
|
186
|
-
remoteEntriesGlobalKey: '__RemoteEntriesList__',
|
|
187
|
-
containersGlobalKey: '__FederationContainers__',
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
thirdRemote: {
|
|
191
|
-
external: {
|
|
192
|
-
serviceName: 'third-remote-service',
|
|
193
|
-
remoteEntriesGlobalKey: '__RemoteEntriesList__',
|
|
194
|
-
containersGlobalKey: '__FederationContainers__',
|
|
195
|
-
remoteEntryPath: '//example.com/path/to/RemoteEntry.js',
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('for exposes', () => {
|
|
203
|
-
const compiler = createCompilerMock();
|
|
204
|
-
|
|
205
|
-
const instance = new ModuleFederationPlugin({
|
|
206
|
-
name: 'service-name',
|
|
207
|
-
filename: 'path/to/RemoteEntry.js',
|
|
208
|
-
exposes: {
|
|
209
|
-
'./One': './path/to/one.js',
|
|
210
|
-
'./Two': './path/to/two.js',
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
instance.apply(compiler);
|
|
215
|
-
expect(getSpy(container.ModuleFederationPlugin).constructor).toBeCalledWith({
|
|
216
|
-
name: 'service-name',
|
|
217
|
-
filename: 'path/to/RemoteEntry.js',
|
|
218
|
-
library: {
|
|
219
|
-
type: 'global',
|
|
220
|
-
name: ['__FederationContainers__', 'service-name'],
|
|
221
|
-
},
|
|
222
|
-
exposes: {
|
|
223
|
-
'./One': './path/to/one.js',
|
|
224
|
-
'./Two': './path/to/two.js',
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('for several call "apply" method', () => {
|
|
230
|
-
const compiler = createCompilerMock();
|
|
231
|
-
|
|
232
|
-
const instance = new ModuleFederationPlugin({
|
|
233
|
-
name: 'service-name',
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
instance.apply(compiler);
|
|
237
|
-
instance.apply(compiler);
|
|
238
|
-
|
|
239
|
-
const calls = getSpy(container.ModuleFederationPlugin).constructor.mock.calls;
|
|
240
|
-
|
|
241
|
-
for (const key of Object.keys(calls[0][0])) {
|
|
242
|
-
expect(calls[1][0][key] === calls[0][0][key]).toBe(true);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|