Mocha tests with extra options or parameters

后端 未结 10 1957
一向
一向 2020-12-04 16:17

I am writing test cases for my Node.js application using Mocha. The test cases need an API key as an extra input option or parameter. The API key is private, so I don\'t wan

10条回答
  •  青春惊慌失措
    2020-12-04 17:13

    I have been reading quite some answers, most of them more complex than the actual solution has to be.

    Let's say I have config.yml or config.json. In my case it's a YAML file.

    First of all I install the yamljs dependency. It has a function called load.

    Basically what I do:

    const YAML = require('yamljs'); const ymlConfig = YAML.load('./config.yml');

    Then I go for:

    process.env.setting1 = ymlConfig.setting1; process.env.setting2 = ymlConfig.setting2;

    And of course - this is all done in your test file.

提交回复
热议问题