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

[Feature] Support for Component Tests in Angular apps #14153

Open
jhanink opened this issue May 13, 2022 · 57 comments
Open

[Feature] Support for Component Tests in Angular apps #14153

jhanink opened this issue May 13, 2022 · 57 comments

Comments

@jhanink
Copy link

jhanink commented May 13, 2022

Please support Component Testing for Angular.

In v1.22.0, there is experimental support for react, vue, and svelte Component Tests

https://github.com/microsoft/playwright/releases/tag/v1.22.0

F997E557-0366-4AF7-BB76-1BCDA37C0611

@vitalics
Copy link

@jhanink please provide how your see API in ideal world for component testing angular app.

@vitalics
Copy link

@mxschmitt @jhanink I thing is a good idea to support angular applications. But let me put some notes.

React/vue has a simple API (aka ReactDOM.render function) to put the component in your DOM node. Angular applications has not such API. The minimal repro:

index.html

<body>
  <app-root></app-root>
// angular runtime
<script src="runtime.js" type="module"></script> 
<script src="polyfills.js" type="module"></script>
// compiled app
<script src="main.js" type="module"></script>
</body>

main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule, Component } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

@Component({
  selector: 'app-root',
  template:'<span>{{ title }} app is running!</span>' 
})
export class AppComponent {
  title = 'my-app';
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }


platformBrowserDynamic().bootstrapModule(AppModule)

@tytusplanck-8451
Copy link

Does Angular v14 help resolve and make this simpler? With standalone components coming I think this could be similar to the React/Vue/Svelte examples.

RFC from Anular for context.

@ExFlo
Copy link

ExFlo commented Jun 30, 2022

Does Angular v14 help resolve and make this simpler? With standalone components coming I think this could be similar to the React/Vue/Svelte examples.

RFC from Anular for context.

About the new setup with standalone component angular docs

@Tallyb
Copy link

Tallyb commented Sep 6, 2022

That will be great.
In order for this to work with traditional component (read: not standalone), you will need to do something like Testbed which is the compilation context for an angular component. Only that will give you a renderable component. You might want to look at storybook angular library, which is dealing with the same thing basically (render a single component in isolation).

@e-oz
Copy link

e-oz commented Sep 6, 2022

Playwright is so amazing that I want to replace all our e2e tests, including tests in libraries, with Playwright.
Would be amazing to have Angular components support, at least standalone components.

@Waterstraal
Copy link

Support for Angular would be great! Cypress has proven it is technically possible, even without standalone components, if I'm not mistaken :).

@sand4rt
Copy link
Collaborator

sand4rt commented Nov 15, 2022

Another obstacle is that Playwright transpiles the components with Vite and Angular has no Vite support as far as i know.

@yjaaidi
Copy link

yjaaidi commented Dec 7, 2022

Just released Angular support here: https://github.com/jscutlery/devkit/tree/main/packages/playwright-ct-angular
but you'll have to follow the Versatile Angular Style: standalone, inject(), inline templates & styles.

@e-oz
Copy link

e-oz commented Dec 7, 2022

I hope PW team will not postpone this feature because of previous comment :)

@yjaaidi
Copy link

yjaaidi commented Dec 9, 2022

While the current implementation only works with Versatile Angular Style.
Using this angular vite plugin might help supporting most use cases. https://github.com/analogjs/analog/tree/main/packages/vite-plugin-angular

@yjaaidi
Copy link

yjaaidi commented Dec 9, 2022

I also opened an issue to merge efforts.

#19380

@sand4rt
Copy link
Collaborator

sand4rt commented Dec 20, 2022

@brandonroberts May I ask if you think it is realistic/desirable to use your Vite plugin for Angular? Saw you said something about it earlier in: analogjs/analog#20 (comment) 😄

@brandonroberts
Copy link

@sand4rt yes, it's possible to use it. I've tested a working solution with Playwright Component Tests and Angular using the Vite plugin. Supports inline/external styles and constructor DI

@sand4rt
Copy link
Collaborator

sand4rt commented Dec 20, 2022

Awesome! Do you still have the solution? Perhaps it can help with the integration if the Playwright team decides to use it?

@brandonroberts
Copy link

I don't have the solution I worked on before, but I remember the steps to get it working. I'll recreate it and push up a repo and we can decide what to do from there

@brandonroberts
Copy link

brandonroberts commented Dec 22, 2022

Here's the repo! https://github.com/brandonroberts/analog-playwright-component-tests

Of course it will need more work to override providers and such, but its a start

@sand4rt
Copy link
Collaborator

sand4rt commented Mar 29, 2023

Hi all, i'm also building a library for testing Angular components with Playwright due to the absence of @yjaaidi. It is still work in progress: https://github.com/sand4rt/playwright-ct-angular.

edit: It is ready for use. If you have any feedback, let me know. @brandon thanks for the repo, managed to integrate your Vite plugin!

@edbzn
Copy link

edbzn commented Apr 22, 2023

Hi all, i'm also building a library for testing Angular components with Playwright due to the absence of @yjaaidi.

@sand4rt Why have you not opened issues against our repository? We could have joined the effort instead of splitting the work with multiple community solutions.

@sand4rt
Copy link
Collaborator

sand4rt commented Apr 22, 2023

@edbzn I worked on it before @yjaaidi released the lib. Tried to collaborate and combine efforts several times without luck see: #19395 for example. So then i decided to publish a separate one.

@yjaaidi
Copy link

yjaaidi commented Apr 22, 2023

Hi @sand4rt, I was off for a while and catching up now.
As mentioned by @edbzn, we were ok with merging efforts in Playwright, not another library. In addition to this, I am not the only maintainer of @jscutlery/devkit and @edbzn could have helped.

Also, we are sad to see that there is no credit for our work in your library.

@sand4rt
Copy link
Collaborator

sand4rt commented Apr 22, 2023

Also, we are sad to see that there is no credit for our work in your library.

Which part do you think i should have give credit for? I think that the library i made looks/works nothing like yours right?

Edit: Not sure if the Playwright team is focusing on other things, but im still open to collaborate on official support.

@the-ult
Copy link

the-ult commented Jun 20, 2023

Any news on combining/merging any of the above Angular Component Testing solutions in Playwright?

@brandonroberts
Copy link

I think official Vite support is coming to Angular 17 next month.

@Tallyb was this discussed somewhere? Official support would be great.

@yjaaidi
Copy link

yjaaidi commented Oct 24, 2023

I think official Vite support is coming to Angular 17 next month.

Yes @Tallyb! Actually, you can already opt-in to vite since v16 by replacing @angular-devkit/build-angular:browser with @angular-devkit/build-angular:browser-esbuild

That said, this doesn't change things concerning the integration with Playwright etc... as Angular will not expose a vite plugin yet.
But Brandon is here to bridge the gap.

@yjaaidi
Copy link

yjaaidi commented Oct 24, 2023

@brandonroberts I think that @Tallyb meant that Angular 17 has official vite support.

@brandonroberts
Copy link

@brandonroberts I think that @Tallyb meant that Angular 17 has official vite support.

Ahh, ok

@mxschmitt
Copy link
Member

Would like to create a PR, but it is up to the Playwright team. It's also an option to discuss it at my repo or create a community repo, all fine with me :)

We discussed it in our team meeting. We are interested in landing the Angular support inside the Playwright repository if its like the other frameworks covered with tests/does not depend on a lot of external dependencies. Thanks!

@yjaaidi
Copy link

yjaaidi commented Oct 24, 2023

Perfect! Thank you @mxschmitt!
@sand4rt do you mind creating the PR based on @sand4rt/playwright-ct-angular then we can discuss the details directly on the PR? This way the decisions will be easier to track. What do you think?

Thank you in advance.

@sand4rt
Copy link
Collaborator

sand4rt commented Oct 24, 2023

Awesome! The repo i currently have is like the other frameworks, covered with tests and no external dependencies other than Angular and @brandonroberts's Vite plugin. Will create an PR ASP so we can attack it from multiple angles:)

@sand4rt
Copy link
Collaborator

sand4rt commented Oct 24, 2023

Hi all, see the PR above. Curious to hear what you all think! I'll go through it again as well later on this week.

@yjaaidi
Copy link

yjaaidi commented Oct 25, 2023

Cool! Thx @sand4rt!

@kddsultan
Copy link

I think official Vite support is coming to Angular 17 next month.

How is that support relevant for this discussion/issue? Thanks

@R-Bower
Copy link

R-Bower commented Nov 21, 2023

I think official Vite support is coming to Angular 17 next month.

How is that support relevant for this discussion/issue? Thanks

https://playwright.dev/docs/test-components#under-the-hood

Playwright is using Vite to create the components bundle and serve it.

@muhamedkarajic
Copy link

I think official Vite support is coming to Angular 17 next month.

How is that support relevant for this discussion/issue? Thanks

Its cause Playwright is using vite under the hood thats why Angular is not able to run with it.

@muhamedkarajic
Copy link

muhamedkarajic commented Feb 14, 2024

Any update on this, I would be really interested to give it a try in the production? Angular 17 shipped with official esmodule builder, that might help push this issue forward.

@Waterstraal
Copy link

@yjaaidi @pavelfeldman @mxschmitt @sand4rt Kindly requesting an update on this issue. Is this still expected to land somewhere this year?

Thank you!

@yjaaidi
Copy link

yjaaidi commented Mar 11, 2024

Hey @Waterstraal! we are working on that 😊

@SerkanSipahi
Copy link

we are working on that 😊

@yjaaidi this is awesome, thanks. What is the current status?

@yjaaidi
Copy link

yjaaidi commented Apr 16, 2024

Everything's ready here sand4rt#5
We're just waiting for any feedback from @sand4rt and eventually the merge and the review by the team.

@zargham-leanix
Copy link

@yjaaidi is there any way to try this out locally ?

@yjaaidi
Copy link

yjaaidi commented May 2, 2024

Hey @zargham-leanix, if you just want to play around with it you can clone this https://github.com/yjaaidi/playwright/tree/hello-angular-ct, head to tests/components/ct-angular and run npm test.

Otherwise, you can npm run build && cd packages/playwright-ct-angular && npm link then npm link @playwright/playwright-ct-angular to use it wherever you want.

@muhamedkarajic
Copy link

muhamedkarajic commented May 9, 2024

Everything's ready here sand4rt#5 We're just waiting for any feedback from @sand4rt and eventually the merge and the review by the team.

OMG. Thank you for this, incredable!

@muhamedkarajic
Copy link

muhamedkarajic commented May 15, 2024

Hey @zargham-leanix, if you just want to play around with it you can clone this https://github.com/yjaaidi/playwright/tree/hello-angular-ct, head to tests/components/ct-angular and run npm test.

Otherwise, you can cd packages/playwright-ct-angular; npm link then npm link @playwright/playwright-ct-angular to use it wherever you want.

@yjaaidi I am not able to get it working by following those instructions. I get the following error:

Error: Cannot find module '/Users/muhamedkarajic/GitHub/playwright/node_modules/@playwright/experimental-ct-core/lib/program.js'

I am supposed to use @playwright/playwright-ct-angular and install it locally in another repo. What do I have to do else to get it to run, I have tried also installing to local playwright in packages but still no luck.

@yjaaidi
Copy link

yjaaidi commented May 21, 2024

Hi @muhamedkarajic, it seems that the library was not built first.
Try running npm run build. (I just updated my previous comment to add the command, so you didn't miss it 😉)

@CosminGramada
Copy link

CosminGramada commented May 21, 2024

Hi @yjaaidi

Just to confirm, this is still waiting for review, merge and release, correct?

@muhamedkarajic
Copy link

When will this be finally merged?

@muhamedkarajic
Copy link

And when will this be finally merged? Asked he again.

@tomczakmarcel
Copy link

And when will this be finally merged? Asked he again.

+1

@idgMaciej
Copy link

Hi @muhamedkarajic, it seems that the library was not built first. Try running npm run build. (I just updated my previous comment to add the command, so you didn't miss it 😉)

Hi @yjaaidi
I would like to learn more about component tests with Angular and since official PR stuck for weeks now I wanted to try your solution. Unfortunately I cannot run it. After:

  • cloning repo
  • switch to "hello-angular-ct" branch (tests/components/ct-angular is not there on main)
  • npm install
    I have executed npm run build && cd packages/playwright-ct-angular && npm link as you mentioned above from root dir. That was without any issues. But then I cannot run npm link @playwright/playwright-ct-angular because there is no "playwright-ct-angular":

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@playwright%2fplaywright-ct-angular - Not found
'@playwright/playwright-ct-angular@*' is not in this registry.

not sure which step I have missed.
Can you please take a look or point me to some other repo that I can give a shot with component tests before (hopefully) Playwright officially support this?

@jhanink
Copy link
Author

jhanink commented Sep 5, 2024

This has been a fun ride over the past 2.5 years

The good news is - it might be ready to ship soon.
The bad news is - it might not be ready to ship soon.
😜

@muhamedkarajic
Copy link

muhamedkarajic commented Oct 16, 2024

Who are we? Angular devs. What do we want?! Playwright component testing built in for Angular! When do we want it? This year, not next!

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

Successfully merging a pull request may close this issue.