NativeScript / NativeScript/nativescript-cli
Node is not defined when running jasmine tests with karma
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 1.1k
- 派生
- 204
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 8
描述
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();

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"
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 test-main.ts 和报告中显示的 package.json 版本开始,然后在链接的 sandbox 项目中使用 ng test 重现失败。跟踪 “Node is not defined” 错误,同时比较两个与 zone 相关的导入和 Karma 配置。Jasmine 测试能够在没有该错误的情况下运行即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, javascript, node.js, typescript
- 领域
- mobile-dev, testing-qa
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100