Skip to content
Merged
3 changes: 3 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Please ensure test cases to cover your features.

Running tests requires MySQL server and an empty database. You can run `bash` command given below to create `test` database

> [!NOTE]
> The database name must be exactly "test".

```bash
# assuming MySQL have a user root with no password
echo "CREATE DATABASE test;" | mysql -uroot
Expand Down
8 changes: 7 additions & 1 deletion test/common.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ if (process.env.MYSQL_USE_TLS === '1') {
};
}

const configURI = `mysql://${config.user}:${config.password}@${config.host}:${config.port}/${config.database}`;
const encUser = encodeURIComponent(config.user ?? '');
const encPass = encodeURIComponent(config.password ?? '');
const host = config.host;
const port = config.port;
const db = config.database;

const configURI = `mysql://${encUser}:${encPass}@${host}:${port}/${db}`;

exports.SqlString = require('sqlstring');
exports.config = config;
Expand Down
31 changes: 16 additions & 15 deletions test/esm/integration/connection/test-column-inspect.test.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { test, assert, describe, beforeEach } from 'poku';
import { assert, describe, afterEach, beforeEach, it } from 'poku';
import util from 'node:util';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const common = require('../../../common.test.cjs');

(async () => {
const connection = common.createConnection().promise();
await describe('Custom inspect for column definition', async () => {
let connection;

describe('Custom inspect for column definition', common.describeOptions);
beforeEach(async () => {
connection = common.createConnection().promise();
await connection.query(`DROP TABLE IF EXISTS test_fields`);
});

beforeEach(
async () => await connection.query(`DROP TABLE IF EXISTS test_fields`),
{ assert: false }
);
afterEach(async () => {
await connection.end();
});

await test(async () => {
await it('maps fields to schema-like description when depth > 1', async () => {
const schema = `
id INT NOT NULL AUTO_INCREMENT,
weight INT(2) UNSIGNED ZEROFILL,
Expand Down Expand Up @@ -76,8 +78,8 @@ const common = require('../../../common.test.cjs');
}
});

common.version >= 16 &&
(await test(async () => {
if (common.version >= 16) {
await it('shows detailed description when depth < 1', async () => {
await connection.query(`
CREATE TEMPORARY TABLE test_fields2 (
id INT,
Expand Down Expand Up @@ -108,7 +110,6 @@ const common = require('../../../common.test.cjs');
}),
'should show detailed description when depth is < 1'
);
}));

await connection.end();
})();
});
}
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
'use strict';

const { assert, describe, test } = require('poku');
const { assert, describe, beforeEach, afterEach, it } = require('poku');
const common = require('../../common.test.cjs');

describe(async () => {
const connection = common.createConnection();
describe('test stream error destroy connection:', async () => {
let connection;

await test('Ensure stream ends in case of error', async () => {
beforeEach(() => (connection = common.createConnection()));

afterEach(async () => {
await connection.end();
});

await it('Ensure stream ends in case of error', async () => {
connection.query(
[
'CREATE TEMPORARY TABLE `items` (',
Expand Down Expand Up @@ -40,7 +46,7 @@ describe(async () => {
for await (const _ of rows) break; // forces return () -> destroy()
});

await test('end: Ensure stream emits error then close on server-side query error', async () => {
await it('end: Ensure stream emits error then close on server-side query error', async () => {
let uncaughtExceptionError;

const stream = connection
Expand All @@ -64,7 +70,7 @@ describe(async () => {
);
});

await test('close: Ensure stream emits error then close on server-side query error', async () => {
await it('close: Ensure stream emits error then close on server-side query error', async () => {
let uncaughtExceptionError;

const stream = connection
Expand All @@ -87,6 +93,4 @@ describe(async () => {
"Table 'test.invalid_table' doesn't exist"
);
});

connection.end();
});