Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
Bringing beta up to date with production v1.0.40
  • Loading branch information
scottnonnenberg committed Dec 5, 2017
2 parents acc94ed + 1432d98 commit f013eed
Show file tree
Hide file tree
Showing 19 changed files with 663 additions and 239 deletions.
135 changes: 73 additions & 62 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,71 +335,82 @@ module.exports = function(grunt) {
});
});

grunt.registerTask('unit-tests', 'Run unit tests inside Electron', function() {
var environment = grunt.option('env') || 'test';
var done = this.async();
var failure;

var Application = require('spectron').Application;
var electronBinary = process.platform === 'win32' ? 'electron.cmd' : 'electron';
var app = new Application({
path: path.join(__dirname, 'node_modules', '.bin', electronBinary),
args: [path.join(__dirname, 'main.js')],
env: {
NODE_ENV: environment
}
});

function getMochaResults() {
return window.mochaResults;
function runTests(environment, cb) {
var failure;
var Application = require('spectron').Application;
var electronBinary = process.platform === 'win32' ? 'electron.cmd' : 'electron';
var app = new Application({
path: path.join(__dirname, 'node_modules', '.bin', electronBinary),
args: [path.join(__dirname, 'main.js')],
env: {
NODE_ENV: environment
}
});

app.start().then(function() {
return app.client.waitUntil(function() {
return app.client.execute(getMochaResults).then(function(data) {
return Boolean(data.value);
});
}, 10000, 'Expected to find window.mochaResults set!');
}).then(function() {
return app.client.execute(getMochaResults);
}).then(function(data) {
var results = data.value;
if (results.failures > 0) {
console.error(results.reports);
failure = function() {
grunt.fail.fatal('Found ' + results.failures + ' failing unit tests.');
};
return app.client.log('browser');
} else {
grunt.log.ok(results.passes + ' tests passed.');
}
}).then(function(logs) {
if (logs) {
console.error();
console.error('Because tests failed, printing browser logs:');
console.error(logs);
}
}).catch(function (error) {
function getMochaResults() {
return window.mochaResults;
}

app.start().then(function() {
return app.client.waitUntil(function() {
return app.client.execute(getMochaResults).then(function(data) {
return Boolean(data.value);
});
}, 10000, 'Expected to find window.mochaResults set!');
}).then(function() {
return app.client.execute(getMochaResults);
}).then(function(data) {
var results = data.value;
if (results.failures > 0) {
console.error(results.reports);
failure = function() {
grunt.fail.fatal('Something went wrong: ' + error.message + ' ' + error.stack);
grunt.fail.fatal('Found ' + results.failures + ' failing unit tests.');
};
}).then(function () {
// We need to use the failure variable and this early stop to clean up before
// shutting down. Grunt's fail methods are the only way to set the return value,
// but they shut the process down immediately!
return app.stop();
}).then(function() {
if (failure) {
failure();
}
done();
}).catch(function (error) {
console.error('Second-level error:', error.message, error.stack);
if (failure) {
failure();
}
done();
});
return app.client.log('browser');
} else {
grunt.log.ok(results.passes + ' tests passed.');
}
}).then(function(logs) {
if (logs) {
console.error();
console.error('Because tests failed, printing browser logs:');
console.error(logs);
}
}).catch(function (error) {
failure = function() {
grunt.fail.fatal('Something went wrong: ' + error.message + ' ' + error.stack);
};
}).then(function () {
// We need to use the failure variable and this early stop to clean up before
// shutting down. Grunt's fail methods are the only way to set the return value,
// but they shut the process down immediately!
return app.stop();
}).then(function() {
if (failure) {
failure();
}
cb();
}).catch(function (error) {
console.error('Second-level error:', error.message, error.stack);
if (failure) {
failure();
}
cb();
});
}

grunt.registerTask('unit-tests', 'Run unit tests w/Electron', function() {
var environment = grunt.option('env') || 'test';
var done = this.async();

runTests(environment, done);
});

grunt.registerTask('lib-unit-tests', 'Run libtextsecure unit tests w/Electron', function() {
var environment = grunt.option('env') || 'test-lib';
var done = this.async();

runTests(environment, done);
});

grunt.registerMultiTask('test-release', 'Test packaged releases', function() {
Expand Down Expand Up @@ -473,7 +484,7 @@ module.exports = function(grunt) {

grunt.registerTask('tx', ['exec:tx-pull', 'locale-patch']);
grunt.registerTask('dev', ['default', 'watch']);
grunt.registerTask('test', ['jshint', 'jscs', 'unit-tests']);
grunt.registerTask('test', ['jshint', 'jscs', 'unit-tests', 'lib-unit-tests']);
grunt.registerTask('copy_dist', ['gitinfo', 'copy:res', 'copy:src']);
grunt.registerTask('date', ['gitinfo', 'getExpireTime']);
grunt.registerTask('prep-release', ['gitinfo', 'clean-release', 'fetch-release']);
Expand Down
11 changes: 11 additions & 0 deletions app/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,19 @@ function fetch(logPath) {
return path.join(logPath, file)
});

// creating a manual log entry for the final log result
var now = new Date();
const fileListEntry = {
level: 30, // INFO
time: now.toJSON(),
msg: 'Loaded this list of log files from logPath: ' + files.join(', '),
};

return Promise.all(paths.map(fetchLog)).then(function(results) {
const data = _.flatten(results);

data.push(fileListEntry);

return _.sortBy(data, 'time');
});
}
Expand Down
5 changes: 5 additions & 0 deletions config/test-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"storageProfile": "test",
"disableAutoUpdate": true,
"openDevTools": false
}
28 changes: 21 additions & 7 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@
function start() {
var currentVersion = window.config.version;
var lastVersion = storage.get('version');
var newVersion = !lastVersion || currentVersion !== lastVersion;
storage.put('version', currentVersion);

if (!lastVersion || currentVersion !== lastVersion) {
if (newVersion) {
console.log('New version detected:', currentVersion);
}

Expand All @@ -99,7 +100,7 @@
console.log('listening for registration events');
Whisper.events.on('registration_done', function() {
console.log('handling registration event');
Whisper.RotateSignedPreKeyListener.init(Whisper.events);
Whisper.RotateSignedPreKeyListener.init(Whisper.events, newVersion);
connect(true);
});

Expand All @@ -112,7 +113,7 @@
console.log('Import was interrupted, showing import error screen');
appView.openImporter();
} else if (Whisper.Registration.everDone()) {
Whisper.RotateSignedPreKeyListener.init(Whisper.events);
Whisper.RotateSignedPreKeyListener.init(Whisper.events, newVersion);
connect();
appView.openInbox({
initialLoadComplete: initialLoadComplete
Expand Down Expand Up @@ -377,14 +378,22 @@
return ConversationController.getOrCreateAndWait(id, 'private')
.then(function(conversation) {
return new Promise(function(resolve, reject) {
var activeAt = conversation.get('active_at');

// The idea is to make any new contact show up in the left pane. If
// activeAt is null, then this contact has been purposefully hidden.
if (activeAt !== null) {
activeAt = activeAt || Date.now();
}

if (details.profileKey) {
conversation.set({profileKey: details.profileKey});
}
conversation.save({
name: details.name,
avatar: details.avatar,
color: details.color,
active_at: conversation.get('active_at') || Date.now(),
active_at: activeAt,
}).then(resolve, reject);
}).then(function() {
if (details.verified) {
Expand Down Expand Up @@ -421,7 +430,13 @@
type: 'group',
};
if (details.active) {
updates.active_at = Date.now();
var activeAt = conversation.get('active_at');

// The idea is to make any new group show up in the left pane. If
// activeAt is null, then this group has been purposefully hidden.
if (activeAt !== null) {
updates.active_at = activeAt || Date.now();
}
} else {
updates.left = true;
}
Expand Down Expand Up @@ -553,8 +568,7 @@

function onError(ev) {
var error = ev.error;
console.log(error);
console.log(error.stack);
console.log('background onError:', error && error.stack ? error.stack : error);

if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) {
Whisper.Registration.remove();
Expand Down
Loading

0 comments on commit f013eed

Please sign in to comment.