Skip to content

Commit 842014f

Browse files
committed
test: wait for the issued token in the auth store tests
On Windows, the auth-guard and cli-auth store tests read an auth.json with no token. The store holds an empty auth.json from startup and devframe writes the token a moment later. On POSIX the wait for mode 0600 also waited for that write, since the file is only chmodded once the token lands, but on Windows the mode is not checked, so the wait ended as soon as the empty file existed. Wait for the token itself, then check the mode where the platform has one.
1 parent 3995823 commit 842014f

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎packages/devtools/src/__tests__/auth-guard.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,16 @@ describe('initPangularHub one-time code', () => {
385385

386386
const dir = authStoreDir(process.cwd(), home);
387387
const file = join(dir, 'auth.json');
388-
await vi.waitFor(() => expectPrivate(file, 0o600), { timeout: 3000 });
388+
// The store holds an empty `auth.json` from startup and devframe writes the token a moment
389+
// later, so wait for the token itself. Only on POSIX does the mode check also wait for it.
390+
await vi.waitFor(
391+
() => {
392+
expect(Object.keys(JSON.parse(readFileSync(file, 'utf8')).trusted)).toHaveLength(1);
393+
expectPrivate(file, 0o600);
394+
},
395+
{ timeout: 3000 },
396+
);
389397
expectPrivate(dir, 0o700);
390-
expect(Object.keys(JSON.parse(readFileSync(file, 'utf8')).trusted)).toHaveLength(1);
391398
expect(existsSync(join(home, '.devframes', 'devframe', 'auth.json'))).toBe(false);
392399
});
393400

‎packages/devtools/src/__tests__/cli-auth.test.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ describe('pangular dev access', () => {
126126
);
127127
expect(await rpc.requestTrustWithCode(code)).toBeTruthy();
128128
const dir = authStoreDir(REPO, home);
129-
await vi.waitFor(() => expectPrivate(join(dir, 'auth.json'), 0o600), {
130-
timeout: 3000,
131-
});
129+
// The store holds an empty `auth.json` from startup and devframe writes the token a moment
130+
// later, so wait for the token itself. Only on POSIX does the mode check also wait for it.
131+
const file = join(dir, 'auth.json');
132+
await vi.waitFor(
133+
() => {
134+
expect(Object.keys(JSON.parse(readFileSync(file, 'utf8')).trusted)).toHaveLength(1);
135+
expectPrivate(file, 0o600);
136+
},
137+
{ timeout: 3000 },
138+
);
132139
expectPrivate(dir, 0o700);
133-
expect(
134-
Object.keys(JSON.parse(readFileSync(join(dir, 'auth.json'), 'utf8')).trusted),
135-
).toHaveLength(1);
136140
}, 40_000);
137141
});

0 commit comments

Comments
 (0)