From 4cef2ec394f169f2cb37e33f24dd7129c4770c85 Mon Sep 17 00:00:00 2001 From: Rhys Date: Mon, 8 Jan 2024 13:23:17 -0500 Subject: [PATCH] chore: use package json version for tests (#649) --- src/test/suite/connectionController.test.ts | 18 +++---- ...aygroundSelectedCodeActionProvider.test.ts | 12 ++--- .../suite/telemetry/telemetryService.test.ts | 51 ++++++++++--------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/test/suite/connectionController.test.ts b/src/test/suite/connectionController.test.ts index abd4639ae..7845d1417 100644 --- a/src/test/suite/connectionController.test.ts +++ b/src/test/suite/connectionController.test.ts @@ -32,6 +32,9 @@ import { } from './dbTestHelper'; import type { LoadedConnection } from '../../storage/connectionStorage'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version } = require('../../../package.json'); + const testDatabaseConnectionName = 'localhost:27088'; const testDatabaseURI2WithTimeout = 'mongodb://shouldfail?connectTimeoutMS=1000&serverSelectionTimeoutMS=1000'; @@ -245,8 +248,7 @@ suite('Connection Controller Test Suite', function () { }); test('the connection model loads both global and workspace stored connection models', async () => { - const expectedDriverUrl = - 'mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0'; + const expectedDriverUrl = `mongodb://localhost:27088/?appname=mongodb-vscode+${version}`; await vscode.workspace .getConfiguration('mdb.connectionSaving') @@ -850,7 +852,7 @@ suite('Connection Controller Test Suite', function () { ); assert.strictEqual( connections[0].connectionOptions?.connectionString.includes( - 'appname=mongodb-vscode+0.0.0-dev.0' + `appname=mongodb-vscode+${version}` ), true ); @@ -894,8 +896,7 @@ suite('Connection Controller Test Suite', function () { assert.deepStrictEqual(connectionInfo, { id: 'c4871b21-92c4-40e2-a2c2-fdd551cff114', connectionOptions: { - connectionString: - 'mongodb+srv://username:somepassword@host.u88dd.test.test/?authSource=admin&readPreference=primary&appname=mongodb-vscode+0.0.0-dev.0&ssl=true', + connectionString: `mongodb+srv://username:somepassword@host.u88dd.test.test/?authSource=admin&readPreference=primary&appname=mongodb-vscode+${version}&ssl=true`, }, }); }); @@ -914,7 +915,7 @@ suite('Connection Controller Test Suite', function () { delete mongoClientConnectionOptions.options.oidc?.openBrowser; assert.deepStrictEqual(mongoClientConnectionOptions, { - url: 'mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0', + url: `mongodb://localhost:27088/?appname=mongodb-vscode+${version}`, options: { autoEncryption: undefined, monitorCommands: true, @@ -929,11 +930,10 @@ suite('Connection Controller Test Suite', function () { }); test('_getConnectionStringWithProxy returns string with proxy options', () => { - const expectedConnectionStringWithProxy = - 'mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0&proxyHost=localhost&proxyPassword=gwce7tr8733ujbr&proxyPort=3378&proxyUsername=test'; + const expectedConnectionStringWithProxy = `mongodb://localhost:27088/?appname=mongodb-vscode+${version}&proxyHost=localhost&proxyPassword=gwce7tr8733ujbr&proxyPort=3378&proxyUsername=test`; const connectionString = testConnectionController._getConnectionStringWithProxy({ - url: 'mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0', + url: `mongodb://localhost:27088/?appname=mongodb-vscode+${version}`, options: { proxyHost: 'localhost', proxyPassword: 'gwce7tr8733ujbr', diff --git a/src/test/suite/editors/playgroundSelectedCodeActionProvider.test.ts b/src/test/suite/editors/playgroundSelectedCodeActionProvider.test.ts index 1871438fc..795c65048 100644 --- a/src/test/suite/editors/playgroundSelectedCodeActionProvider.test.ts +++ b/src/test/suite/editors/playgroundSelectedCodeActionProvider.test.ts @@ -14,6 +14,9 @@ import { ExportToLanguageMode } from '../../../types/playgroundType'; import { TEST_DATABASE_URI } from '../dbTestHelper'; import { ExtensionContextStub } from '../stubs'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version } = require('../../../../package.json'); + const expect = chai.expect; suite('Playground Selected CodeAction Provider Test Suite', function () { @@ -385,8 +388,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () { expectedResult = { namespace: 'db.coll', type: null, - content: - "# Requires the PyMongo package.\n# https://api.mongodb.com/python/current\n\nclient = MongoClient('mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0')\nfilter={\n 'name': '22'\n}\n\nresult = client['db']['coll'].find(\n filter=filter\n)", + content: `# Requires the PyMongo package.\n# https://api.mongodb.com/python/current\n\nclient = MongoClient('mongodb://localhost:27088/?appname=mongodb-vscode+${version}')\nfilter={\n 'name': '22'\n}\n\nresult = client['db']['coll'].find(\n filter=filter\n)`, language: 'python', }; @@ -460,8 +462,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () { expectedResult = { namespace: 'db.coll', type: null, - content: - "# Requires the MongoDB Ruby Driver\n# https://docs.mongodb.com/ruby-driver/master/\n\nclient = Mongo::Client.new('mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0', :database => 'db')\n\nresult = client.database['coll'].find({\n 'name' => '22'\n})", + content: `# Requires the MongoDB Ruby Driver\n# https://docs.mongodb.com/ruby-driver/master/\n\nclient = Mongo::Client.new('mongodb://localhost:27088/?appname=mongodb-vscode+${version}', :database => 'db')\n\nresult = client.database['coll'].find({\n 'name' => '22'\n})`, language: 'ruby', }; @@ -535,8 +536,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () { expectedResult = { namespace: 'db.coll', type: null, - content: - '// Requires the MongoDB Go Driver\n// https://go.mongodb.org/mongo-driver\nctx := context.TODO()\n\n// Set client options\nclientOptions := options.Client().ApplyURI("mongodb://localhost:27088/?appname=mongodb-vscode+0.0.0-dev.0")\n\n// Connect to MongoDB\nclient, err := mongo.Connect(ctx, clientOptions)\nif err != nil {\n log.Fatal(err)\n}\ndefer func() {\n if err := client.Disconnect(ctx); err != nil {\n log.Fatal(err)\n }\n}()\n\n// Find data\ncoll := client.Database("db").Collection("coll")\n_, err = coll.Find(ctx, bson.D{{"name", "22"}})\nif err != nil {\n log.Fatal(err)\n}', + content: `// Requires the MongoDB Go Driver\n// https://go.mongodb.org/mongo-driver\nctx := context.TODO()\n\n// Set client options\nclientOptions := options.Client().ApplyURI("mongodb://localhost:27088/?appname=mongodb-vscode+${version}")\n\n// Connect to MongoDB\nclient, err := mongo.Connect(ctx, clientOptions)\nif err != nil {\n log.Fatal(err)\n}\ndefer func() {\n if err := client.Disconnect(ctx); err != nil {\n log.Fatal(err)\n }\n}()\n\n// Find data\ncoll := client.Database("db").Collection("coll")\n_, err = coll.Find(ctx, bson.D{{"name", "22"}})\nif err != nil {\n log.Fatal(err)\n}`, language: 'go', }; diff --git a/src/test/suite/telemetry/telemetryService.test.ts b/src/test/suite/telemetry/telemetryService.test.ts index ea48e2da5..eac8ee584 100644 --- a/src/test/suite/telemetry/telemetryService.test.ts +++ b/src/test/suite/telemetry/telemetryService.test.ts @@ -15,6 +15,9 @@ import { mdbTestExtension } from '../stubbableMdbExtension'; import { DatabaseTreeItem, DocumentTreeItem } from '../../../explorer'; import { DataServiceStub } from '../stubs'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { version } = require('../../../../package.json'); + const expect = chai.expect; chai.use(sinonChai); @@ -129,7 +132,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Command Run', properties: { command: 'mdb.addConnection', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -149,8 +152,8 @@ suite('Telemetry Controller Test Suite', () => { is_used_connect_screen: false, is_used_command_palette: true, is_used_saved_connection: false, - vscode_mdb_extension_version: '0.0.0-dev.0', - extension_version: '0.0.0-dev.0', + vscode_mdb_extension_version: version, + extension_version: version, }, }) ); @@ -170,8 +173,8 @@ suite('Telemetry Controller Test Suite', () => { is_used_connect_screen: true, is_used_command_palette: false, is_used_saved_connection: false, - vscode_mdb_extension_version: '0.0.0-dev.0', - extension_version: '0.0.0-dev.0', + vscode_mdb_extension_version: version, + extension_version: version, }, }) ); @@ -191,8 +194,8 @@ suite('Telemetry Controller Test Suite', () => { is_used_connect_screen: false, is_used_command_palette: false, is_used_saved_connection: true, - vscode_mdb_extension_version: '0.0.0-dev.0', - extension_version: '0.0.0-dev.0', + vscode_mdb_extension_version: version, + extension_version: version, }, }) ); @@ -209,7 +212,7 @@ suite('Telemetry Controller Test Suite', () => { properties: { source: 'treeview', success: true, - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -223,7 +226,7 @@ suite('Telemetry Controller Test Suite', () => { sinon.match({ anonymousId, event: 'Document Edited', - properties: { source: 'playground', extension_version: '0.0.0-dev.0' }, + properties: { source: 'playground', extension_version: version }, }) ); }); @@ -241,7 +244,7 @@ suite('Telemetry Controller Test Suite', () => { type: 'other', partial: false, error: false, - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -261,7 +264,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Loaded', properties: { file_type: 'mongodb', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -280,7 +283,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Loaded', properties: { file_type: 'mongodbjs', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -295,7 +298,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Saved', properties: { file_type: 'mongodbjs', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -311,7 +314,7 @@ suite('Telemetry Controller Test Suite', () => { properties: { screen: 'helpPanel', link_id: 'linkId', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -335,7 +338,7 @@ suite('Telemetry Controller Test Suite', () => { with_import_statements: false, with_builders: false, with_driver_syntax: false, - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -361,7 +364,7 @@ suite('Telemetry Controller Test Suite', () => { with_import_statements: false, with_builders: false, with_driver_syntax: false, - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -551,7 +554,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'search', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -576,7 +579,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'createCollection', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -593,7 +596,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'createDatabase', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -611,7 +614,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'index', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -648,7 +651,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'cloneDocument', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -663,7 +666,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'crud', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -680,7 +683,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'crud', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) ); @@ -697,7 +700,7 @@ suite('Telemetry Controller Test Suite', () => { event: 'Playground Created', properties: { playground_type: 'crud', - extension_version: '0.0.0-dev.0', + extension_version: version, }, }) );