Nativescript-cli: On adding test frameworks their peerDependencies are not installed

Created on 30 Nov 2016  路  8Comments  路  Source: NativeScript/nativescript-cli

Steps to reproduce:

  1. Create app and add platform
  2. tns test init --framework jasmine/mocha
  3. tns test android/ios

Expected result: Tests are executes and results are shown
Actual result: Exception Error: Cannot find module 'jasmine-core'...

bug unit testing

Most helpful comment

I think that after seeing the message about the unmet peer dependency -its clear what you have to do. However, it would be great to update the docs with a note that you will have to manually add a dependency based on the testing framework you choose. It would help people who just follow the guide.

@Pip3r4o moving peer-dependecy to dependency is out of our reach, as it is the karma-jamine package that has the peer-dep.

All 8 comments

_Problem_

Only occurs when the user has installed globally npm version 3.x. The difference between npm 2.x and 3.x is that, npm 2.x installs all peer-dependencies of a package and npm 3.x does not.
Example: lets install the following package with package.json like:

{
  "name": "some-dependency",
  "version": "1.0.0",
  "peer-dependencies": {
    "peer-dep-1": "0.0.1"
  }
}

So if we do:
npm install some-dependency --save with npm 2.x, peer-dep-1 will be installed, but if we do the same with npm 3.x peer-dep-1 will not be installed. This happens, because npm 3.x does not install the peer-dependencies.

_Possible solutions_

  • Forcefully install the peer dependencies of all packages when using tns init command. When doing it with npm 2.x, nothing will happen.
  • Add missing peer dependency to tns init command (harder to maintain)
  • fix in package (move from peer-dependency to dependency)

@Plamen5kov how about leaving the responsibility of installing dev peer dependencies to the developer? Messages output by npm are verbose enough where peer dependencies are concerned.

I think that after seeing the message about the unmet peer dependency -its clear what you have to do. However, it would be great to update the docs with a note that you will have to manually add a dependency based on the testing framework you choose. It would help people who just follow the guide.

@Pip3r4o moving peer-dependecy to dependency is out of our reach, as it is the karma-jamine package that has the peer-dep.

https://github.com/NativeScript/nativescript-cli/pull/2693 fix jasmin and qunit successfully, but you still need to manually install mocha.

CLI is now adding peer dependencies, but the problem is that mocha is not longer peer dependency.
May be we should close the issue add some notes here:
https://docs.nativescript.org/tooling/testing#configure-your-project

I believe the $ tns test init command should provide a project that's ready for writing tests, without the need to install any dependencies additionally. We can improve our logic here:
https://github.com/NativeScript/nativescript-cli/blob/master/lib/commands/test-init.ts#L7-L9
https://github.com/NativeScript/nativescript-cli/blob/master/lib/commands/test-init.ts#L32-L33

To add the required depdendencies (as mocha).

The issue is still reproducible .. running

tns test init --framework mocha
tns test ios

is failing with

Error: Cannot find module 'mocha'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

donker picture donker  路  3Comments

PeterStaev picture PeterStaev  路  3Comments

ZMW9 picture ZMW9  路  3Comments

farfromrefug picture farfromrefug  路  3Comments

NickIliev picture NickIliev  路  3Comments