test-electron: wait to run tests until protos are ready

This commit is contained in:
Evan Hahn 2020-11-04 11:44:32 -06:00 committed by Evan Hahn
parent 8e598688e7
commit 618c0fce1e
4 changed files with 54 additions and 28 deletions

View File

@ -5,11 +5,40 @@
// eslint-disable-next-line func-names
(function() {
window.textsecure = window.textsecure || {};
window.textsecure.protobuf = {};
const FILES_TO_LOAD = [
'SignalService.proto',
'SignalStorage.proto',
'SubProtocol.proto',
'DeviceMessages.proto',
'Stickers.proto',
function loadProtoBufs(filename) {
return dcodeIO.ProtoBuf.loadProtoFile(
// Just for encrypting device names
'DeviceName.proto',
// Metadata-specific protos
'UnidentifiedDelivery.proto',
// Groups
'Groups.proto',
];
let remainingFilesToLoad = FILES_TO_LOAD.length;
const hasFinishedLoading = () => remainingFilesToLoad <= 0;
let onLoadCallbacks = [];
window.textsecure = window.textsecure || {};
window.textsecure.protobuf = {
onLoad: callback => {
if (hasFinishedLoading()) {
setTimeout(callback, 0);
} else {
onLoadCallbacks.push(callback);
}
},
};
FILES_TO_LOAD.forEach(filename => {
dcodeIO.ProtoBuf.loadProtoFile(
{ root: window.PROTO_ROOT, file: filename },
(error, result) => {
if (error) {
@ -29,22 +58,13 @@
for (const protoName in protos) {
textsecure.protobuf[protoName] = protos[protoName];
}
remainingFilesToLoad -= 1;
if (hasFinishedLoading()) {
onLoadCallbacks.forEach(callback => callback());
onLoadCallbacks = [];
}
}
);
}
loadProtoBufs('SignalService.proto');
loadProtoBufs('SignalStorage.proto');
loadProtoBufs('SubProtocol.proto');
loadProtoBufs('DeviceMessages.proto');
loadProtoBufs('Stickers.proto');
// Just for encrypting device names
loadProtoBufs('DeviceName.proto');
// Metadata-specific protos
loadProtoBufs('UnidentifiedDelivery.proto');
// Groups
loadProtoBufs('Groups.proto');
});
})();

View File

@ -52,8 +52,10 @@
<!-- Uncomment to start tests without code coverage enabled -->
<script type="text/javascript">
mocha.run();
window.Signal.conversationControllerStart();
window.textsecure.protobuf.onLoad(() => {
mocha.run();
window.Signal.conversationControllerStart();
});
</script>
</body>
</html>

View File

@ -397,13 +397,15 @@
<!-- Uncomment to start tests without code coverage enabled -->
<script type="text/javascript">
window.Signal.conversationControllerStart();
window.textsecure.protobuf.onLoad(() => {
window.Signal.conversationControllerStart();
window.test.pendingDescribeCalls.forEach(args => {
describe(...args);
window.test.pendingDescribeCalls.forEach(args => {
describe(...args);
});
mocha.run();
});
mocha.run();
</script>
</body>
</html>

4
ts/textsecure.d.ts vendored
View File

@ -212,7 +212,9 @@ type SubProtocolProtobufTypes = {
WebSocketResponseMessage: typeof WebSocketResponseMessageClass;
};
type ProtobufCollectionType = DeviceMessagesProtobufTypes &
type ProtobufCollectionType = {
onLoad: (callback: () => unknown) => void;
} & DeviceMessagesProtobufTypes &
DeviceNameProtobufTypes &
GroupsProtobufTypes &
SignalServiceProtobufTypes &