代码之家  ›  专栏  ›  技术社区  ›  ether_joe

设置Jasmine+Webdriver-“无法在模块外使用导入”

  •  0
  • ether_joe  · 技术社区  · 5 年前

    我尝试在浏览器中使用webdriver和Jasmine针对react应用程序设置一个基本的自动测试。我使用页面对象模型来描述我正在测试的应用程序,如下所示:

    Example page object from JasmineBDD

    import { SplashScreen } from './page_models/splash_screen.page'
    ^^^^^^
    
    SyntaxError: Cannot use import statement outside a module
    

    我用本地电话给wdio启动测试, node node_modules/.bin/wdio ./spec/support/wdio.conf.js . 如何在一个环境中运行Jasmine规范代码,使其位于模块上下文中?

    谢谢:)

    0 回复  |  直到 5 年前
        1
  •  0
  •   Xotabu4    5 年前

    nodejs版本<13不支持ES6导入/导出。你需要使用传统 require

    在nodejs 13+中,您可以启用ES6导入/导出支持。这是未经测试的,可能是一些水下岩石。但你可以试试: https://medium.com/@nodejs/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663

        2
  •  0
  •   ether_joe    5 年前

    结果我需要打电话 babel/register 在我的茉莉花配置中:

       beforeSession: function (config, capabilities, specs) {
          require('@babel/register');
        },