Skip to content

Commit

Permalink
instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
Methuselah96 committed Apr 7, 2024
1 parent c8cf847 commit 8b33ca9
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 77 deletions.
6 changes: 0 additions & 6 deletions packages/redux-devtools-instrument/babel.config.esm.json

This file was deleted.

6 changes: 0 additions & 6 deletions packages/redux-devtools-instrument/babel.config.json

This file was deleted.

9 changes: 9 additions & 0 deletions packages/redux-devtools-instrument/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.test.json', useESM: true }],
},
};
6 changes: 0 additions & 6 deletions packages/redux-devtools-instrument/jest.config.js

This file was deleted.

27 changes: 9 additions & 18 deletions packages/redux-devtools-instrument/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,30 @@
"lib",
"src"
],
"main": "lib/cjs/instrument.js",
"module": "lib/esm/instrument.js",
"types": "lib/types/instrument.d.ts",
"main": "lib/instrument.js",
"types": "lib/instrument.d.ts",
"type": "module",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/reduxjs/redux-devtools.git"
},
"scripts": {
"build": "pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"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",
"build": "tsc",
"clean": "rimraf lib",
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"lint": "eslint . --ext .ts",
"type-check": "tsc --noEmit",
"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": {
"@babel/runtime": "^7.24.1",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
"@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",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.0",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/redux-devtools-instrument/src/instrument.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import difference from 'lodash/difference';
import union from 'lodash/union';
import isPlainObject from 'lodash/isPlainObject';
import { difference, isPlainObject, union } from 'lodash-es';
import {
Action,
Observer,
Expand All @@ -10,7 +8,7 @@ import {
StoreEnhancer,
StoreEnhancerStoreCreator,
} from 'redux';
import getSymbolObservable from './getSymbolObservable';
import getSymbolObservable from './getSymbolObservable.js';

export const ActionTypes = {
PERFORM_ACTION: 'PERFORM_ACTION',
Expand Down
29 changes: 20 additions & 9 deletions packages/redux-devtools-instrument/test/instrument.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { jest } from '@jest/globals';
import { createStore, compose, Reducer, Store, Action } from 'redux';
import { from, Observable } from 'rxjs';
import { mapValues } from 'lodash-es';
import {
ActionCreators,
EnhancedStore,
instrument,
LiftedStore,
LiftedState,
} from '../src/instrument';
import { from, Observable } from 'rxjs';
import _ from 'lodash';
LiftedAction,
} from '../src/instrument.js';

type CounterAction = { type: 'INCREMENT' } | { type: 'DECREMENT' };
function counter(state = 0, action: CounterAction) {
Expand Down Expand Up @@ -713,7 +715,16 @@ describe('instrument', () => {

it('should use dynamic maxAge', () => {
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(
counter,
instrument(undefined, { maxAge: getMaxAge }),
Expand All @@ -729,10 +740,10 @@ describe('instrument', () => {
expect(getMaxAge.mock.calls[0][0].type).toContain('INIT');
expect(getMaxAge.mock.calls[0][1]).toBeUndefined();
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].stagedActionIds).toEqual([0]);
expect(getMaxAge.mock.calls[2][1].nextActionId).toBe(2);
expect(getMaxAge.mock.calls[2][1].stagedActionIds).toEqual([0, 1]);
expect(getMaxAge.mock.calls[1][1]!.nextActionId).toBe(1);
expect(getMaxAge.mock.calls[1][1]!.stagedActionIds).toEqual([0]);
expect(getMaxAge.mock.calls[2][1]!.nextActionId).toBe(2);
expect(getMaxAge.mock.calls[2][1]!.stagedActionIds).toEqual([0, 1]);

expect(store.getState()).toBe(2);
expect(Object.keys(liftedStoreState.actionsById)).toHaveLength(3);
Expand Down Expand Up @@ -1155,7 +1166,7 @@ describe('instrument', () => {
function filterStackAndTimestamps<S, A extends Action<string>>(
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
// @ts-ignore
delete action.timestamp;
Expand Down
4 changes: 2 additions & 2 deletions packages/redux-devtools-instrument/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.esm.base.json",
"compilerOptions": {
"outDir": "lib/types",
"outDir": "lib",
"types": ["node"]
},
"include": ["src"]
Expand Down
2 changes: 1 addition & 1 deletion packages/redux-devtools-instrument/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.esm.base.json",
"compilerOptions": {
"types": ["jest", "node"]
},
Expand Down
32 changes: 7 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tsconfig.esm.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es2020",
"module": "node16",
"moduleResolution": "node16",
"declaration": true,
"strict": true,
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit 8b33ca9

Please sign in to comment.