How to setup protractor to import AMD modules with requirejs

后端 未结 3 363
天涯浪人
天涯浪人 2021-01-14 14:01

I\'m trying to import an AMD module (ES6 module transpiled in ES5) in a protractor test. I\'m using the Page Object pattern. And the Page Object is the module I\'m trying to

3条回答
  •  难免孤独
    2021-01-14 14:57

    A solution is to use amdefine as it is described in requirejs.org/docs/node.html#3 the drawback of this solution is that you need to prepend every module by the following line :

    if (typeof define !== 'function') { var define = require('amdefine')(module) }
    

    In my specific case, because I'm using traceur to transpile ES6 files, I chose to use commonjs module instead of AMD for e2e tests. The reason it's different from unit tests executed by Karma (where I can easily use AMD) is the fact that protractor tests are executed by Node.js and not by the browser. So, I changed the traceur modules options for e2e tests only to this:

    {
          "modules": "commonjs",
          "script": false,
          "types": true,
          "annotations": true,
          "memberVariables":true,
          "outputLanguage": "es5"
    }
    

提交回复
热议问题