Skip to content

Commit

Permalink
chore: use package json version for tests (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Jan 8, 2024
1 parent ad25872 commit 4cef2ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
18 changes: 9 additions & 9 deletions src/test/suite/connectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -894,8 +896,7 @@ suite('Connection Controller Test Suite', function () {
assert.deepStrictEqual(connectionInfo, {
id: 'c4871b21-92c4-40e2-a2c2-fdd551cff114',
connectionOptions: {
connectionString:
'mongodb+srv://username:[email protected]/?authSource=admin&readPreference=primary&appname=mongodb-vscode+0.0.0-dev.0&ssl=true',
connectionString: `mongodb+srv://username:[email protected]/?authSource=admin&readPreference=primary&appname=mongodb-vscode+${version}&ssl=true`,
},
});
});
Expand All @@ -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,
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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',
};

Expand Down Expand Up @@ -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',
};

Expand Down Expand Up @@ -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',
};

Expand Down
51 changes: 27 additions & 24 deletions src/test/suite/telemetry/telemetryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -209,7 +212,7 @@ suite('Telemetry Controller Test Suite', () => {
properties: {
source: 'treeview',
success: true,
extension_version: '0.0.0-dev.0',
extension_version: version,
},
})
);
Expand All @@ -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 },
})
);
});
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand Down Expand Up @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand Down Expand Up @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand All @@ -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,
},
})
);
Expand Down

0 comments on commit 4cef2ec

Please sign in to comment.