【问题标题】:Can't get the TypeORM tests to run无法运行 TypeORM 测试
【发布时间】:2020-10-31 23:36:42
【问题描述】:

我正在尝试在本地运行 TypeORM 测试。我正在使用 Docker 镜像来运行所有数据库,只需运行:

docker-compose up

我将ormconfig.json.dist 复制到ormconfig.json,然后运行:

npm run compile ; npm run test

它因这个错误而崩溃:

> npm run compile ; npm run test

> typeorm@0.2.25 compile C:\Users\pupeno\Documents\Flexpoint Tech\js\typeorm
> rimraf ./build && tsc


> typeorm@0.2.25 test C:\Users\pupeno\Documents\Flexpoint Tech\js\typeorm
> rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test



  √ github issues > #3158 Cannot run sync a second time (475ms)
  √ github issues > #3588 Migration:generate issue with onUpdate using mysql 8.0 (116ms)
  benchmark > bulk-save > case1
connecting
    1) "before all" hook for "testing bulk save of 10.000 objects"
    2) "after all" hook for "testing bulk save of 10.000 objects"


  2 passing (1m)
  2 failing

  1) benchmark > bulk-save > case1
       "before all" hook for "testing bulk save of 10.000 objects":
     Error: Timeout of 60000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\pupeno\Documents\Flexpoint Tech\js\typeorm\build\compiled\test\benchmark\bulk-save-case1\bulk-save-case1.js)
      at listOnTimeout (internal/timers.js:551:17)
      at processTimers (internal/timers.js:494:7)

  2) benchmark > bulk-save > case1
       "after all" hook for "testing bulk save of 10.000 objects":
     TypeError: Cannot read property 'map' of undefined
      at Object.closeTestingConnections (test\utils\test-utils.ts:285:36)
      at Context.<anonymous> (test\benchmark\bulk-save-case1\bulk-save-case1.ts:16:17)
      at processImmediate (internal/timers.js:458:21)



npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! typeorm@0.2.25 test: `rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the typeorm@0.2.25 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pupeno\scoop\persist\nodejs\cache\_logs\2020-07-11T09_15_28_115Z-debug.log

尝试调试正在发生的事情,据我所见,连接到 PostgreSQL 数据库时超时,但其他数据库似乎工作并使用与 @ 中相同的凭据连接到我的 PSQL 客户端 (DataGrip) 987654328@ 也可以。

我尝试的另一件事是不启动 docker 映像,而是启动我自己的本地 PostgreSQL,使用正确的凭据设置用户和数据库并尝试运行测试。同样的错误。

我正在构建一个使用 TypeORM 并成功连接到同一个 PostgreSQL 的应用程序。他们的测试似乎通过了:https://app.circleci.com/pipelines/github/typeorm/typeorm/1319/workflows/cf7bf4d0-5c6f-485f-803b-64eff385676b/jobs/2012

还有什么想法可以尝试或可能发生什么?

【问题讨论】:

  • 您是否尝试过使用postgres 驱动程序的其他测试?他们都失败了吗?顺便说一句,github.com/typeorm/typeorm/blob/… 有一个有趣的评论:todo(AlexMesser): check why tests are failing under postgres driver 让你流连忘返。
  • 我将失败的测试注释掉,其他测试也以同样的方式失败。

标签: typeorm


【解决方案1】:

我做了一些挖掘,

这些测试是针对所有数据库引擎执行的,如果您对 PostgreSQL 以外的测试不感兴趣,请在 ormconfig.json 中为其他引擎设置 skip 标志。

在其他情况下,您需要解决其他数据库的问题:

我发现问题的一个原因是 MariaDB 不允许来自外部网络的连接,因此如果容器在 composer 网络中运行,则无法从主机网络(运行 npm 测试的地方)连接到它。 为了克服这个问题:

  1. 使用命名项目启动 docker-compose(这将为网络提供一个名称:) docker-compose -p test up -d
  2. 执行允许 root 从任何主机连接的 SQL: docker-compose -p test run --rm mariadb mysql -hmariadb -uroot -padmin -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'.%' IDENTIFIED BY 'admin' WITH GRANT OPTION;\nFLUSH PRIVILEGES;"

之后,mariaDB 的npm run test 就通过了。

MariaDB 容器 docs 提到 MYSQL_ROOT_HOST 应该做同样的工作 - 但由于未知原因,它不起作用。

记得使用 down 和项目名称:docker-compose -p test down

我还发现ormconfig.json 声明没有跳过对 SAP 数据库的测试,但是在 docker-compose.yml 中未启用 SAP 数据库引擎

【讨论】:

  • 你怎么知道是 MariaDB?我确实尝试在此处按照您的步骤操作,但遇到了完全相同的错误。
  • 我在 ormconfig.json 文件中跳过它找到了它
猜你喜欢
  • 2019-03-13
  • 2011-11-12
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
相关资源
最近更新 更多