我正在尝试使用@web/test-runner作为我在snowpack上的测试运行程序。到目前为止,我成功地使用@web/test-runner-playwright启动了一个无头浏览器来运行我的测试。现在,我需要一个测试框架(即jest)来利用它的test和expect结构。
如何在上面的设置中使用jest?
我试图直接从@jest/globals导入这些信息,但是我说Do not import '@jest/globals' outside of the Jest test environment时出错了,这是可以理解的。
我不想使用jest作为测试运行程序,因为我希望将snowpack管道与测试结合起来,并在实际的无头浏览器中运行测试。这就是我使用@web/test-runner的原因。
如何将jest与@web/test-runner集成
发布于 2021-11-20 09:19:01
我能让它和玩笑-浏览器-全球一起工作
const { esbuildPlugin } = require('@web/dev-server-esbuild')
module.exports = {
nodeResolve: true,
files: ['src/**/*.spec.{ts,tsx}'],
plugins: [
esbuildPlugin({
ts: true,
tsx: true,
jsxFactory: 'h',
jsxFragment: 'Fragment',
}),
],
coverageConfig: {
include: ['src/**/*.{ts,tsx}'],
},
testRunnerHtml: testFramework => `
<html>
<head>
<script type="module" src="${testFramework}"></script>
<script type="module">import 'jest-browser-globals';</script>
</head>
</html>
`,
}这个配置正在使用esbuild进行捆绑,这个插件运行得非常快,我建议您删除它。
同样的测试运行在浏览器中的jest (node+jsdom)和web测试运行程序中.调试和源代码映射都运行得很好。
发布于 2021-04-01 16:21:21
我认为方法是在jest配置中设置一个定制流道。如果我有什么工作,我会把它张贴在这里!
发布于 2021-04-17 15:38:28
除非您有非常具体的要求,否则不要使用Jest。Jest并不完全支持ECMAScript模块。而且,由于您正在使用现代网络提供的工具,我假设您会对使用ECMAScript最新版本感兴趣。你可以在这里读到更多关于它的信息-- https://jestjs.io/docs/ecmascript-modules
您可以使用mocha + chai与web测试运行程序相结合。您可以从这里引用此设置- https://github.com/snowpackjs/snowpack/tree/main/create-snowpack-app/app-template-react-typescript。
https://stackoverflow.com/questions/66084506
复制相似问题