使用.env.local与剧作家
我正在为我的NextJS项目设置一些剧作家测试。我的.env.local
中已经有环境变量,我想将它们拉入我的测试env中。
我正在查看该文档,并且看到我可以添加require(“ dotenv”)。config();
到我的playwright.config.js
,但是什么也没有发生当我这样做时(由于不确定
。 :{foo:process.env.foo} 从playwright.config.js
将我的变量移至.env
文件而不是。 Env.Local
,没有任何帮助
。
I'm setting up some first playwright tests for my nextjs project. I already have environment variables in my .env.local
and I'd like to pull them into my test env.
I'm looking at the documentation and I see that I can add require("dotenv").config();
to my playwright.config.js
but nothing is happening when I do that (the scripts are erroring out because of undefined
.
I tried both calling process.env.foo
directly within the script, and also adding a use: {foo: process.env.FOO}
clause to the playwright.config.js
and moving my variables to .env
file instead of .env.local
but nothing worked.
Help would be much appreciated! thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读使用dotenv path with Jest 我发现解决方案是为了配置
require
语句:.env.local
After reading using dotenv path with JEST I found the solution is to configure the
require
statement:.env.local
- set the varsnext.js具有第一方
@next/env/env
可以在playwright.config.ts
文件中使用的软件包,以确保playwright知道所需的环境。Next.js has a first party
@next/env
package that can be used in theplaywright.config.ts
file to ensure Playwright knows about the desired environment.