I've been trying to set up a testing example according to the common guidelines: Testing in Ionic, Ionic GitHub Example
My project's package.json
:
{
"name": "starter-with-testing",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"test": "karma start ./test-config/karma.conf.js"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "4.7.0",
"@ionic-native/splash-screen": "4.7.0",
"@ionic-native/status-bar": "4.7.0",
"@ionic/storage": "2.1.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "^3.1.10",
"@types/jasmine": "^2.8.8",
"@types/node": "^10.3.4",
"angular2-template-loader": "^0.6.2",
"html-loader": "^0.5.5",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^2.0.3",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.1",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"null-loader": "^0.1.1",
"protractor": "^5.3.2",
"ts-loader": "^4.4.1",
"ts-node": "^6.1.2",
"typescript": "~2.6.2"
},
"description": "An Ionic project"
}
Attempt at $ npm test
results in an error:
Chrome 67.0.3396 (Linux 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught Error: Module build failed: Error: You may be using an old version of webpack; please check you're using at least version 4\n at successfulTypeScriptInstance (/home/alexey/spaces/cordova/starter-with-testing/node_modules/ts-loader/dist/instances.js:168:15)\n at Object.getTypeScriptInstance (/home/alexey/spaces/cordova/starter-with-testing/node_modules/ts-loader/dist/instances.js:51:12)\n at Object.loader (/home/alexey/spaces/cordova/starter-with-testing/node_modules/ts-loader/dist/index.js:16:41)"
That is, webpack 4.x required. Indeed,
$ npm list webpack
[email protected] /home/alexey/spaces/cordova/starter-with-
testing
└─┬ @ionic/[email protected]
└── [email protected]
What am I supposed to do?
UPD:
I've got It looks like your post is mostly code; please add some more details.
fatal error. Your question couldn't be submitted.
I'm really at a loss about more details. There is a dependency hell; please, help. I'll humbly submit whatever additional details you ask.
It was hard to understand how testing works for unit testing in ionic applications. Whether the real code runs, does it runs completely like a full app, or just function we call is executed. We will clarify many such doubts in this series. In reality — it is a mix — where some part is real code and some part is fake code (fake data or functions).
The webpack configuration file ( webpack.config.js) describes the files and options required to package and bundle an application. We need to update it as follows:
As the Unit test can only tell you what is stored in the variables — it can’t tell you what happened in the browser and what was rendered. We will also be covering this topic in this series.
Unit Testing — It deals which checking only the JavaScript ( or Typescript) part of the code. It is called Unit as we check only one unit of code specification at a time it can be a single condition or some functions output. However, this testing doesn’t tell us about whether the whole system works fine or not.
I had the same problem, and fixed it by downgrading my ts-loader and ts-node to the versions used in the ionic-unit-testing-example
repository.
I.e. in package.json
:
{
//...
"devDependencies": {
//...
"ts-loader": "^3.0.3",
"ts-node": "^3.0.2",
//...
}
//...
}
It's ts-loader
that's complaining, so I'm not sure if the ts-node
downgrade is actually required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With