Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jest typescript测试运行两次,一次用于ts文件,一次用于js文件_Typescript_Jestjs - Fatal编程技术网

Jest typescript测试运行两次,一次用于ts文件,一次用于js文件

Jest typescript测试运行两次,一次用于ts文件,一次用于js文件,typescript,jestjs,Typescript,Jestjs,我开始使用Jest和typescript编写一些测试,但是我遇到了一些错误,问题似乎是测试运行了两次,一次针对ts文件,第二次针对js文件 typescript测试通过,但编译的javascript测试没有通过 yarn run v1.5.1 $ jest PASS src/__tests__/some.test.ts (7.955s) ● Console console.log src/lib/google-analytics/ga-api.ts:75 Succs

我开始使用Jest和typescript编写一些测试,但是我遇到了一些错误,问题似乎是测试运行了两次,一次针对ts文件,第二次针对js文件

typescript测试通过,但编译的javascript测试没有通过

yarn run v1.5.1
$ jest
 PASS  src/__tests__/some.test.ts (7.955s)
  ● Console

    console.log src/lib/google-analytics/ga-api.ts:75
      Succsess!!
    console.log src/__tests__/some.test.ts:42
      { reports: { batchGet: [Function: batchGet] } }

 FAIL  dist/__tests__/some.test.js
  ● Console

    console.log dist/lib/google-analytics/ga-api.js:64
      Reject

  ● it gets a full google analytics report

    No key or keyFile set.

      68 |
      69 |         return new Promise((resolve, reject) => {
    > 70 |             jwtClient.authorize((err: any) => {
      71 |                 if (err) {
      72 |                     console.log("Reject");
      73 |                     reject(err);

      at GoogleToken.<anonymous> (node_modules/googleapis/node_modules/gtoken/src/index.ts:102:13)
      at step (node_modules/googleapis/node_modules/gtoken/build/src/index.js:42:23)
      at Object.next (node_modules/googleapis/node_modules/gtoken/build/src/index.js:23:53)
      at node_modules/googleapis/node_modules/gtoken/build/src/index.js:17:71
      at Object.<anonymous>.__awaiter (node_modules/googleapis/node_modules/gtoken/build/src/index.js:13:12)
      at GoogleToken.Object.<anonymous>.GoogleToken.getTokenAsync (node_modules/googleapis/node_modules/gtoken/build/src/index.js:102:16)
      at GoogleToken.Object.<anonymous>.GoogleToken.getToken (node_modules/googleapis/node_modules/gtoken/src/index.ts:93:17)
      at JWT.<anonymous> (node_modules/googleapis/node_modules/google-auth-library/src/auth/jwtclient.ts:181:37)
      at step (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:57:23)
      at Object.next (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:38:53)
      at node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:32:71
      at Object.<anonymous>.__awaiter (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:28:12)
      at JWT.Object.<anonymous>.JWT.refreshToken (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:181:16)
      at JWT.<anonymous> (node_modules/googleapis/node_modules/google-auth-library/src/auth/jwtclient.ts:154:31)
      at step (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:57:23)
      at Object.next (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:38:53)
      at node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:32:71
      at Object.<anonymous>.__awaiter (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:28:12)
      at JWT.Object.<anonymous>.JWT.authorizeAsync (node_modules/googleapis/node_modules/google-auth-library/build/src/auth/jwtclient.js:156:16)
      at JWT.Object.<anonymous>.JWT.authorize (node_modules/googleapis/node_modules/google-auth-library/src/auth/jwtclient.ts:147:12)
      at Promise (src/lib/google-analytics/ga-api.ts:70:23)
      at GoogleAnalyticsApiClient.getGCPAuthToken (src/lib/google-analytics/ga-api.ts:69:16)
      at GoogleAnalyticsApiClient.<anonymous> (src/lib/google-analytics/ga-api.ts:52:42)
      at dist/lib/google-analytics/ga-api.js:7:71
      at Object.<anonymous>.__awaiter (dist/lib/google-analytics/ga-api.js:3:12)
      at GoogleAnalyticsApiClient.getGaApiClient (dist/lib/google-analytics/ga-api.js:50:16)
      at Object.<anonymous>.test (src/__tests__/some.test.ts:41:14)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        9.516s
Ran all test suites.
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c jest
Directory: /Users/carlosbernal/Documents/Grability/DataScience/ga-downloader
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/Users/carlosbernal/Documents/Grability/DataScience/ga-downloader/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
纱线运行v1.5.1
$jest
通过src/\uuuuu测试\uuuu/some.test.ts(7.955s)
● 安慰
console.log src/lib/google analytics/ga api.ts:75
成功!!
console.log src/\uuuuu tests\uuuu/some.test.ts:42
{报告:{batchGet:[函数:batchGet]}
失败dist/\uuuu测试\uuuu/some.test.js
● 安慰
console.log dist/lib/google analytics/ga api.js:64
拒绝
● 它得到了一份完整的谷歌分析报告
未设置密钥或密钥文件。
68 |
69 |返回新承诺((解决、拒绝)=>{
>70 | jwtClient.authorize((错误:any)=>{
71 |如果(错误){
72 |控制台日志(“拒绝”);
73 |拒绝(错误);
在谷歌令牌上。(node_modules/googleapis/node_modules/gtoken/src/index.ts:102:13)
在步骤(node_modules/googleapis/node_modules/gtoken/build/src/index.js:42:23)
在Object.next(node_modules/googleapis/node_modules/gtoken/build/src/index.js:23:53)
在node_modules/googleapis/node_modules/gtoken/build/src/index.js:17:71
at Object..\uuu waiter(node\u modules/googleapis/node\u modules/gtoken/build/src/index.js:13:12)
在GoogleToken.Object..GoogleToken.getTokenAsync(node_modules/googleapis/node_modules/gtoken/build/src/index.js:102:16)
在GoogleToken.Object..GoogleToken.getToken(node_modules/googleapis/node_modules/gtoken/src/index.ts:93:17)
在JWT(node_modules/googleapis/node_modules/google auth library/src/auth/jwtclient.ts:181:37)
在步骤(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:57:23)
在Object.next(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:38:53)
在node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:32:71
在Object..\uuuu waiter(node\u modules/googleapis/node\u modules/google auth library/build/src/auth/jwtclient.js:28:12)
在JWT.Object..JWT.refreshToken(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:181:16)
在JWT(node_modules/googleapis/node_modules/google auth library/src/auth/jwtclient.ts:154:31)
在步骤(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:57:23)
在Object.next(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:38:53)
在node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:32:71
在Object..\uuuu waiter(node\u modules/googleapis/node\u modules/google auth library/build/src/auth/jwtclient.js:28:12)
在JWT.Object..JWT.authorizeAsync(node_modules/googleapis/node_modules/google auth library/build/src/auth/jwtclient.js:156:16)
在JWT.Object..JWT.authorize(node_modules/googleapis/node_modules/google auth library/src/auth/jwtclient.ts:147:12)
承诺(src/lib/google分析/ga-api.ts:70:23)
在GoogleAnalyticsApicClient.getGCPAuthToken(src/lib/google analytics/ga api.ts:69:16)
在GoogleAnalyticsApicClient。(src/lib/google analytics/ga api.ts:52:42)
在dist/lib/google analytics/ga api.js:7:71
at Object..\uu waiter(dist/lib/google analytics/ga-api.js:3:12)
在GoogleAnalyticsApiClient.getgaapclient(dist/lib/google analytics/ga-api.js:50:16)
at Object..test(src/__tests\u_/some.test.ts:41:14)
测试套件:1个失败,1个通过,共2个
测试:1次失败,1次通过,共2次
快照:共0个
时间:9.516秒
运行所有测试套件。
错误发生意外错误:“命令失败。
退出代码:1
命令:sh
论点:-c笑话
目录:/Users/carlosbernal/Documents/Grability/DataScience/ga downloader
输出:
".
信息如果您认为这是一个bug,请打开一个bug报告,报告中包含“/Users/carlosbernal/Documents/grabbility/DataScience/ga downloader/warn error.log”中提供的信息。
信息访问https://yarnpkg.com/en/docs/cli/run 有关此命令的文档。
这在ts玩笑中是正常的还是我缺少了一些额外的配置

这是正常的还是我缺少了一些额外的配置

您应该仅将
根设置为
/src

module.exports={
“根”:[
“/src”
],
“转变”:{
“^.+\.tsx?$”:“ts笑话”
},
“testRegex”:“(/\uuuuu tests./**)(\\.\.\124;/)(test | spec))\\\.tsx?$”,
“moduleFileExtensions”:[
“ts”,
“tsx”,
“js”,
“jsx”,
“json”,
“节点”
],
}

我也只测试
.tsx?
文件(无
.jsx?
);)

如果使用IDE,您可能只想禁用那些IDE中发生的
.ts
.js
编译,以避免生成给您带来问题的
.js
文件


对于IntelliJ/Webstorm用户:请参阅首选项|语言与框架|类型脚本,更改时重新编译(取消选中)

也有同样的问题,在类型脚本中使用aws cdk,为了防止它,我在jest-config.js的testPathIgnorePatterns属性中添加了
.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testPathIgnorePatterns: [".d.ts", ".js"]
};

这在我的设置中不起作用,因为我使用的是用TypeScript编写的jest快照序列化程序。:(我认为从
moduleFileExtensions
中删除
/jsx?/
可以修复此问题,但目前它会触发此错误:
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  testPathIgnorePatterns: [".d.ts", ".js"]
};