Skip to content

Commit 3714220

Browse files
ci: fix URI-encoding and connection not terminated in tests (#3871)
* fix(docs): improve the contribution guidelines to state that the test database name must be called "test" * fix(test): fix tests, particularly those with hardcoded test as the schema/db name, to catch and not hang if the assertion fails. * fix(test): Fix URI encoding for user/password in common.test.config * fix(docs): address code review comments suggestion * fix(docs): address code review comments suggestion, remove extra space * fix(tests): refactor unit tests as per code review * fix(tests): remove unnecessary async callback --------- Co-authored-by: Weslley Araújo <[email protected]>
1 parent 38f3748 commit 3714220

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

Contributing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ Please ensure test cases to cover your features.
9191

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

94+
> [!NOTE]
95+
> The database name must be exactly "test".
96+
9497
```bash
9598
# assuming MySQL have a user root with no password
9699
echo "CREATE DATABASE test;" | mysql -uroot

test/common.test.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ if (process.env.MYSQL_USE_TLS === '1') {
2727
};
2828
}
2929

30-
const configURI = `mysql://${config.user}:${config.password}@${config.host}:${config.port}/${config.database}`;
30+
const encUser = encodeURIComponent(config.user ?? '');
31+
const encPass = encodeURIComponent(config.password ?? '');
32+
const host = config.host;
33+
const port = config.port;
34+
const db = config.database;
35+
36+
const configURI = `mysql://${encUser}:${encPass}@${host}:${port}/${db}`;
3137

3238
exports.SqlString = require('sqlstring');
3339
exports.config = config;

test/esm/integration/connection/test-column-inspect.test.mjs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { test, assert, describe, beforeEach } from 'poku';
1+
import { assert, describe, afterEach, beforeEach, it } from 'poku';
22
import util from 'node:util';
33
import { createRequire } from 'node:module';
44

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

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

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

13-
beforeEach(
14-
async () => await connection.query(`DROP TABLE IF EXISTS test_fields`),
15-
{ assert: false }
16-
);
16+
afterEach(async () => {
17+
await connection.end();
18+
});
1719

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

79-
common.version >= 16 &&
80-
(await test(async () => {
81+
if (common.version >= 16) {
82+
await it('shows detailed description when depth < 1', async () => {
8183
await connection.query(`
8284
CREATE TEMPORARY TABLE test_fields2 (
8385
id INT,
@@ -108,7 +110,6 @@ const common = require('../../../common.test.cjs');
108110
}),
109111
'should show detailed description when depth is < 1'
110112
);
111-
}));
112-
113-
await connection.end();
114-
})();
113+
});
114+
}
115+
});

test/integration/connection/test-stream-error-destroy-connection.test.cjs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
'use strict';
22

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

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

9-
await test('Ensure stream ends in case of error', async () => {
9+
beforeEach(() => (connection = common.createConnection()));
10+
11+
afterEach(async () => {
12+
await connection.end();
13+
});
14+
15+
await it('Ensure stream ends in case of error', async () => {
1016
connection.query(
1117
[
1218
'CREATE TEMPORARY TABLE `items` (',
@@ -40,7 +46,7 @@ describe(async () => {
4046
for await (const _ of rows) break; // forces return () -> destroy()
4147
});
4248

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

4652
const stream = connection
@@ -64,7 +70,7 @@ describe(async () => {
6470
);
6571
});
6672

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

7076
const stream = connection
@@ -87,6 +93,4 @@ describe(async () => {
8793
"Table 'test.invalid_table' doesn't exist"
8894
);
8995
});
90-
91-
connection.end();
9296
});

0 commit comments

Comments
 (0)