Compare commits

..

No commits in common. "master" and "v1.0.25" have entirely different histories.

15 changed files with 11197 additions and 4460 deletions

View File

@ -12,38 +12,30 @@ stages:
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
mirror:
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
- npmci git mirror
tags:
- lossless
- docker
allow_failure: true
- notpriv
auditDevDependencies:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
- npmci command npm audit --audit-level=high
tags:
- lossless
- docker
allow_failure: true
- notpriv
# ====================
# test stage
@ -52,22 +44,28 @@ auditDevDependencies:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm build
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -87,12 +85,11 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -112,9 +109,11 @@ trigger:
pages:
stage: metadata
script:
- npmci node install stable
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command npm run buildDocs
- npmci command tsdoc
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,10 +2,28 @@
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"name": "current file",
"type": "node",
"request": "launch",
"type": "node-terminal"
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
"enum": ["website", "element", "service", "npm"]
}
}
}

View File

@ -2,31 +2,17 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "api.global",
"githost": "gitlab.com",
"gitscope": "apiglobal",
"gitrepo": "test-sdk",
"description": "A software development kit for testing API Gateway handlers.",
"npmPackagename": "@api.global/test-sdk",
"shortDescription": "an sdk for testing ag handlers",
"npmPackagename": "@apiglobal/test-sdk",
"license": "MIT",
"projectDomain": "api.global",
"keywords": [
"API testing",
"SDK",
"development tools",
"API Gateway",
"server simulation",
"handlers testing",
"automated testing",
"TypeScript",
"Node.js"
]
"projectDomain": "api.global"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

11079
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,30 @@
{
"name": "@api.global/test-sdk",
"version": "2.0.2",
"name": "@apiglobal/test-sdk",
"version": "1.0.25",
"private": false,
"description": "A software development kit for testing API Gateway handlers.",
"description": "an sdk for testing ag handlers",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
"build": "(tsbuild --web)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.15.3"
"@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@apiglobal/sdk": "^2.0.1",
"@apiglobal/typedrequest": "^2.0.12",
"@apiglobal/typedrequest-interfaces": "^2.0.1",
"@pushrocks/qenv": "^5.0.2",
"@pushrocks/smartexpress": "^4.0.28",
"@apiglobal/sdk": "^1.0.13",
"@apiglobal/typedrequest": "^1.0.43",
"@apiglobal/typedrequest-interfaces": "^1.0.15",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/smartexpress": "^3.0.76",
"@pushrocks/smartobject": "^1.0.4"
},
"files": [
@ -38,20 +38,5 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module",
"keywords": [
"API testing",
"SDK",
"development tools",
"API Gateway",
"server simulation",
"handlers testing",
"automated testing",
"TypeScript",
"Node.js"
]
}
}

4232
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@

140
readme.md
View File

@ -1,123 +1,39 @@
# @api.global/test-sdk
# @apiglobal/test-sdk
an sdk for testing ag handlers
## Install
To install `@api.global/test-sdk`, you need to have Node.js and npm installed. Follow these steps to install it:
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiglobal/test-sdk)
* [gitlab.com (source)](https://gitlab.com/apiglobal/test-sdk)
* [github.com (source mirror)](https://github.com/apiglobal/test-sdk)
* [docs (typedoc)](https://apiglobal.gitlab.io/test-sdk/)
```bash
npm install @api.global/test-sdk --save
```
This will add `@api.global/test-sdk` to your project's dependencies.
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/apiglobal/test-sdk/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/apiglobal/test-sdk/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@apiglobal/test-sdk)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/apiglobal/test-sdk)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@apiglobal/test-sdk)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@apiglobal/test-sdk)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiglobal/test-sdk)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
This document provides a comprehensive guide on how to effectively utilize the `@api.global/test-sdk` module in your project. We will explore various use cases, demonstrate the SDK's capabilities through code examples, and ensure a thorough understanding of its features. This guide assumes that you have basic knowledge of TypeScript and are familiar with the concepts of asynchronous programming.
### Getting Started
Use TypeScript for best in class intellisense
First, ensure that you are importing the SDK's functionalities as follows:
## Contribution
```typescript
import { AgTestServer, createTestServer, stopTestServer } from '@api.global/test-sdk';
```
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
### Creating and Starting a Test Server
For further information read the linked docs at the top of this readme.
The `@api.global/test-sdk` allows for the creation of test servers with custom handlers. Here's how to set it up:
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```typescript
import { createTestServer } from '@api.global/test-sdk';
// Your custom handler should extend from AAgHandler
class MyCustomHandler extends AAgHandler<any> {
constructor(envManagerArg: AgEnvironment) {
super(envManagerArg);
this.slug = 'mycustomhandler'; // Define a unique slug for your handler
}
// Implement required handler methods here
}
async function setupTestServer() {
const testServer = await createTestServer(MyCustomHandler);
console.log('Test server started successfully');
return testServer;
}
```
### Sending Requests to the Test Server
With the test server running, you can now simulate requests. Let's demonstrate how to send a request to the custom handler and evaluate the response:
```typescript
import { testFire } from '@api.global/test-sdk';
async function testRequest() {
const testResponse = testFire<MyCustomHandler, MyRequestInterface>(
'mycustomhandler', // The slug of your handler
'POST', // The HTTP method
{ // The request body
key: 'value'
}
);
// Expecting a response from the server
const expectedResponse = await testResponse.expect({
expectedKey: 'expectedValue'
});
console.log('The expected response was received:', expectedResponse);
}
```
### Stopping the Test Server
It's important to properly shut down the test server once your testing is complete to free up resources:
```typescript
async function shutdownTestServer() {
await stopTestServer();
console.log('Test server stopped successfully');
}
```
### Full Example
Here's how everything comes together in a script:
```typescript
import { AgTestServer, createTestServer, stopTestServer, testFire } from '@api.global/test-sdk';
class MyCustomHandler extends AAgHandler<any> {
// Implementation of the custom handler...
}
async function main() {
const server = await setupTestServer();
await testRequest();
await shutdownTestServer();
}
main().catch(console.error);
```
This guide provides a foundational understanding of how to utilize `@api.global/test-sdk` for testing purposes. Through the creation of a test server, the execution of requests, and the evaluation of responses, developers can simulate real-world scenarios and ensure that their applications behave as expected in a controlled environment.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as testSdk from '../ts/index.js';
import * as testSdk from '../ts/index';
let testServer: testSdk.AgTestServer;

View File

@ -1,8 +0,0 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@apiglobal/test-sdk',
version: '2.0.2',
description: 'an sdk for testing ag handlers'
}

View File

@ -1,14 +1,14 @@
import * as plugins from './test-sdk.plugins.js';
import { AgTestServer } from './test-sdk.classes.testserver.js';
import * as plugins from './test-sdk.plugins';
import { AgTestServer } from './test-sdk.classes.testserver';
import { AAgHandler } from '@apiglobal/sdk';
export { AgTestServer };
export {
AgTestServer
};
let testServer: AgTestServer;
let handler: AAgHandler<any>;
export const createTestServer = async (handlerArg: {
new (envManagerArg: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any>;
}) => {
export const createTestServer = async (handlerArg: { new(envHandler: plugins.agSdk.AgEnvironment): plugins.agSdk.AAgHandler<any> }) => {
class AgEnvironement extends plugins.agSdk.AgEnvironment {
public qenv = new plugins.qenv.Qenv('./', './.nogit');
public async getEnvVar(nameArg: string) {
@ -44,10 +44,7 @@ export const testFire = <
const responsePromise = typedRequest.fire(requestArg);
const expect = async (expectedResponseArg: T['response']) => {
const actualResponse = await responsePromise;
const comparisonResult = plugins.smartobject.compareObjects(
expectedResponseArg,
actualResponse
);
const comparisonResult = plugins.smartobject.compareObjects(expectedResponseArg, actualResponse);
let throwErrorBool = false;
if (comparisonResult.divergingProperties.length > 0) {
console.log(`The following properties diverged:`);
@ -66,17 +63,12 @@ export const testFire = <
throwErrorBool = true;
}
if (throwErrorBool) {
console.log('Result: response did not comply');
console.log('-> expected:');
console.log(expectedResponseArg);
console.log('-> but actually received:');
console.log(actualResponse);
throw new Error('response did not comply');
}
return actualResponse;
};
return {
expect,
expect
};
};

View File

@ -1,4 +1,4 @@
import * as plugins from './test-sdk.plugins.js';
import * as plugins from './test-sdk.plugins';
export class AgTestServer {
public handlers: Array<plugins.agSdk.AAgHandler<any>> = [];

View File

@ -1,14 +0,0 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}