Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ct): angular component testing #27783

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

sand4rt
Copy link
Collaborator

@sand4rt sand4rt commented Oct 24, 2023

closes: #14153 and https://github.com/sand4rt/playwright-ct-angular

TODO

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@pavelfeldman
Copy link
Member

What's out plan here, is it ready to land? Is it based on Younes's work or is this something different?

Copy link

@yjaaidi yjaaidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @sand4rt!
Here are a couple of things that would be nice to solve before merging.
Let me know if you want me to contribute to your branch directly with some PRs.

The main discussion here is about vite plugin replacement and configuration.

packages/playwright-ct-angular/registerSource.mjs Outdated Show resolved Hide resolved
packages/playwright-ct-angular/registerSource.mjs Outdated Show resolved Hide resolved
packages/playwright-ct-angular/index.js Outdated Show resolved Hide resolved
packages/playwright-ct-angular/package.json Outdated Show resolved Hide resolved
@yjaaidi
Copy link

yjaaidi commented Oct 25, 2023

What's out plan here, is it ready to land?

Hey @pavelfeldman! I just shared my feedback with @sand4rt.
Once we agree on that and fix what can be fixed, the PR should be ready.

Is it based on Younes's work or is this something different?

It doesn't matter anymore. There was just a misunderstanding.
We were just a bit disappointed for not merging efforts but now we are working together to provide what the community is waiting for and that's what matters.

@sand4rt
Copy link
Collaborator Author

sand4rt commented Oct 27, 2023

Hey guys, thanks for the comments! I'm AFK for a couple of days. Will hopefully look at the PR by the end of next week as well

Copy link

@edbzn edbzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added logo is the Angular.js one, here's the link to the correct Angular logo.

packages/playwright-ct-angular/index.js Outdated Show resolved Hide resolved
@sand4rt
Copy link
Collaborator Author

sand4rt commented Nov 5, 2023

The added logo is the Angular.js one, here's the link to the correct Angular logo.

Hi @edbzn, thanks for the input! Would you like to make the change by creating a PR against this branch? See #27783 (comment) for more details

edit: Angular just released their new logo: https://angular.dev/press-kit

This comment has been minimized.

@yjaaidi
Copy link

yjaaidi commented Nov 13, 2023

I just noticed that the tests themselves are using Angular 15.
Should we create a different folder for Angular 16 & Angular 17 and that would require lots of duplication?
Or should we do something at the test-all.spec.js level but that would be a bit too magical?
Or should the "experimental" CT only handle the last version of the framework?
cc. @mxschmitt @pavelfeldman @sand4rt

@yjaaidi
Copy link

yjaaidi commented Nov 21, 2023

Hey @sand4rt, I just created a create-playwright PR microsoft/create-playwright#106 to move the Angular vite plugin config to "user-land".

This way, we can update the todo list as this:

  • Do not handle routing and let users use router testing harness
  • Update tests to use Angular 17
  • Update the documentation
  • Remove @analogjs/vite-plugin-angular dependency & setup.
  • Update https://github.com/microsoft/create-playwright to generate playwright config with @analogjs/vite-plugin-angular and add it to project dependencies.

Here are the advantages of moving the Angular vite plugin setup to the create-playwright generator:

  • @analogjs/vite-plugin-angular has to catch up with Angular internals to make it work for future versions. Currently, the Angular internals it relies on can break at any Angular minor or patch version. Meaning that @playwright/experimental-ct-angular will have to catch up to by updating the dependency which also means a new Playwright release.
  • Users can easily choose the @analogjs/vite-plugin-angular version of their choice.
  • Users can easily choose the @analogjs/vite-plugin-angular configuration of their choice.
  • Users can easily choose another plugin.
  • This doesn't add any dependency to this workspace.

The drawbacks are:

  • It doesn't work out of the box if users don't use the generator or if they use the package manually without reading the docs.
  • Users will have to manually keep @analogjs/vite-plugin-angular up-to-date.

Of course, this is just a temporary solution until the Angular team releases an official vite plugin which will at least warranty major version compatibility.

@yjaaidi
Copy link

yjaaidi commented Feb 15, 2024

Hey @sand4rt are you available in the upcoming days or weeks so we can finish this 😊
Maybe if you could just update your branch I could send you a PR.
Thanks!

@flobacher
Copy link

Great news @yjaaidi and @sand4rt! Thank you so much for your effort time and persistence!!!

@sand4rt
Copy link
Collaborator Author

sand4rt commented Feb 22, 2024

Maybe if you could just update your branch I could send you a PR.

Hey @yjaaidi, #29544 needs to be resolved before i can update. I could resolve the merge conflicts later on if needed, so don't let that hold you back.

For the people willing to contribute; beta testing would also help a lot to ensure everything operates as expected, your feedback is very welcome!

@yjaaidi
Copy link

yjaaidi commented Feb 23, 2024

Thanks @sand4rt!
@edbzn and I had to update and fix #29544 before moving forward.

I think that we have everything now 😊:

  • ✨ it works with thew new transformation
  • ✨ template rendering (thanks to the new transformation system, amazing job @pavelfeldman)
  • ✨ signal inputs support
  • ✨ moved out analog vite plugin from the package
  • ✨ Angular 17 support
  • ✨ and passing providers

Cf. sand4rt#5

@maartentibau
Copy link

Great great great work! Thank you!!
At this moment this will only support standalone components right?

@zargham-leanix
Copy link

Great work @sand4rt @yjaaidi
When this PR is expected to be merged ?

sand4rt and others added 10 commits May 7, 2024 22:29
* feat(ct): angular component testing

* test(ct): test non-event-emitter outputs

* test(ct): test output listener replacement

* feat(ct): support non-event-emitter outputs

* docs(ct): angular

* fix(ct): angular source maps

* chore(ct): new angular logo

* refactor(ct-angular): bump to Angular 17 and move out analogjs plugin

Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>

* refactor(ct-angular): fix component resolution by temporary removing analogjs plugin

Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>

* refactor(ct-angular): fix mount

Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>

* refactor(ct-angular): disable analog plugin as it breaks component registration

* refactor(ct-angular): fix input forwarding

* refactor(ct-angular): fix angular outputs

* refactor(ct-angular): fix angular slots

* test(ct-angular): fix all tests

* test(ct-angular): fix all angular tests

* test(ct-angular): use analog's vite plugin to handle template files

* refactor(ct-angular): remove router-specific code

* refactor(ct-angular): clean up dependencies

* refactor(ct-angular): remove compiler import

* refactor(ct-angular): fix vite version mismatch in tests

* refactor(ct-angular): bump @playwright/experimental-ct-angular to 1.42.0-next

* test(ct-angular): add tests for template rendering

* feat(ct-angular): render simple template

* feat(ct-angular): render template with child components

* feat(ct-angular): render component with signal inputs

* test(ct-angular): make input required

* test(ct-angular): remove now useless import

* feat(ct-angular): allow setting providers

* refactor(ct-angular): clean up slots remains

* feat(ct): angular component testing

* test(ct): test non-event-emitter outputs

* test(ct): test output listener replacement

* feat(ct): support non-event-emitter outputs

* fix(ct): angular source maps

* docs(ct): angular

* chore(ct): new angular logo

* feat(ct-angular): add pw-angular bin

* test(ct-angular): fix type check

use strict dependencies versions to reduce unpredictable behavior as package-lock.json is gitignored

* refactor(ct-angular): remove useless NODE_ENV=test

as we are setting the tsconfig manually
Cf. #5 (comment)

* refactor(ct-angular): use playwright.config.mts as analog vite plugin is esm only

* chore(ct-angular): lint

* fix(ct-angular): resolve Angular component usages

* fix(ct-angular): resolve Angular imports/providers usages

* test(ct-angular): test url change

* test(ct-angular): remove duplicate test

* chore(ct-angular): remove useless pw-angular cli

* chore(ct-angular): remove duplicate PlaywrightTestConfig type

* feat(ct-angular): export the right types

* chore(ct-angular): tidy up

* feat(ct-angular): throw an explicit error when mounting JSX

* chore(ct-angular): remove vite from devDependencies as not used anymore

* chore(ct-angular): remove useless skipLibCheck flag

* chore(ct-angular): remove useless @angular/compiler

Angular's esbuild plugin will automatically add it in jit mode anyway.
Users who really want to use another plugin that requires it can still add it manually to their playwright/index.ts.

* test(ct-angular): improve output listener update test

* chore(ct): revert adapters imports and template

---------

Co-authored-by: sand4rt <info@mesander.com>
Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented May 9, 2024

Test results for "tests 1"

27323 passed, 661 skipped
✔️✔️✔️

Merge workflow run.

@sand4rt
Copy link
Collaborator Author

sand4rt commented May 10, 2024

Hey @pavelfeldman, the PR is finally set for review by the Playwright team! We have deliberately kept the adapter minimal for now and postponed the documentation until more people have tested it and shared their feedback. We would like to gradually make improvements here and there after the merge.

@rainerhahnekamp
Copy link
Contributor

Congratulations to all of you. That's a milestone in Angular testing history!

Just a small remark: From what I've seen, there is no possibility to provide services, right?

If that's the case, it would be great to add this as the next feature once this branch is merged.

As you know, the vast majority of Angular Components usually depend on Services. If we could mock these services, the number of people who could test on a large scale would increase "exponentially."

Either way, congratulations and a thousand thanks again. I'm looking forward to it

@sand4rt
Copy link
Collaborator Author

sand4rt commented May 11, 2024

Congratulations to all of you. That's a milestone in Angular testing history!

Just a small remark: From what I've seen, there is no possibility to provide services, right?

If that's the case, it would be great to add this as the next feature once this branch is merged.

As you know, the vast majority of Angular Components usually depend on Services. If we could mock these services, the number of people who could test on a large scale would increase "exponentially."

Either way, congratulations and a thousand thanks again. I'm looking forward to it

Providers/imports are still open for discussion indeed. We've decided to merge the library first before continuing the discussion: sand4rt#5 (comment)

I think it could either be supported like the other frameworks through the hooksConfig:

// playwright/index.ts
beforeMount(async ({ TestBed, hooksConfig }) => {
  TestBed.configureTestingModule({
    imports: hooksConfig?.imports,
    providers: hooksConfig?.providers
  });
});
test('hooks config', async ({ mount }) => {
  const component = await mount(AngularComponent, {
    hooksConfig: {
      imports: [Component],
      providers: [Service],
    }
  });
  await expect(component).toContainText('boop');
});

or with dedicated APIs:

test('imports and providers', async ({ mount }) => {
  const component = await mount(AngularComponent, {
    imports: [Component],
    providers: [Service],
  });
  await expect(component).toContainText('boop');
});

@rainerhahnekamp
Copy link
Contributor

Understood, then let's wait for the merge and then continue the discussion. Congrats again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support for Component Tests in Angular apps