node.js - 测试:mocha 尝试在 linux 上运行 cygwin 命令
问题描述
我有一个使用 maven-frontend-plugin 安装所有节点(npm 包)并运行所有 npm 测试的 maven 项目。在 linux 下由于 cygwin 命令失败。
在 pom 中定义了 maven-frontend-plugin 配置,在构建过程中安装 npm 并尝试使用 mocha 运行测试后出现错误。
如果尝试直接使用 Node 运行测试可以在任何环境下使用“mvn clean package”,它在 linux 上都会失败
在 Windows 下,没有任何以前的安装工作。
里面的绒球
```xml
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<!-- Install Node and npm -->
<execution>
<id>install-node-npm</id>
<goals><goal>install-node-and-npm</goal></goals>
<configuration>
<nodeVersion>${frontend-maven-plugin.node.version}</nodeVersion>
<npmVersion>${frontend-maven-plugin.npm.version}</npmVersion>
</configuration>
</execution>
<!-- Install npm modules -->
<execution>
<id>npm-install-modules</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<!-- lint && mocha && nyc coverage -->
<execution>
<id>npm run-script lint</id>
<phase>test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script lint</arguments>
</configuration>
</execution>
<execution>
<id>npm run-script test:coverage</id>
<phase>test</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script test:coverage</arguments>
</configuration>
</execution>
<!-- build angular application -->
<execution>
<id>npm run-script prod</id>
<phase>prepare-package</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script prod</arguments>
</configuration>
</execution>
</executions>
```
Inisde package.json
```json
scripts:{
...
"test:coverage": "nyc npm run-script test:mocha || exit 0",
...
}
```
Linux 失败:
nyc npm run-script test:mocha
ERROR : <base_path>/node/npm:2
(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Module.replacementCompile (node_modules/append-transform/index.js:58:13)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.<anonymous> (node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
已解决使用最新版本的问题在 Ubuntu 上消失了
<frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>
使用安装了 maven 的 Kubernetes pod 之前没有安装任何 Node 仍然无法正常工作。请注意,它适用于没有 nyc 和 mocha 的所有其他项目。
我仍在寻找缺少的东西
解决方案
Kubernetes pod 内部的问题与路径有关。
将正确的 NODE_PATH 值设置为环境变量,该过程运行良好
推荐阅读
- restsharp - 如何使用 restsharp 发布复杂的 Json 数据(正文)?
- c - 用c语言用俄语符号修改字符串
- javascript - 如何提高 React Native 应用程序的性能?
- angular - 使用 Angular 6 中的 TAB 在 Kendo 网格导航中跳过不可编辑的单元格
- ide - 如何在自身上复制行?
- json - laravel whereJson 包含在 laravel 审计中
- geometry - 检查任何两个对象之间的距离是否在指定网格内的算法
- php - Symfony 3.4.:抛出错误时未显示堆栈跟踪
- json.net - 解析仅包含对象值的文本
- android - 在相对布局中显示不同位置和大小的图像