NativeScript / NativeScript/nativescript-cli

Node is not defined when running jasmine tests with karma

Đang mở
#5,458 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

unit testing
Ngôn ngữ chính
JavaScript
Star
1.1k
Fork
204
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
8

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với test-main.ts và các phiên bản package.json được nêu trong báo cáo, sau đó tái hiện lỗi bằng ng test trong dự án sandbox được liên kết. So sánh hai import liên quan đến zone và cấu hình Karma trong khi theo dõi lỗi “Node is not defined”. Hoàn tất khi các bài kiểm thử Jasmine chạy mà không có lỗi đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, javascript, node.js, typescript
Lĩnh vực
mobile-dev, testing-qa
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.