[add] testing via mocha
This commit is contained in:
parent
7743d513e4
commit
a9faec506d
13 changed files with 3382 additions and 156 deletions
6
lib/node/node_modules/.package-lock.json
generated
vendored
6
lib/node/node_modules/.package-lock.json
generated
vendored
|
@ -106,6 +106,12 @@
|
|||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mocha": {
|
||||
"version": "10.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz",
|
||||
"integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
"version": "1.1.1",
|
||||
"dev": true,
|
||||
|
|
21
lib/node/node_modules/@types/mocha/LICENSE
generated
vendored
Normal file
21
lib/node/node_modules/@types/mocha/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE
|
15
lib/node/node_modules/@types/mocha/README.md
generated
vendored
Normal file
15
lib/node/node_modules/@types/mocha/README.md
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Installation
|
||||
> `npm install --save @types/mocha`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for mocha (https://mochajs.org).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mocha.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Wed, 22 Nov 2023 00:24:48 GMT
|
||||
* Dependencies: none
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Kazi Manzur Rashid](https://github.com/kazimanzurrashid), [otiai10](https://github.com/otiai10), [Vadim Macagon](https://github.com/enlight), [Andrew Bradley](https://github.com/cspotcode), [Dmitrii Sorin](https://github.com/1999), [Noah Hummel](https://github.com/strangedev), and [nicojs](https://github.com/nicojs).
|
2916
lib/node/node_modules/@types/mocha/index.d.ts
generated
vendored
Normal file
2916
lib/node/node_modules/@types/mocha/index.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
55
lib/node/node_modules/@types/mocha/package.json
generated
vendored
Normal file
55
lib/node/node_modules/@types/mocha/package.json
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"name": "@types/mocha",
|
||||
"version": "10.0.6",
|
||||
"description": "TypeScript definitions for mocha",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mocha",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Kazi Manzur Rashid",
|
||||
"githubUsername": "kazimanzurrashid",
|
||||
"url": "https://github.com/kazimanzurrashid"
|
||||
},
|
||||
{
|
||||
"name": "otiai10",
|
||||
"githubUsername": "otiai10",
|
||||
"url": "https://github.com/otiai10"
|
||||
},
|
||||
{
|
||||
"name": "Vadim Macagon",
|
||||
"githubUsername": "enlight",
|
||||
"url": "https://github.com/enlight"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Bradley",
|
||||
"githubUsername": "cspotcode",
|
||||
"url": "https://github.com/cspotcode"
|
||||
},
|
||||
{
|
||||
"name": "Dmitrii Sorin",
|
||||
"githubUsername": "1999",
|
||||
"url": "https://github.com/1999"
|
||||
},
|
||||
{
|
||||
"name": "Noah Hummel",
|
||||
"githubUsername": "strangedev",
|
||||
"url": "https://github.com/strangedev"
|
||||
},
|
||||
{
|
||||
"name": "nicojs",
|
||||
"githubUsername": "nicojs",
|
||||
"url": "https://github.com/nicojs"
|
||||
}
|
||||
],
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/mocha"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {},
|
||||
"typesPublisherContentHash": "de34ee99a18094486419f8e3b6c2a3f81f623ecdcbc5f6f4cfe46236c7df5831",
|
||||
"typeScriptVersion": "4.5"
|
||||
}
|
7
lib/node/package-lock.json
generated
7
lib/node/package-lock.json
generated
|
@ -5,6 +5,7 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.6",
|
||||
"bcrypt": "^5.1.1",
|
||||
"nodemailer": "^6.9.13",
|
||||
"sqlite3": "^5.1.7",
|
||||
|
@ -114,6 +115,12 @@
|
|||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mocha": {
|
||||
"version": "10.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz",
|
||||
"integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
"version": "1.1.1",
|
||||
"dev": true,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.6",
|
||||
"bcrypt": "^5.1.1",
|
||||
"nodemailer": "^6.9.13",
|
||||
"sqlite3": "^5.1.7",
|
||||
|
|
12
readme.md
12
readme.md
|
@ -18,6 +18,18 @@
|
|||
- `tools/build` ausführen
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
### Voraussetzungen
|
||||
|
||||
- [mocha](https://mochajs.org/) (Debian-Paket-Name: `mocha`)
|
||||
|
||||
|
||||
### Anweisungen
|
||||
|
||||
- `tools/test` ausführen
|
||||
|
||||
|
||||
## Betrieb
|
||||
|
||||
### Voraussetzungen
|
||||
|
|
|
@ -124,29 +124,11 @@ namespace _espe.conf
|
|||
|
||||
|
||||
/**
|
||||
* @todo mandatory fields
|
||||
*/
|
||||
export async function load(
|
||||
path : string
|
||||
) : Promise<void>
|
||||
export function inject(
|
||||
conf_raw : any
|
||||
) : void
|
||||
{
|
||||
let conf_raw : any;
|
||||
if (! (await lib_plankton.file.exists(path))) {
|
||||
// return Promise.reject<void>(new Error("configuration file not found: " + path + "; using fallback"));
|
||||
conf_raw = {};
|
||||
}
|
||||
else {
|
||||
try {
|
||||
conf_raw = lib_plankton.json.decode(await lib_plankton.file.read(path));
|
||||
}
|
||||
catch (error) {
|
||||
conf_raw = null;
|
||||
}
|
||||
}
|
||||
if (conf_raw === null) {
|
||||
return Promise.reject<void>("configuration file could not be read");
|
||||
}
|
||||
else {
|
||||
_data = {
|
||||
"general": (
|
||||
((node_general) => ({
|
||||
|
@ -254,8 +236,16 @@ namespace _espe.conf
|
|||
},
|
||||
"password_policy": (
|
||||
((node_settings_password_policy) => ({
|
||||
"minimum_length": (node_settings_password_policy["minimum_length"] ?? 8),
|
||||
"maximum_length": (node_settings_password_policy["maximum_length"] ?? 240),
|
||||
"minimum_length": (
|
||||
("minimum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["minimum_length"]
|
||||
: 8
|
||||
),
|
||||
"maximum_length": (
|
||||
("maximum_length" in node_settings_password_policy)
|
||||
? node_settings_password_policy["maximum_length"]
|
||||
: 240
|
||||
),
|
||||
"must_contain_letter": (node_settings_password_policy["must_contain_letter"] ?? true),
|
||||
"must_contain_number": (node_settings_password_policy["must_contain_number"] ?? true),
|
||||
"must_contain_special_character": (node_settings_password_policy["must_contain_special_character"] ?? true),
|
||||
|
@ -271,6 +261,34 @@ namespace _espe.conf
|
|||
),
|
||||
"admins": (conf_raw["admins"] ?? []),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @todo mandatory fields
|
||||
*/
|
||||
export async function load(
|
||||
path : string
|
||||
) : Promise<void>
|
||||
{
|
||||
let conf_raw : any;
|
||||
if (! (await lib_plankton.file.exists(path))) {
|
||||
// return Promise.reject<void>(new Error("configuration file not found: " + path + "; using fallback"));
|
||||
conf_raw = {};
|
||||
}
|
||||
else {
|
||||
try {
|
||||
conf_raw = lib_plankton.json.decode(await lib_plankton.file.read(path));
|
||||
}
|
||||
catch (error) {
|
||||
conf_raw = null;
|
||||
}
|
||||
}
|
||||
if (conf_raw === null) {
|
||||
return Promise.reject<void>("configuration file could not be read");
|
||||
}
|
||||
else {
|
||||
inject(conf_raw);
|
||||
// process.stderr.write(JSON.stringify(_data, undefined, "\t"));
|
||||
return Promise.resolve<void>(undefined);
|
||||
}
|
||||
|
|
130
source/tests.mocha.ts
Normal file
130
source/tests.mocha.ts
Normal file
|
@ -0,0 +1,130 @@
|
|||
const nm_assert = require("assert");
|
||||
|
||||
describe(
|
||||
"member.validate_password",
|
||||
() => {
|
||||
const cases : Array<
|
||||
{
|
||||
name : string;
|
||||
input : {
|
||||
conf : any;
|
||||
password : string;
|
||||
};
|
||||
output : Array<
|
||||
{
|
||||
incident : string;
|
||||
details : Record<string, any>;
|
||||
}
|
||||
>;
|
||||
}
|
||||
> = [
|
||||
{
|
||||
"name": "minimum_length:negative",
|
||||
"input": {
|
||||
"conf": {
|
||||
"settings": {
|
||||
"password_policy": {
|
||||
"minimum_length": 5,
|
||||
"maximum_length": null,
|
||||
"must_contain_letter": false,
|
||||
"must_contain_number": false,
|
||||
"must_contain_special_character": false,
|
||||
}
|
||||
}
|
||||
},
|
||||
"password": "abcde"
|
||||
},
|
||||
"output": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "minimum_lengt:positive",
|
||||
"input": {
|
||||
"conf": {
|
||||
"settings": {
|
||||
"password_policy": {
|
||||
"minimum_length": 5,
|
||||
"maximum_length": null,
|
||||
"must_contain_letter": false,
|
||||
"must_contain_number": false,
|
||||
"must_contain_special_character": false,
|
||||
}
|
||||
}
|
||||
},
|
||||
"password": "abcd"
|
||||
},
|
||||
"output": [
|
||||
{
|
||||
"incident": "too_short",
|
||||
"details": {
|
||||
"minimum_length": 5,
|
||||
"actual_length": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "maximum_length:negative",
|
||||
"input": {
|
||||
"conf": {
|
||||
"settings": {
|
||||
"password_policy": {
|
||||
"minimum_length": null,
|
||||
"maximum_length": 5,
|
||||
"must_contain_letter": false,
|
||||
"must_contain_number": false,
|
||||
"must_contain_special_character": false,
|
||||
}
|
||||
}
|
||||
},
|
||||
"password": "abcde"
|
||||
},
|
||||
"output": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "maximum_lengt:positive",
|
||||
"input": {
|
||||
"conf": {
|
||||
"settings": {
|
||||
"password_policy": {
|
||||
"minimum_length": null,
|
||||
"maximum_length": 5,
|
||||
"must_contain_letter": false,
|
||||
"must_contain_number": false,
|
||||
"must_contain_special_character": false,
|
||||
}
|
||||
}
|
||||
},
|
||||
"password": "abcdef"
|
||||
},
|
||||
"output": [
|
||||
{
|
||||
"incident": "too_long",
|
||||
"details": {
|
||||
"maximum_length": 5,
|
||||
"actual_length": 6
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
cases.forEach(
|
||||
case_ => {
|
||||
it(
|
||||
case_.name,
|
||||
() => {
|
||||
_espe.conf.inject(case_.input.conf);
|
||||
const result : Array<
|
||||
{
|
||||
incident : string;
|
||||
details : Record<string, any>;
|
||||
}
|
||||
> = _espe.service.member.validate_password(case_.input.password);
|
||||
nm_assert.deepEqual(result, case_.output);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
13
tools/build
13
tools/build
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## args
|
||||
|
||||
if [ $# -ge 1 ] ; then arg1=$1 && shift ; else arg1="" ; fi
|
||||
|
||||
|
||||
## exec
|
||||
|
||||
make --file=tools/makefile
|
||||
targets=""
|
||||
targets="${targets} build/espe"
|
||||
if [ ${arg1} == "-t" ] ; then targets="${targets} test" ; fi
|
||||
|
||||
make --file=tools/makefile ${targets}
|
||||
|
|
|
@ -15,8 +15,13 @@ cmd_cp := cp
|
|||
## rules
|
||||
|
||||
.PHONY: default
|
||||
default: node_modules ${dir_build}/espe
|
||||
default: main
|
||||
|
||||
.PHONY: main
|
||||
main: node_modules ${dir_build}/espe
|
||||
|
||||
.PHONY: test
|
||||
test: ${dir_build}/espe-test.mocha.js
|
||||
|
||||
.PHONY: node_modules
|
||||
node_modules:
|
||||
|
@ -24,7 +29,7 @@ node_modules:
|
|||
@ ${cmd_log} "node modules …"
|
||||
@ ${cmd_cp} -r -u ${dir_lib}/node/node_modules/* ${dir_build}/node_modules/
|
||||
|
||||
${dir_temp}/espe-unlinked.js: \
|
||||
${dir_temp}/espe-core.js ${dir_temp}/espe-core.d.ts: \
|
||||
${dir_lib}/plankton/plankton.d.ts \
|
||||
${dir_source}/helpers.ts \
|
||||
${dir_source}/database.ts \
|
||||
|
@ -37,9 +42,6 @@ ${dir_temp}/espe-unlinked.js: \
|
|||
${dir_source}/api/base.ts \
|
||||
${dir_source}/api/actions/session_begin.ts \
|
||||
${dir_source}/api/actions/session_end.ts \
|
||||
${dir_source}/api/actions/email.ts \
|
||||
${dir_source}/api/actions/verification_get.ts \
|
||||
${dir_source}/api/actions/verification_check.ts \
|
||||
${dir_source}/api/actions/member_project.ts \
|
||||
${dir_source}/api/actions/member_summon.ts \
|
||||
${dir_source}/api/actions/member_info.ts \
|
||||
|
@ -48,14 +50,44 @@ ${dir_temp}/espe-unlinked.js: \
|
|||
${dir_source}/api/actions/member_read.ts \
|
||||
${dir_source}/api/actions/member_modify.ts \
|
||||
${dir_source}/api/functions.ts \
|
||||
${dir_source}/conf.ts \
|
||||
${dir_source}/conf.ts
|
||||
@ ${cmd_log} "compile | core …"
|
||||
@ ${cmd_mkdir} $(dir $@)
|
||||
@ tsc --lib es2020 $^ --outFile ${dir_temp}/espe-core.js --declaration
|
||||
|
||||
${dir_temp}/espe-main-raw.js: \
|
||||
${dir_lib}/plankton/plankton.d.ts \
|
||||
${dir_temp}/espe-core.d.ts \
|
||||
${dir_source}/main.ts
|
||||
@ ${cmd_log} "compile …"
|
||||
@ ${cmd_log} "compile | main …"
|
||||
@ ${cmd_mkdir} $(dir $@)
|
||||
@ tsc --lib es2020 $^ --outFile $@
|
||||
|
||||
${dir_build}/espe: ${dir_source}/head.js ${dir_lib}/plankton/plankton.js ${dir_temp}/espe-unlinked.js
|
||||
@ ${cmd_log} "link …"
|
||||
${dir_temp}/espe-test-raw.js: \
|
||||
${dir_lib}/plankton/plankton.d.ts \
|
||||
${dir_temp}/espe-core.d.ts \
|
||||
${dir_lib}/node/node_modules/@types/mocha/index.d.ts \
|
||||
${dir_source}/tests.mocha.ts
|
||||
@ ${cmd_log} "compile | test …"
|
||||
@ ${cmd_mkdir} $(dir $@)
|
||||
@ tsc --lib es2020 $^ --outFile $@
|
||||
|
||||
${dir_build}/espe: \
|
||||
${dir_source}/head.js \
|
||||
${dir_lib}/plankton/plankton.js \
|
||||
${dir_temp}/espe-core.js \
|
||||
${dir_temp}/espe-main-raw.js
|
||||
@ ${cmd_log} "link | main …"
|
||||
@ ${cmd_mkdir} $(dir $@)
|
||||
@ ${cmd_cat} $^ > $@
|
||||
@ ${cmd_chmod} +x $@
|
||||
|
||||
${dir_build}/espe-test.mocha.js: \
|
||||
${dir_source}/head.js \
|
||||
${dir_lib}/plankton/plankton.js \
|
||||
${dir_temp}/espe-core.js \
|
||||
${dir_temp}/espe-test-raw.js
|
||||
@ ${cmd_log} "link | test …"
|
||||
@ ${cmd_mkdir} $(dir $@)
|
||||
@ ${cmd_cat} $^ > $@
|
||||
@ ${cmd_chmod} +x $@
|
||||
|
|
4
tools/test
Executable file
4
tools/test
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
tools/build -t
|
||||
mocha build/espe-test.mocha.js
|
Loading…
Add table
Reference in a new issue