Skip to content

Commit

Permalink
fix(mockValues): assign, not merge, override value when is a mock to …
Browse files Browse the repository at this point in the history
…prevent maximum callstack size exceeded errors
  • Loading branch information
Pmyl committed Sep 12, 2020
1 parent eff01f7 commit 7431d80
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 100 deletions.
3 changes: 2 additions & 1 deletion config/modules/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = merge(base({
},
output: {
path: path.resolve(__dirname, "../../dist")
}
},
externals: ['ts-auto-mock/extension']
});
162 changes: 67 additions & 95 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@types/jasmine": "^3.5.13",
"@types/lodash-es": "^4.17.3",
"@types/node": "^14.6.0",
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1",
Expand Down
13 changes: 10 additions & 3 deletions src/merge/merge.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { merge } from 'lodash-es';
import { mergeWith, isObject } from 'lodash-es';
import { ɵMarker as Marker } from 'ts-auto-mock/extension';
import { PartialDeep } from '../partial/partial';

export class Merge {
public static merge<T>(a: T, b: PartialDeep<T>): T {
return merge(a, b);
return mergeWith(a, b, (objValue: unknown, srcValue: unknown) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (isObject(srcValue) && srcValue[Marker.instance.get()]) {
return srcValue;
}
});
}

public static mergeIterator<T>(
a: T,
b: (index: number) => PartialDeep<T>,
index: number
): T {
return merge(a, b(index));
return Merge.merge(a, b(index));
}
}
Loading

0 comments on commit 7431d80

Please sign in to comment.