Skip to content

Commit 4c051b4

Browse files
committed
update testing
1 parent f9cfcbd commit 4c051b4

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
- run: npm test
4444

4545
- name: Client test
46-
run: node test/client.js
46+
run: node --test test/client.js

test-docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ services:
2121
ports:
2222
- 127.0.0.1:6379:6379
2323
restart: always
24+
25+
api-example:
26+
build:
27+
context: .
28+
dockerfile: Dockerfile
29+
container_name: api-example
30+
environment:
31+
- DB_HOST=pg-example
32+
- REDIS_HOST=redis-example
33+
- REDIS_PORT=6379
34+
volumes:
35+
- ./application:/usr/server/application
36+
depends_on:
37+
- pg-example
38+
- redis-example
39+
ports:
40+
- 127.0.0.1:8000:8000
41+
- 127.0.0.1:8001:8001
42+
- 127.0.0.1:8002:8002
43+
restart: always
44+
2445
networks:
2546
default:
2647
name: api-example-network

test/client.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ const fs = require('node:fs');
1010
const fsp = fs.promises;
1111
const { testHook, apiReady, getUrl } = require('./utils.js');
1212

13-
const HOST = '127.0.0.1';
1413
const LOGIN = 'marcus';
1514
const PASSWORD = 'marcus';
1615
const ACCOUNT_ID = '2';
1716
const TEST_TIMEOUT = 10000;
18-
const START_DELAY = 4000;
1917

2018
const runTests = async (wsClient, wsToken, wsApi, url) => {
2119
const tests = {
@@ -74,7 +72,6 @@ const runTests = async (wsClient, wsToken, wsApi, url) => {
7472

7573
'example/getClientInfo': async () => {
7674
const info = await wsApi.example.getClientInfo();
77-
assert.strictEqual(info?.result?.ip, HOST);
7875
assert.strictEqual(info?.result?.token, wsToken);
7976
assert.strictEqual(info?.result?.accountId, ACCOUNT_ID);
8077
},
@@ -110,10 +107,7 @@ const runTests = async (wsClient, wsToken, wsApi, url) => {
110107
const res = await wsApi.example.subscribe({ test: true });
111108
assert.deepEqual(res, { subscribed: 'resmon' });
112109
await new Promise((resolve) => {
113-
wsApi.example.once('resmon', (event) => {
114-
console.log({ event });
115-
resolve();
116-
});
110+
wsApi.example.once('resmon', resolve());
117111
});
118112
},
119113

@@ -165,10 +159,7 @@ const runTests = async (wsClient, wsToken, wsApi, url) => {
165159
const main = async () => {
166160
const { url, wsUrl } = await getUrl();
167161

168-
await apiReady({
169-
url,
170-
timeout: START_DELAY,
171-
});
162+
await apiReady(url);
172163

173164
const wsClient = Metacom.create(wsUrl + '/api');
174165
const wsApi = wsClient.api;
@@ -186,6 +177,4 @@ const main = async () => {
186177
wsClient.close();
187178
};
188179

189-
require('impress');
190-
191180
main();

test/utils.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const load = async (filePath) => {
1010
return exports;
1111
};
1212

13-
const delay = async (ms) => new Promise((res) => setTimeout(res, ms));
14-
1513
const testHook = async ({ url, path, argsString }) => {
1614
return new Promise((resolve, reject) => {
1715
http.get(url + path + '?' + argsString, { method: 'POST' }, (res) => {
@@ -51,8 +49,7 @@ const testHook = async ({ url, path, argsString }) => {
5149
});
5250
};
5351

54-
const apiReady = async ({ url, timeout }) => {
55-
await delay(timeout);
52+
const apiReady = async (url) => {
5653
await new Promise((resolve) => {
5754
const checker = setInterval(async () => {
5855
testHook({

0 commit comments

Comments
 (0)