Skip to content

Commit

Permalink
chore: Refactor to generate cjs and mjs test suite
Browse files Browse the repository at this point in the history
y
  • Loading branch information
hessjcg committed Jan 8, 2025
1 parent 25f5ccd commit 448b385
Show file tree
Hide file tree
Showing 20 changed files with 380 additions and 699 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
dist-test/
scripts/
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
],
"license": "Apache-2.0",
"scripts": {
"clean": "rm -rf dist",
"compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
"clean": "rm -rf dist ; rm -rf dist-test",
"compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json && tsc -p tsconfig-systemtest.json && tsc -p tsconfig-systemtest-esm.json",
"prepare": "rm -rf dist && npm run compile && node ./scripts/fixup.cjs",
"pretest": "npm run prepare",
"presnap": "npm run prepare",
Expand Down Expand Up @@ -88,4 +88,4 @@
"google-auth-library": "^9.2.0",
"p-throttle": "^7.0.0"
}
}
}
11 changes: 11 additions & 0 deletions scripts/fixup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {readdir, readFile, writeFile} = require('node:fs/promises');

const cjsDistFolder = resolve(__dirname, '../dist/cjs');
const mjsDistFolder = resolve(__dirname, '../dist/mjs');
const cjsSystemTestDistFolder = resolve(__dirname, '../dist-test/cjs');
const mjsSystemTestDistFolder = resolve(__dirname, '../dist-test/mjs');

async function addModuleSystemTypeFile() {
await writeFile(
Expand All @@ -31,6 +33,15 @@ async function addModuleSystemTypeFile() {
resolve(mjsDistFolder, 'package.json'),
JSON.stringify({ type: 'module' })
);
await writeFile(
resolve(cjsSystemTestDistFolder, 'package.json'),
JSON.stringify({ type: 'commonjs' })
);

await writeFile(
resolve(mjsSystemTestDistFolder, 'package.json'),
JSON.stringify({ type: 'module' })
);
}

async function fixupImportFileExtensions() {
Expand Down
61 changes: 61 additions & 0 deletions system-test/mysql-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

function mysqlTests(t, connectorModule, mysql2PromiseModule) {
const mysql = mysql2PromiseModule;
const {Connector, AuthTypes, IpAddressTypes} = connectorModule;

t.test('open connection and run basic mysql commands', async t => {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName: String(process.env.MYSQL_CONNECTION_NAME),
});
const conn = await mysql.createConnection({
...clientOpts,
user: String(process.env.MYSQL_USER),
password: String(process.env.MYSQL_PASS),
database: String(process.env.MYSQL_DB),
});

const [result] = await conn.query('SELECT NOW();');
const [row] = result;
const returnedDate = row['NOW()'];
t.ok(returnedDate.getTime(), 'should have valid returned date object');

await conn.end();
connector.close();
});

t.test('open IAM connection and run basic mysql commands', async t => {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName: String(process.env.MYSQL_IAM_CONNECTION_NAME),
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
const conn = await mysql.createConnection({
...clientOpts,
user: String(process.env.MYSQL_IAM_USER),
database: String(process.env.MYSQL_DB),
});

const [[result]] = await conn.query('SELECT NOW();');
const returnedDate = result['NOW()'];
t.ok(returnedDate.getTime(), 'should have valid returned date object');

await conn.end();
connector.close();
});
}
export {mysqlTests};
60 changes: 0 additions & 60 deletions system-test/mysql2-connect.cjs

This file was deleted.

60 changes: 0 additions & 60 deletions system-test/mysql2-connect.mjs

This file was deleted.

68 changes: 0 additions & 68 deletions system-test/mysql2-connect.ts

This file was deleted.

95 changes: 0 additions & 95 deletions system-test/pg-connect.cjs

This file was deleted.

Loading

0 comments on commit 448b385

Please sign in to comment.