mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 17:02:17 -05:00
Fix integration test setup and teardown... some tests stil fails
This commit is contained in:
parent
f740b27659
commit
f8f7588c93
@ -179,7 +179,6 @@ module.exports = function(grunt) {
|
|||||||
'test/unit/email/email-dao-test.js',
|
'test/unit/email/email-dao-test.js',
|
||||||
'test/unit/email/account-test.js',
|
'test/unit/email/account-test.js',
|
||||||
'test/unit/email/search-test.js',
|
'test/unit/email/search-test.js',
|
||||||
'test/unit/controller/app/dialog-ctrl-test.js',
|
|
||||||
'test/unit/controller/login/add-account-ctrl-test.js',
|
'test/unit/controller/login/add-account-ctrl-test.js',
|
||||||
'test/unit/controller/login/create-account-ctrl-test.js',
|
'test/unit/controller/login/create-account-ctrl-test.js',
|
||||||
'test/unit/controller/login/validate-phone-ctrl-test.js',
|
'test/unit/controller/login/validate-phone-ctrl-test.js',
|
||||||
@ -189,6 +188,7 @@ module.exports = function(grunt) {
|
|||||||
'test/unit/controller/login/login-privatekey-download-ctrl-test.js',
|
'test/unit/controller/login/login-privatekey-download-ctrl-test.js',
|
||||||
'test/unit/controller/login/login-set-credentials-ctrl-test.js',
|
'test/unit/controller/login/login-set-credentials-ctrl-test.js',
|
||||||
'test/unit/controller/login/login-ctrl-test.js',
|
'test/unit/controller/login/login-ctrl-test.js',
|
||||||
|
'test/unit/controller/app/dialog-ctrl-test.js',
|
||||||
'test/unit/controller/app/privatekey-upload-ctrl-test.js',
|
'test/unit/controller/app/privatekey-upload-ctrl-test.js',
|
||||||
'test/unit/controller/app/account-ctrl-test.js',
|
'test/unit/controller/app/account-ctrl-test.js',
|
||||||
'test/unit/controller/app/set-passphrase-ctrl-test.js',
|
'test/unit/controller/app/set-passphrase-ctrl-test.js',
|
||||||
@ -206,7 +206,7 @@ module.exports = function(grunt) {
|
|||||||
files: {
|
files: {
|
||||||
'test/integration/index.browserified.js': [
|
'test/integration/index.browserified.js': [
|
||||||
'test/main.js',
|
'test/main.js',
|
||||||
/*'test/integration/email-dao-test.js'*/
|
'test/integration/email-dao-test.js'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
options: browserifyOpt
|
options: browserifyOpt
|
||||||
@ -281,7 +281,6 @@ module.exports = function(grunt) {
|
|||||||
'node_modules/jquery/dist/jquery.min.js',
|
'node_modules/jquery/dist/jquery.min.js',
|
||||||
'src/lib/angular/angular.js',
|
'src/lib/angular/angular.js',
|
||||||
'src/lib/angular/angular-route.js',
|
'src/lib/angular/angular-route.js',
|
||||||
'src/lib/angular/angular-animate.js',
|
|
||||||
'src/lib/angular/angular-mocks.js',
|
'src/lib/angular/angular-mocks.js',
|
||||||
'src/lib/lawnchair/lawnchair-git.js',
|
'src/lib/lawnchair/lawnchair-git.js',
|
||||||
'src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js',
|
'src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js',
|
||||||
@ -296,6 +295,9 @@ module.exports = function(grunt) {
|
|||||||
integrationTest: {
|
integrationTest: {
|
||||||
src: [
|
src: [
|
||||||
'src/lib/underscore/underscore.js',
|
'src/lib/underscore/underscore.js',
|
||||||
|
'node_modules/jquery/dist/jquery.min.js',
|
||||||
|
'src/lib/angular/angular.js',
|
||||||
|
'src/lib/angular/angular-mocks.js',
|
||||||
'src/lib/lawnchair/lawnchair-git.js',
|
'src/lib/lawnchair/lawnchair-git.js',
|
||||||
'src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js',
|
'src/lib/lawnchair/lawnchair-adapter-webkit-sqlite-git.js',
|
||||||
'src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js',
|
'src/lib/lawnchair/lawnchair-adapter-indexed-db-git.js',
|
||||||
|
@ -4,9 +4,8 @@ var ImapClient = require('imap-client'),
|
|||||||
BrowserCrow = require('browsercrow'),
|
BrowserCrow = require('browsercrow'),
|
||||||
BrowserSMTP = require('browsersmtp'),
|
BrowserSMTP = require('browsersmtp'),
|
||||||
SmtpClient = require('wo-smtpclient'),
|
SmtpClient = require('wo-smtpclient'),
|
||||||
LawnchairDAO = require('../../src/js/dao/lawnchair-dao'),
|
LawnchairDAO = require('../../src/js/service/lawnchair'),
|
||||||
DeviceStorageDAO = require('../../src/js/dao/devicestorage-dao'),
|
DeviceStorageDAO = require('../../src/js/service/devicestorage'),
|
||||||
appController = require('../../src/js/app-controller'),
|
|
||||||
mailreader = require('mailreader'),
|
mailreader = require('mailreader'),
|
||||||
PgpMailer = require('pgpmailer'),
|
PgpMailer = require('pgpmailer'),
|
||||||
config = require('../../src/js/app-config').config,
|
config = require('../../src/js/app-config').config,
|
||||||
@ -14,9 +13,8 @@ var ImapClient = require('imap-client'),
|
|||||||
|
|
||||||
describe('Email DAO integration tests', function() {
|
describe('Email DAO integration tests', function() {
|
||||||
this.timeout(100000);
|
this.timeout(100000);
|
||||||
chai.config.includeStack = true;
|
|
||||||
|
|
||||||
var emailDao, imapClient, imapMessages, imapFolders, imapServer, smtpServer, smtpClient, userStorage,
|
var accountService, emailDao, imapClient, imapMessages, imapFolders, imapServer, smtpServer, smtpClient, userStorage,
|
||||||
mockKeyPair, inbox, spam;
|
mockKeyPair, inbox, spam;
|
||||||
|
|
||||||
var testAccount = {
|
var testAccount = {
|
||||||
@ -25,7 +23,11 @@ describe('Email DAO integration tests', function() {
|
|||||||
xoauth2: 'testtoken'
|
xoauth2: 'testtoken'
|
||||||
};
|
};
|
||||||
|
|
||||||
before(function(done) {
|
beforeEach(function(done) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test data
|
||||||
|
//
|
||||||
|
|
||||||
imapMessages = [{
|
imapMessages = [{
|
||||||
raw: 'Message-id: <c>\r\nSubject: hello 3\r\n\r\nWorld 3!',
|
raw: 'Message-id: <c>\r\nSubject: hello 3\r\n\r\nWorld 3!',
|
||||||
@ -129,6 +131,10 @@ describe('Email DAO integration tests', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test server setup
|
||||||
|
//
|
||||||
|
|
||||||
var serverUsers = {};
|
var serverUsers = {};
|
||||||
serverUsers[testAccount.user] = {
|
serverUsers[testAccount.user] = {
|
||||||
password: testAccount.pass,
|
password: testAccount.pass,
|
||||||
@ -180,10 +186,27 @@ describe('Email DAO integration tests', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test client setup
|
||||||
|
//
|
||||||
|
|
||||||
// don't multithread, Function.prototype.bind() is broken in phantomjs in web workers
|
// don't multithread, Function.prototype.bind() is broken in phantomjs in web workers
|
||||||
window.Worker = undefined;
|
window.Worker = undefined;
|
||||||
navigator.online = true;
|
navigator.online = true;
|
||||||
|
|
||||||
|
sinon.stub(mailreader, 'startWorker', function() {});
|
||||||
|
sinon.stub(openpgp, 'initWorker', function() {});
|
||||||
|
|
||||||
|
// build and inject angular services
|
||||||
|
angular.module('email-integration-test', ['woEmail']);
|
||||||
|
angular.mock.module('email-integration-test');
|
||||||
|
angular.mock.inject(function($injector) {
|
||||||
|
accountService = $injector.get('account');
|
||||||
|
initAccountService();
|
||||||
|
});
|
||||||
|
|
||||||
|
function initAccountService() {
|
||||||
|
// create imap/smtp clients with stubbed tcp sockets
|
||||||
imapClient = new ImapClient({
|
imapClient = new ImapClient({
|
||||||
auth: {
|
auth: {
|
||||||
user: testAccount.user,
|
user: testAccount.user,
|
||||||
@ -196,17 +219,8 @@ describe('Email DAO integration tests', function() {
|
|||||||
imapClient._client.client._TCPSocket = imapServer.createTCPSocket();
|
imapClient._client.client._TCPSocket = imapServer.createTCPSocket();
|
||||||
imapClient._listeningClient.client._TCPSocket = imapServer.createTCPSocket();
|
imapClient._listeningClient.client._TCPSocket = imapServer.createTCPSocket();
|
||||||
imapClient.onError = function(err) {
|
imapClient.onError = function(err) {
|
||||||
console.log('IMAP error.', err);
|
console.error('IMAP error.', err);
|
||||||
console.log('IMAP reconnecting...');
|
throw err;
|
||||||
// re-init client modules on error
|
|
||||||
appController.onConnect(function(err) {
|
|
||||||
if (err) {
|
|
||||||
console.error('IMAP reconnect failed!', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('IMAP reconnect attempt complete.');
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
smtpClient = new SmtpClient('localhost', 25, {
|
smtpClient = new SmtpClient('localhost', 25, {
|
||||||
@ -224,42 +238,36 @@ describe('Email DAO integration tests', function() {
|
|||||||
// phantomjs is really slow, so setting the tcp socket timeouts to 200s will effectively disarm the timeout
|
// phantomjs is really slow, so setting the tcp socket timeouts to 200s will effectively disarm the timeout
|
||||||
imapClient._client.client.TIMEOUT_SOCKET_LOWER_BOUND = smtpClient.TIMEOUT_SOCKET_LOWER_BOUND = 200000;
|
imapClient._client.client.TIMEOUT_SOCKET_LOWER_BOUND = smtpClient.TIMEOUT_SOCKET_LOWER_BOUND = 200000;
|
||||||
|
|
||||||
sinon.stub(mailreader, 'startWorker', function() {});
|
// stub the onConnect function to inject the test imap/smtp clients
|
||||||
sinon.stub(openpgp, 'initWorker', function() {});
|
sinon.stub(accountService, 'onConnect', function(cb) {
|
||||||
|
accountService._emailDao.onConnect({
|
||||||
sinon.stub(appController, 'onConnect', function(cb) {
|
|
||||||
appController._emailDao.onConnect({
|
|
||||||
imapClient: imapClient,
|
imapClient: imapClient,
|
||||||
pgpMailer: new PgpMailer({
|
pgpMailer: new PgpMailer({
|
||||||
tls: {
|
tls: {
|
||||||
ca: 'random string'
|
ca: 'random string'
|
||||||
}
|
}
|
||||||
}, appController._pgpbuilder)
|
}, accountService._pgpbuilder)
|
||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// clear the local database before each test
|
||||||
var cleanup = new DeviceStorageDAO(new LawnchairDAO());
|
var cleanup = new DeviceStorageDAO(new LawnchairDAO());
|
||||||
cleanup.init(testAccount.user, function(err) {
|
cleanup.init(testAccount.user);
|
||||||
expect(err).to.not.exist;
|
|
||||||
cleanup.clear(function(err) {
|
cleanup.clear(function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
appController.start({
|
|
||||||
onError: function() {}
|
|
||||||
}, function(err) {
|
|
||||||
expect(err).to.not.exist;
|
|
||||||
|
|
||||||
// stub rest request to key server
|
userStorage = accountService._accountStore;
|
||||||
sinon.stub(appController._emailDao._keychain._publicKeyDao, 'get').yields(null, mockKeyPair.publicKey);
|
|
||||||
sinon.stub(appController._emailDao._keychain._publicKeyDao, 'getByUserId').yields(null, mockKeyPair.publicKey);
|
|
||||||
|
|
||||||
userStorage = appController._userStorage;
|
accountService.init({
|
||||||
|
|
||||||
appController.init({
|
|
||||||
emailAddress: testAccount.user
|
emailAddress: testAccount.user
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
|
|
||||||
emailDao = appController._emailDao;
|
emailDao = accountService._emailDao;
|
||||||
|
|
||||||
|
// stub rest request to key server
|
||||||
|
sinon.stub(emailDao._keychain._publicKeyDao, 'get').yields(null, mockKeyPair.publicKey);
|
||||||
|
sinon.stub(emailDao._keychain._publicKeyDao, 'getByUserId').yields(null, mockKeyPair.publicKey);
|
||||||
|
|
||||||
emailDao.onIncomingMessage = function(messages) {
|
emailDao.onIncomingMessage = function(messages) {
|
||||||
expect(messages.length).to.equal(imapMessages.length);
|
expect(messages.length).to.equal(imapMessages.length);
|
||||||
@ -284,20 +292,19 @@ describe('Email DAO integration tests', function() {
|
|||||||
}, function(err) {
|
}, function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
|
|
||||||
appController.onConnect(function(err) {
|
accountService.onConnect(function(err) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function(done) {
|
afterEach(function(done) {
|
||||||
openpgp.initWorker.restore();
|
openpgp.initWorker.restore();
|
||||||
mailreader.startWorker.restore();
|
mailreader.startWorker.restore();
|
||||||
appController.onConnect.restore();
|
accountService.onConnect.restore();
|
||||||
|
|
||||||
imapClient._client.close();
|
imapClient._client.close();
|
||||||
imapClient._listeningClient.close();
|
imapClient._listeningClient.close();
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
if (window.mochaPhantomJS) {
|
if (window.mochaPhantomJS) {
|
||||||
mochaPhantomJS.run();
|
mochaPhantomJS.run();
|
||||||
} else {
|
} else {
|
||||||
|
setTimeout(function() {
|
||||||
mocha.run();
|
mocha.run();
|
||||||
|
}, 1000)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user