Running a set of actions before every test-file in mocha

前端 未结 2 1796
我寻月下人不归
我寻月下人不归 2021-02-19 02:34

I\'ve started recently working with mocha to test my expressjs server. My tests are separated to multiple files and most of them contain some duplicated segments (Mostly before

2条回答
  •  梦毁少年i
    2021-02-19 03:11

    Why not mocha -r or even using mocha.opts?

    Have your common file in, say, init.js and then run

    mocha -r `./init`
    

    Which will cause mocha to run and load ./init.js before loading any of the mocha test files.

    You could also put it in mocha.opts inside your tests directory, and have its contents be

    --require ./init
    

提交回复
热议问题