node.js - jest-dev-server 的使用示例中的 config/start.js 是什么
问题描述
尝试使用 jest-dev-server 设置 jest(请参见此处)。在使用示例中,它们引用了 config/start.js。这个文件在哪里/是什么?
// global-setup.js
const { setup: setupDevServer } = require('jest-dev-server')
module.exports = async function globalSetup() {
await setupDevServer({
command: `node config/start.js --port=3000`,
launchTimeout: 50000,
port: 3000,
})
// Your global setup
}
解决方案
以下是如何在 Node + JEST 中使用“jest-dev-server”npm 包,它将在运行测试之前启动 Web 服务器。
在你的 jest.config.js 文件中添加这个(根据需要更改文件路径):
// A path to a module which exports an async function that is triggered once before all test suites
"globalSetup": "<rootDir>/spec/config/globalSetup.js",
// A path to a module which exports an async function that is triggered once after all test suites
"globalTeardown": "<rootDir>/spec/config/globalTeardown.js",
现在添加一个 globalSetup.js 文件:
const { setup: setupDevServer } = require('jest-dev-server')
module.exports = async function globalSetup() {
await setupDevServer({
command: 'node entryPointScriptToStartYourWebApp.js',
launchTimeout: 10000,
port: 3000
})
// Your global setup
console.log("globalSetup.js was invoked");
}
现在添加一个 globalTeardown.js 文件:
const { teardown: teardownDevServer } = require('jest-dev-server')
module.exports = async function globalTeardown() {
await teardownDevServer()
// Your global teardown
console.log("globalTeardown.js was invoked");
}
推荐阅读
- asp.net - IIS Web.config 将一个子文件夹重定向到另一个
- python - TypeError:字符串索引必须是整数(在 lambda 函数中)
- c# - 如何以编程方式更新 Word 字段?
- python - 拆分包含“.”的字符串 不使用内置函数
- python-3.x - 如何将广播数据包发送到特定的 MAC 地址
- javascript - ASP.NET MVC 在按钮单击错误时调用 javascript 函数:“未捕获 RangeError:超出最大调用堆栈大小”
- laravel - 我无法通过 laravel-sendgrid-driver 传递自定义变量
- c# - 在 ASP.Net Core 中上传大文件时出现 CORS 失败
- python - 与 model.fit 不兼容的形状
- c# - System.ValueTuple 找不到 Winform 指定的文件