【发布时间】:2025-12-08 18:05:02
【问题描述】:
我有以下设置来运行“it”测试:
X is environment variable
if( X == "all" || X == "some value" )
read directory and run test using it() with callbacks
if( X == "all" || X == "some other value")
read directory and run some it() tests with callback
我面临的问题是,当我给出“某个值”或“某个其他值”时,所有的 it() 测试都运行得很好。但是当环境变量为“all”时,在运行第一个 it() 测试时,会出现第二个 if 语句的目录内容。我正在使用 fs.readdirSync(dir) 来读取内容,并且我知道 mochatest 异步运行它们,因此,第二个目录的内容出现在第一个测试中。是否可以阻止第二个 if 语句的执行,直到第一个 if 中的所有 it() 测试成功完成?或使其同步运行的任何替代方法。
【问题讨论】: