Use esbuild
This commit is contained in:
parent
3c1ccce9bd
commit
0174687542
25 changed files with 528 additions and 906 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
@ -8,7 +8,7 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import AbortController from 'abort-controller';
|
||||
import { IMAGE_JPEG, stringToMIMEType } from '../../types/MIME';
|
||||
import * as log from '../../logging/log';
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
import {
|
||||
fetchLinkPreviewImage,
|
||||
|
@ -24,16 +24,12 @@ describe('link preview fetching', () => {
|
|||
return sinon.stub();
|
||||
}
|
||||
|
||||
let sandbox: sinon.SinonSandbox;
|
||||
let warn: sinon.SinonStub;
|
||||
let logger: Pick<LoggerType, 'warn'>;
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
warn = sandbox.stub(log, 'warn');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
warn = sinon.stub();
|
||||
logger = { warn };
|
||||
});
|
||||
|
||||
describe('fetchLinkPreviewMetadata', () => {
|
||||
|
@ -196,7 +192,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
);
|
||||
|
||||
sinon.assert.notCalled(warn);
|
||||
|
@ -229,7 +226,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -249,7 +247,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -434,7 +433,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -451,7 +451,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -473,7 +474,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -517,7 +519,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -798,7 +801,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
),
|
||||
'title',
|
||||
'foo bar'
|
||||
|
@ -893,7 +897,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewMetadata(
|
||||
fakeFetch,
|
||||
'https://example.com',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1166,7 +1171,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewImage(
|
||||
fakeFetch,
|
||||
'https://example.com/img',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1196,7 +1202,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewImage(
|
||||
fakeFetch,
|
||||
'https://example.com/img',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1264,7 +1271,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewImage(
|
||||
fakeFetch,
|
||||
'https://example.com/img',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1289,7 +1297,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewImage(
|
||||
fakeFetch,
|
||||
'https://example.com/img',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1319,7 +1328,8 @@ describe('link preview fetching', () => {
|
|||
await fetchLinkPreviewImage(
|
||||
fakeFetch,
|
||||
'https://example.com/img',
|
||||
new AbortController().signal
|
||||
new AbortController().signal,
|
||||
logger
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
@ -580,7 +580,12 @@ describe('Message', () => {
|
|||
});
|
||||
|
||||
it("shows a notification's emoji on non-Linux", function test() {
|
||||
this.sandbox.stub(window.Signal.OS, 'isLinux').returns(false);
|
||||
this.sandbox.replace(window.Signal, 'OS', {
|
||||
...window.Signal.OS,
|
||||
isLinux() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
createMessage({
|
||||
|
@ -597,7 +602,12 @@ describe('Message', () => {
|
|||
});
|
||||
|
||||
it('hides emoji on Linux', function test() {
|
||||
this.sandbox.stub(window.Signal.OS, 'isLinux').returns(true);
|
||||
this.sandbox.replace(window.Signal, 'OS', {
|
||||
...window.Signal.OS,
|
||||
isLinux() {
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
createMessage({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// Copyright 2021-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as sinon from 'sinon';
|
||||
|
@ -8,14 +8,14 @@ import type { ConversationAttributesType } from '../model-types.d';
|
|||
import { UUID } from '../types/UUID';
|
||||
|
||||
import { routineProfileRefresh } from '../routineProfileRefresh';
|
||||
import * as getProfileStub from '../util/getProfile';
|
||||
|
||||
describe('routineProfileRefresh', () => {
|
||||
let sinonSandbox: sinon.SinonSandbox;
|
||||
let getProfileFn: sinon.SinonStub;
|
||||
|
||||
beforeEach(() => {
|
||||
sinonSandbox = sinon.createSandbox();
|
||||
sinonSandbox.stub(getProfileStub, 'getProfile').resolves(undefined);
|
||||
getProfileFn = sinon.stub();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -87,9 +87,10 @@ describe('routineProfileRefresh', () => {
|
|||
allConversations: [conversation1, conversation2],
|
||||
ourConversationId: UUID.generate().toString(),
|
||||
storage,
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.notCalled(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.notCalled(getProfileFn);
|
||||
sinon.assert.notCalled(storage.put);
|
||||
});
|
||||
|
||||
|
@ -101,15 +102,16 @@ describe('routineProfileRefresh', () => {
|
|||
allConversations: [conversation1, conversation2],
|
||||
ourConversationId: UUID.generate().toString(),
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
conversation1.get('uuid'),
|
||||
conversation1.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
conversation2.get('uuid'),
|
||||
conversation2.get('e164')
|
||||
);
|
||||
|
@ -126,21 +128,22 @@ describe('routineProfileRefresh', () => {
|
|||
allConversations: [recentlyActive, inactive, neverActive],
|
||||
ourConversationId: UUID.generate().toString(),
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(getProfileFn);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
recentlyActive.get('uuid'),
|
||||
recentlyActive.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
inactive.get('uuid'),
|
||||
inactive.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
neverActive.get('uuid'),
|
||||
neverActive.get('e164')
|
||||
);
|
||||
|
@ -154,18 +157,11 @@ describe('routineProfileRefresh', () => {
|
|||
allConversations: [notMe, me],
|
||||
ourConversationId: me.id,
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
notMe.get('uuid'),
|
||||
notMe.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
me.get('uuid'),
|
||||
me.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(getProfileFn, notMe.get('uuid'), notMe.get('e164'));
|
||||
sinon.assert.neverCalledWith(getProfileFn, me.get('uuid'), me.get('e164'));
|
||||
});
|
||||
|
||||
it('skips conversations that were refreshed in the last hour', async () => {
|
||||
|
@ -178,16 +174,17 @@ describe('routineProfileRefresh', () => {
|
|||
allConversations: [neverRefreshed, recentlyFetched],
|
||||
ourConversationId: UUID.generate().toString(),
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(getProfileStub.getProfile as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(getProfileFn);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
neverRefreshed.get('uuid'),
|
||||
neverRefreshed.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
recentlyFetched.get('uuid'),
|
||||
recentlyFetched.get('e164')
|
||||
);
|
||||
|
@ -220,30 +217,31 @@ describe('routineProfileRefresh', () => {
|
|||
],
|
||||
ourConversationId: UUID.generate().toString(),
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
privateConversation.get('uuid'),
|
||||
privateConversation.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
recentlyActiveGroupMember.get('uuid'),
|
||||
recentlyActiveGroupMember.get('e164')
|
||||
);
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
inactiveGroupMember.get('uuid'),
|
||||
inactiveGroupMember.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
memberWhoHasRecentlyRefreshed.get('uuid'),
|
||||
memberWhoHasRecentlyRefreshed.get('e164')
|
||||
);
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
groupConversation.get('uuid'),
|
||||
groupConversation.get('e164')
|
||||
);
|
||||
|
@ -288,11 +286,12 @@ describe('routineProfileRefresh', () => {
|
|||
],
|
||||
ourConversationId: me.id,
|
||||
storage: makeStorage(),
|
||||
getProfileFn,
|
||||
});
|
||||
|
||||
[...activeConversations, ...inactiveGroupMembers].forEach(conversation => {
|
||||
sinon.assert.calledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
conversation.get('uuid'),
|
||||
conversation.get('e164')
|
||||
);
|
||||
|
@ -300,7 +299,7 @@ describe('routineProfileRefresh', () => {
|
|||
|
||||
[me, ...shouldNotBeIncluded].forEach(conversation => {
|
||||
sinon.assert.neverCalledWith(
|
||||
getProfileStub.getProfile as sinon.SinonStub,
|
||||
getProfileFn,
|
||||
conversation.get('uuid'),
|
||||
conversation.get('e164')
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
@ -31,7 +31,6 @@ import { ReadStatus } from '../../../messages/MessageReadStatus';
|
|||
import { ContactSpoofingType } from '../../../util/contactSpoofing';
|
||||
import { CallMode } from '../../../types/Calling';
|
||||
import { UUID } from '../../../types/UUID';
|
||||
import * as groups from '../../../groups';
|
||||
import {
|
||||
getDefaultConversation,
|
||||
getDefaultConversationWithUuid,
|
||||
|
@ -42,6 +41,7 @@ import {
|
|||
defaultChooseGroupMembersComposerState,
|
||||
defaultSetGroupMetadataComposerState,
|
||||
} from '../../../test-both/helpers/defaultComposerStates';
|
||||
import { updateRemoteConfig } from '../../../test-both/helpers/RemoteConfigStub';
|
||||
|
||||
const {
|
||||
cantAddContactToGroup,
|
||||
|
@ -83,7 +83,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
|
||||
sinonSandbox.stub(window.Whisper.events, 'trigger');
|
||||
|
||||
createGroupStub = sinonSandbox.stub(groups, 'createGroupV2');
|
||||
createGroupStub = sinon.stub();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -686,7 +686,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
});
|
||||
|
||||
it('calls groups.createGroupV2', async () => {
|
||||
await createGroup()(
|
||||
await createGroup(createGroupStub)(
|
||||
sinon.spy(),
|
||||
() => ({
|
||||
...getEmptyRootState(),
|
||||
|
@ -706,7 +706,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
});
|
||||
|
||||
it("trims the group's title before calling groups.createGroupV2", async () => {
|
||||
await createGroup()(
|
||||
await createGroup(createGroupStub)(
|
||||
sinon.spy(),
|
||||
() => ({
|
||||
...getEmptyRootState(),
|
||||
|
@ -732,7 +732,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
|
||||
const dispatch = sinon.spy();
|
||||
|
||||
const createGroupPromise = createGroup()(
|
||||
const createGroupPromise = createGroup(createGroupStub)(
|
||||
dispatch,
|
||||
() => ({
|
||||
...getEmptyRootState(),
|
||||
|
@ -764,7 +764,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
|
||||
const dispatch = sinon.spy();
|
||||
|
||||
const createGroupPromise = createGroup()(
|
||||
const createGroupPromise = createGroup(createGroupStub)(
|
||||
dispatch,
|
||||
() => ({
|
||||
...getEmptyRootState(),
|
||||
|
@ -796,7 +796,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
|
||||
const dispatch = sinon.spy();
|
||||
|
||||
await createGroup()(
|
||||
await createGroup(createGroupStub)(
|
||||
dispatch,
|
||||
() => ({
|
||||
...getEmptyRootState(),
|
||||
|
@ -1572,15 +1572,15 @@ describe('both/state/ducks/conversations', () => {
|
|||
return dispatch.getCall(0).args[0];
|
||||
}
|
||||
|
||||
let remoteConfigGetValueStub: sinon.SinonStub;
|
||||
|
||||
beforeEach(() => {
|
||||
remoteConfigGetValueStub = sinonSandbox
|
||||
.stub(window.Signal.RemoteConfig, 'getValue')
|
||||
.withArgs('global.groupsv2.maxGroupSize')
|
||||
.returns('22')
|
||||
.withArgs('global.groupsv2.groupSizeHardLimit')
|
||||
.returns('33');
|
||||
beforeEach(async () => {
|
||||
await updateRemoteConfig([
|
||||
{ name: 'global.groupsv2.maxGroupSize', value: '22', enabled: true },
|
||||
{
|
||||
name: 'global.groupsv2.groupSizeHardLimit',
|
||||
value: '33',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds conversation IDs to the list', () => {
|
||||
|
@ -1657,11 +1657,21 @@ describe('both/state/ducks/conversations', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('defaults the maximum recommended size to 151', () => {
|
||||
[undefined, 'xyz'].forEach(value => {
|
||||
remoteConfigGetValueStub
|
||||
.withArgs('global.groupsv2.maxGroupSize')
|
||||
.returns(value);
|
||||
it('defaults the maximum recommended size to 151', async () => {
|
||||
for (const value of [null, 'xyz']) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await updateRemoteConfig([
|
||||
{
|
||||
name: 'global.groupsv2.maxGroupSize',
|
||||
value,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: 'global.groupsv2.groupSizeHardLimit',
|
||||
value: '33',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const state = {
|
||||
...getEmptyState(),
|
||||
|
@ -1670,7 +1680,7 @@ describe('both/state/ducks/conversations', () => {
|
|||
const action = getAction(uuid(), state);
|
||||
|
||||
assert.strictEqual(action.payload.maxRecommendedGroupSize, 151);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('shows the maximum group size modal when first reaching the maximum group size', () => {
|
||||
|
@ -1735,13 +1745,17 @@ describe('both/state/ducks/conversations', () => {
|
|||
assert.deepEqual(result, state);
|
||||
});
|
||||
|
||||
it('defaults the maximum group size to 1001 if the recommended maximum is smaller', () => {
|
||||
[undefined, 'xyz'].forEach(value => {
|
||||
remoteConfigGetValueStub
|
||||
.withArgs('global.groupsv2.maxGroupSize')
|
||||
.returns('2')
|
||||
.withArgs('global.groupsv2.groupSizeHardLimit')
|
||||
.returns(value);
|
||||
it('defaults the maximum group size to 1001 if the recommended maximum is smaller', async () => {
|
||||
for (const value of [null, 'xyz']) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await updateRemoteConfig([
|
||||
{ name: 'global.groupsv2.maxGroupSize', value: '2', enabled: true },
|
||||
{
|
||||
name: 'global.groupsv2.groupSizeHardLimit',
|
||||
value,
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const state = {
|
||||
...getEmptyState(),
|
||||
|
@ -1750,15 +1764,22 @@ describe('both/state/ducks/conversations', () => {
|
|||
const action = getAction(uuid(), state);
|
||||
|
||||
assert.strictEqual(action.payload.maxGroupSize, 1001);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('defaults the maximum group size to (recommended maximum + 1) if the recommended maximum is more than 1001', () => {
|
||||
remoteConfigGetValueStub
|
||||
.withArgs('global.groupsv2.maxGroupSize')
|
||||
.returns('1234')
|
||||
.withArgs('global.groupsv2.groupSizeHardLimit')
|
||||
.returns('2');
|
||||
it('defaults the maximum group size to (recommended maximum + 1) if the recommended maximum is more than 1001', async () => {
|
||||
await updateRemoteConfig([
|
||||
{
|
||||
name: 'global.groupsv2.maxGroupSize',
|
||||
value: '1234',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: 'global.groupsv2.groupSizeHardLimit',
|
||||
value: '2',
|
||||
enabled: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const state = {
|
||||
...getEmptyState(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue