Skip to content

Commit 2288c6a

Browse files
committed
chore: Refactor to generate cjs and mjs test suite
y
1 parent 25f5ccd commit 2288c6a

19 files changed

+379
-699
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
],
3636
"license": "Apache-2.0",
3737
"scripts": {
38-
"clean": "rm -rf dist",
39-
"compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
38+
"clean": "rm -rf dist ; rm -rf dist-test",
39+
"compile": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json && tsc -p tsconfig-systemtest.json && tsc -p tsconfig-systemtest-esm.json",
4040
"prepare": "rm -rf dist && npm run compile && node ./scripts/fixup.cjs",
4141
"pretest": "npm run prepare",
4242
"presnap": "npm run prepare",
@@ -88,4 +88,4 @@
8888
"google-auth-library": "^9.2.0",
8989
"p-throttle": "^7.0.0"
9090
}
91-
}
91+
}

scripts/fixup.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const {readdir, readFile, writeFile} = require('node:fs/promises');
2020

2121
const cjsDistFolder = resolve(__dirname, '../dist/cjs');
2222
const mjsDistFolder = resolve(__dirname, '../dist/mjs');
23+
const cjsSystemTestDistFolder = resolve(__dirname, '../dist-test/cjs');
24+
const mjsSystemTestDistFolder = resolve(__dirname, '../dist-test/mjs');
2325

2426
async function addModuleSystemTypeFile() {
2527
await writeFile(
@@ -31,6 +33,15 @@ async function addModuleSystemTypeFile() {
3133
resolve(mjsDistFolder, 'package.json'),
3234
JSON.stringify({ type: 'module' })
3335
);
36+
await writeFile(
37+
resolve(cjsSystemTestDistFolder, 'package.json'),
38+
JSON.stringify({ type: 'commonjs' })
39+
);
40+
41+
await writeFile(
42+
resolve(mjsSystemTestDistFolder, 'package.json'),
43+
JSON.stringify({ type: 'module' })
44+
);
3445
}
3546

3647
async function fixupImportFileExtensions() {

system-test/mysql-tests.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function mysqlTests(t, connectorModule, mysql2PromiseModule) {
16+
const mysql = mysql2PromiseModule;
17+
const {Connector, AuthTypes, IpAddressTypes} = connectorModule;
18+
19+
t.test('open connection and run basic mysql commands', async t => {
20+
const connector = new Connector();
21+
const clientOpts = await connector.getOptions({
22+
instanceConnectionName: String(process.env.MYSQL_CONNECTION_NAME),
23+
});
24+
const conn = await mysql.createConnection({
25+
...clientOpts,
26+
user: String(process.env.MYSQL_USER),
27+
password: String(process.env.MYSQL_PASS),
28+
database: String(process.env.MYSQL_DB),
29+
});
30+
31+
const [result] = await conn.query('SELECT NOW();');
32+
const [row] = result;
33+
const returnedDate = row['NOW()'];
34+
t.ok(returnedDate.getTime(), 'should have valid returned date object');
35+
36+
await conn.end();
37+
connector.close();
38+
});
39+
40+
t.test('open IAM connection and run basic mysql commands', async t => {
41+
const connector = new Connector();
42+
const clientOpts = await connector.getOptions({
43+
instanceConnectionName: String(process.env.MYSQL_IAM_CONNECTION_NAME),
44+
ipType: IpAddressTypes.PUBLIC,
45+
authType: AuthTypes.IAM,
46+
});
47+
const conn = await mysql.createConnection({
48+
...clientOpts,
49+
user: String(process.env.MYSQL_IAM_USER),
50+
database: String(process.env.MYSQL_DB),
51+
});
52+
53+
const [[result]] = await conn.query('SELECT NOW();');
54+
const returnedDate = result['NOW()'];
55+
t.ok(returnedDate.getTime(), 'should have valid returned date object');
56+
57+
await conn.end();
58+
connector.close();
59+
});
60+
}
61+
export {mysqlTests};

system-test/mysql2-connect.cjs

Lines changed: 0 additions & 60 deletions
This file was deleted.

system-test/mysql2-connect.mjs

Lines changed: 0 additions & 60 deletions
This file was deleted.

system-test/mysql2-connect.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

system-test/pg-connect.cjs

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)