Skip to content

Commit

Permalink
fix: ensure useplayers not nil (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaton authored Dec 26, 2023
1 parent c20ca73 commit d1816ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/userplayers-nil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@empirica/core": patch
---

Ensure `usePlayers` never returns undefined (expect in unmanaged games).
9 changes: 9 additions & 0 deletions lib/@empirica/core/src/admin/runloop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ export class Runloop<
const res = await Promise.allSettled(promises);
for (const r of res) {
if (r.status === "rejected") {
// We can ignore invalid transition errors, as they are likely due to
// the same transition triggered concurrently from multiple places.
if (
r.reason instanceof String &&
r.reason.includes("invalid transition")
) {
continue;
}

warn(`failed load: ${r.reason}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "../../react/hooks";
import { Lobby as DefaultLobby } from "./Lobby";
import { Steps, StepsFunc } from "./Steps";
import { useGame, usePlayer, useRound, useStage } from "./hooks";
import { useGame, usePlayer, usePlayers, useRound, useStage } from "./hooks";

export interface EmpiricaContextProps {
children: React.ReactNode;
Expand Down Expand Up @@ -168,6 +168,7 @@ function EmpiricaInnerContext({
unmanagedGame = false,
}: EmpiricaInnerContextProps) {
const player = usePlayer();
const players = usePlayers();
const game = useGame();
const stage = useStage();
const round = useRound();
Expand All @@ -192,7 +193,7 @@ function EmpiricaInnerContext({
return <Exit exitSteps={exitSteps} finished={finished} />;
}

if (!unmanagedGame && (!stage || !round)) {
if (!unmanagedGame && (!stage || !round || !players)) {
return <LoadingComp />;
}

Expand Down
4 changes: 1 addition & 3 deletions tests/stress/tests/attributes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { sleep } from "./utils";
// test.
test.describe.configure({ mode: "serial" });

test.only("attribute as object, correct equality check", async ({
browser,
}) => {
test("attribute as object, correct equality check", async ({ browser }) => {
const ctx = new Context(browser);

const playerCount = 2;
Expand Down
6 changes: 3 additions & 3 deletions tests/stress/tests/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ test("1 x 10 player", async ({ browser }) => {
await ctx.close();
});

test("10 full games, 2 players", async ({ browser }) => {
test("2-round 5-stage-each game, 2 players", async ({ browser }) => {
const ctx = new Context(browser);

const playerCount = 2;
const roundCount = 1;
const stageCount = 10;
const roundCount = 2;
const stageCount = 5;
const totalStages = roundCount * stageCount;

await ctx.start();
Expand Down

0 comments on commit d1816ad

Please sign in to comment.