Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 0 additions & 404 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"types/"
],
"scripts": {
"test": "npm run lint && npm run types && metatests test/",
"test": "npm run lint && npm run types && node --test",
"types": "tsc -p types/tsconfig.json",
"lint": "eslint . && prettier -c \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.ts\"",
"fix": "eslint . --fix && prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.ts\""
Expand All @@ -79,7 +79,6 @@
"@types/ws": "^8.18.1",
"eslint": "^9.28.0",
"eslint-config-metarhia": "^9.1.2",
"metatests": "^0.9.0",
"prettier": "^3.5.3",
"typescript": "^5.8.3"
}
Expand Down
52 changes: 27 additions & 25 deletions test/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const path = require('node:path');
const metavm = require('metavm');
const metatests = require('metatests');
const { Api } = require('../lib/api.js');

const root = process.cwd();
Expand All @@ -17,33 +18,34 @@ const application = {
config: { server: { timeouts: {} } },
};

metatests.testAsync('lib/api load', async (test) => {
test('lib/api load - should load API correctly', async () => {
const api = new Api('api', application);
await api.load();
const { example } = api.collection;
test.strictSame(example.default, 1);

assert.strictEqual(example.default, 1);
const { add } = example['1'];
test.strictSame(add.constructor.name, 'Procedure');
test.strictSame(typeof add.method, 'function');
test.strictSame(add.method.constructor.name, 'AsyncFunction');
assert.strictEqual(add.constructor.name, 'Procedure');
assert.strictEqual(typeof add.method, 'function');
assert.strictEqual(add.method.constructor.name, 'AsyncFunction');

const exportsKeys = ['parameters', 'method', 'returns'];
test.strictSame(Object.keys(add.exports), exportsKeys);
test.strictSame(typeof add.script, 'function');
test.strictSame(add.methodName, 'method');
test.strictSame(typeof add.application, 'object');
test.strictSame(add.parameters.constructor.name, 'Schema');
test.strictSame(add.returns.constructor.name, 'Schema');
test.strictSame(add.errors, null);
test.strictSame(add.semaphore, null);
test.strictSame(add.caption, '');
test.strictSame(add.description, '');
test.strictSame(add.access, '');
test.strictSame(add.validate, null);
test.strictSame(add.timeout, 0);
test.strictSame(add.serializer, null);
test.strictSame(add.protocols, null);
test.strictSame(add.deprecated, false);
test.strictSame(add.assert, null);
test.strictSame(add.examples, null);
test.end();
assert.deepStrictEqual(Object.keys(add.exports), exportsKeys);
assert.strictEqual(typeof add.script, 'function');
assert.strictEqual(add.methodName, 'method');
assert.strictEqual(typeof add.application, 'object');
assert.strictEqual(add.parameters.constructor.name, 'Schema');
assert.strictEqual(add.returns.constructor.name, 'Schema');
assert.strictEqual(add.errors, null);
assert.strictEqual(add.semaphore, null);
assert.strictEqual(add.caption, '');
assert.strictEqual(add.description, '');
assert.strictEqual(add.access, '');
assert.strictEqual(add.validate, null);
assert.strictEqual(add.timeout, 0);
assert.strictEqual(add.serializer, null);
assert.strictEqual(add.protocols, null);
assert.strictEqual(add.deprecated, false);
assert.strictEqual(add.assert, null);
assert.strictEqual(add.examples, null);
});
49 changes: 25 additions & 24 deletions test/application.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const { EventEmitter } = require('node:events');
const wt = require('node:worker_threads');
const metatests = require('metatests');
const cwd = process.cwd();

wt.workerData = { id: 0, kind: 'server', root: cwd, path: cwd, port: 8000 };
const application = require('../lib/application.js');

metatests.test('lib/application', (test) => {
test.strictSame(application instanceof EventEmitter, true);
test.strictSame(application.constructor.name, 'Application');
test.strictSame(application.kind, 'server');
test.strictSame(application.initialization, true);
test.strictSame(application.finalization, false);
test.strictSame(typeof application.root, 'string');
test.strictSame(typeof application.path, 'string');
test.strictSame(application.schemas.constructor.name, 'Schemas');
test.strictSame(application.static.constructor.name, 'Static');
test.strictSame(application.cert.constructor.name, 'Cert');
test.strictSame(application.resources.constructor.name, 'Static');
test.strictSame(application.api.constructor.name, 'Api');
test.strictSame(application.lib.constructor.name, 'Code');
test.strictSame(application.db.constructor.name, 'Code');
test.strictSame(application.bus.constructor.name, 'Code');
test.strictSame(application.starts, []);
test.strictSame(application.config, null);
test.strictSame(application.logger, null);
test.strictSame(application.console, null);
test.strictSame(application.auth, null);
test.strictSame(application.watcher, null);
test.end();
test('lib/application - should have correct application properties', () => {
assert.strictEqual(application instanceof EventEmitter, true);
assert.strictEqual(application.constructor.name, 'Application');
assert.strictEqual(application.kind, 'server');
assert.strictEqual(application.initialization, true);
assert.strictEqual(application.finalization, false);
assert.strictEqual(typeof application.root, 'string');
assert.strictEqual(typeof application.path, 'string');
assert.strictEqual(application.schemas.constructor.name, 'Schemas');
assert.strictEqual(application.static.constructor.name, 'Static');
assert.strictEqual(application.cert.constructor.name, 'Cert');
assert.strictEqual(application.resources.constructor.name, 'Static');
assert.strictEqual(application.api.constructor.name, 'Api');
assert.strictEqual(application.lib.constructor.name, 'Code');
assert.strictEqual(application.db.constructor.name, 'Code');
assert.strictEqual(application.bus.constructor.name, 'Code');
assert.deepStrictEqual(application.starts, []);
assert.strictEqual(application.config, null);
assert.strictEqual(application.logger, null);
assert.strictEqual(application.console, null);
assert.strictEqual(application.auth, null);
assert.strictEqual(application.watcher, null);
});
29 changes: 15 additions & 14 deletions test/bus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const path = require('node:path');
const metatests = require('metatests');
const { Code } = require('../lib/code.js');

const root = process.cwd();
Expand All @@ -16,19 +17,19 @@ const application = {
},
};

metatests.testAsync('lib/bus', async (test) => {
test('lib/bus - should load bus correctly', async () => {
const bus = new Code('bus', application);
test.strictSame(bus.name, 'bus');
test.strictSame(bus.path, path.join(root, 'test/bus'));
test.strictSame(typeof bus.application, 'object');
test.strictSame(bus.tree, {});
assert.strictEqual(bus.name, 'bus');
assert.strictEqual(bus.path, path.join(root, 'test/bus'));
assert.strictEqual(typeof bus.application, 'object');
assert.deepStrictEqual(bus.tree, {});

await bus.load();
test.strictSame(Object.keys(bus.tree), ['math', 'worldTime']);
test.strictSame(bus.tree.math.parent, bus.tree);
test.strictSame(typeof bus.tree.math, 'object');
test.strictSame(typeof bus.tree.math.eval, 'function');
test.strictSame(bus.tree.math.eval.constructor.name, 'AsyncFunction');
test.strictSame(typeof bus.tree.math['.service'], 'function');
test.strictSame(bus.tree.math['.service'].url, 'https://api.mathjs.org');
test.end();
assert.deepStrictEqual(Object.keys(bus.tree), ['math', 'worldTime']);
assert.strictEqual(bus.tree.math.parent, bus.tree);
assert.strictEqual(typeof bus.tree.math, 'object');
assert.strictEqual(typeof bus.tree.math.eval, 'function');
assert.strictEqual(bus.tree.math.eval.constructor.name, 'AsyncFunction');
assert.strictEqual(typeof bus.tree.math['.service'], 'function');
assert.strictEqual(bus.tree.math['.service'].url, 'https://api.mathjs.org');
});
19 changes: 9 additions & 10 deletions test/cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const path = require('node:path');
const metatests = require('metatests');
const { Place } = require('../lib/place.js');

const root = process.cwd();
Expand All @@ -16,11 +17,9 @@ const application = {
},
};

metatests.testAsync('lib/place', async (test) => {
test.plan(17);

test.strictSame(typeof Place, 'function');
test.strictSame(Place.name, 'Place');
test('lib/place - should load place correctly', async () => {
assert.strictEqual(typeof Place, 'function');
assert.strictEqual(Place.name, 'Place');

class EmptyPlace extends Place {
constructor(place, application) {
Expand All @@ -29,13 +28,13 @@ metatests.testAsync('lib/place', async (test) => {
}

async change(filePath) {
test.strictSame(this.constructor.name, 'EmptyPlace');
test.strictSame(typeof filePath, 'string');
assert.strictEqual(this.constructor.name, 'EmptyPlace');
assert.strictEqual(typeof filePath, 'string');
}
}

const place = new EmptyPlace('lib', application);
await place.load();
test.strictSame(place.name, 'lib');
test.strictSame(place.empty, true);
assert.strictEqual(place.name, 'lib');
assert.strictEqual(place.empty, true);
});
18 changes: 10 additions & 8 deletions test/cert.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const cp = require('node:child_process');
const metatests = require('metatests');
const { Cert } = require('../lib/cert.js');

const WIN = process.platform === 'win32';
Expand All @@ -24,16 +25,17 @@ const application = {
},
};

metatests.testAsync('lib/cert', async (test) => {
if (WIN) return void test.end();
test('lib/cert - should load certificates correctly', async () => {
if (WIN) return;

let cert = new Cert('cert', application, { ext: ['pem'] });
await cert.load();
test.strictSame(cert.files.size, 3);
test.strictSame(cert.domains.size, 5);
assert.strictEqual(cert.files.size, 3);
assert.strictEqual(cert.domains.size, 5);

fs.copyFileSync(certPath + 'self.pem', certPath + 'key.pem');
cert = new Cert('cert', application, { ext: ['pem'] });
await cert.load();
test.strictSame(cert.files.size, 3);
test.strictSame(cert.domains.size, 0);
test.end();
assert.strictEqual(cert.files.size, 3);
assert.strictEqual(cert.domains.size, 0);
});
29 changes: 15 additions & 14 deletions test/code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const { test } = require('node:test');
const assert = require('node:assert');
const path = require('node:path');
const metatests = require('metatests');
const { Code } = require('../lib/code.js');

const root = process.cwd();
Expand All @@ -16,19 +17,19 @@ const application = {
},
};

metatests.testAsync('lib/code', async (test) => {
test('lib/code - should load code correctly', async () => {
const code = new Code('lib', application);
test.strictSame(code.name, 'lib');
test.strictSame(typeof code.path, 'string');
test.strictSame(typeof code.application, 'object');
test.strictSame(code.tree, {});
assert.strictEqual(code.name, 'lib');
assert.strictEqual(typeof code.path, 'string');
assert.strictEqual(typeof code.application, 'object');
assert.deepStrictEqual(code.tree, {});

await code.load();
test.strictSame(Object.keys(code.tree), ['example', 'utils']);
test.strictSame(code.tree.example.parent, code.tree);
test.strictSame(typeof code.tree.example.add, 'object');
test.strictSame(typeof code.tree.example.doSomething, 'function');
test.strictSame(typeof code.tree.example.stop, 'function');
test.strictSame(typeof code.tree.example.start, 'function');
test.strictSame(code.tree.utils.UNITS.length, 9);
test.end();
assert.deepStrictEqual(Object.keys(code.tree), ['example', 'utils']);
assert.strictEqual(code.tree.example.parent, code.tree);
assert.strictEqual(typeof code.tree.example.add, 'object');
assert.strictEqual(typeof code.tree.example.doSomething, 'function');
assert.strictEqual(typeof code.tree.example.stop, 'function');
assert.strictEqual(typeof code.tree.example.start, 'function');
assert.strictEqual(code.tree.utils.UNITS.length, 9);
});
22 changes: 11 additions & 11 deletions test/deps.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';

const metatests = require('metatests');
const { test } = require('node:test');
const assert = require('node:assert');
const deps = require('../lib/deps.js');
const { node, npm, metarhia } = deps;

metatests.test('lib/deps', async (test) => {
test('lib/deps - should have correct dependencies structure', async () => {
const expectedNamespaces = ['node', 'npm', 'metarhia', 'notLoaded', 'wt'];
test.strictSame(Object.keys(deps), expectedNamespaces);
test.strictSame(typeof node, 'object');
test.strictSame(typeof node.os, 'object');
test.strictSame(typeof npm, 'object');
test.strictSame(typeof npm.ws, 'function');
test.strictSame(typeof metarhia, 'object');
test.strictSame(typeof metarhia.metaschema, 'object');
test.strictSame(deps.notLoaded instanceof Set, true);
test.end();
assert.deepStrictEqual(Object.keys(deps), expectedNamespaces);
assert.strictEqual(typeof node, 'object');
assert.strictEqual(typeof node.os, 'object');
assert.strictEqual(typeof npm, 'object');
assert.strictEqual(typeof npm.ws, 'function');
assert.strictEqual(typeof metarhia, 'object');
assert.strictEqual(typeof metarhia.metaschema, 'object');
assert.strictEqual(deps.notLoaded instanceof Set, true);
});
Loading
Loading