Skip to content

Commit acd58ae

Browse files
André Anderssonandreandersson
André Andersson
authored andcommitted
feat: support signal input from angular 17.1
Adds a custom transformer to transform Angular Code, specifically, signals (input, query and models) to behave better in jit-environment. Solves help-me-mom#7976
1 parent 940dc1a commit acd58ae

10 files changed

+510
-2
lines changed

.circleci/config.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ commands:
9191
paths:
9292
- ./e2e/<< parameters.dir >>/node_modules
9393
- ~/.cache/puppeteer
94+
- ./transformers
9495
test:
9596
parameters:
9697
dir:
@@ -164,6 +165,7 @@ jobs:
164165
paths:
165166
- ./node_modules
166167
- ~/.cache/puppeteer
168+
- ./transformers
167169
- run:
168170
name: Prettier
169171
command: npm run prettier:check
@@ -172,7 +174,7 @@ jobs:
172174
command: npx commitlint -V --from=origin/master
173175
- run:
174176
name: Lint code style
175-
command: npm run lint -- --ignore-pattern e2e/ --ignore-pattern tests-e2e/
177+
command: npm run lint -- --ignore-pattern e2e/ --ignore-pattern tests-e2e/ --ignore-pattern transformers/
176178
- run:
177179
name: Lint typescript
178180
command: npm run ts:check
@@ -250,6 +252,7 @@ jobs:
250252
paths:
251253
- ./tests-e2e/node_modules
252254
- ~/.cache/puppeteer
255+
- ./transformers
253256
- run:
254257
name: E2E
255258
command: npm run e2e
@@ -282,6 +285,7 @@ jobs:
282285
paths:
283286
- ./docs/node_modules
284287
- ~/.cache/puppeteer
288+
- ./transformers
285289
- run:
286290
name: Docs
287291
command: npm run build:docs
@@ -368,6 +372,7 @@ jobs:
368372
- ./e2e/a5es5/node_modules
369373
- ~/.cache/puppeteer
370374
- /ProgramData/nvm/temp
375+
- ./transformers
371376
- run:
372377
name: Spreading Build
373378
command: |

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ node_modules/
1919
test-reports/
2020
tests-e2e/.angular
2121
tmp/
22+
transformers/
2223

2324
**/*.sh
2425
**/*.snap
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, input } from '@angular/core';
2+
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';
3+
4+
@Component({
5+
selector: 'test-component',
6+
template: '<h1>{{ header() }}</h1>',
7+
standalone: true,
8+
})
9+
class TestComponent {
10+
public readonly header = input.required<string>();
11+
}
12+
13+
// See https://github.com/help-me-mom/ng-mocks/issues/7976
14+
describe('issue-7976', () => {
15+
beforeEach(() => MockBuilder(TestComponent));
16+
17+
it('should print header', () => {
18+
const fixture = MockRender(TestComponent, {
19+
header: 'Hello world!',
20+
});
21+
22+
expect(ngMocks.formatText(fixture)).toBe('Hello world!');
23+
});
24+
});

karma.conf.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import path from 'node:path';
55
import { Config } from 'karma';
66
import puppeteer from 'puppeteer';
77
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
8+
import { Program } from 'typescript';
9+
10+
import { angularJitApplicationTransform } from './transformers/jit-transform.js';
811

912
process.env.CHROME_BIN = puppeteer.executablePath();
1013

@@ -120,6 +123,9 @@ export default (config: Config) => {
120123
options: {
121124
configFile: './tsconfig.json',
122125
transpileOnly: true,
126+
getCustomTransformers: (program: Program) => ({
127+
before: [angularJitApplicationTransform(program)],
128+
}),
123129
},
124130
},
125131
],

0 commit comments

Comments
 (0)