NativeScript / NativeScript/nativescript-cli

Node is not defined when running jasmine tests with karma

Offen
#5,458 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

unit testing
Vorherrschende Sprache
JavaScript
Sterne
1.1k
Forks
204
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
8

Beschreibung

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"
}

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit test-main.ts und den im Bericht angegebenen package.json-Versionen und reproduziere dann den Fehler mit ng test im verlinkten Sandbox-Projekt. Vergleiche die beiden zonenbezogenen Imports und die Karma-Konfiguration, während du den Fehler „Node is not defined“ verfolgst. Erledigt ist die Aufgabe, wenn die Jasmine-Tests ohne diesen Fehler ausgeführt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, javascript, node.js, typescript
Bereich
mobile-dev, testing-qa
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.