gpt4 book ai didi

node.js - jest-dev-server 的使用示例中的 config/start.js 是什么

转载 作者:太空宇宙 更新时间:2023-11-04 00:02:35 25 4
gpt4 key购买 nike

尝试使用 jest-dev-server ( see here ) 设置 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
}

最佳答案

以下是如何将“jest-dev-server”npm 包与 Node + JEST 一起使用,它将在运行测试之前启动 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");
}

关于node.js - jest-dev-server 的使用示例中的 config/start.js 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53960303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com