How can I service assets when I run an ng test using the latest angular-cli (beta 15 w / webpack)?

When I try to run the ng test, all my modules and components load correctly, but any of the assets that I include in the <img> tags are not displayed because they are not served in the / assets folder (for example, they will be in the assembly or during development using ng-service)

In addition to this, it would be nice to know how to get the global styles.scss / css file that will be included in the test, since I can only get these styles if I drop CSS into the component and disable ViewEncapsulation.

I am in the latest version of angular-cli webpack (beta 15)

Any help is appreciated.

+7
angular webpack typescript angular-cli
source share
1 answer

I found the answer!

By default, karma settings in angular-cli (webpack) do not serve your data folder by default, but itโ€™s very easy to add (after sifting the documentation)

below is a screenshot of my results and the code I added to make it work

enter image description here

On the left you can see how my image of Billy Mays is now filed, on the right, if you look at the json file section, I added the following:

 { pattern: './src/assets/**', watched: false, included:false, nocache:false, served:true } 

I also added the proxies property to take in served content (the default is http: // localhost: [karma port number] / base

 proxies: { '/assets/': '/base/src/assets/' }, 

By specifying /assets/ as the folder proxy, karma uses the localhost:[karma port number]/assets path localhost:[karma port number]/assets instead of the default value.

I am happy that I was able to answer my question, and I hope that this will help some people starting with angular-cli!

+9
source share

All Articles