Невозможно выполнить тест с использованием mailListener Ошибка: _mailListener.default.on не является функцией - PullRequest
0 голосов
/ 21 октября 2019

невозможно выполнить тест для проверки входящей почты после отправки отзыва пользователем, конфигурация, касающаяся прослушивателя почты, работает нормально, так как я вижу в консоли, что аутентификация прошла успешно, я думаю, что проблема в коде сама по себе может быть связана с экспортом и импортомперепробовал много способов но всегда показывает мне .... это не функция

/

//spec
import mailListener from 'mail-listener-next';
import UserFeedbackPage from '../pages/UserFeedbackPage';
import D from '../data-provider/conf-data.js';
import Menu from '../pages/Menu.js';

const page = new UserFeedbackPage();
const menu = new Menu();

describe('User Feedback Menu', function () {
    function getLastEmail() {
        const deferred = protractor.promise.defer();
        console.log('Waiting for an email...');

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

    // menu.isAdminViewPresent();
    beforeAll(function () {
        browser.sleep(1000);
        menu.click_user_feedback_button();
    });

    it('1-should login with a registration code sent to an email', function (
{
        page.Verify_user_feedback_modal_is_loaded_properly();
        page.Fill_all_required_fields(D.feedbackMsg);
        page.Verify_user_feedback_has_been_sent();
        const flow = protractor.promise.controlFlow();

        flow.execute(getLastEmail).then(function (email) {
        // browser.await(getLastEmail).then(function (email) {
            expect(email.subject).toEqual('thetester@thesemso.com submitted feedback');
            expect(email.headers.to).toEqual('sadd@sd.com');

            // extract registration code from the email message
            const pattern = /User feedback details: accountId: 2323, related To: (\w+)/g;
            const regCode = pattern.exec(email.text)[1];

            console.log(regCode);
        });
        });
});

//conf.js

exports.config = {
	framework: 'jasmine2',
	directConnect: true,
	// baseUrl: 'http://localhost:4200/',
	// seleniumAddress: 'http://localhost:4444/wd/hub/',

	localSeleniumStandaloneOpts:
        {
        	jvmArgs: [
        		'-Dwebdriver.edge.driver=../../../node_modules/protractor/node_modules/webdriver-manager/selenium/MicrosoftWebDriver.exe',
        		'-Dwebdriver.gecko.driver=../../../node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.20.0.exe',
        		'-Dwebdriver.chrome.driver=../../../node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.46.exe',
        		'-Dwebdriver.ie.driver=../../../node_modules/protractor/node_modules/webdriver-manager/selenium/IEDriverServer.exe'
        	]
        },

	multiCapabilities: [
		{
			browserName: 'chrome',
			sharedTestFiles: true,
			maxInstances: 10,
			chromeOptions: {
				// 'args': ['start-maximized', '--no-sandbox', '--headless', '--disable-gpu', '--window-size=1920,1080'] // enter this into line above before pushing to dev
				args: ['start-maximized', '--no-sandbox', '--window-size=1920,1080']
			}
		},
		
	],
	specs: [

		'./tests/UserFeedbackTests.js',
	
	],

	onPrepare() {
		require('@babel/register', '@babel/plugin-transform-runtime');
		browser.ignoreSynchronization = true;

		const url = 'https://dasas.com/'; // comment it before pushing
		exports.url = url;
		browser.get(url);
		browser.sleep(3000);


	

		const MailListener = require('mail-listener-next');
		// import MailListener from 'mail-listener2';

		const mailListener = new MailListener({
			username: 'asas@maessas.com',
			password: 'asass',
			host: 'imap.gmail.com',
			port: 993, // imap port
			tls: true,
			connTimeout: 10000, // Default by node-imap
			authTimeout: 5000, // Default by node-imap,
			debug: console.log, // Or your custom function with only one incoming argument. Default: null
			tlsOptions: { rejectUnauthorized: false },
			mailbox: 'INBOX', // mailbox to monitor
			searchFilter: ['UNSEEN', 'FLAGGED'], // the search filter being used after an IDLE notification has been retrieved
			markSeen: true, // all fetched email willbe marked as seen and not fetched next time
			fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
			mailParserOptions: { streamAttachments: true }, // options to be passed to mailParser lib.
			attachments: true, // download attachments as they are encountered to the project directory
			attachmentOptions: { directory: 'attachments/' } // specify a download directory for attachments
		});

		mailListener.start(); // start listening

// stop listening
// mailListener.stop();

		mailListener.on('server:connected', function () {
			console.log('imapConnected');
		});

		mailListener.on('server:disconnected', function () {
			console.log('imapDisconnected');
		});

		mailListener.on('error', function (err) {
			console.log(err);
		});

		// eslint-disable-next-line no-unused-vars
		mailListener.on('mail', function (mail, seqno, attributes) {
			// do something with mail object including attachments
			console.log('emailParsed', mail);
			// mail processing code goes here
		});

		mailListener.on('attachment', function (attachment) {
			console.log(attachment.path);
		});

// it's possible to access imap object from node-imap library for performing additional actions. E.x.
// 		mailListener.imap.move(:msguids, :mailboxes, function(){});
	},

	onComplete() {
		// eslint-disable-next-line no-undef
		mailListener.stop();
	},


	strict: true,

	// Options to be passed to Jasmine.
	jasmineNodeOpts: {
		defaultTimeoutInterval: 50000000,
		showColors: true,
		isVerbose: true,
		includeStackTrace: true,
		showTiming: true,
		realtimeFailure: true
	},


};


//console log for mail-listener 
[connection] Connected to host
<= '* OK Gimap ready for requests from 77.221.1.171 b1mb203173194wrq'
=> 'A0 CAPABILITY'
<= '* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH'
<= 'A0 OK Thats all she wrote! b1mb203173194wrq'
=> 'A1 LOGIN "asdsd@sd.com" "wqewe"'
<= '* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584'
<= 'A1 OK asdsd@sd.com authenticated (Success)'
=> 'A2 NAMESPACE'
<= '* NAMESPACE (("" "/")) NIL NIL'
<= 'A2 OK Success'
=> 'A3 LIST "" ""'
<= '* LIST (\\Noselect) "/" "/"'
<= 'A3 OK Success'
=> 'A4 SELECT "INBOX" (CONDSTORE)'
<= '* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen $NotPhishing $Phishing)'
<= '* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen $NotPhishing $Phishing \\*)] Flags permitted.'
<= '* OK [UIDVALIDITY 1] UIDs valid.'
<= '* 2268 EXISTS'
<= '* 0 RECENT'
<= '* OK [UIDNEXT 30144] Predicted next UID.'
<= '* OK [HIGHESTMODSEQ 3285691]'
<= 'A4 OK [READ-WRITE] INBOX selected. (Success)'
imapConnected
=> 'A5 UID SEARCH UNSEEN FLAGGED'
<= '* SEARCH'
<= 'A5 OK SEARCH completed (Success)'
=> 'IDLE IDLE'
<= '+ idling'





Waiting for an email...

Failed: _mailListenerNext.default.on is not a function
TypeError: _mailListenerNext.default.on is not a function
    at on (C:\mc-portal\src\test\test-smoke\tests/UserFeedbackTests.js:25:22)
    at TaskQueue.execute_ (C:\Users\amrka\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)

From asynchronous test: 
Error: 
    at Suite.it (C:\sdmc-sd\src\test\test-smoke\tests/UserFeedbackTests.js:45:5)
    at addSpecsToSuite (C:\Users\ss\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1107:25)
    at Env.describe (C:\Users\sss\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1074:7)
    at describe (C:\Users\ss\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:4399:18)
    at Object.describe (C:\mc-portal\src\test\test-smoke\tests/UserFeedbackTests.js:20:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (C:\mc-portal\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.newLoader [as .js] (C:\mc-portal\node_modules\pirates\lib\index.js:104:7)
'
...