Reactjs 将react脚本测试更改为使用.env.development而不是.env.test运行

Reactjs 将react脚本测试更改为使用.env.development而不是.env.test运行,reactjs,jestjs,create-react-app,Reactjs,Jestjs,Create React App,我试过了 dotenv_config_path=./.env.development react-scripts test 但它仍然没有使用.env.development 如何强制react scripts test使用.env.development中的内容运行,正如Jest中的节点所建议的那样默认为test,但可以使用环境变量进行更改 createreact应用程序提供了一个固执己见的笑话设置。可以看出,NODE_ENV被强制为test。可能的选项是在Jest全局设置或测试文件中弹出或重

我试过了

dotenv_config_path=./.env.development react-scripts test
但它仍然没有使用.env.development

如何强制
react scripts test
使用
.env.development
中的内容运行,正如Jest中的
节点所建议的那样默认为
test
,但可以使用环境变量进行更改

createreact应用程序提供了一个固执己见的笑话设置。可以看出,
NODE_ENV
被强制为
test
。可能的选项是在Jest全局设置或测试文件中弹出或重新初始化
dotenv
,或使
process.env.NODE\u env
只读,以便它不能被
react脚本重新定义,例如:

node -r ./test-dev-env.js ./node_modules/react-scripts/scripts/test.js
其中test-dev-env.js是:

Object.defineProperty(process.env, 'NODE_ENV', { value: 'development', writable: false });

我不记得它是否适用于CRA设置,但您是否尝试过
NODE_ENV=development react scripts test
?@EstusFlask是的,但它不起作用