WebdriverIo Mocha测试中的顶级等待



我正在尝试使用WebdriverIO的顶级等待,但一直低于错误

[0-0]从"axios"导入axios;[0-]^[0-][0-]SyntaxError:无法在module的wrapSafe(node:internal/modules/cjs/loader:1031:15([0-]的Object.compileFunction(node:vm:352:18([0-]处的模块[0-]外使用import语句_compile(node:internal/modules/cjs/loader:1065:27。(节点:internal/modules/esm/transverse:190:29(ModuleJob.run处的[0-0](节点:internal/modules/esm/module_job:185:25(异步ESMLoader.import处的async Promise.all(索引0([0-0]处的[0-0](节点:internal/modules/esm/loader:281:24(

如果我包括";类型":"模块";在包.json中我得到低于错误

错误@wdio/config:ConfigParser:无法从/Users/anilp/custom folder/experiences/wdio-mocha sync/node_modules/@wdio-config/build/lib/FileSystemPathService.js加载ES模块/Users/anilp/custom-foolder/experies/wdio-mocha sync/wdio.conf.js的配置文件/Users/sanilp/ccustom-folder/experties/wdio mocha sync/ode_modules。wdio.conf.js被视为ES模块文件,因为它是一个.js文件;类型":"模块";它将该包范围内的所有.js文件声明为ES模块。相反,将wdio.conf.js重命名为以.cjs结尾,将需要的代码更改为使用在所有CommonJS模块中都可用的dynamicimport((,或者更改";类型":"模块";至";类型":"commonjs";在/Users/anilp/custom folder/experiences/wdio-mocha sync/package.json中,将所有.js文件视为CommonJS(对所有ES模块使用.mjs(。

框架:Mocha+WebdriverIO

import axios from 'axios';
// top-level await: Node >= v14.8.0 with ESM test file
const tests = await new Promise(async (resolve) => {
const response = await axios.get("https://api.github.com/users", {
headers: {
Accept: "application/vnd.github.v3+json"
}
});
resolve(response.data)
});

describe('My Login application', () => {
tests.forEach((d) => {
it(`correctly print details of ${d.login} args`, function() {
console.log(d);
});
});
});

我一直在寻找同样的东西,并找到了这个PRhttps://github.com/webdriverio/webdriverio/pull/6812.看起来wdio还不支持顶级等待。可能是版本8.

最新更新