diff --git a/.eslintignore b/.eslintignore index 809abf6752..26bcd55404 100644 --- a/.eslintignore +++ b/.eslintignore @@ -19,3 +19,4 @@ tests-failures/ tmp/ **/*.sh +**/.nvmrc diff --git a/.prettierignore b/.prettierignore index 8ba4651443..efae5bb38e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -17,3 +17,4 @@ test-reports/ tmp/ **/*.sh +**/.nvmrc diff --git a/docker-compose.yml b/docker-compose.yml index 18cf9571d2..65da625a11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -110,6 +110,8 @@ services: working_dir: /app volumes: - ./e2e/a9:/app + - gyp:/root/.node-gyp + - npm:/root/.npm command: - npm - install diff --git a/e2e/a10/.nvmrc b/e2e/a10/.nvmrc new file mode 100644 index 0000000000..82c219143e --- /dev/null +++ b/e2e/a10/.nvmrc @@ -0,0 +1 @@ +12.22.12 diff --git a/e2e/a11/.nvmrc b/e2e/a11/.nvmrc new file mode 100644 index 0000000000..82c219143e --- /dev/null +++ b/e2e/a11/.nvmrc @@ -0,0 +1 @@ +12.22.12 diff --git a/e2e/a12/.nvmrc b/e2e/a12/.nvmrc new file mode 100644 index 0000000000..82c219143e --- /dev/null +++ b/e2e/a12/.nvmrc @@ -0,0 +1 @@ +12.22.12 diff --git a/e2e/a13/.nvmrc b/e2e/a13/.nvmrc new file mode 100644 index 0000000000..82c219143e --- /dev/null +++ b/e2e/a13/.nvmrc @@ -0,0 +1 @@ +12.22.12 diff --git a/e2e/a14/.nvmrc b/e2e/a14/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/e2e/a14/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/e2e/a5es2015/.nvmrc b/e2e/a5es2015/.nvmrc new file mode 100644 index 0000000000..369689dd81 --- /dev/null +++ b/e2e/a5es2015/.nvmrc @@ -0,0 +1 @@ +6.17.1 diff --git a/e2e/a6/.nvmrc b/e2e/a6/.nvmrc new file mode 100644 index 0000000000..29d3fcd554 --- /dev/null +++ b/e2e/a6/.nvmrc @@ -0,0 +1 @@ +8.17.0 diff --git a/e2e/a7/.nvmrc b/e2e/a7/.nvmrc new file mode 100644 index 0000000000..29d3fcd554 --- /dev/null +++ b/e2e/a7/.nvmrc @@ -0,0 +1 @@ +8.17.0 diff --git a/e2e/a8/.nvmrc b/e2e/a8/.nvmrc new file mode 100644 index 0000000000..dc08cc7bd0 --- /dev/null +++ b/e2e/a8/.nvmrc @@ -0,0 +1 @@ +10.24.1 diff --git a/e2e/a9/.nvmrc b/e2e/a9/.nvmrc new file mode 100644 index 0000000000..82c219143e --- /dev/null +++ b/e2e/a9/.nvmrc @@ -0,0 +1 @@ +12.22.12 diff --git a/e2e/jasmine/.nvmrc b/e2e/jasmine/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/e2e/jasmine/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/e2e/jest/.nvmrc b/e2e/jest/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/e2e/jest/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/e2e/min/.nvmrc b/e2e/min/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/e2e/min/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/e2e/nx/.nvmrc b/e2e/nx/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/e2e/nx/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts b/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts index b0a5041fb5..f3d9e2cd46 100644 --- a/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts +++ b/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts @@ -87,10 +87,10 @@ const generateTouches = (moduleDef: Partial>, touche if (!Object.prototype.hasOwnProperty.call(def, '__ngMocksTouches')) { const local = new Set(); const meta = coreReflectMeta(def); + coreDefineProperty(def, '__ngMocksTouches', local, false); if (meta) { generateTouches(meta, local); } - coreDefineProperty(def, '__ngMocksTouches', local, false); } mapValues(def.__ngMocksTouches, touches); diff --git a/package.json b/package.json index 636c1ca291..df277841bb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/renovate.json b/renovate.json index dba48ca81e..2ade891a41 100644 --- a/renovate.json +++ b/renovate.json @@ -22,7 +22,7 @@ }, { - "packagePatterns": ["satantime/puppeteer-node", "@types/node"], + "packagePatterns": ["satantime/puppeteer-node", "@types/node", "node"], "major": { "enabled": false }, diff --git a/tests-e2e/.nvmrc b/tests-e2e/.nvmrc new file mode 100644 index 0000000000..431076a948 --- /dev/null +++ b/tests-e2e/.nvmrc @@ -0,0 +1 @@ +16.16.0 diff --git a/tests/issue-3095/test.spec.ts b/tests/issue-3095/test.spec.ts new file mode 100644 index 0000000000..53c7b7a969 --- /dev/null +++ b/tests/issue-3095/test.spec.ts @@ -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(); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index e80be31354..c8d934ee68 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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: { @@ -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: {