Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of oplog dependency #1032

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
44cd5ce
:books: test: Remove duplicate entry in test documentation.
make-github-pseudonymous-again Dec 25, 2024
ac68c27
:woman_technologist: dx(tests): Improve Mocha's output when run in a …
make-github-pseudonymous-again Jul 25, 2024
af7e497
:woman_technologist: dx(`_test/fixtures`): Add missing `Meteor` import.
make-github-pseudonymous-again Jul 10, 2024
6ec6c74
:woman_technologist: dx(`Accounts`): Remove rate-limiting in all tests.
make-github-pseudonymous-again Jul 10, 2024
4cf858b
:woman_technologist: dx(tests): Allow to use `undefined` in template …
make-github-pseudonymous-again Jul 10, 2024
66e69bb
:woman_technologist: dx(tests): Draft generic `waitFor` utility.
make-github-pseudonymous-again Dec 29, 2024
43cc81a
:woman_technologist: dx(tests): Increase timeout of `fetchPDF` server…
make-github-pseudonymous-again Dec 29, 2024
b2c6748
:recycle: refactor(user): Update `Account.createUser{Async}` usage.
make-github-pseudonymous-again Jul 10, 2024
cd25a06
:woman_technologist: dx: Allow to define event emitters.
make-github-pseudonymous-again Jul 8, 2024
3d557e6
:package: deps: Add `@functional-abstraction/type`.
make-github-pseudonymous-again Dec 27, 2024
243990f
:adhesive_bandage: fix(endpoints): Execute endpoints calls in isolation.
make-github-pseudonymous-again Dec 11, 2024
090707e
:recycle: refactor(`api/_apply`): Extract `AsyncLock`.
make-github-pseudonymous-again Dec 29, 2024
f9a124f
:woman_technologist: dx(`AsyncLock`): Implement non-blocking `acquire`.
make-github-pseudonymous-again Dec 29, 2024
2d0b739
:woman_technologist: dx(`lock`): Add context managers.
make-github-pseudonymous-again Dec 29, 2024
e0ebadc
:construction: progress(`api/query/watch`): Initial implementation.
make-github-pseudonymous-again Jan 2, 2025
06974b4
:recycle: refactor(`api/query/watch`): Extract `class Queue`.
make-github-pseudonymous-again Dec 28, 2024
281c39d
:recycle: refactor(`api/query/watch`): Extract `AsyncQueue`.
make-github-pseudonymous-again Dec 29, 2024
c20a98f
:construction: progress(`api/update`): Draft `isDiffEmpty`.
make-github-pseudonymous-again Jan 1, 2025
e8ce740
:construction: progress: Implement longest increasing subsequence sea…
make-github-pseudonymous-again Dec 29, 2024
01ca5c4
:construction: progress(`observe`): Implement `diffSequences`.
make-github-pseudonymous-again Dec 29, 2024
cadd383
:construction: progress(`observe`): Implement `diffSets`.
make-github-pseudonymous-again Dec 29, 2024
5674715
:construction: progress: Leverage `watch` in `makeObservedQueryPublic…
make-github-pseudonymous-again Dec 27, 2024
700c8e1
:woman_technologist: dx: Keep track of collections by name in a regis…
make-github-pseudonymous-again Jul 10, 2024
d8f951d
:construction: progress(collections): Allow to unregister a collection.
make-github-pseudonymous-again Dec 29, 2024
94d96f7
:woman_technologist: dx(tests): Add `withMockCollection` fixture.
make-github-pseudonymous-again Dec 29, 2024
2301dd1
:construction: progress(`observeSequenceChanges`): Initial implementa…
make-github-pseudonymous-again Dec 27, 2024
037b81b
:construction: progress(`observeSetChanges`): Initial implementation.
make-github-pseudonymous-again Dec 27, 2024
8e7b1b3
:woman_technologist: dx: Add missing methods for `meteor/mongo`'s `Cu…
make-github-pseudonymous-again Jul 7, 2024
c7788fb
:recycle: refactor: Depend on internals instead of `Meteor` in `api/s…
make-github-pseudonymous-again Jul 7, 2024
59c01a1
:construction: progress: Implement `duplicates`.
make-github-pseudonymous-again Dec 28, 2024
e413ad8
:construction: progress: Implement `unique`.
make-github-pseudonymous-again Dec 28, 2024
62c9331
:recycle: refactor(`api/publication`): Leverage `observeSetChanges`.
make-github-pseudonymous-again Jul 7, 2024
c7490e7
:recycle: refactor(`api/consultations`): Leverage `observeSetChanges`.
make-github-pseudonymous-again Jul 7, 2024
ca21618
:recycle: refactor(`api/createTagCollection`): Leverage `observeSetCh…
make-github-pseudonymous-again Jul 7, 2024
eb1c42a
:recycle: refactor(`api/makeCachedFindOneOpt`): Leverage `observeSetC…
make-github-pseudonymous-again Jul 7, 2024
33817f9
:recycle: refactor(`api/makeFilteredCollection`): Leverage `observeSe…
make-github-pseudonymous-again Jul 7, 2024
a6d114d
:recycle: refactor(`api/publication/patient/noShows`): Use `observeSe…
make-github-pseudonymous-again Jul 7, 2024
9a6c61e
:recycle: refactor(`api/.../frequencyBySex`): Use `observeSetChanges`.
make-github-pseudonymous-again Jul 7, 2024
84903c0
:recycle: refactor(`api/stats`): Leverage `observeSetChanges`.
make-github-pseudonymous-again Jul 7, 2024
34671b6
:broom: cleaning: Remove unused `ObserverHandle`.
make-github-pseudonymous-again Dec 28, 2024
9885b38
:microscope: test(`ui/stats/useFrequencyStats`): Increase coverage.
make-github-pseudonymous-again Jul 10, 2024
692a220
:recycle: refactor(`frequencyBySex`): Hide 0 counts to simplify testing.
make-github-pseudonymous-again Jul 10, 2024
2106a3c
:microscope: test(`useFrequencyStats`): Cover patients updates.
make-github-pseudonymous-again Jul 10, 2024
a9322d4
:woman_technologist: dx(tests): Add `dropOwners` fixture.
make-github-pseudonymous-again Jul 10, 2024
b35fb99
:microscope: test(`useAvailability`): Cover common usage.
make-github-pseudonymous-again Jul 10, 2024
fa16f42
:woman_technologist: dx(tests): Increase timeout of appointments E2E …
make-github-pseudonymous-again Jul 10, 2024
aa8fa69
:recycle: refactor(appointments): Make patient names optional for upd…
make-github-pseudonymous-again Jul 10, 2024
eda5e4e
:microscope: test(`useNoShowsForPatient`): Cover common usage.
make-github-pseudonymous-again Jul 10, 2024
70f1374
:recycle: refactor(`makeFilteredCollection`): Leverage `publishCursor…
make-github-pseudonymous-again Jul 10, 2024
456c36b
:adhesive_bandage: fix(`useSubscription`): Set `loading = false` on s…
make-github-pseudonymous-again Jul 11, 2024
8038c4e
:construction: progress: Disable oplog integration.
make-github-pseudonymous-again Dec 27, 2024
b82203b
:bicyclist: perf(mongodb): Configure min/max connection pool size.
make-github-pseudonymous-again Dec 27, 2024
728dda4
:construction: progress: Add types for Meteor.
make-github-pseudonymous-again Dec 27, 2024
0fbacd9
:broom: cleaning: Remove unused `makeCachedFindOneOpt`.
make-github-pseudonymous-again Jan 2, 2025
4856df3
:construction: progress(`subscribe`): Self-manage subscription recycl…
make-github-pseudonymous-again Jan 2, 2025
cb91202
:construction: progress: Self-manage `useCursor` effects.
make-github-pseudonymous-again Dec 27, 2024
e0698eb
:adhesive_bandage: fix: Rewrite `useSetting` using `useItem`.
make-github-pseudonymous-again Dec 27, 2024
aa3a8fc
:test_tube: test(`ReactivePatientChip`): Cover rendering 70 chips con…
make-github-pseudonymous-again Dec 27, 2024
7601efb
:woman_technologist: dx: Only render 60 `<ReactivePatientChip>`s in t…
make-github-pseudonymous-again Dec 28, 2024
f71b44e
:woman_technologist: dx: Increase timeout in `ReactivePatientChip` test.
make-github-pseudonymous-again Dec 12, 2024
14ddead
:woman_technologist: dx(tests): Increase timeout of patient PI editin…
make-github-pseudonymous-again Dec 31, 2024
8bc8dbf
:woman_technologist: dx: Add utility to debug Meteor subscriptions.
make-github-pseudonymous-again Dec 31, 2024
c076502
:adhesive_bandage: fix(`useSubscription`): Do not delay garbage colle…
make-github-pseudonymous-again Jan 1, 2025
a4efc2e
:construction: progress(`subscribe`): Allow `async` `on{Ready,Stop}` …
make-github-pseudonymous-again Jan 1, 2025
ceda082
:adhesive_bandage: fix(`useFind`): Handle `Cursor#observeAsync` errors.
make-github-pseudonymous-again Jan 1, 2025
f2ab31c
:construction: progress(`defer`): Initial implementation.
make-github-pseudonymous-again Jul 25, 2024
4e56085
:adhesive_bandage: fix(`createTagCollection`): Progress on loading st…
make-github-pseudonymous-again Dec 28, 2024
3c8de2a
:adhesive_bandage: fix(`makeDebouncedResultsQuery`): Correct loading …
make-github-pseudonymous-again Dec 28, 2024
3fe9c4e
:adhesive_bandage: fix(`makeFilteredCollection`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
134db75
:adhesive_bandage: fix(`makeQuery`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
b873736
:adhesive_bandage: fix(`useDocumentVersions`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
cbfaa51
:adhesive_bandage: fix(`useMergeInfo`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
33312f0
:adhesive_bandage: fix: Correct subscription recycling logic.
make-github-pseudonymous-again Jan 2, 2025
3cb4477
:adhesive_bandage: fix(types): Correct Timeout definition.
make-github-pseudonymous-again Dec 28, 2024
26024be
:test_tube: test(appointments): Increase app tests timeouts.
make-github-pseudonymous-again Dec 28, 2024
c75933f
:recycle: refactor(search): Extract `usePatientsSearchResults`.
make-github-pseudonymous-again Dec 28, 2024
712ebd0
:test_tube: test: Cover `useSubscription` loading state on second call.
make-github-pseudonymous-again Dec 28, 2024
97a2f28
:test_tube: test: Cover `useConsultation`.
make-github-pseudonymous-again Dec 28, 2024
c85788a
:adhesive_bandage: fix(`<ConsultationEditorHeader>`): Avoid update re…
make-github-pseudonymous-again Dec 28, 2024
2918753
:adhesive_bandage: fix(`<PatientPersonalInformation>`): Avoid update …
make-github-pseudonymous-again Dec 28, 2024
bc486fa
:test_tube: test: Increase timeout of password change test.
make-github-pseudonymous-again Dec 28, 2024
784dd56
:adhesive_bandage: fix(`makeFindOne`): Avoid loading flicker.
make-github-pseudonymous-again Dec 28, 2024
9cf89cf
:adhesive_bandage: fix(`useSetting`): Avoid loading flicker.
make-github-pseudonymous-again Dec 28, 2024
b879e9a
:recycle: refactor(AppointmentCancellationDialog): Leverage `readOnly`.
make-github-pseudonymous-again Dec 28, 2024
d5fd9ea
:bicyclist: perf(`AppointmentCancellationDialog`): Memoize input `ren…
make-github-pseudonymous-again Dec 28, 2024
e743478
:recycle: refactor: Rewrite `<AppointmentsForPatient>` for readability.
make-github-pseudonymous-again Dec 10, 2024
8791d1b
:construction: progress: Fix potential bug in `makeCachedFindOne`.
make-github-pseudonymous-again Dec 11, 2024
16043b3
:recycle: refactor: Experiment `Promise.all` map instead of `await` c…
make-github-pseudonymous-again Dec 11, 2024
7553c81
:bicyclist: perf(subscribe): Allow recycling subs pending collection.
make-github-pseudonymous-again Dec 12, 2024
c7a79cb
:adhesive_bandage: fix(`useSubscription`): Handle nullable publications.
make-github-pseudonymous-again Dec 12, 2024
2d9dab2
:woman_technologist: dx(tests): Correctly unmount and remount app tests.
make-github-pseudonymous-again Dec 10, 2024
9942755
:recycle: refactor(`ui/users`): Simplify menus anchoring and opening …
make-github-pseudonymous-again Jan 1, 2025
066605c
:bicyclist: perf(`useRandom`): Memoize update function.
make-github-pseudonymous-again Jan 1, 2025
11e6d56
:construction: progress(`makeObservedQueryHook`): Allow to configure …
make-github-pseudonymous-again Jan 1, 2025
3a07404
:construction: progress(`makeObservedQueryHook`): Allow disabling query.
make-github-pseudonymous-again Jan 1, 2025
898c186
:adhesive_bandage: fix(`patientsUpdate`): Allow to reset resettable f…
make-github-pseudonymous-again Jan 1, 2025
029760a
:adhesive_bandage: fix(`PatientPersonalInformation`): Reduce test fla…
make-github-pseudonymous-again Jan 1, 2025
7c2e44a
:construction: progress(`PatientPersonalInformation`): Fix undo.
make-github-pseudonymous-again Dec 22, 2024
964b320
:recycle: refactor(`api/update`): Extract `hasOwn`.
make-github-pseudonymous-again Dec 29, 2024
05eb423
:recycle: refactor(collections): Improve document diffing and updatin…
make-github-pseudonymous-again Jan 1, 2025
c23fcc4
:construction: progress(`events`): Leverage `observeSetChanges`.
make-github-pseudonymous-again Dec 27, 2024
55ccde9
:construction: progress: Add comment on how to make events views reac…
make-github-pseudonymous-again Jul 5, 2024
e3dd9f1
:construction: progress(`publishEvents`): Fix signature types.
make-github-pseudonymous-again Dec 28, 2024
23dec4f
:woman_technologist: dx(`events/intersects`): Use silent error on bad…
make-github-pseudonymous-again Jul 11, 2024
c7208ae
:microscope: test(`useIntersectingEvents`): Cover common usage.
make-github-pseudonymous-again Jul 11, 2024
46a607b
:adhesive_bandage: fix(`useEvents`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
cdda79c
:adhesive_bandage: fix(`useIntersectingEvents`): Correct loading state.
make-github-pseudonymous-again Dec 28, 2024
fdeb32f
:construction: progress(`addTooltip`): Unwrap if tooltip title is `un…
make-github-pseudonymous-again Jan 1, 2025
f070756
:recycle: refactor(`LoadingButtonIcon`): Fix typing.
make-github-pseudonymous-again Jan 1, 2025
264c78a
:recycle: refactor(`FixedFab`): Fix typing.
make-github-pseudonymous-again Jan 1, 2025
b6873be
:woman_technologist: dx(`useFind`): Add sequentiality invariant asser…
make-github-pseudonymous-again Jan 1, 2025
4573994
:woman_technologist: dx: Warn between tests if change streams are sti…
make-github-pseudonymous-again Jan 1, 2025
96cf3e7
:woman_technologist: dx(`watch`): Log maximum number of active streams.
make-github-pseudonymous-again Jan 1, 2025
23e7002
:children_crossing: ux(`FullTextSearchResultRoutes`): Defer query input.
make-github-pseudonymous-again Jan 1, 2025
0fdeba2
:recycle: refactor(`TagDetails`): Leverage `useRandom`.
make-github-pseudonymous-again Jan 1, 2025
e00478a
:adhesive_bandage: fix(documents): Avoid crash in report page when lo…
make-github-pseudonymous-again Jan 1, 2025
77c20cd
:recycle: refactor(`PatientPersonalInformation`): Simplify query `deps`.
make-github-pseudonymous-again Jan 1, 2025
58e8475
:wrench: config(tests): Force `StrictMode` with `render{,Hook}`.
make-github-pseudonymous-again Dec 19, 2024
2a41c66
:truck: refactor: Rename `Publication` to `PublicationEndpoint`.
make-github-pseudonymous-again Dec 28, 2024
184296a
:recycle: refactor(`useFind`): Extract `findClientEffect`.
make-github-pseudonymous-again Dec 29, 2024
516770f
:recycle: refactor(`useSubscription`): Allow to configure callbacks.
make-github-pseudonymous-again Dec 29, 2024
a509361
:construction: progress(`subscribe`): GC `onReady` and `onStop` callb…
make-github-pseudonymous-again Dec 22, 2024
608c7ff
:construction: progress(`<PatientPersonalInformation>`): Fix dirty pr…
make-github-pseudonymous-again Dec 22, 2024
6be3960
:construction: progress(`useQuery`): Initial implementation.
make-github-pseudonymous-again Jan 1, 2025
5dc3835
:adhesive_bandage: fix(`useIntersectingEvents`): Avoid loading flicker.
make-github-pseudonymous-again Jan 1, 2025
1b71fac
:recycle: refactor(`imports/api/makeCachedFindOne`): Leverage `docume…
make-github-pseudonymous-again Dec 29, 2024
c797dde
:adhesive_bandage: fix(`<ReactivePatientCard>`): Update when resuscit…
make-github-pseudonymous-again Dec 29, 2024
3d3f889
:woman_technologist: dx(`useIntersectingEvents`): Format note.
make-github-pseudonymous-again Dec 29, 2024
d389733
:woman_technologist: dx(`useEvents`): Format note.
make-github-pseudonymous-again Dec 29, 2024
8af4802
:adhesive_bandage: fix(`useEvents`): Avoid loading flicker.
make-github-pseudonymous-again Dec 29, 2024
8c9da78
:broom: cleaning: Remove unused `ObserveChangesCallbacks`.
make-github-pseudonymous-again Dec 29, 2024
9934ced
:adhesive_bandage: fix(`ConsultationEditor`): Fix in-book number load…
make-github-pseudonymous-again Dec 24, 2024
b827ff9
:recycle: refactor(`<ConsultationEditor>`): Rewrite `<Loader>` signat…
make-github-pseudonymous-again Dec 24, 2024
5d31851
:adhesive_bandage: fix(`makeDebouncedResultsQuery`): Avoid loading fl…
make-github-pseudonymous-again Dec 25, 2024
081258b
:recycle: refactor(books): Move hooks to `/ui`.
make-github-pseudonymous-again Dec 25, 2024
f88e8cd
:adhesive_bandage: fix(`makeQuery`): Avoid loading flicker.
make-github-pseudonymous-again Dec 25, 2024
aa8dff8
:microscope: test: Increase coverage target to 71%.
make-github-pseudonymous-again Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .deploy/default/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"public": {

},
"packages": {
"mongo": {
"options": {
"minPoolSize": 100,
"maxPoolSize": 1000
},
"oplogUrl": "",
"oplogIncludeCollections": []
}
}
}
15 changes: 15 additions & 0 deletions .deploy/ghcr.io/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"public": {

},
"packages": {
"mongo": {
"options": {
"minPoolSize": 100,
"maxPoolSize": 1000
},
"oplogUrl": "",
"oplogIncludeCollections": []
}
}
}
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ PORT=3000

MONGO_VERSION=5.0
MONGO_URL=mongodb://patient-db:27017/meteor
MONGO_OPLOG_URL=""

HTTP_FORWARDED_COUNT=1
8 changes: 8 additions & 0 deletions .github/workflows/ci:build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
- uses: actions/checkout@v4
with:
sparse-checkout: |
settings.json
scripts/healthcheck.cjs
scripts/assert-replica-set.js
.github/actions/docker/container/is-healthy/action.yml
Expand Down Expand Up @@ -176,11 +177,18 @@ jobs:
container: mongodb
timeout: 60

- name: Configure server
id: configure-server
run: |
echo "settings=$(tr -d '\r\n' < settings.json)" >> "${GITHUB_OUTPUT}"

- name: Run server
id: server
env:
ROOT_URL: http://localhost
MONGO_URL: mongodb://localhost:27017/meteor
MONGO_OPLOG_URL: ""
METEOR_SETTINGS: ${{ steps.configure-server.outputs.meteor-settings }}
PORT: 3000
run: |
cd dist
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ci:build:image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
- uses: actions/checkout@v4
with:
sparse-checkout: |
settings.json
scripts/assert-replica-set.js
.github/actions/docker/container/ip-address/action.yml
.github/actions/docker/container/is-healthy/action.yml
Expand Down Expand Up @@ -138,10 +139,17 @@ jobs:
container: mongodb
timeout: 60

- name: Configure server
id: configure-server
run: |
echo "settings=$(tr -d '\r\n' < settings.json)" >> "${GITHUB_OUTPUT}"

- name: Run server
env:
ROOT_URL: http://localhost
MONGO_URL: mongodb://mongodb:27017/meteor
MONGO_OPLOG_URL: ""
METEOR_SETTINGS: ${{ steps.configure-server.outputs.meteor-settings }}
PORT: 3000
run: |
docker container run \
Expand All @@ -151,6 +159,8 @@ jobs:
--publish "${PORT}:${PORT}" \
--env "ROOT_URL=${ROOT_URL}" \
--env "MONGO_URL=${MONGO_URL}" \
--env "MONGO_OPLOG_URL=${MONGO_OPLOG_URL}" \
--env "METEOR_SETTINGS=${METEOR_SETTINGS}" \
--env "PORT=${PORT}" \
--name server \
${{ steps.server-image-url.outputs.url }}
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ EXPOSE 3000
ENV \
ROOT_URL="http://localhost" \
PORT="3000" \
MONGO_URL="mongodb://localhost:27017/meteor"
MONGO_URL="mongodb://localhost:27017/meteor" \
MONGO_OPLOG_URL=""

HEALTHCHECK \
--interval=21s \
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 67%
target: 71%
threshold: 1%
patch:
default:
Expand Down
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- ROOT_URL=${ROOT_URL}
- PORT=${PORT}
- MONGO_URL=${MONGO_URL}
- MONGO_OPLOG_URL=${MONGO_OPLOG_URL}
- METEOR_SETTINGS=${METEOR_SETTINGS}
- HTTP_FORWARDED_COUNT=${HTTP_FORWARDED_COUNT}
depends_on:
patient-db:
Expand Down
136 changes: 123 additions & 13 deletions imports/_test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

import {assert, expect} from 'chai';

import {cleanup as unmount} from '@testing-library/react';
import {Meteor} from 'meteor/meteor';

import totalOrder from 'total-order';
import {sorted} from '@iterable-iterator/sorted';

import sleep from '../lib/async/sleep';

// eslint-disable-next-line import/no-unassigned-import
import '../api/endpoint/_dev/_disableRateLimiting';
import logout from '../api/user/logout';
import define from '../api/collection/define';
import {removeCollection} from '../api/collection/registry';
import invoke from '../api/endpoint/invoke';
import call from '../api/endpoint/call';
import reset from '../api/endpoint/_dev/reset';
Expand All @@ -16,6 +23,10 @@
import type Selector from '../api/query/Selector';
import appIsReady from '../app/isReady';
import isAppTest from '../app/isAppTest';
import {_router} from '../ui/App';
import {getWatchStreamCount} from '../api/query/watch';

import {unmount as _unmount} from './react';

export {
default as randomId,
Expand All @@ -25,6 +36,28 @@

let resolving = 0;

export const waitFor = async (condition: () => boolean) => {
while (!condition()) {
// eslint-disable-next-line no-await-in-loop
await sleep(50);
}
};

export const withMockCollection =
<T extends Document, U = T>(
callback: (collection: Collection<T, U>) => Promise<void> | void,

Check warning on line 48 in imports/_test/fixtures.ts

View check run for this annotation

Codecov / codecov/patch

imports/_test/fixtures.ts#L48

Added line #L48 was not covered by tests
) =>
async () => {
const collectionName = '__mocks__';
const collection = define<T, U>(collectionName);
try {
await callback(collection);
} finally {
await collection.dropCollectionAsync();
removeCollection(collectionName);
}
};

const resolveOnPopstate = async () =>
new Promise<void>((resolve) => {
let pos = ++resolving;
Expand Down Expand Up @@ -77,17 +110,43 @@
return history.length - 1;
};

const mount = isAppTest()
? () => {
_router.navigate('/');
}
: // eslint-disable-next-line @typescript-eslint/no-empty-function
() => {};

const unmount = isAppTest()
? () => {
_router.navigate('/_test/unmount');
}
: () => {
_unmount();
};

const assertChangeStreamWatchersAreOff = () => {
const n = getWatchStreamCount();
if (n !== 0) {
console.warn(`ChangeStream watch count is different from 0 (got ${n})!`);
}
};

export const client = (title, fn) => {
if (Meteor.isClient) {
const cleanup = async () => {
await logout();
unmount();
assertChangeStreamWatchersAreOff();
mount();
await call(reset);
};

let original;

const prepare = async () => {
// @ts-expect-error TODO
await import('./mocha.css');
await import('../../client/polyfill');

original = await forgetHistory();
Expand Down Expand Up @@ -174,23 +233,71 @@

export const dropIds = (x) => x.map(dropId);

export const create = (template, extra) => {
if (typeof template === 'function') return extra ?? template();
export const dropOwner = ({owner, ...rest}) => {
assert(typeof owner === 'string');
return rest;
};

export const dropOwners = (x) => x.map(dropOwner);

type Created<T> = T extends {[K in keyof T]: T[K]}
? {[K in keyof T]: Created<T[K]>}
: T extends () => any
? ReturnType<T>
: never;

type Extra<T> = T extends any[]
? Created<T>
: T extends {[K in keyof T]: T[K]}
? Partial<Created<T>>
: T extends () => any
? ReturnType<T>
: never;

export function create<T extends () => any>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T>;
export function create<T extends {[K in keyof T]: T[K]}>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T>;

export function create<T>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T> {
if (typeof template === 'function') return hasExtra ? extra : template();
if (Array.isArray(template)) {
return template
.map((x, i) => create(x, extra?.[i]))
.concat(extra?.slice(template.length) ?? []);
return (template as Array<T[keyof T]>)
.map((x, i) =>
create(
x,
extra?.[i],
Object.prototype.hasOwnProperty.call(extra ?? [], i),
),
)
.concat(extra?.slice(template.length) ?? []) as Created<T>;
}

return Object.fromEntries(
(extra === undefined ? [] : Object.entries(extra)).concat(
Object.entries(template).map(([key, value]) => [
key,
create(value, extra?.[key]),
]),
Object.entries(template as {[K in keyof T]: T[K]}).map(
<V>([key, value]: [string, V]) => [
key,
create(
value,
extra?.[key],
Object.prototype.hasOwnProperty.call(extra ?? {}, key),
),
],
),
),
);
};
) as Created<T>;
}

export const findOneOrThrow = async <T extends Document, U = T>(
collection: Collection<T, U>,
Expand All @@ -204,4 +311,7 @@
return result!;
};

export const makeTemplate = (template) => (extra?) => create(template, extra);
export const makeTemplate = (template) => (extra?) =>
create(template, extra, extra !== undefined);

export const isNode = () => Meteor.isServer;
38 changes: 38 additions & 0 deletions imports/_test/mocha.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
div#mocha {
z-index: 99999999;
opacity: 0;
position: fixed;
top: 64px;
left: 73px;
right: 0;
background: white;
margin: 0;
padding: 1em;
overflow: auto;
height: calc(100% - 64px);
}

div#mocha:hover {
opacity: 0.9;
}

div#mocha > ul#mocha-report > li.suite > ul > li.test::before {
font-size: 18px;
line-height: 1em;
}

div#mocha > ul#mocha-report > li.suite > ul > li.test.pass::before {
color: #0b9;
}

div#mocha > ul#mocha-report > li.suite > ul > li.test.fail::before {
color: #b00;
}

div#mocha > ul#mocha-stats {
position: initial;
}

div#mocha > ul#mocha-report > li.suite > h1 {
font-size: 0.8em;
}
13 changes: 13 additions & 0 deletions imports/_test/react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {configure as configureReact} from '@testing-library/react';

configureReact({
reactStrictMode: true,
});

export {
render,
renderHook,
waitFor,
waitForElementToBeRemoved,
cleanup as unmount,
} from '@testing-library/react';
Loading
Loading