mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-25 02:53:53 +03:00
instrument
This commit is contained in:
parent
c8cf847681
commit
8b33ca9cc8
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"presets": [
|
|
||||||
["@babel/preset-env", { "targets": "defaults", "modules": false }],
|
|
||||||
"@babel/preset-typescript"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"presets": [
|
|
||||||
["@babel/preset-env", { "targets": "defaults" }],
|
|
||||||
"@babel/preset-typescript"
|
|
||||||
]
|
|
||||||
}
|
|
9
packages/redux-devtools-instrument/jest.config.cjs
Normal file
9
packages/redux-devtools-instrument/jest.config.cjs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module.exports = {
|
||||||
|
extensionsToTreatAsEsm: ['.ts'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^(\\.{1,2}/.*)\\.js$': '$1',
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.test.json', useESM: true }],
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,6 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
preset: 'ts-jest',
|
|
||||||
transform: {
|
|
||||||
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }],
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -20,39 +20,30 @@
|
||||||
"lib",
|
"lib",
|
||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"main": "lib/cjs/instrument.js",
|
"main": "lib/instrument.js",
|
||||||
"module": "lib/esm/instrument.js",
|
"types": "lib/instrument.d.ts",
|
||||||
"types": "lib/types/instrument.d.ts",
|
"type": "module",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/reduxjs/redux-devtools.git"
|
"url": "https://github.com/reduxjs/redux-devtools.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
|
"build": "tsc",
|
||||||
"build:cjs": "babel src --extensions \".ts\" --out-dir lib/cjs",
|
|
||||||
"build:esm": "babel src --config-file ./babel.config.esm.json --extensions \".ts\" --out-dir lib/esm",
|
|
||||||
"build:types": "tsc --emitDeclarationOnly",
|
|
||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"test": "jest",
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"type-check": "tsc --noEmit",
|
"type-check": "tsc --noEmit",
|
||||||
"prepack": "pnpm run clean && pnpm run build",
|
"prepack": "pnpm run clean && pnpm run build",
|
||||||
"prepublish": "pnpm run type-check && pnpm run lint && pnpm run test"
|
"prepublish": "pnpm run lint && pnpm run test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.24.1",
|
"lodash-es": "^4.17.21"
|
||||||
"lodash": "^4.17.21"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.24.1",
|
"@jest/globals": "^29.7.0",
|
||||||
"@babel/core": "^7.24.3",
|
|
||||||
"@babel/eslint-parser": "^7.24.1",
|
|
||||||
"@babel/plugin-transform-runtime": "^7.24.3",
|
|
||||||
"@babel/preset-env": "^7.24.3",
|
|
||||||
"@babel/preset-typescript": "^7.24.1",
|
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/lodash": "^4.17.0",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.11.30",
|
"@types/node": "^20.11.30",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||||
"@typescript-eslint/parser": "^7.4.0",
|
"@typescript-eslint/parser": "^7.4.0",
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import difference from 'lodash/difference';
|
import { difference, isPlainObject, union } from 'lodash-es';
|
||||||
import union from 'lodash/union';
|
|
||||||
import isPlainObject from 'lodash/isPlainObject';
|
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
Observer,
|
Observer,
|
||||||
|
@ -10,7 +8,7 @@ import {
|
||||||
StoreEnhancer,
|
StoreEnhancer,
|
||||||
StoreEnhancerStoreCreator,
|
StoreEnhancerStoreCreator,
|
||||||
} from 'redux';
|
} from 'redux';
|
||||||
import getSymbolObservable from './getSymbolObservable';
|
import getSymbolObservable from './getSymbolObservable.js';
|
||||||
|
|
||||||
export const ActionTypes = {
|
export const ActionTypes = {
|
||||||
PERFORM_ACTION: 'PERFORM_ACTION',
|
PERFORM_ACTION: 'PERFORM_ACTION',
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
|
import { jest } from '@jest/globals';
|
||||||
import { createStore, compose, Reducer, Store, Action } from 'redux';
|
import { createStore, compose, Reducer, Store, Action } from 'redux';
|
||||||
|
import { from, Observable } from 'rxjs';
|
||||||
|
import { mapValues } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
ActionCreators,
|
ActionCreators,
|
||||||
EnhancedStore,
|
EnhancedStore,
|
||||||
instrument,
|
instrument,
|
||||||
LiftedStore,
|
LiftedStore,
|
||||||
LiftedState,
|
LiftedState,
|
||||||
} from '../src/instrument';
|
LiftedAction,
|
||||||
import { from, Observable } from 'rxjs';
|
} from '../src/instrument.js';
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
type CounterAction = { type: 'INCREMENT' } | { type: 'DECREMENT' };
|
type CounterAction = { type: 'INCREMENT' } | { type: 'DECREMENT' };
|
||||||
function counter(state = 0, action: CounterAction) {
|
function counter(state = 0, action: CounterAction) {
|
||||||
|
@ -713,7 +715,16 @@ describe('instrument', () => {
|
||||||
|
|
||||||
it('should use dynamic maxAge', () => {
|
it('should use dynamic maxAge', () => {
|
||||||
let max = 3;
|
let max = 3;
|
||||||
const getMaxAge = jest.fn().mockImplementation(() => max);
|
const getMaxAge = jest
|
||||||
|
.fn<
|
||||||
|
(
|
||||||
|
currentLiftedAction: LiftedAction<number, CounterAction, null>,
|
||||||
|
previousLiftedState:
|
||||||
|
| LiftedState<number, CounterAction, null>
|
||||||
|
| undefined,
|
||||||
|
) => number
|
||||||
|
>()
|
||||||
|
.mockImplementation(() => max);
|
||||||
store = createStore(
|
store = createStore(
|
||||||
counter,
|
counter,
|
||||||
instrument(undefined, { maxAge: getMaxAge }),
|
instrument(undefined, { maxAge: getMaxAge }),
|
||||||
|
@ -729,10 +740,10 @@ describe('instrument', () => {
|
||||||
expect(getMaxAge.mock.calls[0][0].type).toContain('INIT');
|
expect(getMaxAge.mock.calls[0][0].type).toContain('INIT');
|
||||||
expect(getMaxAge.mock.calls[0][1]).toBeUndefined();
|
expect(getMaxAge.mock.calls[0][1]).toBeUndefined();
|
||||||
expect(getMaxAge.mock.calls[1][0].type).toBe('PERFORM_ACTION');
|
expect(getMaxAge.mock.calls[1][0].type).toBe('PERFORM_ACTION');
|
||||||
expect(getMaxAge.mock.calls[1][1].nextActionId).toBe(1);
|
expect(getMaxAge.mock.calls[1][1]!.nextActionId).toBe(1);
|
||||||
expect(getMaxAge.mock.calls[1][1].stagedActionIds).toEqual([0]);
|
expect(getMaxAge.mock.calls[1][1]!.stagedActionIds).toEqual([0]);
|
||||||
expect(getMaxAge.mock.calls[2][1].nextActionId).toBe(2);
|
expect(getMaxAge.mock.calls[2][1]!.nextActionId).toBe(2);
|
||||||
expect(getMaxAge.mock.calls[2][1].stagedActionIds).toEqual([0, 1]);
|
expect(getMaxAge.mock.calls[2][1]!.stagedActionIds).toEqual([0, 1]);
|
||||||
|
|
||||||
expect(store.getState()).toBe(2);
|
expect(store.getState()).toBe(2);
|
||||||
expect(Object.keys(liftedStoreState.actionsById)).toHaveLength(3);
|
expect(Object.keys(liftedStoreState.actionsById)).toHaveLength(3);
|
||||||
|
@ -1155,7 +1166,7 @@ describe('instrument', () => {
|
||||||
function filterStackAndTimestamps<S, A extends Action<string>>(
|
function filterStackAndTimestamps<S, A extends Action<string>>(
|
||||||
state: LiftedState<S, A, null>,
|
state: LiftedState<S, A, null>,
|
||||||
) {
|
) {
|
||||||
state.actionsById = _.mapValues(state.actionsById, (action) => {
|
state.actionsById = mapValues(state.actionsById, (action) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
delete action.timestamp;
|
delete action.timestamp;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.esm.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "lib/types",
|
"outDir": "lib",
|
||||||
"types": ["node"]
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src"]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.esm.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["jest", "node"]
|
"types": ["jest", "node"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -2050,37 +2050,19 @@ importers:
|
||||||
|
|
||||||
packages/redux-devtools-instrument:
|
packages/redux-devtools-instrument:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime':
|
lodash-es:
|
||||||
specifier: ^7.24.1
|
|
||||||
version: 7.24.1
|
|
||||||
lodash:
|
|
||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@babel/cli':
|
'@jest/globals':
|
||||||
specifier: ^7.24.1
|
specifier: ^29.7.0
|
||||||
version: 7.24.1(@babel/core@7.24.3)
|
version: 29.7.0
|
||||||
'@babel/core':
|
|
||||||
specifier: ^7.24.3
|
|
||||||
version: 7.24.3
|
|
||||||
'@babel/eslint-parser':
|
|
||||||
specifier: ^7.24.1
|
|
||||||
version: 7.24.1(@babel/core@7.24.3)(eslint@8.57.0)
|
|
||||||
'@babel/plugin-transform-runtime':
|
|
||||||
specifier: ^7.24.3
|
|
||||||
version: 7.24.3(@babel/core@7.24.3)
|
|
||||||
'@babel/preset-env':
|
|
||||||
specifier: ^7.24.3
|
|
||||||
version: 7.24.3(@babel/core@7.24.3)
|
|
||||||
'@babel/preset-typescript':
|
|
||||||
specifier: ^7.24.1
|
|
||||||
version: 7.24.1(@babel/core@7.24.3)
|
|
||||||
'@types/jest':
|
'@types/jest':
|
||||||
specifier: ^29.5.12
|
specifier: ^29.5.12
|
||||||
version: 29.5.12
|
version: 29.5.12
|
||||||
'@types/lodash':
|
'@types/lodash-es':
|
||||||
specifier: ^4.17.0
|
specifier: ^4.17.12
|
||||||
version: 4.17.0
|
version: 4.17.12
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.11.30
|
specifier: ^20.11.30
|
||||||
version: 20.11.30
|
version: 20.11.30
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2020",
|
"target": "es2020",
|
||||||
"module": "node16",
|
"module": "node16",
|
||||||
|
"moduleResolution": "node16",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user