Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
905139785a | |||
c84a7192fb | |||
8dd8ce1b15 | |||
7022ae1a3c | |||
7ef17f9c41 | |||
aa8dcb734e | |||
c36459dfcc | |||
36903d2d6c | |||
c54493ddbc | |||
e98f109dcc | |||
32704386ee | |||
8ec3d593c1 | |||
f3f05b89d9 | |||
7104c8b1b5 | |||
dcb4ee301b | |||
df12f0ad83 | |||
01823fb683 | |||
649e69e1f2 | |||
05a361046e | |||
a551989f8b |
@ -6,8 +6,8 @@ on:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
IMAGE: code.foss.global/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
@ -26,7 +26,7 @@ jobs:
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
pnpm install -g @ship.zone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
@ -6,8 +6,8 @@ on:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
IMAGE: code.foss.global/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
@ -26,7 +26,7 @@ jobs:
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
@ -54,7 +54,7 @@ jobs:
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
@ -82,7 +82,7 @@ jobs:
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
@ -104,7 +104,7 @@ jobs:
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
|
59
changelog.md
59
changelog.md
@ -1,5 +1,64 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-11-23 - 5.5.3 - fix(docs)
|
||||
Update description and keywords in package files for clarity
|
||||
|
||||
- Updated project description in package.json and npmextra.json for better clarity.
|
||||
- Enhanced keywords list in package.json and npmextra.json to cover more relevant topics.
|
||||
- Revised README.md content to provide a more comprehensive usage guide and correct mismatched sections.
|
||||
|
||||
## 2024-11-23 - 5.5.2 - fix(core)
|
||||
Apply code cleanup and refactoring.
|
||||
|
||||
|
||||
## 2024-11-23 - 5.5.1 - fix(core)
|
||||
Update dependencies and add jestExpect export
|
||||
|
||||
- Updated '@push.rocks/qenv' to '^6.1.0' in dependencies.
|
||||
- Updated 'expect' package version to '^29.7.0' in dependencies.
|
||||
- Updated '@types/node' to '^22.9.3' in devDependencies.
|
||||
- Added jestExpect export in ts_node/index.ts.
|
||||
|
||||
## 2024-11-06 - 5.5.0 - feat(tapnodetools)
|
||||
Add TestFileProvider for handling Docker Alpine image
|
||||
|
||||
- Introduced TestFileProvider in TapNodeTools.
|
||||
- Added method to retrieve Docker Alpine image as a local tarball.
|
||||
|
||||
## 2024-11-06 - 5.4.4 - fix(dependencies)
|
||||
Update smarts3 dependency to version 2.2.5
|
||||
|
||||
|
||||
## 2024-11-06 - 5.4.3 - fix(TapNodeTools)
|
||||
Fix server port default value in createSmarts3 method
|
||||
|
||||
- The `createSmarts3` method in `TapNodeTools` now explicitly sets the port to 3003.
|
||||
|
||||
## 2024-11-06 - 5.4.2 - fix(dependencies)
|
||||
Update smarts3 dependency version to fix issues.
|
||||
|
||||
- Changed the version of @push.rocks/smarts3 from ^2.2.1 to ^2.2.2.
|
||||
|
||||
## 2024-11-06 - 5.4.1 - fix(ci)
|
||||
Fix CI configuration URL and package installation paths.
|
||||
|
||||
- Updated Docker image URL in CI config.
|
||||
- Fixed repository URL format in package.json.
|
||||
- Corrected npmci package installation path.
|
||||
|
||||
## 2024-11-06 - 5.4.0 - feat(node)
|
||||
Add smartmongo and smarts3 integration in node tools
|
||||
|
||||
- Added createSmartmongo method to TapNodeTools for creating SmartMongo instances.
|
||||
- Added createSmarts3 method to TapNodeTools for creating Smarts3 instances.
|
||||
- Updated dependencies with smartmongo and smarts3 in package.json.
|
||||
|
||||
## 2024-09-19 - 5.3.0 - feat(TapNodeTools)
|
||||
Add getEnvVarOnDemand method to TapNodeTools
|
||||
|
||||
- Introduced a new method getEnvVarOnDemand to the TapNodeTools class to fetch environment variables on demand.
|
||||
- Enhanced getQenv function in TapNodeTools class to cache the Qenv instance for better performance.
|
||||
|
||||
## 2024-09-19 - 5.2.2 - fix(core)
|
||||
Ensure reliability in test setup and execution
|
||||
|
||||
|
@ -14,22 +14,32 @@
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "tapbundle",
|
||||
"description": "A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.",
|
||||
"description": "A comprehensive testing automation library that provides a wide range of utilities and tools for TAP (Test Anything Protocol) based testing, especially suitable for projects using tapbuffer.",
|
||||
"npmPackagename": "@push.rocks/tapbundle",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"testing",
|
||||
"automation",
|
||||
"TAP",
|
||||
"test anything protocol",
|
||||
"Test Anything Protocol",
|
||||
"unit testing",
|
||||
"integration testing",
|
||||
"JavaScript",
|
||||
"TypeScript",
|
||||
"JavaScript",
|
||||
"test runner",
|
||||
"test framework",
|
||||
"web helpers",
|
||||
"test utilities"
|
||||
"test utilities",
|
||||
"asynchronous testing",
|
||||
"environment variables",
|
||||
"crypto",
|
||||
"shell commands",
|
||||
"Node.js",
|
||||
"cloud storage",
|
||||
"browser testing",
|
||||
"UI components",
|
||||
"parallel testing",
|
||||
"test lifecycle management"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
38
package.json
38
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@push.rocks/tapbundle",
|
||||
"private": false,
|
||||
"version": "5.2.2",
|
||||
"description": "A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.",
|
||||
"version": "5.5.3",
|
||||
"description": "A comprehensive testing automation library that provides a wide range of utilities and tools for TAP (Test Anything Protocol) based testing, especially suitable for projects using tapbuffer.",
|
||||
"exports": {
|
||||
".": "./dist_ts/index.js",
|
||||
"./node": "./dist_ts_node/index.js"
|
||||
@ -15,32 +15,38 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/tapbundle.git"
|
||||
"url": "git+https://code.foss.global/push.rocks/tapbundle.git"
|
||||
},
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/tapbundle/issues"
|
||||
"url": "https://code.foss.global/push.rocks/tapbundle/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/tapbundle",
|
||||
"homepage": "https://code.foss.global/push.rocks/tapbundle#readme",
|
||||
"dependencies": {
|
||||
"@open-wc/testing": "^4.0.0",
|
||||
"@push.rocks/consolecolor": "^2.0.2",
|
||||
"@push.rocks/qenv": "^6.0.5",
|
||||
"@push.rocks/qenv": "^6.1.0",
|
||||
"@push.rocks/smartcrypto": "^2.0.4",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartenv": "^5.0.12",
|
||||
"@push.rocks/smartexpect": "^1.2.1",
|
||||
"@push.rocks/smartfile": "^11.0.21",
|
||||
"@push.rocks/smartjson": "^5.0.20",
|
||||
"@push.rocks/smartmongo": "^2.0.10",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartpromise": "^4.0.4",
|
||||
"@push.rocks/smartrequest": "^2.0.23",
|
||||
"@push.rocks/smarts3": "^2.2.5",
|
||||
"@push.rocks/smartshell": "^3.0.6",
|
||||
"@push.rocks/smarttime": "^4.0.8"
|
||||
"@push.rocks/smarttime": "^4.0.8",
|
||||
"expect": "^29.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.43",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@types/node": "^22.5.5",
|
||||
"@types/node": "^22.9.3",
|
||||
"randomstring": "^1.3.0"
|
||||
},
|
||||
"files": [
|
||||
@ -62,14 +68,24 @@
|
||||
"testing",
|
||||
"automation",
|
||||
"TAP",
|
||||
"test anything protocol",
|
||||
"Test Anything Protocol",
|
||||
"unit testing",
|
||||
"integration testing",
|
||||
"JavaScript",
|
||||
"TypeScript",
|
||||
"JavaScript",
|
||||
"test runner",
|
||||
"test framework",
|
||||
"web helpers",
|
||||
"test utilities"
|
||||
"test utilities",
|
||||
"asynchronous testing",
|
||||
"environment variables",
|
||||
"crypto",
|
||||
"shell commands",
|
||||
"Node.js",
|
||||
"cloud storage",
|
||||
"browser testing",
|
||||
"UI components",
|
||||
"parallel testing",
|
||||
"test lifecycle management"
|
||||
]
|
||||
}
|
||||
|
4436
pnpm-lock.yaml
generated
4436
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
249
readme.md
249
readme.md
@ -1,122 +1,209 @@
|
||||
# @push.rocks/tapbundle
|
||||
tap bundled for tapbuffer
|
||||
|
||||
A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.
|
||||
|
||||
## Install
|
||||
Install the package by running the following command in your terminal:
|
||||
|
||||
To install the package, execute:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/tapbundle --save-dev
|
||||
```
|
||||
|
||||
This will add `@push.rocks/tapbundle` to your project's `devDependencies`.
|
||||
This command will add `@push.rocks/tapbundle` to your project's `devDependencies`, ensuring it is only used during development and testing.
|
||||
|
||||
## Usage
|
||||
The `@push.rocks/tapbundle` package is a tap-compatible testing framework written in TypeScript, intended for use with tapbuffer. It includes a range of useful features enabling easy setup and execution of tests, assertion handling through `expect` and `expectAsync`, as well as auxiliary tools for delay and colored console output.
|
||||
|
||||
### Getting Started
|
||||
First, ensure your project is set up with Typescript and supports ESM syntax. You can then import `tap`, `expect`, and `expectAsync` from `@push.rocks/tapbundle` to start defining your tests.
|
||||
The `@push.rocks/tapbundle` is a versatile testing framework compatible with TAP, designed using TypeScript to facilitate robust and scalable testing of applications, whether you are dealing with unit tests, integration tests, or simply need a streamlined way to automate assertions across your application’s lifecycle. The framework is especially useful if you are already using or planning to use tapbuffer.
|
||||
|
||||
```typescript
|
||||
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
|
||||
```
|
||||
**Getting Started**
|
||||
|
||||
Here is a simple test example:
|
||||
To begin using `tapbundle`, ensure that your TypeScript project is configured for ESM syntax. Here's how you can set it up and start writing your tests:
|
||||
|
||||
```typescript
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
1. **Basic Setup**
|
||||
|
||||
tap.test('should succeed on true assertion', async () => {
|
||||
return expect(true).toBeTrue();
|
||||
});
|
||||
First, import the necessary modules:
|
||||
|
||||
tap.start();
|
||||
```
|
||||
```typescript
|
||||
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
|
||||
```
|
||||
|
||||
### Defining Tests
|
||||
You can define tests with descriptions and async functions. The `tap` instance manages test execution, supports test skipping, and managing exclusive tests with the `.only` modifier.
|
||||
Start with a simple test to ensure everything is set up correctly:
|
||||
|
||||
```typescript
|
||||
const myTest = tap.test('expect true to be true', async () => {
|
||||
expect(true).toBeTrue();
|
||||
});
|
||||
```typescript
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
|
||||
const skippedTest = tap.skip.test('this test is skipped', async () => {
|
||||
// This will not be executed
|
||||
});
|
||||
tap.test('Initial test succeeds', async () => {
|
||||
return expect(true).toBeTrue();
|
||||
});
|
||||
|
||||
tap.only.test('only this test will run', async () => {
|
||||
expect('TapBundle').toContainString('Tap');
|
||||
});
|
||||
tap.start();
|
||||
```
|
||||
|
||||
tap.start();
|
||||
```
|
||||
The above code establishes a basic test environment, using the `tap` instance to manage execution flow and `expect` for assertions.
|
||||
|
||||
### Using `expect` and `expectAsync`
|
||||
The package provides `expect` and `expectAsync` for assertions:
|
||||
2. **Defining and Organizing Tests**
|
||||
|
||||
```typescript
|
||||
await expectAsync(Promise.resolve(true)).toBeResolved();
|
||||
expect(5).toBeGreaterThan(2);
|
||||
```
|
||||
You can define tests using the `tap.test` method, where you provide a description and an asynchronous function:
|
||||
|
||||
### Handling Asynchronous Operations
|
||||
`tapbundle` facilitates working with async operations in tests. You can introduce delays or set timeouts:
|
||||
```typescript
|
||||
tap.test('basic arithmetic test', async () => {
|
||||
expect(1 + 1).toEqual(2);
|
||||
});
|
||||
```
|
||||
|
||||
```typescript
|
||||
tap.test('async operation with delay', async (tools) => {
|
||||
await tools.delayFor(2000); // Wait for 2000 milliseconds
|
||||
expect(true).toBeTrue();
|
||||
});
|
||||
**Async Tests Handling**
|
||||
|
||||
tap.start();
|
||||
```
|
||||
Use `expectAsync` for promises or async operations:
|
||||
|
||||
### Advanced Usage
|
||||
#### Pre Tasks
|
||||
You can define tasks to run before test execution begins:
|
||||
```typescript
|
||||
tap.test('async operation test', async () => {
|
||||
const fetchData = async () => Promise.resolve('data');
|
||||
await expectAsync(fetchData()).toBeResolved();
|
||||
});
|
||||
```
|
||||
|
||||
```typescript
|
||||
tap.preTask('setup database', async () => {
|
||||
// Perform setup here
|
||||
});
|
||||
3. **Tools for Advanced Testing**
|
||||
|
||||
tap.test('test database connection', async () => {
|
||||
// Test the setup
|
||||
});
|
||||
`tapbundle` equips you with tools for sophisticated test scenarios:
|
||||
|
||||
tap.start();
|
||||
```
|
||||
- **Delay and Timing**
|
||||
|
||||
#### Accessing Test Metadata
|
||||
Each test returns a `TapTest` instance, from which you can access metadata and manipulate test behavior:
|
||||
Integrated delay methods are handy for simulating timeouts and waiting states:
|
||||
|
||||
```typescript
|
||||
const test = tap.test('metadata example', async (tools) => {
|
||||
tools.allowFailure();
|
||||
expect(true).toBeTrue();
|
||||
});
|
||||
```typescript
|
||||
tap.test('test with delay', async (tools) => {
|
||||
await tools.delayFor(500); // waits for 500ms
|
||||
expect(true).toBeTrue();
|
||||
});
|
||||
```
|
||||
|
||||
tap.start().then(() => {
|
||||
console.log(`Test duration: ${test.hrtMeasurement.milliSeconds}ms`);
|
||||
});
|
||||
```
|
||||
- **Custom Pre Tasks**
|
||||
|
||||
### Running Tests
|
||||
Tests are executed by calling `tap.start()`. This method runs all defined tests in sequence and respects `.skip` and `.only` modifiers.
|
||||
Set up tasks to run before your test suite begins. This can be setup operations like initializing databases:
|
||||
|
||||
### Debugging and Output
|
||||
`@push.rocks/tapbundle` supports colored console output via `consolecolor` to help with debugging and test result readability:
|
||||
```typescript
|
||||
tap.preTask('initialize environment', async () => {
|
||||
console.log('Setting up preconditions');
|
||||
});
|
||||
```
|
||||
|
||||
```typescript
|
||||
tap.test('colored output', async (tools) => {
|
||||
const coloredString = await tools.coloredString('Hello, world!', 'green');
|
||||
console.log(coloredString);
|
||||
});
|
||||
4. **Execution and Control**
|
||||
|
||||
tap.start();
|
||||
```
|
||||
- **Running Tests**
|
||||
|
||||
This detailed guide covers the most important aspects of using `@push.rocks/tapbundle` for testing in your TypeScript projects. Explore the included functions and tools to fully leverage this comprehensive testing framework.
|
||||
Call `tap.start()` to execute your suite. Handle specific conditions using `.skip` or `.only`:
|
||||
|
||||
```typescript
|
||||
tap.skip.test('skip this test', async () => {
|
||||
// This test will be ignored
|
||||
});
|
||||
|
||||
tap.only.test('run this test exclusively', async () => {
|
||||
// Only this test will run among defined tests
|
||||
});
|
||||
```
|
||||
|
||||
- **Handling Errors and Debugging**
|
||||
|
||||
Make use of `consolecolor` to make outputs readable:
|
||||
|
||||
```typescript
|
||||
tap.test('test with colored output', async (tools) => {
|
||||
const message = await tools.coloredString('Test Passed!', 'green');
|
||||
console.log(message);
|
||||
});
|
||||
```
|
||||
|
||||
5. **Integration with Node Tools**
|
||||
|
||||
For operations involving the shell or environment-specific setups, use Node tools provided:
|
||||
|
||||
```typescript
|
||||
import { tapNodeTools } from './ts_node/index.js';
|
||||
|
||||
tap.test('execute shell command', async () => {
|
||||
const result = await tapNodeTools.runCommand('ls -la');
|
||||
expect(result.exitCode).toEqual(0);
|
||||
});
|
||||
|
||||
tap.test('create HTTPS certificate', async () => {
|
||||
const { key, cert } = await tapNodeTools.createHttpsCert('localhost');
|
||||
expect(key).toInclude('-----BEGIN RSA PRIVATE KEY-----');
|
||||
expect(cert).toInclude('-----BEGIN CERTIFICATE-----');
|
||||
});
|
||||
```
|
||||
|
||||
6. **Working with Environment Variables**
|
||||
|
||||
Leverage the power of dynamic environment management using `qenv`:
|
||||
|
||||
```typescript
|
||||
tap.test('use environment variable', async (tools) => {
|
||||
const dbUrl = await tools.getEnvVarOnDemand('DB_URL');
|
||||
expect(dbUrl).toBeDefined();
|
||||
});
|
||||
```
|
||||
|
||||
7. **Managing Asynchronous Behavior**
|
||||
|
||||
The framework allows for precise control over asynchronous processes, introducing race conditions or coordinated delays:
|
||||
|
||||
```typescript
|
||||
tap.test('controlled async scenario', async (tools) => {
|
||||
const asyncOp = async () => Promise.resolve('complete');
|
||||
tools.timeout(1000); // if operation exceeds 1000ms, test fails
|
||||
const result = await asyncOp();
|
||||
expect(result).toBe('complete');
|
||||
});
|
||||
```
|
||||
|
||||
8. **Web Testing Utilities**
|
||||
|
||||
If your testing involves browser environments, make use of the `webhelpers` utilities, for instance with libraries like Open WC:
|
||||
|
||||
```typescript
|
||||
import { webhelpers } from './webhelpers.js';
|
||||
|
||||
tap.test('web component test', async () => {
|
||||
const element = await webhelpers.fixture(webhelpers.html`<my-element></my-element>`);
|
||||
expect(element.shadowRoot.querySelector('div')).toBeDefined();
|
||||
});
|
||||
```
|
||||
|
||||
9. **Using Webhelpers in Browser**
|
||||
|
||||
Make the tests more interactive, especially for UI Components:
|
||||
|
||||
```typescript
|
||||
tap.preTask('Setup pre-task for UI test', async () => {
|
||||
console.log('Setting up for UI tests');
|
||||
});
|
||||
|
||||
tap.test('UI test with Web Component', async () => {
|
||||
const myEl = await webhelpers.fixture(webhelpers.html`<div id="myEl">Content</div>`);
|
||||
expect(myEl.id).toBe('myEl');
|
||||
});
|
||||
```
|
||||
|
||||
10. **Leveraging Smartmongo and Smarts3**
|
||||
|
||||
Whether you’re working with databases or cloud storage simulations:
|
||||
|
||||
```typescript
|
||||
tap.test('Smartmongo setup test', async () => {
|
||||
const smartmongo = await tapNodeTools.createSmartmongo();
|
||||
await smartmongo.stop();
|
||||
});
|
||||
|
||||
tap.test('Smarts3 setup', async () => {
|
||||
const smarts3 = await tapNodeTools.createSmarts3();
|
||||
console.log('Smarts3 running');
|
||||
await smarts3.stop();
|
||||
});
|
||||
```
|
||||
|
||||
Integrating `@push.rocks/tapbundle` streamlines your test management in complex projects. With these tools, intricate scenarios from unit tests to more elaborate integrated environments become easier to handle, providing a structured flow to achieve reliable testing outcomes. Happy testing!
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
|
@ -23,10 +23,10 @@ const test3 = tap.test(
|
||||
async () => {
|
||||
expect(
|
||||
(await test1.testPromise).hrtMeasurement.milliSeconds <
|
||||
(await test2).hrtMeasurement.milliSeconds
|
||||
(await test2).hrtMeasurement.milliSeconds,
|
||||
).toBeTrue();
|
||||
expect((await test2.testPromise).hrtMeasurement.milliSeconds > 10).toBeTrue();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const test4 = tap.skip.test('my 4th test -> should fail', async (tools) => {
|
||||
|
@ -15,4 +15,14 @@ tap.test('should create a https cert', async () => {
|
||||
expect(cert).toInclude('-----BEGIN CERTIFICATE-----');
|
||||
});
|
||||
|
||||
tap.test('should create a smartmongo instance', async () => {
|
||||
const smartmongo = await tapNodeTools.createSmartmongo();
|
||||
await smartmongo.stop();
|
||||
});
|
||||
|
||||
tap.test('should create a smarts3 instance', async () => {
|
||||
const smarts3 = await tapNodeTools.createSmarts3();
|
||||
await smarts3.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -17,10 +17,10 @@ const test3 = tap.test(
|
||||
async () => {
|
||||
expect(
|
||||
(await test1.testPromise).hrtMeasurement.milliSeconds <
|
||||
(await test2).hrtMeasurement.milliSeconds
|
||||
(await test2).hrtMeasurement.milliSeconds,
|
||||
).toBeTrue();
|
||||
expect((await test2.testPromise).hrtMeasurement.milliSeconds > 1000).toBeTrue();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const test4 = tap.test('my 4th test -> should fail', async (tools) => {
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/tapbundle',
|
||||
version: '5.2.2',
|
||||
description: 'A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.'
|
||||
version: '5.5.3',
|
||||
description: 'A comprehensive testing automation library that provides a wide range of utilities and tools for TAP (Test Anything Protocol) based testing, especially suitable for projects using tapbuffer.'
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ export class Tap<T> {
|
||||
public test(
|
||||
testDescription: string,
|
||||
testFunction: ITestFunction<T>,
|
||||
modeArg: 'normal' | 'only' | 'skip' = 'normal'
|
||||
modeArg: 'normal' | 'only' | 'skip' = 'normal',
|
||||
): TapTest<T> {
|
||||
const localTest = new TapTest<T>({
|
||||
description: testDescription,
|
||||
@ -67,7 +67,7 @@ export class Tap<T> {
|
||||
description: testDescription,
|
||||
testFunction,
|
||||
parallel: true,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ export class Tap<T> {
|
||||
failReasons.push(
|
||||
`Test ${tapTest.testKey + 1} failed with status ${tapTest.status}:\n` +
|
||||
`|| ${tapTest.description}\n` +
|
||||
`|| for more information please take a look the logs above`
|
||||
`|| for more information please take a look the logs above`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ export class Tap<T> {
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
process.exit(codeArg);
|
||||
}, 10)
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ export class TapTest<T = unknown> {
|
||||
}
|
||||
this.hrtMeasurement.stop();
|
||||
console.log(
|
||||
`ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`
|
||||
`ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`,
|
||||
);
|
||||
this.status = 'success';
|
||||
this.testDeferred.resolve(this);
|
||||
@ -64,7 +64,7 @@ export class TapTest<T = unknown> {
|
||||
} catch (err: any) {
|
||||
this.hrtMeasurement.stop();
|
||||
console.log(
|
||||
`not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`
|
||||
`not ok ${testNumber} - ${this.description} # time=${this.hrtMeasurement.milliSeconds}ms`,
|
||||
);
|
||||
this.testDeferred.resolve(this);
|
||||
this.testResultDeferred.resolve(err);
|
||||
|
@ -1,12 +1,20 @@
|
||||
import { TestFileProvider } from './classes.testfileprovider.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
class TapNodeTools {
|
||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||
public testFileProvider = new TestFileProvider();
|
||||
|
||||
constructor() {}
|
||||
|
||||
private qenv: plugins.qenv.Qenv;
|
||||
public async getQenv(): Promise<plugins.qenv.Qenv> {
|
||||
return new plugins.qenv.Qenv('./', '.nogit/');
|
||||
this.qenv = this.qenv || new plugins.qenv.Qenv('./', '.nogit/');
|
||||
return this.qenv;
|
||||
}
|
||||
public async getEnvVarOnDemand(envVarNameArg: string): Promise<string> {
|
||||
const qenv = await this.getQenv();
|
||||
return qenv.getEnvVarOnDemand(envVarNameArg);
|
||||
}
|
||||
|
||||
public async runCommand(commandArg: string): Promise<any> {
|
||||
@ -62,6 +70,29 @@ class TapNodeTools {
|
||||
cert: pemCert,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* create and return a smartmongo instance
|
||||
*/
|
||||
public async createSmartmongo() {
|
||||
const smartmongoMod = await import('@push.rocks/smartmongo');
|
||||
const smartmongoInstance = new smartmongoMod.SmartMongo();
|
||||
await smartmongoInstance.start();
|
||||
return smartmongoInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* create and return a smarts3 instance
|
||||
*/
|
||||
public async createSmarts3() {
|
||||
const smarts3Mod = await import('@push.rocks/smarts3');
|
||||
const smarts3Instance = new smarts3Mod.Smarts3({
|
||||
port: 3003,
|
||||
cleanSlate: true,
|
||||
});
|
||||
await smarts3Instance.start();
|
||||
return smarts3Instance;
|
||||
}
|
||||
}
|
||||
|
||||
export const tapNodeTools = new TapNodeTools();
|
||||
|
17
ts_node/classes.testfileprovider.ts
Normal file
17
ts_node/classes.testfileprovider.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from './paths.js';
|
||||
|
||||
export const fileUrls = {
|
||||
dockerAlpineImage: 'https://code.foss.global/testassets/docker/raw/branch/main/alpine.tar',
|
||||
}
|
||||
|
||||
export class TestFileProvider {
|
||||
public async getDockerAlpineImageAsLocalTarball(): Promise<string> {
|
||||
const filePath = plugins.path.join(paths.testFilesDir, 'alpine.tar')
|
||||
// fetch the docker alpine image
|
||||
const response = await plugins.smartrequest.getBinary(fileUrls.dockerAlpineImage);
|
||||
await plugins.smartfile.fs.ensureDir(paths.testFilesDir);
|
||||
const AlpineBuffer = await plugins.smartfile.memory.toFs(response.body, filePath);
|
||||
return filePath;
|
||||
}
|
||||
}
|
@ -1 +1,5 @@
|
||||
export * from './classes.tapnodetools.js';
|
||||
|
||||
import { expect as jestExpect } from 'expect';
|
||||
|
||||
export { jestExpect };
|
||||
|
4
ts_node/paths.ts
Normal file
4
ts_node/paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export const cwd = process.cwd();
|
||||
export const testFilesDir = plugins.path.join(cwd, './.nogit/testfiles/');
|
@ -1,12 +1,16 @@
|
||||
// node native
|
||||
import * as crypto from 'crypto';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export { crypto,fs };
|
||||
export { crypto,fs, path, };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartcrypto from '@push.rocks/smartcrypto';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { qenv, smartcrypto, smartshell };
|
||||
export { qenv, smartcrypto, smartfile, smartpath, smartrequest, smartshell, };
|
||||
|
@ -6,9 +6,11 @@
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user