-
Notifications
You must be signed in to change notification settings - Fork 12k
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 request] Ability to serve and run tests against pre-compiled output directory #5378
Comments
Before discussing anything else, I would like to mention that your first point was true a while ago, but has since been fixed in #4691. So files in |
I agree that there is a need for this sort of functionality, but not as far reaching as you propose. Unit testing is not a real scenario in my opinion. Build code does not include unit tests, and it doesn't make any sense to try and run outside unit tests over already built code. The e2e scenario is also a minor issue since you can disable serving via So as long as you can serve the built version somehow, you can e2e test it right now. So that leaves us with the matter of consistency and debugging 'real' builds. You mentioned running a simple http server. But you must agree that is a poor simulacrum of your real server. The only real point of commonality are that it serves files somehow. So the need for consistency is not being fulfilled, and the debugging one only partially. I think that the very least such a server would need is:
So I argue that simulating ones real server with fidelity is not just a matter of firing up a simple http server. That is not to say this isn't a real need. It is. And if we had this, there would be a lot of problems that would be caught before the app is deployed somewhere. So I would like to see such a command in the CLI in the future. Something like |
I'm actually running ngServe with most of the criteria you listed today (custom host name, ssl cert, same routing, fallback) this is needed because our app has an oAuth scenario that requires https and a valid hostname in the callback URI. I'm using IIS in production (I work at Microsoft btw) so I'm happy with just a similar enough http server for e2e tests, and honestly the web pack dev server does fine. We also have a staging deployment and flighting / rollback so the e2e's are just the first line of defense. I suppose given the criteria you mentioned it might just make more sense to not even use ng to spin up the server because everyone will have their own production server story so building the app then running your own server for E2Es and local prod-like testing makes more sense. |
I would like to add an argument. I'm fond of VS Code because it has some great remote debugging possibilities. With the current version of the cli this is no longer possible as the .map files only exist in memory and VS Code needs them physically. |
I agree for all of the reasons stated above. Most compelling to me is the reduction of unnecessary work on CI builds. In addition, the issue about running against a production-like environment isn't so much about running against the real deployment environment, as it is running against the code that you actually intend to deploy to your server, to then be served to your client (we are, after all, testing client applications that a dumb server just serves up). When something odd happens in an e2e build, there's little ability to truly introspect what the test is running against, short of obtaining a whole separate environment and deploying code (this is difficult in corporate environments where setting an environment up and/or sharing environments for different purposes, i.e. mock or instrumented code, can be a huge pain in the neck). Another use case is that doing things like instrumenting code for coverage details before a one-off test run, or as mentioned above, editor configuration, becomes much simpler. Free the compiled assets :-D! |
I am very surprised that there's no option for the Is there already someone working on this topic ? I can be a volunteer in case |
Is there any plans to solve that problem? |
To me the most important problem to solve is testing. |
Hi, is there any progress on this topic? |
To me the primary motivation here is to avoid building twice on CI server, but the added benefit of testing on the same compiled output is compelling as well 😄 |
How about a ng build that run internally ng test with an option to skip tests? |
Generally I like that idea, however it raises a series of questions I guess, like where do the compiled test files go? Is the build triggered with the tests suitable for the production? Is the code splitting of production and tests even possible in a convenient way? Will ng-packagr then run the tests? |
According to this comment (angular/angular#12409 (comment)), the speed problem I mentioned above (#5378 (comment)) has been resolved. The other problems remain. I still have to validate the speed to make sure. |
Following up from 2022, I think Filipe's original comment is still pretty accurate. Unit test builds are distinct from typical application builds, using different files (includes test files, doesn't include application bootstrap), so you can't just
When it comes to debugging and serving for unit tests, devservers typically differ from prod servers. To be truly identical you need to do use your prod server for testing, which means it should support live reload, sourcemaps, etc. Doing so also means you're using production data for testing, which should generally be mocked. A separate test server with mock data is usually the best way to address this. The only middle ground is if your prod server is effectively a static file server, but at that point using a separate dev server is identical anyways and doesn't really cause any challenges. Hopefully that helps explain some of our thought process around this. As a result, we don't think there's much value in supporting a test setup that works from a pre-compiled directory. |
Except that you totally could by simply
Tell that to Java and Maven! They've been doing test builds as part of the build process since forever! Yes there is no other use for that code but to run the test, but...uhh...isn't that the only point to writing the test too? The value is that by decoupling the production build, you are assured that your
Yes, and JVM test runners differ from running from the main, but at least the code under test is the same, and only compiled once! You're not testing the servers, you're testing the code you wrote, compiled, and are going to deploy. You're confusing a runtime constraint with a compile time constraint. Anyways, I doubt you're reopening, but I disagree, for the record 😁 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
There is currently no way to serve the site (or run tests) against the result of a previously executed
ng build
. This is problematic for a few reasons explained in detail below.This is a continuation of the discussion started here: #4975
ATTN: @johnpapa / @filipesilva
Motivation
Consistency - There are some inconsistencies between
ng serve
and whatng build
places in thedist
folder. For instance,ng serve
serves everything in the root of thesrc
directory which means that static assets can be loaded fromsrc
that will not be available after deployment.Debugging - Sometimes it's useful to be able to serve the app exactly as it will be deployed. I've used this when debugging AOT related issues that only present at run-time in a production build. There are other options for this scenario, but running simple http server in the dist folder was the easiest option, but I think ng-cli should be able to use it's included server for this instead of me needing to use another http server.
Deployment pipeline - currently my continuous deployment is building the app 3 times. Once each for
ng test
,ng e2e
,ng build
. Ideally I could runng build
then run the tests against the code in the dist folder.The text was updated successfully, but these errors were encountered: