Skip to content

Commit

Permalink
Merge pull request #3096 from satanTime/issues/3095
Browse files Browse the repository at this point in the history
fix(core): preventing recursion of self pointers #3095
  • Loading branch information
satanTime authored Jul 14, 2022
2 parents 255eefe + 793a3c5 commit 105fbc1
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tests-failures/
tmp/

**/*.sh
**/.nvmrc
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test-reports/
tmp/

**/*.sh
**/.nvmrc
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ services:
working_dir: /app
volumes:
- ./e2e/a9:/app
- gyp:/root/.node-gyp
- npm:/root/.npm
command:
- npm
- install
Expand Down
1 change: 1 addition & 0 deletions e2e/a10/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.12
1 change: 1 addition & 0 deletions e2e/a11/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.12
1 change: 1 addition & 0 deletions e2e/a12/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.12
1 change: 1 addition & 0 deletions e2e/a13/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.12
1 change: 1 addition & 0 deletions e2e/a14/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
1 change: 1 addition & 0 deletions e2e/a5es2015/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.17.1
1 change: 1 addition & 0 deletions e2e/a6/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.17.0
1 change: 1 addition & 0 deletions e2e/a7/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.17.0
1 change: 1 addition & 0 deletions e2e/a8/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.24.1
1 change: 1 addition & 0 deletions e2e/a9/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.12
1 change: 1 addition & 0 deletions e2e/jasmine/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
1 change: 1 addition & 0 deletions e2e/jest/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
1 change: 1 addition & 0 deletions e2e/min/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
1 change: 1 addition & 0 deletions e2e/nx/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
2 changes: 1 addition & 1 deletion libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ const generateTouches = (moduleDef: Partial<Record<dependencyKeys, any>>, touche
if (!Object.prototype.hasOwnProperty.call(def, '__ngMocksTouches')) {
const local = new Set<any>();
const meta = coreReflectMeta(def);
coreDefineProperty(def, '__ngMocksTouches', local, false);
if (meta) {
generateTouches(meta, local);
}
coreDefineProperty(def, '__ngMocksTouches', local, false);
}

mapValues(def.__ngMocksTouches, touches);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"postinstall": "husky install",
"release": "export $(cat .env) && semantic-release",
"build": "npm run clean && npm run build:webpack && npm run build:types && cp CHANGELOG.md dist/libs/ng-mocks && cp README.md dist/libs/ng-mocks && cp LICENSE dist/libs/ng-mocks && cp libs/ng-mocks/package.json dist/libs/ng-mocks/package.json && cp libs/ng-mocks/migrations.json dist/libs/ng-mocks/migrations.json && cp -R examples dist/libs/ng-mocks",
"build:dev": "MODE=development npm run build",
"build:webpack": "webpack",
"build:types": "dts-bundle-generator --no-banner -o ./dist/libs/ng-mocks/index.d.ts --project ./libs/ng-mocks/tsconfig.build.cjs.json --no-check --export-referenced-types=false ./libs/ng-mocks/src/index.ts",
"build:all": "npm run lint && npm run build && npm run test",
Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},

{
"packagePatterns": ["satantime/puppeteer-node", "@types/node"],
"packagePatterns": ["satantime/puppeteer-node", "@types/node", "node"],
"major": {
"enabled": false
},
Expand Down
1 change: 1 addition & 0 deletions tests-e2e/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
43 changes: 43 additions & 0 deletions tests/issue-3095/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Directive } from '@angular/core';
import { TestBed } from '@angular/core/testing';

import { MockRender } from 'ng-mocks';

class RecursiveDirective {}
Directive({
selector: 'recursive',
providers: [
{
provide: RecursiveDirective,
useExisting: RecursiveDirective,
},
],
})(RecursiveDirective);

@Directive({
selector: 'target',
providers: [
{
provide: RecursiveDirective,
useValue: null,
},
],
})
class TargetDirective {}

// When ng-mocks generates touches, it can meet recursions when a declaration provides itself in own providers.
// In this case, ng-mocks shouldn't cause infinity loop.
describe('issue-3095', () => {
beforeEach(() =>
TestBed.configureTestingModule({
declarations: [TargetDirective],
}).compileComponents(),
);

it('renders directive', () => {
const fixture = MockRender(TargetDirective);
expect(() =>
fixture.point.injector.get(RecursiveDirective),
).not.toThrow();
});
});
8 changes: 4 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const path = require('node:path');

module.exports = [
{
mode: 'production',
devtool: 'source-map',
mode: process.env.MODE || 'production',
devtool: process.env.MODE ? false : 'source-map',
entry: './libs/ng-mocks/src/index.ts',
target: ['web', 'es3'],
output: {
Expand Down Expand Up @@ -36,8 +36,8 @@ module.exports = [
},
},
{
mode: 'production',
devtool: 'source-map',
mode: process.env.MODE || 'production',
devtool: process.env.MODE ? false : 'source-map',
entry: './libs/ng-mocks/src/index.ts',
target: ['web', 'es2015'],
experiments: {
Expand Down

0 comments on commit 105fbc1

Please sign in to comment.