diff --git a/packages/cli-repl/src/arg-mapper.spec.ts b/packages/cli-repl/src/arg-mapper.spec.ts index a3d85aedb8..f154904b43 100644 --- a/packages/cli-repl/src/arg-mapper.spec.ts +++ b/packages/cli-repl/src/arg-mapper.spec.ts @@ -1,5 +1,5 @@ import mapCliToDriver from './arg-mapper'; -import CliOptions from './cli-options'; +import { CliOptions } from '@mongosh/service-provider-server'; import { expect } from 'chai'; describe('arg-mapper.mapCliToDriver', () => { diff --git a/packages/cli-repl/src/arg-mapper.ts b/packages/cli-repl/src/arg-mapper.ts index c418bc19d0..2a2b3ba6ea 100644 --- a/packages/cli-repl/src/arg-mapper.ts +++ b/packages/cli-repl/src/arg-mapper.ts @@ -1,5 +1,4 @@ -import CliOptions from './cli-options'; -import { NodeOptions } from '@mongosh/service-provider-server'; +import { NodeOptions, CliOptions } from '@mongosh/service-provider-server'; import setValue from 'lodash.set'; /** diff --git a/packages/cli-repl/src/arg-parser.ts b/packages/cli-repl/src/arg-parser.ts index 11de7f4007..604908d970 100644 --- a/packages/cli-repl/src/arg-parser.ts +++ b/packages/cli-repl/src/arg-parser.ts @@ -1,4 +1,4 @@ -import CliOptions from './cli-options'; +import { CliOptions } from '@mongosh/service-provider-server'; import { USAGE } from './constants'; import i18n from '@mongosh/i18n'; import minimist from 'minimist'; diff --git a/packages/cli-repl/src/cli-repl.ts b/packages/cli-repl/src/cli-repl.ts index e70c5783bb..06e0007ef2 100644 --- a/packages/cli-repl/src/cli-repl.ts +++ b/packages/cli-repl/src/cli-repl.ts @@ -1,6 +1,6 @@ /* eslint no-console: 0, no-sync: 0*/ -import { CliServiceProvider, NodeOptions } from '@mongosh/service-provider-server'; +import { CliServiceProvider, NodeOptions, CliOptions } from '@mongosh/service-provider-server'; import { ShellInternalState } from '@mongosh/shell-api'; import ShellEvaluator from '@mongosh/shell-evaluator'; import formatOutput, { formatError } from './format-output'; @@ -11,7 +11,6 @@ import { MongoshWarning } from '@mongosh/errors'; import { changeHistory, retractPassword } from '@mongosh/history'; import { REPLServer, Recoverable } from 'repl'; import jsonParse from 'fast-json-parse'; -import CliOptions from './cli-options'; import completer from './completer'; import i18n from '@mongosh/i18n'; import { ObjectId } from 'bson'; diff --git a/packages/cli-repl/src/index.ts b/packages/cli-repl/src/index.ts index 217f0f0225..3af9c8f539 100644 --- a/packages/cli-repl/src/index.ts +++ b/packages/cli-repl/src/index.ts @@ -1,7 +1,6 @@ import CliRepl from './cli-repl'; import parseCliArgs from './arg-parser'; import mapCliToDriver from './arg-mapper'; -import generateUri from './uri-generator'; import completer from './completer'; import clr from './clr'; import { USAGE, TELEMETRY, MONGOSH_WIKI } from './constants'; @@ -15,7 +14,6 @@ export { MONGOSH_WIKI, CliRepl, completer, - generateUri, parseCliArgs, mapCliToDriver }; diff --git a/packages/cli-repl/src/run.ts b/packages/cli-repl/src/run.ts index eee73396cc..feeacf3472 100644 --- a/packages/cli-repl/src/run.ts +++ b/packages/cli-repl/src/run.ts @@ -1,12 +1,15 @@ -import { CliRepl, parseCliArgs, mapCliToDriver, generateUri, USAGE } from './index'; +import { CliRepl, parseCliArgs, mapCliToDriver, USAGE } from './index'; +import { generateUri } from '@mongosh/service-provider-server'; try { const options = parseCliArgs(process.argv); const { version } = require('../package.json'); if (options.help) { + // eslint-disable-next-line no-console console.log(USAGE); } else if (options.version) { + // eslint-disable-next-line no-console console.log(version); } else { process.title = 'mongosh'; @@ -17,5 +20,6 @@ try { new CliRepl(driverUri, { appname, ...driverOptions }, options); } } catch (e) { + // eslint-disable-next-line no-console console.log(e.message); } diff --git a/packages/cli-repl/test/e2e.spec.ts b/packages/cli-repl/test/e2e.spec.ts index 19a6bac83c..cd3adda6f8 100644 --- a/packages/cli-repl/test/e2e.spec.ts +++ b/packages/cli-repl/test/e2e.spec.ts @@ -1,7 +1,11 @@ import { MongoClient } from 'mongodb'; import { eventually } from './helpers'; import { TestShell } from './test-shell'; -import { startTestServer } from '../../../testing/integration-testing-hooks'; +import { + startTestServer, + LOCAL_INSTANCE_HOST, + LOCAL_INSTANCE_PORT +} from '../../../testing/integration-testing-hooks'; describe('e2e', function() { const connectionString = startTestServer(); @@ -42,6 +46,57 @@ describe('e2e', function() { }); }); + describe('set db', () => { + describe('via host:port/test', () => { + let shell; + beforeEach(async() => { + shell = TestShell.start({ args: [`${LOCAL_INSTANCE_HOST}:${LOCAL_INSTANCE_PORT}/testdb1`] }); + await shell.waitForPrompt(); + shell.assertNoErrors(); + }); + it('db set correctly', async() => { + await shell.executeLine('db'); + shell.assertNoErrors(); + + await eventually(() => { + shell.assertContainsOutput('testdb1'); + }); + }); + }); + describe('via mongodb://uri', () => { + let shell; + beforeEach(async() => { + shell = TestShell.start({ args: [`mongodb://${LOCAL_INSTANCE_HOST}:${LOCAL_INSTANCE_PORT}/testdb2`] }); + await shell.waitForPrompt(); + shell.assertNoErrors(); + }); + it('db set correctly', async() => { + await shell.executeLine('db'); + shell.assertNoErrors(); + + await eventually(() => { + shell.assertContainsOutput('testdb2'); + }); + }); + }); + describe('legacy db only', () => { + let shell; + beforeEach(async() => { + shell = TestShell.start({ args: ['testdb3', `--port=${LOCAL_INSTANCE_PORT}`] }); + await shell.waitForPrompt(); + shell.assertNoErrors(); + }); + it('db set correctly', async() => { + await shell.executeLine('db'); + shell.assertNoErrors(); + + await eventually(() => { + shell.assertContainsOutput('testdb3'); + }); + }); + }); + }); + describe('with connection string', () => { let db; let client; @@ -109,6 +164,15 @@ describe('e2e', function() { shell.assertNoErrors(); }); + it('db set correctly', async() => { + await shell.executeLine('db'); + shell.assertNoErrors(); + + await eventually(() => { + shell.assertContainsOutput('test'); + }); + }); + it('allows to find documents', async() => { await shell.writeInputLine(`use ${dbName}`); diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.ts index b03a3c8f6e..121f8cb85f 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.ts @@ -8,7 +8,8 @@ import { CommandOptions, WriteConcern, getConnectInfo, - ReplPlatform + ReplPlatform, + DEFAULT_DB } from '@mongosh/service-provider-core'; import StitchTransport from './stitch-transport'; @@ -40,6 +41,7 @@ const ATLAS = 'mongodb-atlas'; class StitchServiceProviderBrowser implements ServiceProvider { readonly stitchTransport: StitchTransport; public readonly platform: ReplPlatform; + public readonly initialDb: string; /** * Create a StitchBrowserTransport from a Stitch app id. * @@ -150,6 +152,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { this.stitchTransport = new StitchTransport(stitchClient, mongoClient); this.platform = ReplPlatform.Browser; + this.initialDb = DEFAULT_DB; } aggregateDb(database: string, pipeline: Document[], options?: Document, dbOptions?: DatabaseOptions): Cursor { diff --git a/packages/service-provider-core/package.json b/packages/service-provider-core/package.json index 7a6187add8..9be9603da9 100644 --- a/packages/service-provider-core/package.json +++ b/packages/service-provider-core/package.json @@ -23,7 +23,8 @@ "node": "^12.4.0" }, "dependencies": { - "mongodb-build-info": "^1.0.0" + "mongodb-build-info": "^1.0.0", + "@mongosh/i18n": "^0.0.5" }, "dependency-check": { "entries": [ diff --git a/packages/service-provider-core/src/admin.ts b/packages/service-provider-core/src/admin.ts index ab09340147..5a8f0a5dfa 100644 --- a/packages/service-provider-core/src/admin.ts +++ b/packages/service-provider-core/src/admin.ts @@ -42,4 +42,9 @@ export default interface Admin { * What platform (Compass/CLI/Browser) */ platform: ReplPlatform; + + /** + * The initial database + */ + initialDb: string; } diff --git a/packages/cli-repl/src/cli-options.ts b/packages/service-provider-core/src/cli-options.ts similarity index 100% rename from packages/cli-repl/src/cli-options.ts rename to packages/service-provider-core/src/cli-options.ts diff --git a/packages/service-provider-core/src/index.ts b/packages/service-provider-core/src/index.ts index 4b77870795..38315fff55 100644 --- a/packages/service-provider-core/src/index.ts +++ b/packages/service-provider-core/src/index.ts @@ -9,6 +9,9 @@ import CommandOptions from './command-options'; import DatabaseOptions from './database-options'; import getConnectInfo from './connect-info'; import { ReplPlatform } from './platform'; +import CliOptions from './cli-options'; +import generateUri, { Scheme } from './uri-generator'; +const DEFAULT_DB = 'test'; export { ServiceProvider, @@ -21,5 +24,9 @@ export { CommandOptions, DatabaseOptions, getConnectInfo, - ReplPlatform + ReplPlatform, + CliOptions, + generateUri, + Scheme, + DEFAULT_DB }; diff --git a/packages/cli-repl/src/uri-generator.spec.ts b/packages/service-provider-core/src/uri-generator.spec.ts similarity index 100% rename from packages/cli-repl/src/uri-generator.spec.ts rename to packages/service-provider-core/src/uri-generator.spec.ts diff --git a/packages/cli-repl/src/uri-generator.ts b/packages/service-provider-core/src/uri-generator.ts similarity index 97% rename from packages/cli-repl/src/uri-generator.ts rename to packages/service-provider-core/src/uri-generator.ts index 7d3b09fa84..f66c1e8b6e 100644 --- a/packages/cli-repl/src/uri-generator.ts +++ b/packages/service-provider-core/src/uri-generator.ts @@ -2,6 +2,7 @@ import i18n from '@mongosh/i18n'; import CliOptions from './cli-options'; +import { DEFAULT_DB } from './index'; /** * URI schemes. @@ -38,11 +39,6 @@ const DEFAULT_PORT = '27017'; */ const CONFLICT = 'cli-repl.uri-generator.no-host-port'; -/** - * The default db name. - */ -const TEST = 'test'; - /** * Validate conflicts in the options. * @@ -128,7 +124,7 @@ function generateUri(options: CliOptions): string { validateConflicts(options); } - return `${Scheme.Mongo}${host || generateHost(options)}:${port || generatePort(options)}/${db || TEST}`; + return `${Scheme.Mongo}${host || generateHost(options)}:${port || generatePort(options)}/${db || DEFAULT_DB}`; } export default generateUri; diff --git a/packages/service-provider-server/src/cli-service-provider.ts b/packages/service-provider-server/src/cli-service-provider.ts index 8998a0e2db..0952db0613 100644 --- a/packages/service-provider-server/src/cli-service-provider.ts +++ b/packages/service-provider-server/src/cli-service-provider.ts @@ -13,7 +13,8 @@ import { WriteConcern, CommandOptions, getConnectInfo, - ReplPlatform + ReplPlatform, + DEFAULT_DB } from '@mongosh/service-provider-core'; import NodeOptions from './node/node-options'; @@ -37,6 +38,7 @@ const DEFAULT_OPTIONS = Object.freeze({ */ class CliServiceProvider implements ServiceProvider { public readonly platform: ReplPlatform; + public readonly initialDb: string; /** * Create a new CLI service provider from the provided URI. * @@ -80,6 +82,11 @@ class CliServiceProvider implements ServiceProvider { this.mongoClient = mongoClient; this.uri = uri; this.platform = ReplPlatform.CLI; + try { + this.initialDb = mongoClient.s.options.dbName || DEFAULT_DB; + } catch (err) { + this.initialDb = DEFAULT_DB; + } } async getNewConnection(uri: string, options: NodeOptions = {}): Promise { diff --git a/packages/service-provider-server/src/compass/compass-service-provider.ts b/packages/service-provider-server/src/compass/compass-service-provider.ts index ee0f9e3d27..4e9791e174 100644 --- a/packages/service-provider-server/src/compass/compass-service-provider.ts +++ b/packages/service-provider-server/src/compass/compass-service-provider.ts @@ -1,6 +1,6 @@ import CliServiceProvider from '../cli-service-provider'; import { MongoClient } from 'mongodb'; -import { ReplPlatform } from '@mongosh/service-provider-core'; +import { DEFAULT_DB, ReplPlatform } from '@mongosh/service-provider-core'; interface DataService { client: { @@ -13,6 +13,7 @@ interface DataService { */ class CompassServiceProvider extends CliServiceProvider { public readonly platform: ReplPlatform; + public readonly initialDb: string; /** * Instantiate a new CompassServiceProvider with the data-service's connected * MongoClient instance. @@ -23,6 +24,11 @@ class CompassServiceProvider extends CliServiceProvider { constructor(mongoClient: MongoClient, uri?: string) { super(mongoClient, uri); this.platform = ReplPlatform.Compass; + try { + this.initialDb = mongoClient.s.options.dbName || DEFAULT_DB; + } catch (err) { + this.initialDb = DEFAULT_DB; + } } /** * Creates a new CompassServiceProvider that uses compass diff --git a/packages/service-provider-server/src/index.ts b/packages/service-provider-server/src/index.ts index fa634ac24f..8d4b62e7fe 100644 --- a/packages/service-provider-server/src/index.ts +++ b/packages/service-provider-server/src/index.ts @@ -2,8 +2,13 @@ import NodeOptions from './node/node-options'; import CliServiceProvider from './cli-service-provider'; import CompassServiceProvider from './compass/compass-service-provider'; +import { DEFAULT_DB, CliOptions, Scheme, generateUri } from '@mongosh/service-provider-core'; export { CliServiceProvider, CompassServiceProvider, - NodeOptions + NodeOptions, + DEFAULT_DB, + CliOptions, + Scheme, + generateUri }; diff --git a/packages/shell-api/src/collection.spec.ts b/packages/shell-api/src/collection.spec.ts index 22472f3c29..e79f419c13 100644 --- a/packages/shell-api/src/collection.spec.ts +++ b/packages/shell-api/src/collection.spec.ts @@ -64,6 +64,7 @@ describe('Collection', () => { beforeEach(() => { bus = stubInterface(); serviceProvider = stubInterface(); + serviceProvider.initialDb = 'test'; internalState = new ShellInternalState(serviceProvider, bus); mongo = new Mongo(internalState); database = new Database(mongo, 'db1'); diff --git a/packages/shell-api/src/database.spec.ts b/packages/shell-api/src/database.spec.ts index 9869f70a1b..dd4363649e 100644 --- a/packages/shell-api/src/database.spec.ts +++ b/packages/shell-api/src/database.spec.ts @@ -107,6 +107,7 @@ describe('Database', () => { beforeEach(() => { bus = stubInterface(); serviceProvider = stubInterface(); + serviceProvider.initialDb = 'test'; internalState = new ShellInternalState(serviceProvider, bus); mongo = new Mongo(internalState); database = new Database(mongo, 'db1'); diff --git a/packages/shell-api/src/explainable.spec.ts b/packages/shell-api/src/explainable.spec.ts index 02668c35ba..33df7365b9 100644 --- a/packages/shell-api/src/explainable.spec.ts +++ b/packages/shell-api/src/explainable.spec.ts @@ -61,6 +61,7 @@ describe('Explainable', () => { beforeEach(() => { bus = stubInterface(); serviceProvider = stubInterface(); + serviceProvider.initialDb = 'test'; internalState = new ShellInternalState(serviceProvider, bus); mongo = new Mongo(internalState); database = new Database(mongo, 'db1'); diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index 8997749dd4..c5a673e20a 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -8,7 +8,7 @@ import { ShellApiClass, shellApiClassDefault } from './decorators'; -import { ReplPlatform } from '@mongosh/service-provider-core'; +import { ReplPlatform, generateUri } from '@mongosh/service-provider-core'; import Database from './database'; import ShellInternalState from './shell-internal-state'; import { CommandResult } from './result'; @@ -34,7 +34,7 @@ export default class Mongo extends ShellApiClass { super(); this.internalState = internalState; this.databases = {}; - this.uri = uri; + this.uri = generateUri({ _: [uri] }); this.options = fleOptions; this.serviceProvider = this.internalState.initialServiceProvider; } diff --git a/packages/shell-api/src/shell-api.spec.ts b/packages/shell-api/src/shell-api.spec.ts index d70508535a..b6fc06773c 100644 --- a/packages/shell-api/src/shell-api.spec.ts +++ b/packages/shell-api/src/shell-api.spec.ts @@ -81,8 +81,12 @@ describe('ShellApi', () => { beforeEach(() => { bus = stubInterface(); - serviceProvider = stubInterface(); + const newSP = stubInterface(); + newSP.initialDb = 'test'; + serviceProvider = stubInterface({ getNewConnection: newSP }); + serviceProvider.initialDb = 'test'; mongo = stubInterface(); + mongo.serviceProvider = serviceProvider; internalState = new ShellInternalState(serviceProvider, bus); internalState.currentDb.mongo = mongo; serviceProvider.platform = ReplPlatform.CLI; @@ -120,9 +124,9 @@ describe('ShellApi', () => { serviceProvider.platform = ReplPlatform.CLI; }); it('returns a new Mongo object', async() => { - const m = await internalState.shellApi.Mongo('uri'); + const m = await internalState.shellApi.Mongo('localhost:27017'); expect(m.shellApiType()).to.equal('Mongo'); - expect(m.uri).to.equal('uri'); + expect(m.uri).to.equal('mongodb://localhost:27017/test'); }); it('fails for non-CLI', async() => { serviceProvider.platform = ReplPlatform.Browser; @@ -133,13 +137,21 @@ describe('ShellApi', () => { } expect.fail('MongoshInvalidInputError not thrown for Mongo'); }); + it('parses URI with mongodb://', async() => { + const m = await internalState.shellApi.Mongo('mongodb://127.0.0.1:27017'); + expect(m.uri).to.equal('mongodb://127.0.0.1:27017'); + }); + it('parses URI with just db', async() => { + const m = await internalState.shellApi.Mongo('dbname'); + expect(m.uri).to.equal('mongodb://127.0.0.1:27017/dbname'); + }); }); describe('connect', () => { it('returns a new DB', async() => { serviceProvider.platform = ReplPlatform.CLI; - const db = await internalState.shellApi.connect('uri', 'username', 'pwd'); + const db = await internalState.shellApi.connect('localhost:27017', 'username', 'pwd'); expect(db.shellApiType()).to.equal('Database'); - expect(db.getMongo().uri).to.equal('uri'); + expect(db.getMongo().uri).to.equal('mongodb://localhost:27017/test'); }); it('fails with no arg', async() => { serviceProvider.platform = ReplPlatform.CLI; @@ -162,8 +174,13 @@ describe('ShellApi', () => { beforeEach(() => { bus = stubInterface(); - serviceProvider = stubInterface(); + const newSP = stubInterface(); + newSP.initialDb = 'test'; + serviceProvider = stubInterface({ getNewConnection: newSP }); + serviceProvider.initialDb = 'test'; + serviceProvider.platform = ReplPlatform.CLI; mongo = stubInterface(); + mongo.serviceProvider = serviceProvider; internalState = new ShellInternalState(serviceProvider, bus); internalState.setCtx({}); internalState.currentDb.mongo = mongo; @@ -205,14 +222,14 @@ describe('ShellApi', () => { serviceProvider.platform = ReplPlatform.CLI; }); it('returns a new Mongo object', async() => { - const m = await internalState.context.Mongo('uri'); + const m = await internalState.context.Mongo('mongodb://127.0.0.1:27017'); expect(m.shellApiType()).to.equal('Mongo'); - expect(m.uri).to.equal('uri'); + expect(m.uri).to.equal('mongodb://127.0.0.1:27017'); }); it('fails for non-CLI', async() => { serviceProvider.platform = ReplPlatform.Browser; try { - await internalState.shellApi.Mongo('uri'); + await internalState.shellApi.Mongo('mongodb://127.0.0.1:27017'); } catch (e) { return expect(e.name).to.equal('MongoshUnimplementedError'); } @@ -222,15 +239,15 @@ describe('ShellApi', () => { describe('connect', () => { it('returns a new DB', async() => { serviceProvider.platform = ReplPlatform.CLI; - const db = await internalState.context.connect('uri'); + const db = await internalState.context.connect('mongodb://127.0.0.1:27017'); expect(db.shellApiType()).to.equal('Database'); - expect(db.getMongo().uri).to.equal('uri'); + expect(db.getMongo().uri).to.equal('mongodb://127.0.0.1:27017'); }); it('handles username/pwd', async() => { serviceProvider.platform = ReplPlatform.CLI; - const db = await internalState.context.connect('uri', 'username', 'pwd'); + const db = await internalState.context.connect('mongodb://127.0.0.1:27017', 'username', 'pwd'); expect(db.shellApiType()).to.equal('Database'); - expect(db.getMongo().uri).to.equal('uri'); + expect(db.getMongo().uri).to.equal('mongodb://127.0.0.1:27017'); expect(db.getMongo().options).to.deep.equal({ auth: { username: 'username', password: 'pwd' } }); }); }); diff --git a/packages/shell-api/src/shell-api.ts b/packages/shell-api/src/shell-api.ts index b8c5a57f57..45354d79d4 100644 --- a/packages/shell-api/src/shell-api.ts +++ b/packages/shell-api/src/shell-api.ts @@ -13,7 +13,7 @@ import Database from './database'; import { CommandResult } from './result'; import ShellInternalState from './shell-internal-state'; import { checkUndefinedUpdate } from './helpers'; -import { ReplPlatform } from '@mongosh/service-provider-core'; +import { ReplPlatform, DEFAULT_DB } from '@mongosh/service-provider-core'; import { MongoshUnimplementedError } from '@mongosh/errors'; @shellApiClassDefault @@ -75,7 +75,8 @@ export default class ShellApi extends ShellApiClass { if (user) options.username = user; if (pwd) options.password = pwd; const mongo = await this.Mongo(uri, Object.keys(options).length ? { auth: options } : {}); - return mongo.getDB('test'); + const db = mongo.serviceProvider.initialDb || DEFAULT_DB; + return mongo.getDB(db); } @returnsPromise diff --git a/packages/shell-api/src/shell-internal-state.ts b/packages/shell-api/src/shell-internal-state.ts index 6fd04962e4..ff88ca3460 100644 --- a/packages/shell-api/src/shell-internal-state.ts +++ b/packages/shell-api/src/shell-internal-state.ts @@ -11,7 +11,7 @@ import { ShellApi } from './index'; import { EventEmitter } from 'events'; -import { Document, ServiceProvider } from '@mongosh/service-provider-core'; +import { Document, ServiceProvider, DEFAULT_DB } from '@mongosh/service-provider-core'; import { MongoshInvalidInputError } from '@mongosh/errors'; import AsyncWriter from '@mongosh/async-rewriter'; import { toIgnore } from './decorators'; @@ -42,7 +42,7 @@ export default class ShellInternalState { if (!cliOptions.nodb) { const mongo = new Mongo(this); this.mongos.push(mongo); - this.currentDb = mongo.getDB('test'); // TODO: set to CLI arg + this.currentDb = mongo.getDB(initialServiceProvider.initialDb || DEFAULT_DB); } else { this.currentDb = new NoDatabase() as Database; } @@ -89,8 +89,10 @@ export default class ShellInternalState { contextObject.toIterator = toIterator; contextObject.print = async(arg): Promise => { if (arg.toReplString) { + // eslint-disable-next-line no-console console.log(await arg.toReplString()); } else { + // eslint-disable-next-line no-console console.log(arg); } }; diff --git a/testing/integration-testing-hooks.ts b/testing/integration-testing-hooks.ts index b5de812de8..ac44c06763 100644 --- a/testing/integration-testing-hooks.ts +++ b/testing/integration-testing-hooks.ts @@ -1,7 +1,8 @@ const mongodbRunnerBefore = require('mongodb-runner/mocha/before'); const mongodbRunnerAfter = require('mongodb-runner/mocha/after'); -const LOCAL_INSTANCE_PORT = 27018; +export const LOCAL_INSTANCE_PORT = 27018; +export const LOCAL_INSTANCE_HOST = 'localhost'; /** * Starts a local server unless the `MONGOSH_TEST_SERVER_URL` @@ -18,7 +19,7 @@ const LOCAL_INSTANCE_PORT = 27018; */ export function startTestServer(): string { const envConnectionString = process.env.MONGOSH_TEST_SERVER_URL; - const localConnectionString = `mongodb://localhost:${LOCAL_INSTANCE_PORT}`; + const localConnectionString = `mongodb://${LOCAL_INSTANCE_HOST}:${LOCAL_INSTANCE_PORT}`; const connectionString = envConnectionString || localConnectionString; if (!envConnectionString) {