Skip to content

Commit

Permalink
feat: support signal input from angular 17.1
Browse files Browse the repository at this point in the history
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

Signed-off-by: André Andersson <[email protected]>
  • Loading branch information
André Andersson authored and andreandersson committed May 20, 2024
1 parent 940dc1a commit 3418f12
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ commands:
paths:
- ./e2e/<< parameters.dir >>/node_modules
- ~/.cache/puppeteer
- ./transformers
test:
parameters:
dir:
Expand Down Expand Up @@ -164,6 +165,7 @@ jobs:
paths:
- ./node_modules
- ~/.cache/puppeteer
- ./transformers
- run:
name: Prettier
command: npm run prettier:check
Expand All @@ -172,7 +174,7 @@ jobs:
command: npx commitlint -V --from=origin/master
- run:
name: Lint code style
command: npm run lint -- --ignore-pattern e2e/ --ignore-pattern tests-e2e/
command: npm run lint -- --ignore-pattern e2e/ --ignore-pattern tests-e2e/ --ignore-pattern transformers/
- run:
name: Lint typescript
command: npm run ts:check
Expand Down Expand Up @@ -250,6 +252,7 @@ jobs:
paths:
- ./tests-e2e/node_modules
- ~/.cache/puppeteer
- ./transformers
- run:
name: E2E
command: npm run e2e
Expand Down Expand Up @@ -282,6 +285,7 @@ jobs:
paths:
- ./docs/node_modules
- ~/.cache/puppeteer
- ./transformers
- run:
name: Docs
command: npm run build:docs
Expand Down Expand Up @@ -368,6 +372,7 @@ jobs:
- ./e2e/a5es5/node_modules
- ~/.cache/puppeteer
- /ProgramData/nvm/temp
- ./transformers
- run:
name: Spreading Build
command: |
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ node_modules/
test-reports/
tests-e2e/.angular
tmp/
transformers/

**/*.sh
**/*.snap
Expand Down
24 changes: 24 additions & 0 deletions e2e/a18/src/tests/issue-7976/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component, input } from '@angular/core';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';

@Component({
selector: 'test-component',
template: '<h1>{{ header() }}</h1>',
standalone: true,
})
class TestComponent {
public readonly header = input.required<string>();
}

// See https://github.com/help-me-mom/ng-mocks/issues/7976
describe('issue-7976', () => {
beforeEach(() => MockBuilder(TestComponent));

it('should print header', () => {
const fixture = MockRender(TestComponent, {
header: 'Hello world!',
});

expect(ngMocks.formatText(fixture)).toBe('Hello world!');
});
});
6 changes: 6 additions & 0 deletions karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import path from 'node:path';
import { Config } from 'karma';
import puppeteer from 'puppeteer';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import { Program } from 'typescript';

import { angularJitApplicationTransform } from './transformers/jit-transform.js';

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

Expand Down Expand Up @@ -120,6 +123,9 @@ export default (config: Config) => {
options: {
configFile: './tsconfig.json',
transpileOnly: true,
getCustomTransformers: (program: Program) => ({
before: [angularJitApplicationTransform(program)],
}),
},
},
],
Expand Down
Loading

0 comments on commit 3418f12

Please sign in to comment.