Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/driver-23ecce9593
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Jan 24, 2025
2 parents 1a2f80b + 10814f0 commit 00f91a9
Show file tree
Hide file tree
Showing 35 changed files with 156 additions and 69 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/test-and-build-from-fork.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test and Build (from fork)
on:
pull_request_target:
branches:
- main
permissions:
contents: write
pull-requests: write

jobs:
test-and-build:
name: Test and Build
if: github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: 20.16.0

- name: Install Dependencies
run: npm ci --omit=optional

- name: Run Checks
run: npm run check
# the glob here just fails
if: ${{ runner.os != 'Windows' }}

- name: Run Tests
env:
NODE_OPTIONS: "--max_old_space_size=4096"
SEGMENT_KEY: ${{ secrets.SEGMENT_KEY_DEV }}
run: npm run test

- name: Enable auto-merge for Dependabot PRs
if: github.event.pull_request.user.login == 'dependabot[bot]'
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
1 change: 1 addition & 0 deletions .github/workflows/test-and-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ permissions:
jobs:
test-and-build:
name: Test and Build
if: github.event.pull_request.user.login != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository

strategy:
matrix:
Expand Down
10 changes: 5 additions & 5 deletions src/commands/launchMongoShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const launchMongoDBShellWithEnv = ({
mdbConnectionString: string;
envVariableString: string;
parentHandle?: string;
}) => {
}): void => {
const mongoDBShell = vscode.window.createTerminal({
name: 'MongoDB Shell',
env: {
Expand All @@ -29,19 +29,19 @@ const launchMongoDBShellWithEnv = ({
mongoDBShell.show();
};

const getPowershellEnvString = () => {
const getPowershellEnvString = (): string => {
return '$Env:MDB_CONNECTION_STRING';
};

const getCmdEnvString = () => {
const getCmdEnvString = (): string => {
return '%MDB_CONNECTION_STRING%';
};

const getGitBashEnvString = () => {
const getGitBashEnvString = (): string => {
return '$MDB_CONNECTION_STRING';
};

const getBashEnvString = () => {
const getBashEnvString = (): string => {
return '$MDB_CONNECTION_STRING';
};

Expand Down
2 changes: 1 addition & 1 deletion src/editors/documentIdStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class DocumentIdStore {
return newDocument.documentIdReference;
}

get(documentIdReference: string) {
get(documentIdReference: string): any {
const existingDocument = this._documents.find(
(item) => item.documentIdReference === documentIdReference
);
Expand Down
3 changes: 2 additions & 1 deletion src/explorer/databaseTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default class DatabaseTreeItem
const sortFunction = (
collectionA: CollectionDetailsType,
collectionB: CollectionDetailsType
) => (collectionA.name || '').localeCompare(collectionB.name || '');
): number =>
(collectionA.name || '').localeCompare(collectionB.name || '');

const collectionTreeEntries = [
...otherCollections.sort(sortFunction),
Expand Down
4 changes: 2 additions & 2 deletions src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const FEATURE_FLAGS = {

export type FeatureFlag = keyof typeof FEATURE_FLAGS;

export const getFeatureFlag = (flag: FeatureFlag) => {
export const getFeatureFlag = (flag: FeatureFlag): boolean => {
if (typeof window === 'object') {
return (window as any).MDB_FEATURE_FLAGS?.[flag];
}
return FEATURE_FLAGS[flag];
};

export const getFeatureFlagsScript = (nonce: string) => {
export const getFeatureFlagsScript = (nonce: string): string => {
return `
<script nonce="${nonce}">window['MDB_FEATURE_FLAGS']=${JSON.stringify(
FEATURE_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Logger implements ILogger {
);
}

private append(type: string, message: string) {
private append(type: string, message: string): void {
// https://code.visualstudio.com/api/references/vscode-api#window.createOutputChannel

Logger.channel.appendLine(
Expand Down
2 changes: 1 addition & 1 deletion src/storage/storageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class StorageController {
return Promise.resolve();
}

getUserIdentity() {
getUserIdentity(): { anonymousId: string } {
let anonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);

// The anonymousId becomes required with analytics-node v6.
Expand Down
4 changes: 2 additions & 2 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TEST_DATABASE_PORT } from './suite/dbTestHelper';

// More information on vscode specific tests: https://github.com/microsoft/vscode-test

async function startTestMongoDBServer() {
async function startTestMongoDBServer(): Promise<MongoCluster> {
console.log('Starting MongoDB server on port', TEST_DATABASE_PORT);
return await MongoCluster.start({
topology: 'standalone',
Expand All @@ -19,7 +19,7 @@ async function startTestMongoDBServer() {

let testMongoDBServer: MongoCluster;

function cleanup() {
function cleanup(): void {
console.log('Stopping MongoDB server on port', TEST_DATABASE_PORT);
void testMongoDBServer?.close();
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/setup-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Object.assign(global, { TextDecoder, TextEncoder });

(global as any).vscodeFake = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
postMessage: (message: unknown) => {},
postMessage: (message: unknown): void => {},
};

(global as any).acquireVsCodeApi = () => {
(global as any).acquireVsCodeApi = (): any => {
return (global as any).vscodeFake;
};
2 changes: 1 addition & 1 deletion src/test/suite/editors/editorsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ suite('Editors Controller Test Suite', () => {
'source=treeview',
].join('')
);
activeTextEditor.document.getText = () => '{';
activeTextEditor.document.getText = (): string => '{';
sandbox.replaceGetter(
vscode.window,
'activeTextEditor',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/collectionTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { contributes } = require('../../../../package.json');

function getTestCollectionTreeItem(
options?: Partial<ConstructorParameters<typeof CollectionTreeItem>[0]>
) {
): CollectionTreeItem {
return new CollectionTreeItem({
collection: {
name: 'testColName',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/databaseTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { contributes } = require('../../../../package.json');

function getTestDatabaseTreeItem(
options?: Partial<ConstructorParameters<typeof DatabaseTreeItem>[0]>
) {
): DatabaseTreeItem {
return new DatabaseTreeItem({
databaseName: mockDatabaseNames[1],
dataService: new DataServiceStub() as unknown as DataService,
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/documentListTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const dataServiceStub = new DataServiceStub() as unknown as DataService;

function getTestDocumentListTreeItem(
options?: Partial<ConstructorParameters<typeof DocumentListTreeItem>[0]>
) {
): DocumentListTreeItem {
return new DocumentListTreeItem({
collectionName: 'collectionName',
databaseName: 'mock_db_name',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/documentTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const dataServiceStub = new DataServiceStub() as unknown as DataService;

function getTestDocumentTreeItem(
options?: Partial<ConstructorParameters<typeof DocumentTreeItem>[0]>
) {
): DocumentTreeItem {
return new DocumentTreeItem({
document: {},
namespace: 'name.space',
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/explorer/fieldTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { contributes } = require('../../../../package.json');

function getTestFieldTreeItem(
options?: Partial<ConstructorParameters<typeof FieldTreeItem>[0]>
) {
): FieldTreeItem {
return new FieldTreeItem({
field: {
name: 'test',
Expand All @@ -40,7 +40,7 @@ function getTestFieldTreeItem(

function getTestSchemaTreeItem(
options?: Partial<ConstructorParameters<typeof SchemaTreeItem>[0]>
) {
): SchemaTreeItem {
return new SchemaTreeItem({
databaseName: 'zebraWearwolf',
collectionName: 'giraffeVampire',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/indexListTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { contributes } = require('../../../../package.json');

function getTestIndexListTreeItem(
options?: Partial<ConstructorParameters<typeof IndexListTreeItem>[0]>
) {
): IndexListTreeItem {
return new IndexListTreeItem({
collectionName: 'zebraWearwolf',
databaseName: 'giraffeVampire',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/schemaTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { contributes } = require('../../../../package.json');

function getTestSchemaTreeItem(
options?: Partial<ConstructorParameters<typeof SchemaTreeItem>[0]>
) {
): SchemaTreeItem {
return new SchemaTreeItem({
databaseName: TEST_DB_NAME,
collectionName: 'cheesePizza',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/streamProcessorTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { contributes } = require('../../../../package.json');

function getTestTreeItem(
options?: Partial<ConstructorParameters<typeof StreamProcessorTreeItem>[0]>
) {
): StreamProcessorTreeItem {
const { name, state } = mockStreamProcessors[1];
return new StreamProcessorTreeItem({
streamProcessorName: name,
Expand Down
35 changes: 25 additions & 10 deletions src/test/suite/oidc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { waitFor } from './waitFor';
import { MongoCluster } from 'mongodb-runner';
import type { MongoClusterOptions } from 'mongodb-runner';
import { OIDCMockProvider } from '@mongodb-js/oidc-mock-provider';
import type { OIDCMockProviderConfig } from '@mongodb-js/oidc-mock-provider';
import type {
MaybePromise,
OIDCMockProviderConfig,
} from '@mongodb-js/oidc-mock-provider';
import { ConnectionString } from 'mongodb-connection-string-url';

import launchMongoShell from '../../commands/launchMongoShell';
Expand Down Expand Up @@ -96,10 +99,12 @@ suite('OIDC Tests', function () {

oidcMockProviderEndpointAccesses = {};
oidcMockProviderConfig = {
getTokenPayload(metadata: Parameters<typeof getTokenPayload>[0]) {
getTokenPayload(
metadata: Parameters<typeof getTokenPayload>[0]
): ReturnType<typeof oidcMockProviderConfig.getTokenPayload> {
return getTokenPayload(metadata);
},
overrideRequestHandler(url, req, res) {
overrideRequestHandler(url, req, res): MaybePromise<void> {
const { pathname } = new URL(url);
oidcMockProviderEndpointAccesses[pathname] ??= 0;
oidcMockProviderEndpointAccesses[pathname]++;
Expand Down Expand Up @@ -217,7 +222,9 @@ suite('OIDC Tests', function () {
.getConfiguration('mdb')
.update('persistOIDCTokens', true);
let tokenFetchCalls = 0;
getTokenPayload = () => {
getTokenPayload = (): ReturnType<
typeof oidcMockProviderConfig.getTokenPayload
> => {
tokenFetchCalls++;
return DEFAULT_TOKEN_PAYLOAD;
};
Expand Down Expand Up @@ -247,7 +254,9 @@ suite('OIDC Tests', function () {
.getConfiguration('mdb')
.update('persistOIDCTokens', false);
let tokenFetchCalls = 0;
getTokenPayload = () => {
getTokenPayload = (): ReturnType<
typeof oidcMockProviderConfig.getTokenPayload
> => {
tokenFetchCalls++;
return DEFAULT_TOKEN_PAYLOAD;
};
Expand Down Expand Up @@ -278,7 +287,7 @@ suite('OIDC Tests', function () {
emitter,
'secondConnectionEstablished'
);
overrideRequestHandler = async (url) => {
overrideRequestHandler = async (url): Promise<void> => {
if (new URL(url).pathname === '/authorize') {
emitter.emit('authorizeEndpointCalled');
// This does effectively mean that our 'fake browser'
Expand All @@ -297,7 +306,7 @@ suite('OIDC Tests', function () {
});

await once(emitter, 'authorizeEndpointCalled');
overrideRequestHandler = () => {};
overrideRequestHandler = (): void => {};
const connected =
await testConnectionController.addNewConnectionStringAndConnect(
connectionString
Expand Down Expand Up @@ -326,7 +335,9 @@ suite('OIDC Tests', function () {
});
let tokenFetchCalls = 0;
let afterReauth = false;
getTokenPayload = () => {
getTokenPayload = (): ReturnType<
typeof oidcMockProviderConfig.getTokenPayload
> => {
tokenFetchCalls++;
return {
...DEFAULT_TOKEN_PAYLOAD,
Expand Down Expand Up @@ -373,7 +384,9 @@ suite('OIDC Tests', function () {
});
let tokenFetchCalls = 0;
let afterReauth = false;
getTokenPayload = () => {
getTokenPayload = (): ReturnType<
typeof oidcMockProviderConfig.getTokenPayload
> => {
tokenFetchCalls++;
return {
...DEFAULT_TOKEN_PAYLOAD,
Expand Down Expand Up @@ -412,7 +425,9 @@ suite('OIDC Tests', function () {

test('shares the oidc state also with the playgrounds', async function () {
let tokenFetchCalls = 0;
getTokenPayload = () => {
getTokenPayload = (): ReturnType<
typeof oidcMockProviderConfig.getTokenPayload
> => {
tokenFetchCalls++;
return DEFAULT_TOKEN_PAYLOAD;
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ suite('Playground', function () {
await vscode.workspace.applyEdit(edit);
await vscode.commands.executeCommand('mdb.runPlayground');

const onDidChangeDiagnostics = () =>
const onDidChangeDiagnostics = (): Promise<unknown> =>
new Promise((resolve) => {
// The diagnostics are set again when the server restarts.
vscode.languages.onDidChangeDiagnostics(resolve);
Expand Down
Loading

0 comments on commit 00f91a9

Please sign in to comment.