NativeScript / nativescript-cli

Command-line interface for building NativeScript apps
https://www.npmjs.com/package/nativescript
Apache License 2.0
1.04k stars 196 forks source link

Cannot setup unit testing for a new project #5637

Open adrian-niculescu opened 2 years ago

adrian-niculescu commented 2 years ago

Issue Description

Create an a new TyepScript app and initialize it for testing with mocha. When running the tests there is an error that the karma.conf.js is missing.

Reproduction

ns create MyApp --ts
cd MyApp
npm install --legacy-peer-deps
ns platform add android
ns test init --framework=mocha
ns test android --emulator --justlaunch

OR for iOS (same result):

ns create MyApp --ts
cd MyApp
npm install --legacy-peer-deps
ns platform add ios
ns test init --framework=mocha
ns test ios --emulator --justlaunch

Relevant log output (if applicable)

Searching for devices...
22 02 2022 15:48:25.625:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
22 02 2022 15:48:25.630:ERROR [config]: Error in config file!
  Error: Cannot find module '/Users/adriann/Developer/MyApp/karma.conf.js'
Require stack:
- /Users/adriann/Developer/MyApp/node_modules/karma/lib/config.js
- /Users/adriann/Developer/MyApp/node_modules/karma/lib/server.js
- /Users/adriann/.nvm/versions/node/v16.14.0/lib/node_modules/nativescript/lib/services/karma-execution.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.parseConfig (/Users/adriann/Developer/MyApp/node_modules/karma/lib/config.js:433:22)
    at new Server (/Users/adriann/Developer/MyApp/node_modules/karma/lib/server.js:81:22)
    at process.<anonymous> (/Users/adriann/.nvm/versions/node/v16.14.0/lib/node_modules/nativescript/lib/services/karma-execution.js:11:23)
    at process.emit (node:events:520:28)
    at emit (node:internal/child_process:938:14)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
Test run failed.

Environment

Environment Result of echo 'y' | npx nativescript-envinfo

OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Shell: /bin/bash
node: 16.14.0
npm: 8.5.1
nativescript: 8.1.5

# android
java: 11.0.11
ndk: Not Found
apis: 29, 30, 31, 32
build_tools: 29.0.2, 29.0.3, 30.0.1, 30.0.2, 30.0.3, 31.0.0
system_images: 
  - android-23 | Google APIs Intel x86 Atom_64
  - android-24 | Google APIs Intel x86 Atom_64
  - android-24 | Google Play Intel x86 Atom
  - android-25 | Google APIs Intel x86 Atom_64
  - android-26 | Google APIs Intel x86 Atom_64
  - android-27 | Google APIs Intel x86 Atom
  - android-28 | Google Play Intel x86 Atom_64
  - android-29 | Google Play Intel x86 Atom_64
  - android-30 | Google Play Intel x86 Atom_64
  - android-31 | Google Play Intel x86 Atom_64
  - android-32 | Google Play Intel x86 Atom_64

# ios
xcode: 12.5.1/12E507
cocoapods: 1.11.2
python: 2.7.16
python3: 3.9.10
ruby: 2.7.5
platforms: 
  - iOS 14.5
  - DriverKit 20.4
  - macOS 11.3
  - tvOS 14.5
  - watchOS 7.4

Dependencies

"dependencies": {
  "@nativescript/core": "~8.1.1",
  "@nativescript/theme": "~3.0.1",
  "@nativescript/unit-test-runner": "^3.0.2"
},
"devDependencies": {
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
  "@nativescript/types": "~8.1.1",
  "@nativescript/webpack": "~5.0.0",
  "@types/karma-chai": "0.1.2",
  "@types/mocha": "9.0.0",
  "chai": "4.3.6",
  "karma": "6.3.16",
  "karma-chai": "0.1.0",
  "karma-coverage": "2.0.3",
  "karma-mocha": "2.0.1",
  "karma-nativescript-launcher": "0.4.0",
  "mocha": "9.1.3",
  "nyc": "15.1.0",
  "typescript": "~4.3.5"
}

Please accept these terms

adrian-niculescu commented 2 years ago

Retested this after NativeScript CLI 8.2.2 was released

ns create MyApp --ts
cd MyApp
npm install
ns platform add ios
ns platform add android
ns platform update ios
ns platform update android
ns test init --framework=mocha
ns test android --emulator --justlaunch

still does not work out-of-the-box, but after adding "@nativescript/android": "^8.2.2", to devDependencies in package.json it worked

Current working environment (after manual adjustments):

echo 'y' | npx nativescript-envinfo
OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Shell: /bin/bash
node: 16.14.0
npm: 8.5.1
nativescript: 8.2.2

# android
java: 11.0.11
ndk: Not Found
apis: 29, 30, 31, 32
build_tools: 29.0.2, 29.0.3, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0
system_images: 
  - android-23 | Google APIs Intel x86 Atom_64
  - android-24 | Google APIs Intel x86 Atom_64
  - android-24 | Google Play Intel x86 Atom
  - android-25 | Google APIs Intel x86 Atom_64
  - android-26 | Google APIs Intel x86 Atom_64
  - android-27 | Google APIs Intel x86 Atom
  - android-28 | Google Play Intel x86 Atom_64
  - android-29 | Google Play Intel x86 Atom_64
  - android-30 | Google Play Intel x86 Atom_64
  - android-31 | Google Play Intel x86 Atom_64
  - android-32 | Google Play Intel x86 Atom_64

# ios
xcode: 12.5.1/12E507
cocoapods: 1.11.2
python: 2.7.16
python3: 3.9.10
ruby: 3.1.1
platforms: 
  - iOS 14.5
  - DriverKit 20.4
  - macOS 11.3
  - tvOS 14.5
  - watchOS 7.4

Dependencies

"dependencies": {
  "@nativescript/core": "~8.2.0",
  "@nativescript/theme": "~3.0.2",
  "@nativescript/unit-test-runner": "^3.0.2"
},
"devDependencies": {
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
  "@nativescript/android": "^8.2.2",
  "@nativescript/ios": "8.2.1",
  "@nativescript/types": "~8.2.0",
  "@nativescript/webpack": "~5.0.6",
  "@types/karma-chai": "0.1.2",
  "@types/mocha": "9.1.0",
  "chai": "4.3.6",
  "karma": "6.3.17",
  "karma-chai": "0.1.0",
  "karma-coverage": "2.2.0",
  "karma-mocha": "2.0.1",
  "karma-nativescript-launcher": "0.4.0",
  "mocha": "9.2.1",
  "nyc": "15.1.0",
  "typescript": "~4.5.5"
}
rigor789 commented 2 years ago
ns create myTestApp --ts
cd myTestApp
ns test init --framework=mocha
ns test android --emulator --justlaunch

These work for me - the only change I had to make (which I'm fixing in the default karma config) was to add hostname: '127.0.0.1' because in node17 localhost get's resolved to the ipv6 address by default, and causes the following error:

Error: connect ECONNREFUSED ::1:9876

Using 127.0.0.1 forces it to use ipv4...

Committed the fix here - will publish along with other fixes later... https://github.com/NativeScript/nativescript-cli/commit/81cb9c37cdd4e24115be79b24b68dfbaf8cdcfd2

adrian-niculescu commented 2 years ago

Ran:

ns create myTestApp --ts
cd myTestApp
ns test init --framework=mocha
ns test android --emulator --justlaunch

with the following error:

Successfully installed on device with identifier 'emulator-5554'.
Unable to apply changes on device: emulator-5554. Error is: Invalid Version: null.

Full logs

$ ns test android --emulator --justlaunch
Searching for devices...
14 03 2022 16:24:21.307:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
14 03 2022 16:24:21.628:INFO [karma-server]: Karma v6.3.17 server started at http://localhost:9876/
14 03 2022 16:24:21.628:INFO [launcher]: Launching browsers android with concurrency unlimited
14 03 2022 16:24:21.632:INFO [launcher]: Starting browser NativeScript Unit Test Runner
Copying template files...
Platform android successfully added. v7.0.1
Preparing project...

Using @nativescript/android which requires nsconfig.json to be present.
Writing nsconfig.json based on the values set in nativescript.config.(js|ts).
You may add nsconfig.json to .gitignore as the CLI will regenerate it as necessary.

resolving "./stop-process.js" to "./stop-process.android.js"
asset vendor.js 6.45 MiB [emitted] (name: vendor) (id hint: defaultVendor)
asset bundle.js 18.8 KiB [emitted] (name: bundle)
asset runtime.js 11.6 KiB [emitted] (name: runtime)
Entrypoint bundle 6.48 MiB = runtime.js 11.6 KiB vendor.js 6.45 MiB bundle.js 18.8 KiB
runtime modules 2.46 KiB 7 modules
orphan modules 356 bytes [orphan] 6 modules
modules by path ./node_modules/@nativescript/ 1.51 MiB 208 modules
modules by path ./node_modules/css-tree/ 317 KiB 113 modules
modules by path ./node_modules/source-map/lib/*.js 36.3 KiB 6 modules
modules by path ./node_modules/reduce-css-calc/dist/ 131 KiB 5 modules
modules by path ./node_modules/postcss-value-parser/lib/*.js 12.5 KiB 5 modules
modules by path ./app/ 693 bytes
  ./app/test.ts 206 bytes [built] [code generated]
  + 2 modules
modules by path ./node_modules/mdn-data/css/*.json 242 KiB
  ./node_modules/mdn-data/css/at-rules.json 11.6 KiB [built] [code generated]
  + 2 modules
+ 4 modules
webpack 5.70.0 compiled successfully in 5251 ms
Webpack compilation complete.
(node:13265) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/adriann/Developer/SANDBOX/myTestApp/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
         ~ applying user-defined configuration from /Users/adriann/Developer/SANDBOX/myTestApp/App_Resources/Android/before-plugins.gradle
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Built aar for @nativescript/core
Updating runtime package.json with configuration values...
Project successfully prepared (android)
Building project...
Gradle build...
         + setting applicationId
         + applying user-defined configuration from /Users/adriann/Developer/SANDBOX/myTestApp/App_Resources/Android/before-plugins.gradle
         + applying user-defined configuration from /Users/adriann/Developer/SANDBOX/myTestApp/App_Resources/Android/app.gradle
         + using android X library androidx.legacy:legacy-support-v4:1.0.0
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: /Users/adriann/Developer/SANDBOX/myTestApp/node_modules/@nativescript/core/platforms/android/core.aar
         + adding aar plugin dependency: /Users/adriann/Developer/SANDBOX/myTestApp/node_modules/@nativescript/core/platforms/android/widgets-release.aar
         + adding aar plugin dependency: /Users/adriann/Developer/SANDBOX/myTestApp/node_modules/@nativescript/unit-test-runner/platforms/android/unit_test_runner.aar
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Project successfully built.
Build time: 40.653 s.
The build result is located at: /Users/adriann/Developer/SANDBOX/myTestApp/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Unable to apply changes on device: emulator-5554. Error is: Invalid Version: null.

Environment

echo 'y' | npx nativescript-envinfo
OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Shell: /bin/bash
node: 16.14.0
npm: 8.5.1
nativescript: 8.2.2

# android
java: 11.0.11
ndk: Not Found
apis: 29, 30, 31, 32
build_tools: 29.0.2, 29.0.3, 30.0.1, 30.0.2, 30.0.3, 31.0.0, 32.0.0
system_images: 
  - android-23 | Google APIs Intel x86 Atom_64
  - android-24 | Google APIs Intel x86 Atom_64
  - android-24 | Google Play Intel x86 Atom
  - android-25 | Google APIs Intel x86 Atom_64
  - android-26 | Google APIs Intel x86 Atom_64
  - android-27 | Google APIs Intel x86 Atom
  - android-28 | Google Play Intel x86 Atom_64
  - android-29 | Google Play Intel x86 Atom_64
  - android-30 | Google Play Intel x86 Atom_64
  - android-31 | Google Play Intel x86 Atom_64
  - android-32 | Google Play Intel x86 Atom_64

# ios
xcode: 12.5.1/12E507
cocoapods: 1.11.2
python: 2.7.16
python3: 3.9.10
ruby: 3.1.1
platforms: 
  - iOS 14.5
  - DriverKit 20.4
  - macOS 11.3
  - tvOS 14.5
  - watchOS 7.4

Dependencies

"dependencies": {
  "@nativescript/core": "~8.2.0",
  "@nativescript/theme": "~3.0.2",
  "@nativescript/unit-test-runner": "^3.0.2"
},
"devDependencies": {
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
  "@nativescript/types": "~8.2.0",
  "@nativescript/webpack": "~5.0.6",
  "@types/karma-chai": "0.1.2",
  "@types/mocha": "9.1.0",
  "chai": "4.3.6",
  "karma": "6.3.17",
  "karma-chai": "0.1.0",
  "karma-coverage": "2.2.0",
  "karma-mocha": "2.0.1",
  "karma-nativescript-launcher": "0.4.0",
  "mocha": "9.2.1",
  "nyc": "15.1.0",
  "typescript": "~4.5.5"
}
adrian-niculescu commented 2 years ago

Using

Dependencies

"dependencies": {
  "@nativescript/core": "~8.2.1",
  "@nativescript/theme": "~3.0.2",
  "@nativescript/unit-test-runner": "^3.0.2"
},
"devDependencies": {
  "@nativescript/android": "~8.1.1",
  "@nativescript/ios": "~8.2.1",
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
  "@nativescript/types": "~8.2.0",
  "@nativescript/webpack": "~5.0.6",
  "@types/karma-chai": "0.1.3",
  "@types/mocha": "9.1.0",
  "chai": "4.3.6",
  "karma": "6.3.17",
  "karma-chai": "0.1.0",
  "karma-coverage": "2.2.0",
  "karma-mocha": "2.0.1",
  "karma-nativescript-launcher": "0.4.0",
  "mocha": "9.2.1",
  "nyc": "15.1.0",
  "typescript": "~4.5.5"
}

then

ns test android --emulator --justlaunch

works as expected.

Observed discrepancies:

rigor789 commented 2 years ago

by default NativeScript CLI 8.2.2 uses @nativescript/android version 7.0.1

That's strange - seems like an npm cache issue locally? It uses latest 8.2.2 for me as expected.

@nativescript/android is not added by the NativeScript CLI to package.json

Not after ns create but after running the app first - it should be added automatically ("@nativescript/android": "8.2.2")

ns platform update android does upgrade the project to use @nativescript/android@8.2.2 but I have the same error with this version.

Check package.json - ~8.2.2 should work, but try with just 8.2.2 without the tilde and see if that makes a difference? The Invalid Version: null. usually meant an unparsable version number somewhere, though I fixed many cases like that in the CLI, and I haven't seen that pop up for a while now. You can run with --log trace to get a stack-trace of where that's coming from, might help me fix it in the cli.

downgrading to @nativescript/android@8.1.1 -> works as expected.

Does that mean no ~ (tilde) in the version? Might be related to above?


Running the same exact commands:

ns create myTestApp --ts
cd myTestApp
ns test init --framework=mocha
ns test android --emulator --justlaunch

Yields this on both my mac and windows machines:

$ ns test android --emulator --justlaunch
Searching for devices...
Starting Android emulator with image Pixel_3_XL_API_30
Waiting for emulator device initialization...
14 03 2022 16:02:15.275:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
14 03 2022 16:02:17.144:INFO [karma-server]: Karma v6.3.17 server started at http://127.0.0.1:9876/
14 03 2022 16:02:17.144:INFO [launcher]: Launching browsers android with concurrency unlimited
14 03 2022 16:02:17.151:INFO [launcher]: Starting browser NativeScript Unit Test Runner
Copying template files...
Platform android successfully added. v8.2.2
Preparing project...
resolving "./stop-process.js" to "./stop-process.android.js"
asset vendor.js 6.45 MiB [emitted] (name: vendor) (id hint: defaultVendor)
asset bundle.js 18.7 KiB [emitted] (name: bundle)
asset runtime.js 11.6 KiB [emitted] (name: runtime)
Entrypoint bundle 6.48 MiB = runtime.js 11.6 KiB vendor.js 6.45 MiB bundle.js 18.7 KiB
runtime modules 2.46 KiB 7 modules
orphan modules 356 bytes [orphan] 6 modules
modules by path ./node_modules/@nativescript/ 1.51 MiB 208 modules
modules by path ./node_modules/css-tree/ 317 KiB 113 modules
modules by path ./node_modules/source-map/lib/*.js 36.3 KiB 6 modules
modules by path ./node_modules/reduce-css-calc/dist/ 131 KiB 5 modules
modules by path ./node_modules/postcss-value-parser/lib/*.js 12.5 KiB 5 modules
modules by path ./app/ 709 bytes
  ./app/test.ts 213 bytes [built] [code generated]
  + 2 modules
modules by path ./node_modules/mdn-data/css/*.json 242 KiB
  ./node_modules/mdn-data/css/at-rules.json 11.6 KiB [built] [code generated]
  + 2 modules
+ 4 modules
webpack 5.70.0 compiled successfully in 5551 ms
Webpack compilation complete.
(node:19592) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\node_modules\tslib\package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
         ~ applying user-defined configuration from C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\App_Resources\Android\before-plugins.gradle
Built aar for @nativescript/core
Updating runtime package.json with configuration values...
Project successfully prepared (android)
Building project...
Gradle build...
         + applying user-defined configuration from C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\App_Resources\Android\before-plugins.gradle
         + setting applicationId
         + applying user-defined configuration from C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\App_Resources\Android\before-plugins.gradle
         + applying user-defined configuration from C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\App_Resources\Android\app.gradle
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\node_modules\@nativescript\core\platforms\android\core.aar
         + adding aar plugin dependency: C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\node_modules\@nativescript\core\platforms\android\widgets-release.aar
         + adding aar plugin dependency: C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\node_modules\@nativescript\unit-test-runner\platforms\android\unit_test_runner.aar
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Project successfully built.
Build time: 39.315 s.
The build result is located at: C:\Users\rigor789\Documents\Code\_tmp\8.2\myTestApp\platforms\android\app\build\outputs\apk\debug\app-debug.apk
Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Restarting application on device emulator-5554...
Successfully synced application org.nativescript.myTestApp on device emulator-5554.
14 03 2022 16:03:41.155:INFO [undefined 0.0.0 (Android SDK)]: Connected on socket -87QqhCv3jHrZuAdAAAB with id NativeScriptUnit-8586
undefined 0.0.0 (Android SDK): Executed 1 of 1 SUCCESS (0.056 secs / 0.001 secs)
TOTAL: 1 SUCCESS
14 03 2022 16:03:42.067:WARN [undefined 0.0.0 (Android SDK)]: Disconnected (0 times) Client disconnected from CONNECTED undefined 0.0.0 (Android SDK) ERROR
  Disconnected Client disconnected from CONNECTED state (server shutting down)
undefined 0.0.0 (Android SDK): Executed 1 of 1 SUCCESS (0.056 secs / 0.001 secs)
adrian-niculescu commented 2 years ago

I cleared the npm cache via

rm -rf ~/.npm/_cacache

(I have npm installed via nvm

then:

ns create myTestApp --ts
cd myTestApp
ns test init --framework=mocha
ns run android

by default NativeScript CLI 8.2.2 uses @NativeScript/android version 7.0.1

That's strange - seems like an npm cache issue locally? It uses latest 8.2.2 for me as expected.

ns test android --emulator --justlaunch # OR ns run android
Searching for devices...
Copying template files...
Platform android successfully added. v7.0.1

It says it adds the 7.0.1 version not 8.2.2. ⚠️

also tried:

ns platform add android
Platform android already added

ns platform update android
Gradle stop services...
Platform android successfully removed.
Copying template files...
Platform android successfully added. v7.0.1
Successfully updated to version  8.2.2

I checked to see if @nativescript/android is installed:

ls node_modules/@nativescript/android
ls: node_modules/@nativescript/android: No such file or directory

So that's the real problem ⚠️

@NativeScript/android is not added by the NativeScript CLI to package.json

Not after ns create but after running the app first - it should be added automatically ("@nativescript/android": "8.2.2")

after

ns test android --emulator --justlaunch # ns run android

I still don't see @nativescript/android in package.json or in node_modules (seems like a CLI issue) ⚠️

ns platform update android does upgrade the project to use @NativeScript/android@8.2.2 but I have the same error with this version.

Check package.json - ~8.2.2 should work, but try with just 8.2.2 without the tilde and see if that makes a difference? The Invalid Version: null. usually meant an unparsable version number somewhere, though I fixed many cases like that in the CLI, and I haven't seen that pop up for a while now. You can run with --log trace to get a stack-trace of where that's coming from, might help me fix it in the cli. Ok, I put "@nativescript/android": "~8.2.2", in package.json as advised; then

npm install @nativescript/android --save-dev
ns clean; npm install; 
ns test android --emulator --justlaunch

works 👍 I think I just needed a ns clean; npm install there. So this can be considered ok.

TL;DR The remaining issues are:

rigor789 commented 2 years ago

Unable to reproduce unfortunately - can you run with --log trace and share the logs? Have no idea why it would pull in 7.0.1 either, unless you are on a 7.x CLI ns -v?

adrian-niculescu commented 2 years ago
ns -v
8.2.2
- Checking for updates...
✔ Up to date.

Logs for

ns test android --emulator --justlaunch --log trace

logs1.log

Reading the logs I've noticed errors that reference this directory

ls -alh ~/.local/share/.nativescript-cli/
total 288
drwxr-xr-x  8 adriann  staff   256B Mar 14 22:34 .
drwxr-xr-x  5 adriann  staff   160B Nov  5 18:52 ..
-rw-r--r--  1 adriann  staff   110K Mar 14 22:34 doctor-cache.json
-rw-r--r--  1 adriann  staff   8.7K Mar  3 09:45 should-migrate-cache-7.2.1.json
-rw-r--r--  1 adriann  staff   228B Sep 17 08:44 should-migrate-cache-8.1.2.json
-rw-r--r--  1 adriann  staff   7.1K Mar  9 09:44 should-migrate-cache-8.1.5.json
-rw-r--r--  1 adriann  staff   115B Mar  9 15:30 should-migrate-cache-8.2.1.json
-rw-r--r--  1 adriann  staff   1.3K Mar 14 21:26 should-migrate-cache-8.2.2.json

cat should-migrate-cache-8.2.2.json
{
    "2e0fd9d73b055d5e341204f8093f6e4469d2f224a0b505dee681de86a57b850a": "a957c219c80192db22d323180cb7bed67ca120e6",
    "ebb28abc612222b448e0778c143e0709e5676aa236438fca600ee72a015b4a57": "b7e4419b27ab5c9386b1b081af4f4b13f8f1c5f6",
    "63f58b9b93ce97ac8ee99f8b335207086f36f2e4a3a9eacc0e7cd4ce2deb7f58": "d83c07b520620800e4ba450279ff6d6c7c77c379",
    "3e6696a7156bcf9d3e3f327a07420a25bf3db42676711d9b39a5fa7ba144bbb3": "79b12920f4972fe569d917fab5997335f9947996",
    "bbad8ca137524ea66b39a131007fbc1b67f8186895137daa77bcea1405fcf352": "ace098c6f4054f916836b5b90b60209a7c8bbb72",
    "473ca51ff929e348e9c88ab66c70bcc2b2b51a092c03fa72edd45f56dd5a4a33": "b7e4419b27ab5c9386b1b081af4f4b13f8f1c5f6",
    "17e11620c3e69b79d48c6ad7d059f8b363b969cb1e36e1e02980ef05cf8cce28": "8abf7f811b3e31f1bbe1726d77c334320ce89417",
    "4eb61a6a1e137d69ac6c32433e67f290277e10eaa156f6c5990600424a4b02ed": "fd059d39b53ae0e2d1940dff6d0d8d4ab77da7ac",
    "ede126d3a50023ecd7fa576a8311304188b00da6d1ecc7f6338a42b933b5a8dc": "cad66fa2b8f538dbe75b50e365458da80872edfc",
    "7b036bf99b27cc193b83fe0ab11e9b5849b76a1d3ee7050ca795ee7de3349e15": "cad66fa2b8f538dbe75b50e365458da80872edfc",
    "be9e30f0eba07ba3d7ab78da18798fa29e4328c2ca6a137ea16e37aa76f0985b": "75fb99132d0ee499d08e33c24c34a49354989b44",
    "6225674723eb3d2bee4a08a15448319073b6ad3461315d77404f79a31813446d": "85a5a3754ef71e347e19091f147566ee1e3d32ce"
}

which I did not know existed and which was not affected by npm uninstall -g nativescript. Do you think it's related? Should I manually delete these files?

rigor789 commented 2 years ago

Delete /Users/adriann/.local/share/.nativescript-cli/user-settings.json - that seems to be invalid too (likely unrelated, but good to clean stuff up to make sure)

adrian-niculescu commented 2 years ago

I don't have the user-settings.json file actually.

ls -alh  ~/.local/share/.nativescript-cli/user-settings.json
ls: /Users/adriann/.local/share/.nativescript-cli/user-settings.json: No such file or directory

As indicated in my reply above:

ls -alh ~/.local/share/.nativescript-cli/
total 288
drwxr-xr-x  8 adriann  staff   256B Mar 14 22:34 .
drwxr-xr-x  5 adriann  staff   160B Nov  5 18:52 ..
-rw-r--r--  1 adriann  staff   110K Mar 14 22:34 doctor-cache.json
-rw-r--r--  1 adriann  staff   8.7K Mar  3 09:45 should-migrate-cache-7.2.1.json
-rw-r--r--  1 adriann  staff   228B Sep 17 08:44 should-migrate-cache-8.1.2.json
-rw-r--r--  1 adriann  staff   7.1K Mar  9 09:44 should-migrate-cache-8.1.5.json
-rw-r--r--  1 adriann  staff   115B Mar  9 15:30 should-migrate-cache-8.2.1.json
-rw-r--r--  1 adriann  staff   1.3K Mar 14 21:26 should-migrate-cache-8.2.2.json
adrian-niculescu commented 2 years ago
cd ~/.local/share/.nativescript-cli
rm -rf *

and repeated the scenario; same error.

Andreea1998 commented 2 years ago

I could also replicate the "Invalid Version:null" problem.

ns create myTestApp --ts; cd myTestApp; ns test init --framework=mocha; ns test android --emulator --justlaunch leads to Screenshot 2022-03-15 at 13 55 15

And I have:

`echo 'y' | npx nativescript-envinfo

OS: macOS 11.5.2
CPU: (8) x64 Apple M1
Shell: /bin/bash
node: 16.14.0
npm: 8.5.4
nativescript: 8.2.2

# android
java: 11.0.11
ndk: Not Found
apis: 24, 29, 30, 31, 32
build_tools: 29.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0
system_images: 
  - android-31 | Google APIs ARM 64 v8a
  - android-31 | Google Play ARM 64 v8a
  - android-32 | Google Play ARM 64 v8a

# ios
xcode: 12.5.1/12E507
cocoapods: 1.11.2
python: 2.7.16
python3: 3.9.10
ruby: 3.1.1
platforms: 
  - iOS 14.5
  - DriverKit 20.4
  - macOS 11.3
  - tvOS 14.5
  - watchOS 7.4

Dependencies


"dependencies": {
  "@nativescript/core": "~8.2.0",
  "@nativescript/theme": "~3.0.2",
  "@nativescript/unit-test-runner": "^3.0.2"
},
"devDependencies": {
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
  "@nativescript/types": "~8.2.0",
  "@nativescript/webpack": "~5.0.6",
  "@types/karma-chai": "0.1.2",
  "@types/mocha": "9.1.0",
  "chai": "4.3.6",
  "karma": "6.3.17",
  "karma-chai": "0.1.0",
  "karma-coverage": "2.2.0",
  "karma-mocha": "2.0.1",
  "karma-nativescript-launcher": "0.4.0",
  "mocha": "9.2.1",
  "nyc": "15.1.0",
  "typescript": "~4.5.5"
}
` 
rigor789 commented 2 years ago

Can someone with an M1 run this command (@triniwiz @NathanWalker):

ns create myTestApp --ts; cd myTestApp; ns test init --framework=mocha; ns test android --emulator --justlaunch
This is what I get ```log ns create myTestApp --ts; cd myTestApp; ns test init --framework=mocha; ns test android --emulator --justlaunch npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated added 389 packages, and audited 390 packages in 5s 46 packages are looking for funding run `npm fund` for details found 0 vulnerabilities [@nativescript/webpack] Initialized config. Project myTestApp was successfully created. Now you can navigate to your project with cd myTestApp and then: Run the project on multiple devices: $ ns run ios $ ns run android Debug the project with Chrome DevTools: $ ns debug ios $ ns debug android For more options consult the docs or run ns --help added 5 packages, and audited 395 packages in 1s 46 packages are looking for funding run `npm fund` for details found 0 vulnerabilities added 73 packages, and audited 468 packages in 1s 51 packages are looking for funding run `npm fund` for details found 0 vulnerabilities added 7 packages, and audited 475 packages in 1s 51 packages are looking for funding run `npm fund` for details found 0 vulnerabilities added 2 packages, and audited 477 packages in 1s 51 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 23 packages, and audited 500 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 1 package, and audited 501 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 1 package, and audited 502 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 8 packages, and audited 510 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. up to date, audited 510 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 2 packages, and audited 512 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 1 package, and audited 513 packages in 1s 58 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. added 57 packages, and audited 570 packages in 1s 60 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. added 2 packages, and audited 572 packages in 1s 60 packages are looking for funding run `npm fund` for details 2 high severity vulnerabilities To address all issues (including breaking changes), run: npm audit fix --force Run `npm audit` for details. Successfully installed plugin @nativescript/unit-test-runner. Tests using mocha were successfully initialized. Added example test: app/tests/example.spec.ts Main test entrypoint created: app/test.ts Added/replaced tsconfig.spec.json Note: @nativescript/unit-test-runner was included in "dependencies" as a convenience to automatically adjust your app's Info.plist on iOS and AndroidManifest.xml on Android to ensure the socket connects properly. For production you may want to move to "devDependencies" and manage the settings yourself. You can now run your tests: $ ns test ios $ ns test android Searching for devices... 15 03 2022 15:00:01.392:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead. 15 03 2022 15:00:01.612:INFO [karma-server]: Karma v6.3.17 server started at http://127.0.0.1:9877/ 15 03 2022 15:00:01.612:INFO [launcher]: Launching browsers android with concurrency unlimited 15 03 2022 15:00:01.616:INFO [launcher]: Starting browser NativeScript Unit Test Runner Copying template files... Platform android successfully added. v8.2.2 Preparing project... resolving "./stop-process.js" to "./stop-process.android.js" asset vendor.js 6.45 MiB [emitted] (name: vendor) (id hint: defaultVendor) asset bundle.js 18.8 KiB [emitted] (name: bundle) asset runtime.js 11.6 KiB [emitted] (name: runtime) Entrypoint bundle 6.48 MiB = runtime.js 11.6 KiB vendor.js 6.45 MiB bundle.js 18.8 KiB runtime modules 2.46 KiB 7 modules orphan modules 356 bytes [orphan] 6 modules modules by path ./node_modules/@nativescript/ 1.51 MiB 208 modules modules by path ./node_modules/css-tree/ 317 KiB 113 modules modules by path ./node_modules/source-map/lib/*.js 36.3 KiB 6 modules modules by path ./node_modules/reduce-css-calc/dist/ 131 KiB 5 modules modules by path ./node_modules/postcss-value-parser/lib/*.js 12.5 KiB 5 modules modules by path ./app/ 693 bytes ./app/test.ts 206 bytes [built] [code generated] + 2 modules modules by path ./node_modules/mdn-data/css/*.json 242 KiB ./node_modules/mdn-data/css/at-rules.json 11.6 KiB [built] [code generated] + 2 modules + 4 modules webpack 5.70.0 compiled successfully in 3841 ms Webpack compilation complete. ~ applying user-defined configuration from /Users/rigor789/Code/_tmp/8.2/myTestApp/App_Resources/Android/before-plugins.gradle Built aar for @nativescript/core Updating runtime package.json with configuration values... Project successfully prepared (android) Building project... Gradle build... + applying user-defined configuration from /Users/rigor789/Code/_tmp/8.2/myTestApp/App_Resources/Android/before-plugins.gradle + setting applicationId + applying user-defined configuration from /Users/rigor789/Code/_tmp/8.2/myTestApp/App_Resources/Android/before-plugins.gradle + applying user-defined configuration from /Users/rigor789/Code/_tmp/8.2/myTestApp/App_Resources/Android/app.gradle + adding nativescript runtime package dependency: nativescript-optimized-with-inspector + adding aar plugin dependency: /Users/rigor789/Code/_tmp/8.2/myTestApp/node_modules/@nativescript/core/platforms/android/core.aar + adding aar plugin dependency: /Users/rigor789/Code/_tmp/8.2/myTestApp/node_modules/@nativescript/core/platforms/android/widgets-release.aar + adding aar plugin dependency: /Users/rigor789/Code/_tmp/8.2/myTestApp/node_modules/@nativescript/unit-test-runner/platforms/android/unit_test_runner.aar Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Project successfully built. Build time: 33.961 s. The build result is located at: /Users/rigor789/Code/_tmp/8.2/myTestApp/platforms/android/app/build/outputs/apk/debug/app-debug.apk Installing on device emulator-5554... Successfully installed on device with identifier 'emulator-5554'. Restarting application on device emulator-5554... Successfully synced application org.nativescript.myTestApp on device emulator-5554. 15 03 2022 15:01:08.838:INFO [NativeScript / 31 (12; sdk_gphone64_x86_64)]: Connected on socket M5Bwoe7umvaOKxx0AAAB with id NativeScriptUnit-7289 NativeScript / 31 (12; sdk_gphone64_x86_64): Executed 1 of 1 SUCCESS (0.062 secs / 0.002 secs) TOTAL: 1 SUCCESS NativeScript / 31 (12; sdk_gphone64_x86_64) ERROR Disconnected Client disconnected from CONNECTED state (server shutting down) NativeScript / 31 (12; sdk_gphone64_x86_64): Executed 1 of 1 SUCCESS (0.062 secs / 0.002 secs) ```

Running echo 'y' | npx nativescript-envinfo afterwards, shows the runtime in devDependencies and everything works (tested on a windows10 and a macos 12.2.1 machine, same outcome)

`echo 'y' | npx nativescript-envinfo` output ```yaml OS: macOS 12.2.1 CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz Shell: /bin/zsh node: 17.6.0 npm: 8.5.1 nativescript: 8.2.2-next-03-11-2022-1970936431 # android java: 11.0.13 ndk: 23.1.7779620 apis: 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 build_tools: 30.0.3, 31.0.0, 32.0.0 system_images: - android-17 | Google APIs Intel x86 Atom - android-19 | Google APIs Intel x86 Atom - android-21 | Google APIs Intel x86 Atom_64 - android-28 | Google APIs Intel x86 Atom - android-29 | Google APIs Intel x86 Atom - android-30 | Intel x86 Atom_64 - android-30 | Google APIs Intel x86 Atom - android-31 | Google APIs Intel x86 Atom_64 # ios xcode: 13.3/13E113 cocoapods: 1.11.2 python: 2.7.18 python3: 3.9.9 ruby: 2.7.4 platforms: - DriverKit 21.4 - iOS 15.4 - macOS 12.3 - tvOS 15.4 - watchOS 8.5 ``` ### Dependencies ```json "dependencies": { "@nativescript/core": "~8.2.0", "@nativescript/theme": "~3.0.2", "@nativescript/unit-test-runner": "^3.0.2" }, "devDependencies": { "@jsdevtools/coverage-istanbul-loader": "3.0.5", "@nativescript/android": "8.2.2", "@nativescript/types": "~8.2.0", "@nativescript/webpack": "~5.0.6", "@types/karma-chai": "0.1.3", "@types/mocha": "9.1.0", "chai": "4.3.6", "karma": "6.3.17", "karma-chai": "0.1.0", "karma-coverage": "2.2.0", "karma-mocha": "2.0.1", "karma-nativescript-launcher": "0.4.0", "mocha": "9.2.2", "nyc": "15.1.0", "typescript": "~4.5.5" } ```
adrian-niculescu commented 2 years ago

I also tried with your version of the CLI

npm install -g nativescript@8.2.2-next-03-11-2022-1970936431

with the same error as before.

rigor789 commented 2 years ago

I'm using @next only to use the 127.0.0.1 ip in the karma config since I'm on node 17 - otherwise it should be identical. Let see if anyone else with an M1 can run the above and report their results - I'm frankly out of ideas what could possibly be causing it to install old runtime, and not add it to package.json for you...

adrian-niculescu commented 2 years ago

Thank you! Note that I am on using an Intel mac (Mac Mini 2018); @Andreea1998 is using M1 according to the env info.

I also tried to replicate your env more exactly

node --version
v17.6.0

npm --version
8.5.1

ns --version
8.2.2-next-03-11-2022-1970936431

with the same error as before.