Cannot find module '../drop-file.js' protractor, angular

本小妞迷上赌 提交于 2020-06-29 08:23:28

问题


I'm trying to use a module (source) in protractor, in a angular 9 app but i'm not able to and get the following error : Error: Error: Cannot find module './drop-file.js'

The error say that it doesn't find the module but the module is correcly called as you can see bellow.

my structure :

drop-file.js
test.po.ts

test.po.ts :

const dropFile = require('./drop-file.js');
export class ReviewPo {
...
  public uploadFiles() {
    ...
          dropFile(dropElement, './image.png');
    ...
  }
}


drop-file.js :

"use strict";

var fs = require('fs');

var path = require('path');

var JS_BIND_INPUT = function JS_BIND_INPUT(target) {
  var input = document.createElement('input');
  input.type = 'file';
  input.style.display = 'none';
  input.addEventListener('change', function () {
    target.scrollIntoView(true);
    var rect = target.getBoundingClientRect(),
      x = rect.left + (rect.width >> 1),
      y = rect.top + (rect.height >> 1),
      data = {
        files: input.files
      };
    ['dragenter', 'dragover', 'drop'].forEach(function (name) {
      var event = document.createEvent('MouseEvent');
      event.initMouseEvent(name, !0, !0, window, 0, 0, 0, x, y, !1, !1, !1, !1, 0, null);
      event.dataTransfer = data;
      target.dispatchEvent(event);
    });
    document.body.removeChild(input);
  }, false);
  document.body.appendChild(input);
  return input;
};


module.exports = function (dropArea, filePath) {
  // get the full path
  filePath = path.resolve(filePath); // assert the file is present

  fs.accessSync(filePath, fs.F_OK); // resolve the drop area

  return dropArea.getWebElement().then(function (element) {
    // bind a new input to the drop area
    browser.executeScript(JS_BIND_INPUT, element).then(function (input) {
      // upload the file to the new input
      input.sendKeys(filePath);
    });
  });
};

来源:https://stackoverflow.com/questions/62629229/cannot-find-module-drop-file-js-protractor-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!