mardi 28 mars 2017

Ionic 2 : Error with test and images

I try to test my Ionic 2 app with Jasmine and Karma. When I run 'npm test' I have this error :

C:\xampp\htdocs\MyApp>npm test

> ionic-hello-world@ test C:\xampp\htdocs\MyApp
> karma start ./test-config/karma.conf.js


webpack: Compiled successfully.
webpack: Compiling...
ts-loader: Using typescript@2.0.9 and C:\xampp\htdocs\MyApp\tsconfig.json
28 03 2017 14:24:17.950:WARN [karma]: No captured browser, open http://localhost:9876/

ERROR in ./src/pages/login/login.html
Module not found: Error: Can't resolve './assets/images/fr.svg' in 'C:\xampp\htdocs\MyApp\src\pages\login'
 @ ./src/pages/login/login.html 1:1614-1647
 @ ./src/pages/login/login.ts
 @ ./src/app/app.component.ts
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./test-config/karma-test-shim.js

ERROR in ./src/pages/login/login.html
Module not found: Error: Can't resolve './assets/images/ch.svg' in 'C:\xampp\htdocs\MyApp\src\pages\login'
 @ ./src/pages/login/login.html 1:1832-1865
 @ ./src/pages/login/login.ts
 @ ./src/app/app.component.ts
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./test-config/karma-test-shim.js

ERROR in ./src/pages/load-screen/load-screen.html
Module not found: Error: Can't resolve './assets/images/logo-yellow.svg' in 'C:\xampp\htdocs\MyApp\src\pages\load-screen'
 @ ./src/pages/load-screen/load-screen.html 1:94-136
 @ ./src/pages/load-screen/load-screen.ts
 @ ./src/pages/login/login.ts
 @ ./src/app/app.component.ts
 @ ./src/app/app.component.spec.ts
 @ ./src \.spec\.ts
 @ ./test-config/karma-test-shim.js
webpack: Failed to compile.
28 03 2017 14:24:17.974:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
28 03 2017 14:24:17.975:INFO [launcher]: Launching browser Chrome with unlimited concurrency
28 03 2017 14:24:18.036:INFO [launcher]: Starting browser Chrome
28 03 2017 14:24:21.892:INFO [Chrome 56.0.2924 (Windows 10 0.0.0)]: Connected on socket Z7t5AaWcca3yDbsDAAAA with id 37780347
Chrome 56.0.2924 (Windows 10 0.0.0) ERROR
  Uncaught Error: Cannot find module "./assets/images/logo-yellow.svg"
  at webpack:///src/pages/load-screen/load-screen.html:1:0 <- karma-test-shim.js:150313
Chrome 56.0.2924 (Windows 10 0.0.0) ERROR
  Uncaught Error: Cannot find module "./assets/images/logo-yellow.svg"
  at webpack:///src/pages/load-screen/load-screen.html:1:0 <- karma-test-shim.js:150313
Chrome 56.0.2924 (Windows 10 0.0.0): Executed 0 of 0 ERROR (1.349 secs / 0 secs)

The problem is the path to my images in my projet. I don't understand why but it's considerate like module.

In fact, if I remove all the path to images in my project, tests works. But I need to keep my images...

There is an example to image's path in my html :

<ion-content padding>
  <div class="loading-screen">
    <img src="assets/images/logo-yellow.svg"><br><br>
    <label></label><br>
    <label></label><br>
    <ion-spinner name="crescent" ></ion-spinner>
  </div>
</ion-content>

Someone have an idea to fix that ?

Aucun commentaire:

Enregistrer un commentaire