久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='FZVcy'></tfoot>

  • <i id='FZVcy'><tr id='FZVcy'><dt id='FZVcy'><q id='FZVcy'><span id='FZVcy'><b id='FZVcy'><form id='FZVcy'><ins id='FZVcy'></ins><ul id='FZVcy'></ul><sub id='FZVcy'></sub></form><legend id='FZVcy'></legend><bdo id='FZVcy'><pre id='FZVcy'><center id='FZVcy'></center></pre></bdo></b><th id='FZVcy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FZVcy'><tfoot id='FZVcy'></tfoot><dl id='FZVcy'><fieldset id='FZVcy'></fieldset></dl></div>
      <legend id='FZVcy'><style id='FZVcy'><dir id='FZVcy'><q id='FZVcy'></q></dir></style></legend>

        <bdo id='FZVcy'></bdo><ul id='FZVcy'></ul>

      <small id='FZVcy'></small><noframes id='FZVcy'>

      1. 使用 .env 文件進行單元測試

        Using .env files for unit testing with jest(使用 .env 文件進行單元測試)

          1. <tfoot id='SJeWv'></tfoot>

              <tbody id='SJeWv'></tbody>
            • <bdo id='SJeWv'></bdo><ul id='SJeWv'></ul>
              <i id='SJeWv'><tr id='SJeWv'><dt id='SJeWv'><q id='SJeWv'><span id='SJeWv'><b id='SJeWv'><form id='SJeWv'><ins id='SJeWv'></ins><ul id='SJeWv'></ul><sub id='SJeWv'></sub></form><legend id='SJeWv'></legend><bdo id='SJeWv'><pre id='SJeWv'><center id='SJeWv'></center></pre></bdo></b><th id='SJeWv'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SJeWv'><tfoot id='SJeWv'></tfoot><dl id='SJeWv'><fieldset id='SJeWv'></fieldset></dl></div>
            • <small id='SJeWv'></small><noframes id='SJeWv'>

              • <legend id='SJeWv'><style id='SJeWv'><dir id='SJeWv'><q id='SJeWv'></q></dir></style></legend>
                  本文介紹了使用 .env 文件進行單元測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  是否可以從 env 文件加載環境變量以在 Jest 中進行單元測試?我希望像這樣對其進行一系列測試:

                  Is it possible to load environment variables from an env file for unit testing purposes in Jest? I'm looking to run a series of tests on it like so:

                  // unit tests for env file
                  describe('env', () => {
                      it('should have a client id', () => {
                          expect(process.env.CLIENT_ID).toBeDefined();
                      });
                      it('should have a client secret', () => {
                          expect(process.env.CLIENT_SECRET).toBeDefined();
                      });
                      it('should have a host', () => {
                          expect(process.env.HOST).toBeDefined();
                      });
                      it('should have a scope', () => {
                          expect(process.env.SCOPE).toBeDefined();
                      });
                      it('should have a response type', () => {
                          expect(process.env.RESPONSE_TYPE).toBeDefined();
                      });
                      it('should have a redirect uri', () => {
                          expect(process.env.REDIRECT_URI).toBeDefined();
                      });
                  });
                  

                  目前,上述所有測試都將失敗,說明變量未定義.最初我使用的是 mocha/chai 設置,它允許我通過使用 dotenv 加載我的所有 env 變量.這涉及通過 webpack 運行所有單元測試并且工作正常.

                  Currently, all the above tests will fail, stating that the variables are undefined. Initially I was using a mocha/chai setup, which allowed me to just load all of my env variables via the use of dotenv. This involved running all unit tests through webpack and worked fine.

                  但是,通過閱讀 文檔 Jest 不會運行測試通過 webpack;相反,模塊是通過 moduleNameMapper 模擬出來的.這適用于其他一切,但我無法加載 env 文件變量.到目前為止,我已經嘗試將 setupFiles 選項用于調用 dotenv.config 的 js 文件,并使用給它的 env 文件的路徑,如下所示:

                  However, from reading the documentation Jest doesn't run tests through webpack; instead modules are mocked out via moduleNameMapper. This works fine for everything else, but I can't get the env file variables to load. So far I've tried using the setupFiles option to a js file that calls dotenv.config with the path of the env file given to it like so:

                  // setup file for jest
                  const dotenv = require('dotenv');
                  dotenv.config({ path: './env' });
                  

                  這不起作用,所以我現在只使用一個 .env.js 文件進行單元測試,并將這個文件傳遞給 setupFiles 選項.但是,為了可維護性,并使其與 webpack 一起用于生產,我想將它們全部保存在一個文件中.以下是 .env.js 文件如何查找以供參考的摘錄

                  This didn't work, so I've now resorted to using just a .env.js file for unit tests and passing this file into the setupFiles option instead. However, for maintainability, and to keep it working with webpack for production, I'd like to just keep it all in one file. Here's an extract of how the .env.js file looks for reference

                  // .env.js extract example
                  process.env.PORT = 3000;
                  process.env.HOST = 'localhost';
                  process.env.CLIENT_ID = 'your client id';
                  process.env.REDIRECT_URI = 'your callback endpoint';
                  

                  推薦答案

                  您使用 ./ 的頂級配置路徑從注入點來看是相對的,您的測試套件可能位于名為test 導致在運行單元測試時找不到它.dotenv.config(); 使用類似于絕對路徑的全局注入策略.

                  Your top config path using ./ is relative from the point of injection, it's likely your test suite might be inside a folder named test which causes it to not be found when running your unit tests. dotenv.config(); Uses global injection strategy which is similar to absolute pathing.

                  這篇關于使用 .env 文件進行單元測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                    <tbody id='bcfVi'></tbody>
                  <legend id='bcfVi'><style id='bcfVi'><dir id='bcfVi'><q id='bcfVi'></q></dir></style></legend>

                  <tfoot id='bcfVi'></tfoot>

                    <small id='bcfVi'></small><noframes id='bcfVi'>

                      • <bdo id='bcfVi'></bdo><ul id='bcfVi'></ul>
                        • <i id='bcfVi'><tr id='bcfVi'><dt id='bcfVi'><q id='bcfVi'><span id='bcfVi'><b id='bcfVi'><form id='bcfVi'><ins id='bcfVi'></ins><ul id='bcfVi'></ul><sub id='bcfVi'></sub></form><legend id='bcfVi'></legend><bdo id='bcfVi'><pre id='bcfVi'><center id='bcfVi'></center></pre></bdo></b><th id='bcfVi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bcfVi'><tfoot id='bcfVi'></tfoot><dl id='bcfVi'><fieldset id='bcfVi'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 国产欧美精品一区二区三区 | 久久综合久久自在自线精品自 | 91免费入口 | 色必久久| 日本久久久久久 | 国产一区三区视频 | 91精品在线看 | 日韩欧美一级精品久久 | 国产综合久久久久久鬼色 | 日韩一区二区三区在线 | 伊人在线 | av毛片 | 精品一区av | 在线观看黄色电影 | 天天看片天天干 | 成在线人视频免费视频 | 久久综合狠狠综合久久 | 中文字幕在线一区二区三区 | 天天干.com| 欧美精品一区三区 | 黄色片在线看 | 国产成人网 | 日韩欧美精品 | 精品国产伦一区二区三区观看说明 | 亚洲精品电影网在线观看 | 久久综合av | 国产精久久久 | 人操人免费视频 | 久久久久国产精品午夜一区 | 亚洲三区在线观看 | 欧美精品一区二区三区在线 | 久久精品国产清自在天天线 | 午夜精品久久久久久久久久久久久 | 亚洲国产成人精品久久久国产成人一区 | 欧美日韩美女 | 国产欧美一级 | 一区二区三区中文字幕 | 久久机热 | 亚洲欧美日韩精品久久亚洲区 | 6080yy精品一区二区三区 | 精品中文字幕一区二区 |