如何为使用 npm 完成的测试定义基本路径

How to define the base path for tests done with npm

我正在开发的 Web 应用程序是一个典型的 Web 应用程序,使用 Angular 作为前端技术,Java spring 引导作为后端。

正如您在上图中看到的,我在名为 filebeat-7.12-darwin-x86_64 的根文件夹中创建了另一个目录,其中包含一些 js 个文件。

当我尝试使用命令 npm run webapp:test 运行 javascript 测试时,我收到了很多错误。我注意到,作为默认配置,lint 尝试分析的 *.js*.ts 文件也在 filebeat-7.12-darwin-x86_64 文件夹中查找。

有一种方法可以指定命令 npm run webapp:test 从哪个文件夹开始测试?我只报告了我提到的命令生成的日志的几行。


> sample-app@0.0.1-SNAPSHOT webapp:test /Users/dummy/git/sample-app
> npm run test


> sample-app@0.0.1-SNAPSHOT pretest /Users/dummy/git/sample-app
> npm run lint


> sample-app@0.0.1-SNAPSHOT lint /Users/dummy/git/sample-app
> eslint . --ext .js,.ts


/Users/dummy/git/sample-app/filebeat-7.12.1-darwin-x86_64/module/barracuda/spamfirewall/config/liblogparser.js
     7:17   error    Require statement not part of import statement                                                              @typescript-eslint/no-var-requires
     8:15   error    Require statement not part of import statement                                                              @typescript-eslint/no-var-requires
    33:1    error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    40:18   error    'DeviceProcessor' is not defined                                                                            no-undef
    43:1    error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    54:13   error    Unsafe return of an any typed value                                                                         @typescript-eslint/no-unsafe-return
    57:35   error    Unnecessary escape character: \-                                                                            no-useless-escape
    59:23   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
    61:20   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
    61:20   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
    61:20   error    Operands of '+' operation must either be both strings or both numbers                                       @typescript-eslint/restrict-plus-operands
    65:1    error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    70:21   error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    71:30   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
    72:16   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
    77:1    error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    77:10   warning  'process' is defined but never used                                                                         @typescript-eslint/no-unused-vars
    83:5    error    Unsafe return of an any typed value                                                                         @typescript-eslint/no-unsafe-return
    86:1    error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
    89:5    error    Unsafe return of an any typed value                                                                         @typescript-eslint/no-unsafe-return
    92:10   warning  'linear_select' is defined but never used                                                                   @typescript-eslint/no-unused-vars
    98:13   error    Expected { after 'if' condition                                                                             curly
    98:37   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
   101:13   error    Expected { after 'if' condition                                                                             curly
   102:13   error    Expected { after 'if' condition                                                                             curly
   102:37   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
   109:30   error    Operands of '+' operation must either be both strings or both numbers. Consider using a template literal    @typescript-eslint/restrict-plus-operands
   127:5    warning  'strip_syslog_priority' is assigned a value but never used                                                  @typescript-eslint/no-unused-vars
   128:21   error    Missing return type on function                                                                             @typescript-eslint/explicit-function-return-type
   133:19   error    Missing return type on function  

提前致谢。

您可以尝试在ng测试中使用--include参数。此选项指定 运行 测试的文件夹。请看:https://angular.io/cli/test#options

或者从 angular.json 文件中排除 ts lint: 在 lint 部分,您可以添加 path/to/folder

"exclude": ["**/filebeat-7.12.1-darwin-x86_64/**"]