nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

Node is not defined when running jasmine tests with karma

Open elatus111 opened this issue 5 years ago • 0 comments

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 7.0.11
  • Cross-platform modules:
  • Android Runtime: 7.0.1
  • iOS Runtime: 7.0.0
  • Plugin(s):
  • NativeScript-Angular: 10.1.0
  • Angular: 10.1.7

Describe the bug When running karma tests I get the error "Node is not defined". This is happening in a sandbox project and an existing project that is being upgraded from Angular/Nativescript-angular 8 to 10. I updated the imports in my test-main.ts to what it seems they should be on however the documentation has not been updated so I am not sure if they are correct. My test-main.ts is below. I was unable to only import '@nativescript/zone-js/testing.jasmine' as my tests would fail with the error that "Zone is not defined". I am able to get the error to go away by importing '@nativescript/zone-js/zone-nativescript' as well, but then I get the error that I described above. This is with node version 10.16.0.

import '@nativescript/zone-js/zone-nativescript'; import '@nativescript/zone-js/testing.jasmine';
import {nsTestBedInit} from '@nativescript/angular/testing'; nsTestBedInit();

error

To Reproduce I created a fresh project using Angular 10 and added nativescript and i get the same issue. Expected behavior Tests would run correctly

Sample project

This is my sandbox project where I am getting the same error.

https://github.com/elatus111/nativescript-angular-sandbox

Additional context Package.json below

{ "name": "angular10project", "version": "0.0.0", "scripts": { "android": "ns run android --no-hmr", "ios": "ns run ios --no-hmr", "mobile": "ns run", "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~10.2.3", "@angular/common": "~10.2.3", "@angular/compiler": "~10.2.3", "@angular/core": "~10.2.3", "@angular/forms": "~10.2.3", "@angular/platform-browser": "~10.2.3", "@angular/platform-browser-dynamic": "~10.2.3", "@angular/router": "~10.0.14", "@nativescript/angular": "~10.1.0", "@nativescript/core": "~7.0.13", "@nativescript/theme": "~2.3.0", "@nativescript/unit-test-runner": "^1.0.2", "reflect-metadata": "~0.1.12", "rxjs": "~6.6.0", "tslib": "^2.0.0", "zone.js": "~0.10.2" }, "devDependencies": { "@angular-devkit/build-angular": "~0.1001.7", "@angular/cli": "~10.1.7", "@angular/compiler-cli": "~10.1.6", "@nativescript/android": "7.0.1", "@nativescript/ios": "~7.0.0", "@nativescript/schematics": "^10.1.0", "@nativescript/tslint-rules": "~0.0.5", "@nativescript/types": "~7.0.0", "@nativescript/webpack": "~3.0.0", "@ngtools/webpack": "~10.0.0", "@types/jasmine": "3.5.14", "@types/jasminewd2": "~2.0.3", "@types/node": "^13.1.1", "codelyzer": "^6.0.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", "karma": "5.2.3", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "4.0.1", "karma-jasmine-html-reporter": "^1.5.0", "karma-nativescript-launcher": "0.4.0", "karma-webpack": "3.0.5", "protractor": "~7.0.0", "ts-node": "~9.1.1", "tslint": "~6.1.0", "typescript": "3.9.7" }, "main": "main.tns.js" }

elatus111 avatar Jan 05 '21 20:01 elatus111