Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Jul 30, 2024
2 parents 45282fd + 1037690 commit a293ec0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1,036 deletions.
949 changes: 4 additions & 945 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 1 addition & 44 deletions packages/btree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "module",
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"check-types": "tsc --noEmit",
"benchmark": "npm run build && node benchmarks.js"
},
Expand Down Expand Up @@ -46,54 +47,10 @@
"@types/bintrees": "^1.0.2",
"@types/collections": "^5.0.2",
"@types/mersenne-twister": "^1.1.2",
"@types/node": "^18.16.0",
"babel-core": "^6.26.3",
"bintrees": "^1.0.2",
"collections": "^5.1.11",
"functional-red-black-tree": "^1.0.1",
"mersenne-twister": "^1.1.0",
"testpack-cli": "^1.1.4",
"ts-node": "^10.9.1",
"typescript": "^5.5.3"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/tests/.*|(\\.|/)test)\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": [
"<rootDir>.*nontest.*",
"<rootDir>/.testpack"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"bail": true,
"testEnvironment": "node"
},
"testpack": {
"packagejson": {
"scripts": {
"test": "echo //for ts-jest bug #618 > workaround.ts && jest"
}
},
"install": [
"[email protected]",
"[email protected]"
],
"verbose": true,
"test-folder": ".testpack",
"rmdir": true,
"dirty": true,
"replace-import//": "// Use the minified version in .testpack",
"replace-import": [
"|./b\\+tree|$P/b+tree|",
"|..?|$P|",
"|..?([/\\\\].*)|$P$1|"
]
}
}
3 changes: 0 additions & 3 deletions packages/datadog/jest.config.js

This file was deleted.

10 changes: 4 additions & 6 deletions packages/datadog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
"@rocicorp/lock": "^1.0.4",
"@rocicorp/logger": "^5.2.2",
"@rocicorp/prettier-config": "^0.2.0",
"@types/node-fetch": "^2.6.2",
"cross-fetch": "^3.1.5",
"replicache": "15.0.1",
"ts-jest": "^29.1.0",
"typescript": "^5.5.3"
"typescript": "^5.5.3",
"vitest": "^2.0.3"
},
"scripts": {
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
"test:watch": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --watch",
"test": "vitest run",
"test:watch": "vitest",
"check-types": "tsc --noEmit",
"format": "prettier --write *",
"check-format": "prettier --check *",
Expand Down
72 changes: 36 additions & 36 deletions packages/datadog/src/datadog-log-sink.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {jest, afterEach, beforeEach, test, expect} from '@jest/globals';
import {resolver} from '@rocicorp/resolver';
import type {ReadonlyJSONObject} from 'replicache';
import {afterEach, beforeEach, expect, test, vi} from 'vitest';
import {
DatadogLogSink,
FORCE_FLUSH_THRESHOLD,
MAX_ENTRY_CHARS,
MAX_LOG_ENTRIES_PER_FLUSH,
} from './datadog-log-sink.js';
import {resolver} from '@rocicorp/resolver';
import realFetch from 'cross-fetch';

const fetch = jest.fn(realFetch);
const originalFetch = globalThis.fetch;
const fetch = vi.fn<typeof originalFetch>();
globalThis.fetch = fetch;

beforeEach(() => {
jest.useFakeTimers();
jest.setSystemTime(0);
vi.useFakeTimers();
vi.setSystemTime(0);
fetch.mockReturnValue(Promise.resolve(new Response('{}')));
});

afterEach(() => {
jest.restoreAllMocks();
vi.clearAllMocks();
});

function stringifyMany(...messages: ReadonlyJSONObject[]): string {
Expand All @@ -30,7 +30,7 @@ test('calling error also calls flush', () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
const flushSpy = jest
const flushSpy = vi
.spyOn(l, 'flush')
.mockImplementation(() => Promise.resolve(undefined));
l.log('error', {usr: {name: 'bob'}}, 'aaa');
Expand All @@ -41,7 +41,7 @@ test('reaching flush threshold also calls flush', () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
const flushSpy = jest
const flushSpy = vi
.spyOn(l, 'flush')
.mockImplementation(() => Promise.resolve(undefined));
for (let i = 0; i < FORCE_FLUSH_THRESHOLD - 1; i++) {
Expand Down Expand Up @@ -101,7 +101,7 @@ test('does not flush more than max entries', async () => {

// Check the third fetch (not flushed till after flush interval
// since message count is below FORCE_FLUSH_THRESHOLD).
jest.advanceTimersByTime(10);
vi.advanceTimersByTime(10);
await fetchLatches[2].promise;
expect(numLogEntriesInRequest(2)).toBe(123);
});
Expand Down Expand Up @@ -181,7 +181,7 @@ test('flushes MAX_LOG_ENTRIES_PER_FLUSH at a time until size is below FORCE_FLUS

// Check the final fetch (not flushed till after flush interval
// since message count is below FORCE_FLUSH_THRESHOLD).
jest.advanceTimersByTime(10);
vi.advanceTimersByTime(10);
await fetchLatches[4].promise;
fetchResponseResolvers[4].resolve({ok: true} as unknown as Response);
expect(numLogEntriesInRequest(4)).toBe(123);
Expand All @@ -191,12 +191,12 @@ test('flush calls fetch', async () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
jest.setSystemTime(1);
vi.setSystemTime(1);
l.log('debug', {usr: {name: 'bob'}}, 'debug message');
jest.setSystemTime(2);
vi.setSystemTime(2);
l.log('info', {usr: {name: 'bob'}}, 'info message');

jest.setSystemTime(10);
vi.setSystemTime(10);
await l.flush();

expect(fetch).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -230,12 +230,12 @@ test('flush calls fetch with specified baseURL', async () => {
apiKey: 'apiKey',
baseURL: new URL('http://custom.base.com/api/path/log'),
});
jest.setSystemTime(1);
vi.setSystemTime(1);
l.log('debug', {usr: {name: 'bob'}}, 'debug message');
jest.setSystemTime(2);
vi.setSystemTime(2);
l.log('info', {usr: {name: 'bob'}}, 'info message');

jest.setSystemTime(10);
vi.setSystemTime(10);
await l.flush();

expect(fetch).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -268,7 +268,7 @@ test('flush truncates large messages and batches', async () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
jest.setSystemTime(1);
vi.setSystemTime(1);
l.log('debug', {usr: {name: 'bob'}}, 'a'.repeat(MAX_ENTRY_CHARS * 2));
l.log('debug', {usr: {name: 'bob'}}, 'b'.repeat(MAX_ENTRY_CHARS / 2));
l.log('debug', {usr: {name: 'bob'}}, 'small message');
Expand Down Expand Up @@ -360,7 +360,7 @@ test('reserved keys are prefixed', async () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
jest.setSystemTime(1);
vi.setSystemTime(1);
l.log(
'debug',
{
Expand All @@ -380,7 +380,7 @@ test('reserved keys are prefixed', async () => {
'debug message',
);

jest.setSystemTime(10);
vi.setSystemTime(10);
await l.flush();

expect(fetch).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -416,7 +416,7 @@ test('Errors in multi arg messages are converted to JSON', async () => {
apiKey: 'apiKey',
});

jest.setSystemTime(1);
vi.setSystemTime(1);
l.log(
'info',
{usr: {name: 'bob'}},
Expand Down Expand Up @@ -458,7 +458,7 @@ test('Errors in single arg messages are converted to JSON', async () => {
apiKey: 'apiKey',
});

jest.setSystemTime(1);
vi.setSystemTime(1);
l.log('info', {usr: {name: 'bob'}}, new Error('Test error msg'));

await l.flush();
Expand Down Expand Up @@ -490,13 +490,13 @@ test('flush calls fetch but includes logs after the error', async () => {
const l = new DatadogLogSink({
apiKey: 'apiKey',
});
jest.useFakeTimers();
jest.setSystemTime(3);
vi.useFakeTimers();
vi.setSystemTime(3);
l.log('error', {usr: {name: 'bob'}}, 'error message');
jest.setSystemTime(4);
vi.setSystemTime(4);
l.log('info', {usr: {name: 'bob'}}, 'info message');

jest.setSystemTime(10);
vi.setSystemTime(10);
await l.flush();

expect(fetch).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -532,9 +532,9 @@ test('flush is called 1s after a log', async () => {
interval: 1000,
});

jest.setSystemTime(3);
vi.setSystemTime(3);
l.log('info', {usr: {name: 'bob'}}, 'info message');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 1);

Expand Down Expand Up @@ -562,9 +562,9 @@ test('flush is called again in case of failure', async () => {
});

fetch.mockReturnValue(Promise.reject(new Error('error')));
jest.setSystemTime(3);
vi.setSystemTime(3);
l.log('info', {usr: {name: 'bob'}}, 'info message');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 1);

Expand All @@ -586,7 +586,7 @@ test('flush is called again in case of failure', async () => {

fetch.mockReturnValue(Promise.resolve(new Response()));
l.log('info', {usr: {name: 'bob'}}, 'info message 2');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 2);

Expand Down Expand Up @@ -624,10 +624,10 @@ test('messages that fail to send 3 times are dropped', async () => {
});

fetch.mockReturnValue(Promise.reject(new Error('error')));
jest.setSystemTime(3);
vi.setSystemTime(3);
l.log('info', {usr: {name: 'bob'}}, 'info message');
l.log('info', {usr: {name: 'bob'}}, 'info message 2');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 1);

Expand Down Expand Up @@ -657,7 +657,7 @@ test('messages that fail to send 3 times are dropped', async () => {
);

l.log('info', {usr: {name: 'bob'}}, 'info message 3');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 2);

Expand Down Expand Up @@ -696,7 +696,7 @@ test('messages that fail to send 3 times are dropped', async () => {
);

l.log('info', {usr: {name: 'bob'}}, 'info message 4');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 3);

Expand Down Expand Up @@ -744,7 +744,7 @@ test('messages that fail to send 3 times are dropped', async () => {

fetch.mockReturnValue(Promise.resolve(new Response()));
l.log('info', {usr: {name: 'bob'}}, 'info message 5');
jest.advanceTimersByTime(1000);
vi.advanceTimersByTime(1000);

await microtasksUntil(() => fetch.mock.calls.length >= 4);

Expand Down
1 change: 1 addition & 0 deletions packages/datadog/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {config as default} from '../shared/src/tool/vitest-config.js';
4 changes: 3 additions & 1 deletion packages/replicache/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export {TEST_LICENSE_KEY} from '@rocicorp/licensing/src/client';
export {consoleLogSink} from '@rocicorp/logger';
export type {LogLevel, LogSink} from '@rocicorp/logger';
export type {MaybePromise} from 'shared/src/types.js';
export type {
JSONObject,
JSONValue,
ReadonlyJSONObject,
ReadonlyJSONValue,
} from 'shared/src/json.js';
export type {MaybePromise} from 'shared/src/types.js';
export type {
Diff as ExperimentalDiff,
DiffOperation as ExperimentalDiffOperation,
Expand Down Expand Up @@ -106,6 +106,8 @@ export type {
WriteTransaction,
} from './transactions.js';
export type {
MakeMutator,
MakeMutators,
MutatorDefs,
MutatorReturn,
Poke,
Expand Down
3 changes: 2 additions & 1 deletion packages/replicache/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {MaybePromise} from 'shared/src/types.js';
import type {Hash} from './hash.js';
import type {ReadonlyJSONValue, WriteTransaction} from './mod.js';
import type {PullResponseV1, PullResponseV1Internal} from './puller.js';
import type {ReadTransactionImpl} from './transactions.js';
import type {MaybePromise} from 'shared/src/types.js';

export type BeginPullResult = {
requestID: string;
Expand Down Expand Up @@ -36,6 +36,7 @@ export type MutatorDefs = {
args?: any,
) => MutatorReturn;
};

export type MakeMutator<
F extends (
tx: WriteTransaction,
Expand Down

0 comments on commit a293ec0

Please sign in to comment.