在Protractor / typescript async / await中无法使用mail-listener2访问电子邮件收件箱

时间:2018-02-21 16:30:44

标签: typescript email async-await protractor

尝试配置mailListener以读取电子邮件,但遇到了我的知识无法解决的问题。

在Config中:

declare var global;
onPrepare: function () {
        const MailListener = require('mail-listener2');

        const mailListener = new MailListener({
            username: "blabla@gmail.com",
            password: "Mypass2222",
            host: "smtp.gmail.com",
            port: 993, // imap port
            tls: true,
            tlsOptions: {rejectUnauthorized: false},
            mailbox: "INBOX", 
            searchFilter: ["UNSEEN", "FLAGGED"],
            markSeen: true,
            fetchUnreadOnStart: true, 
            mailParserOptions: {streamAttachments: true}, 
            attachments: true, 
            attachmentOptions: {directory: "attachments/"} 
        });

        mailListener.start();
        console.log(mailListener);

        mailListener.on("server:connected", function () {
                console.log("Mail listener initialized");
            });
            global.mailListener = mailListener;
}
onCleanUp: function () {
        global.mailListener.stop();
    },

email.ts(Helprer文件):

import { protractor} from "protractor";
declare var global;

function getLastEmail() {
    let deferred = protractor.promise.defer();
    console.log("Waiting for an email...");

    global.mailListener.on("mail", function(mail){
        deferred.fulfill(mail);
    });
    return deferred.promise;
};

module.exports = getLastEmail;

在规格中。 “it”中的测试文件:

await getEmail().then(function (email) {
            expect(email.subject).toEqual("bab is ready");
            expect(email.headers.to).toEqual("no-reply@build-a-list-test.com");

            // extract registration code from the email message
            //const pattern = /Registration code is: (\w+)/g;
            //const regCode = pattern.exec(email.text)[1];

            console.log(getEmail);

        });
        console.log(getEmail)

测试失败: - 错误:超时 - 在jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时内未调用异步回调。             在ontimeout(timers.js:475:11)     在tryOnTimeout(timers.js:310:5)

我怀疑它使用typescript / async / await以另一种方式构建,而不是here但是dunno。

这是一个console.log

MailListener {
  markSeen: true,
  mailbox: 'INBOX',
  searchFilter: [ 'UNSEEN', 'FLAGGED' ],
  fetchUnreadOnStart: true,
  mailParserOptions: { streamAttachments: true },
  attachmentOptions: { directory: 'attachments/' },
  attachments: true,
  imap: 
   Connection {
     domain: null,
     _events: 
      { ready: [Object],
        close: [Object],
        error: [Function: bound imapError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     _config: 
      { localAddress: undefined,
        socket: undefined,
        socketTimeout: 0,
        host: 'smtp.gmail.com',
        port: 993,
        tls: true,
        tlsOptions: [Object],
        autotls: undefined,
        user: 'tylermac2030@gmail.com',
        password: 'Alexandr2030',
        xoauth: undefined,
        xoauth2: undefined,
        connTimeout: 10000,
        authTimeout: 5000,
        keepalive: true },
     _sock: 
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: false,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: null,
        npnProtocol: null,
        alpnProtocol: null,
        authorized: false,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 10,
        connecting: true,
        _hadError: false,
        _handle: [Object],
        _parent: [Object],
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: false,
        _bytesDispatched: 0,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: [Object],
        _requestCert: true,
        _rejectUnauthorized: false,
        [Symbol(asyncId)]: 103,
        [Symbol(bytesRead)]: 0 },
     _tagcount: 0,
     _tmrConn: 
      Timeout {
        _called: false,
        _idleTimeout: 10000,
        _idlePrev: [Object],
        _idleNext: [Object],
        _idleStart: 2568,
        _onTimeout: [Function],
        _timerArgs: undefined,
        _repeat: null,
        _destroyed: false,
        [Symbol(asyncId)]: 107,
        [Symbol(triggerAsyncId)]: 100 },
     _tmrKeepalive: undefined,
     _tmrAuth: undefined,
     _queue: [],
     _box: undefined,
     _idle: { started: undefined, enabled: false },
     _parser: 
      Parser {
        domain: null,
        _events: [Object],
        _eventsCount: 5,
        _maxListeners: undefined,
        _stream: [Object],
        _body: undefined,
        _literallen: 0,
        _literals: [],
        _buffer: '',
        _ignoreReadable: false,
        debug: null,
        _cbReadable: [Function] },
     _curReq: undefined,
     delimiter: undefined,
     namespaces: undefined,
     state: 'disconnected',
     debug: null,
     _onError: [Function],
     _onSocketTimeout: [Function] } }

0 个答案:

没有答案