【问题标题】:start-server-and-test not starting test cases after starting the test serverstart-server-and-test 启动测试服务器后未启动测试用例
【发布时间】:2021-10-26 15:44:28
【问题描述】:

我正在尝试使用start-server-and-test npm 包并想运行测试用例。 为此,我首先需要启动一个测试服务器,然后运行测试命令。 这就是我的package.json 脚本部分的样子。

现在的问题是 start-server-and-test 正在启动测试服务器,但它没有启动测试用例。

{
...
...
  "scripts": {
    "test": "jest --runInBand --config jest.config.json",
    "dev": "nodemon --watch 'src/**' --ext 'ts,js' --exec \"ts-node src/app.ts\"",
    "start": "ts-node src/app.ts",
    "test-server": "MYSQL_TABLE_PREFIX=TEST_ PORT=4001 ts-node src/app.ts",
    "ci": "start-server-and-test 'yarn test-server' http://localhost:4001/ 'yarn test'"
  },
...
...
}

【问题讨论】:

    标签: node.js unit-testing jestjs ts-node


    【解决方案1】:

    所以我发现问题是我的端点 http://localhost:4001/ 没有响应 200 状态代码,因此命令 yarn test 没有被执行。 然后我将端点更改为http://localhost:4001/health,它给出了一个 200 状态代码,然后测试用例被执行。

    所以现在 package.json 看起来像这样

    {
    ...
    ...
      "scripts": {
        "test": "jest --runInBand --config jest.config.json",
        "dev": "nodemon --watch 'src/**' --ext 'ts,js' --exec \"ts-node src/app.ts\"",
        "start": "ts-node src/app.ts",
        "test-server": "MYSQL_TABLE_PREFIX=TEST_ PORT=4001 ts-node src/app.ts",
        "ci": "start-server-and-test 'yarn test-server' http://localhost:4001/health 'yarn test'"
      },
    ...
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多