Skip to content

Commit 417c411

Browse files
committed
fix(tests): readjust type of readReplLogFile
1 parent a9fd752 commit 417c411

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

packages/e2e-tests/test/e2e-tls.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ describe('e2e TLS', function () {
243243
const logPath = path.join(logBasePath, `${shell.logId}_log`);
244244
const logContents = await readReplLogFile(logPath);
245245
expect(
246-
logContents.find((line) => line.id.__value === 1_000_000_049)?.attr
246+
logContents.find((line) => line.id === 1_000_000_049)?.attr
247247
.asyncFallbackError
248248
).to.equal(null); // Ensure that system CA loading happened asynchronously.
249249
expect(
250-
logContents.find((line) => line.id.__value === 1_000_000_049)?.attr
250+
logContents.find((line) => line.id === 1_000_000_049)?.attr
251251
.systemCertsError
252252
).to.equal(null); // Ensure that system CA could be loaded successfully.
253253
});
@@ -280,11 +280,11 @@ describe('e2e TLS', function () {
280280
const logPath = path.join(logBasePath, `${shell.logId}_log`);
281281
const logContents = await readReplLogFile(logPath);
282282
expect(
283-
logContents.find((line) => line.id.__value === 1_000_000_049)?.attr
283+
logContents.find((line) => line.id === 1_000_000_049)?.attr
284284
.asyncFallbackError
285285
).to.equal(null); // Ensure that system CA loading happened asynchronously.
286286
expect(
287-
logContents.find((line) => line.id.__value === 1_000_000_049)?.attr
287+
logContents.find((line) => line.id === 1_000_000_049)?.attr
288288
.systemCertsError
289289
).to.equal(null); // Ensure that system CA could be loaded successfully.
290290
});
@@ -309,8 +309,7 @@ describe('e2e TLS', function () {
309309

310310
const logPath = path.join(logBasePath, `${shell.logId}_log`);
311311
const logContents = await readReplLogFile(logPath);
312-
expect(logContents.find((line) => line.id.__value === 1_000_000_049)).to
313-
.exist;
312+
expect(logContents.find((line) => line.id === 1_000_000_049)).to.exist;
314313
});
315314
}
316315
);

packages/e2e-tests/test/e2e.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { promises as fs, createReadStream } from 'fs';
1414
import { promisify } from 'util';
1515
import path from 'path';
1616
import os from 'os';
17+
import type { MongoLogEntryFromFile } from './repl-helpers';
1718
import { readReplLogFile, setTemporaryHomeDirectory } from './repl-helpers';
1819
import { bson } from '@mongosh/service-provider-core';
1920
import type { Server as HTTPServer } from 'http';
@@ -22,7 +23,6 @@ import { once } from 'events';
2223
import type { AddressInfo } from 'net';
2324
const { EJSON } = bson;
2425
import { sleep } from './util-helpers';
25-
import type { MongoLogEntry } from 'mongodb-log-writer';
2626

2727
const jsContextFlagCombinations: `--jsContext=${'plain-vm' | 'repl'}`[][] = [
2828
[],
@@ -1356,7 +1356,7 @@ describe('e2e', function () {
13561356
let logBasePath: string;
13571357
let historyPath: string;
13581358
let readConfig: () => Promise<any>;
1359-
let readLogFile: <T extends MongoLogEntry>() => Promise<T[]>;
1359+
let readLogFile: <T extends MongoLogEntryFromFile>() => Promise<T[]>;
13601360
let startTestShell: (...extraArgs: string[]) => Promise<TestShell>;
13611361

13621362
beforeEach(function () {
@@ -1393,7 +1393,7 @@ describe('e2e', function () {
13931393
}
13941394
readConfig = async () =>
13951395
EJSON.parse(await fs.readFile(configPath, 'utf8'));
1396-
readLogFile = async <T extends MongoLogEntry>(): Promise<T[]> => {
1396+
readLogFile = async <T extends MongoLogEntryFromFile>(): Promise<T[]> => {
13971397
if (!shell.logId) {
13981398
throw new Error('Shell does not have a logId associated with it');
13991399
}
@@ -1667,7 +1667,7 @@ describe('e2e', function () {
16671667
expect(shell.assertNoErrors());
16681668
await eventually(async () => {
16691669
const log = await readLogFile<
1670-
MongoLogEntry & {
1670+
MongoLogEntryFromFile & {
16711671
c: string;
16721672
ctx: string;
16731673
}

packages/e2e-tests/test/repl-helpers.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import sinonChai from 'sinon-chai';
77
import chaiAsPromised from 'chai-as-promised';
88
import type { MongodSetup } from '../../../testing/integration-testing-hooks';
99
import type { MongoLogEntry } from 'mongodb-log-writer';
10-
import { EJSON } from 'bson';
1110

1211
chai.use(sinonChai);
1312
chai.use(chaiAsPromised);
@@ -49,13 +48,20 @@ function useTmpdir(): { readonly path: string } {
4948
};
5049
}
5150

52-
async function readReplLogFile<T extends MongoLogEntry>(
51+
type MongoLogEntryFromFile = {
52+
t?: {
53+
$date: string;
54+
};
55+
id: number;
56+
} & Omit<MongoLogEntry, 'id' | 't'>;
57+
58+
async function readReplLogFile<T extends MongoLogEntryFromFile>(
5359
logPath: string
5460
): Promise<T[]> {
5561
return (await fs.readFile(logPath, 'utf8'))
5662
.split('\n')
5763
.filter((line) => line.trim())
58-
.map((line) => EJSON.parse(line));
64+
.map((line) => JSON.parse(line));
5965
}
6066

6167
const fakeExternalEditor = async ({
@@ -170,4 +176,5 @@ export {
170176
setTemporaryHomeDirectory,
171177
getCertPath,
172178
connectionStringWithLocalhost,
179+
MongoLogEntryFromFile,
173180
};

0 commit comments

Comments
 (0)