Skip to content

Commit 41040fd

Browse files
committed
Use JavaScript fn names (pop > shift)
1 parent 0b20619 commit 41040fd

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

packages/browser/src/transports/offline.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function unshift(store: Store, value: Uint8Array | string, maxQueueSize:
7979
}
8080

8181
/** Pop the oldest value from the store */
82-
export function pop(store: Store): Promise<Uint8Array | string | undefined> {
82+
export function shift(store: Store): Promise<Uint8Array | string | undefined> {
8383
return store(store => {
8484
return keys(store).then(keys => {
8585
if (keys.length === 0) {
@@ -141,9 +141,9 @@ function createIndexedDbStore(options: BrowserOfflineTransportOptions): OfflineS
141141
//
142142
}
143143
},
144-
pop: async () => {
144+
shift: async () => {
145145
try {
146-
const deserialized = await pop(getStore());
146+
const deserialized = await shift(getStore());
147147
if (deserialized) {
148148
return parseEnvelope(deserialized);
149149
}

packages/browser/test/unit/transports/offline.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
import { createEnvelope } from '@sentry/utils';
1212

1313
import { MIN_DELAY } from '../../../../core/src/transports/offline';
14-
import { createStore, makeBrowserOfflineTransport, pop, push, unshift } from '../../../src/transports/offline';
14+
import { createStore, makeBrowserOfflineTransport, push, shift, unshift } from '../../../src/transports/offline';
1515

1616
function deleteDatabase(name: string): Promise<void> {
1717
return new Promise<void>((resolve, reject) => {
@@ -65,21 +65,21 @@ describe('makeOfflineTransport', () => {
6565

6666
it('indexedDb wrappers push, unshift and pop', async () => {
6767
const store = createStore('test', 'test');
68-
const found = await pop(store);
68+
const found = await shift(store);
6969
expect(found).toBeUndefined();
7070

7171
await push(store, 'test1', 30);
7272
await push(store, new Uint8Array([1, 2, 3, 4, 5]), 30);
7373
await unshift(store, 'test2', 30);
7474

75-
const found2 = await pop(store);
75+
const found2 = await shift(store);
7676
expect(found2).toEqual('test2');
77-
const found3 = await pop(store);
77+
const found3 = await shift(store);
7878
expect(found3).toEqual('test1');
79-
const found4 = await pop(store);
79+
const found4 = await shift(store);
8080
expect(found4).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
8181

82-
const found5 = await pop(store);
82+
const found5 = await shift(store);
8383
expect(found5).toBeUndefined();
8484
});
8585

packages/core/src/transports/offline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function log(msg: string, error?: Error): void {
1414
export interface OfflineStore {
1515
push(env: Envelope): Promise<void>;
1616
unshift(env: Envelope): Promise<void>;
17-
pop(): Promise<Envelope | undefined>;
17+
shift(): Promise<Envelope | undefined>;
1818
}
1919

2020
export type CreateOfflineStore = (options: OfflineTransportOptions) => OfflineStore;
@@ -87,7 +87,7 @@ export function makeOfflineTransport<TO>(
8787
flushTimer = setTimeout(async () => {
8888
flushTimer = undefined;
8989

90-
const found = await store.pop();
90+
const found = await store.shift();
9191
if (found) {
9292
log('Attempting to send previously queued event');
9393
void send(found, true).catch(e => {

packages/core/test/lib/transports/offline.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const createTestTransport = (...sendResults: MockResult<TransportMakeRequestResp
107107
};
108108
};
109109

110-
type StoreEvents = ('push' | 'unshift' | 'pop')[];
110+
type StoreEvents = ('push' | 'unshift' | 'shift')[];
111111

112112
function createTestStore(...popResults: MockResult<Envelope | undefined>[]): {
113113
getCalls: () => StoreEvents;
@@ -130,8 +130,8 @@ function createTestStore(...popResults: MockResult<Envelope | undefined>[]): {
130130
calls.push('unshift');
131131
}
132132
},
133-
pop: async () => {
134-
calls.push('pop');
133+
shift: async () => {
134+
calls.push('shift');
135135
const next = popResults.shift();
136136

137137
if (next instanceof Error) {
@@ -182,7 +182,7 @@ describe('makeOfflineTransport', () => {
182182
await waitUntil(() => getCalls().length == 1, 1_000);
183183

184184
// After a successful send, the store should be checked
185-
expect(getCalls()).toEqual(['pop']);
185+
expect(getCalls()).toEqual(['shift']);
186186
});
187187

188188
it('Envelopes are added after existing envelopes in the queue', async () => {
@@ -197,7 +197,7 @@ describe('makeOfflineTransport', () => {
197197

198198
expect(getSendCount()).toEqual(2);
199199
// After a successful send from the store, the store should be checked again to ensure it's empty
200-
expect(getCalls()).toEqual(['pop', 'pop']);
200+
expect(getCalls()).toEqual(['shift', 'shift']);
201201
});
202202

203203
it('Queues envelope if wrapped transport throws error', async () => {
@@ -259,7 +259,7 @@ describe('makeOfflineTransport', () => {
259259
await waitUntil(() => getCalls().length === 3 && getSendCount() === 1, START_DELAY * 2);
260260

261261
expect(getSendCount()).toEqual(1);
262-
expect(getCalls()).toEqual(['push', 'pop', 'pop']);
262+
expect(getCalls()).toEqual(['push', 'shift', 'shift']);
263263
},
264264
START_DELAY + 2_000,
265265
);
@@ -279,7 +279,7 @@ describe('makeOfflineTransport', () => {
279279
await waitUntil(() => getCalls().length === 3 && getSendCount() === 2, START_DELAY * 2);
280280

281281
expect(getSendCount()).toEqual(2);
282-
expect(getCalls()).toEqual(['pop', 'pop', 'pop']);
282+
expect(getCalls()).toEqual(['shift', 'shift', 'shift']);
283283
},
284284
START_DELAY + 2_000,
285285
);
@@ -299,7 +299,7 @@ describe('makeOfflineTransport', () => {
299299
await waitUntil(() => getCalls().length === 2, START_DELAY * 2);
300300

301301
expect(getSendCount()).toEqual(0);
302-
expect(getCalls()).toEqual(['pop', 'unshift']);
302+
expect(getCalls()).toEqual(['shift', 'unshift']);
303303
},
304304
START_DELAY + 2_000,
305305
);
@@ -361,12 +361,12 @@ describe('makeOfflineTransport', () => {
361361
// We're sending a replay envelope and they always get queued
362362
'push',
363363
// The first envelope popped out fails to send so it gets added to the front of the queue
364-
'pop',
364+
'shift',
365365
'unshift',
366366
// The rest of the attempts succeed
367-
'pop',
368-
'pop',
369-
'pop',
367+
'shift',
368+
'shift',
369+
'shift',
370370
]);
371371

372372
const envelopes = getSentEnvelopes().map(parseEnvelope);
@@ -416,7 +416,7 @@ describe('makeOfflineTransport', () => {
416416

417417
expect(getSendCount()).toEqual(2);
418418
expect(queuedCount).toEqual(0);
419-
expect(getCalls()).toEqual(['pop', 'pop']);
419+
expect(getCalls()).toEqual(['shift', 'shift']);
420420
},
421421
START_DELAY * 3,
422422
);

0 commit comments

Comments
 (0)