2023-08-12 09:40:29 +00:00
# @push.rocks/tapbundle
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.
2020-07-08 00:17:31 +00:00
2024-04-14 16:36:42 +00:00
## Install
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
To install the package, execute:
2024-04-14 16:36:42 +00:00
```bash
npm install @push .rocks/tapbundle --save-dev
```
2024-11-23 17:42:31 +00:00
This command will add `@push.rocks/tapbundle` to your project's `devDependencies` , ensuring it is only used during development and testing.
2020-07-08 00:17:31 +00:00
## Usage
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
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.
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
**Getting Started**
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
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:
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
1. **Basic Setup**
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
First, import the necessary modules:
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
```typescript
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
```
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
Start with a simple test to ensure everything is set up correctly:
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
```typescript
import { tap, expect } from '@push.rocks/tapbundle';
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
tap.test('Initial test succeeds', async () => {
return expect(true).toBeTrue();
});
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
tap.start();
```
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
The above code establishes a basic test environment, using the `tap` instance to manage execution flow and `expect` for assertions.
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
2. **Defining and Organizing Tests**
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
You can define tests using the `tap.test` method, where you provide a description and an asynchronous function:
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.test('basic arithmetic test', async () => {
expect(1 + 1).toEqual(2);
});
```
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
**Async Tests Handling**
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
Use `expectAsync` for promises or async operations:
2022-02-15 15:48:03 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.test('async operation test', async () => {
const fetchData = async () => Promise.resolve('data');
await expectAsync(fetchData()).toBeResolved();
});
```
2022-02-15 15:48:03 +00:00
2024-11-23 17:42:31 +00:00
3. **Tools for Advanced Testing**
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
`tapbundle` equips you with tools for sophisticated test scenarios:
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
- **Delay and Timing**
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
Integrated delay methods are handy for simulating timeouts and waiting states:
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.test('test with delay', async (tools) => {
await tools.delayFor(500); // waits for 500ms
expect(true).toBeTrue();
});
```
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
- **Custom Pre Tasks**
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
Set up tasks to run before your test suite begins. This can be setup operations like initializing databases:
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.preTask('initialize environment', async () => {
console.log('Setting up preconditions');
});
```
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
4. **Execution and Control**
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
- **Running Tests**
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
Call `tap.start()` to execute your suite. Handle specific conditions using `.skip` or `.only` :
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.skip.test('skip this test', async () => {
// This test will be ignored
});
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
tap.only.test('run this test exclusively', async () => {
// Only this test will run among defined tests
});
```
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
- **Handling Errors and Debugging**
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
Make use of `consolecolor` to make outputs readable:
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
```typescript
tap.test('test with colored output', async (tools) => {
const message = await tools.coloredString('Test Passed!', 'green');
console.log(message);
});
```
2024-04-14 16:36:42 +00:00
2024-11-23 17:42:31 +00:00
5. **Integration with Node Tools**
2024-11-06 01:47:44 +00:00
2024-11-23 17:42:31 +00:00
For operations involving the shell or environment-specific setups, use Node tools provided:
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
```typescript
import { tapNodeTools } from './ts_node/index.js';
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
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();
});
```
2020-07-08 00:17:31 +00:00
2024-11-23 17:42:31 +00:00
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!
2024-04-14 16:36:42 +00:00
## License and Legal Information
2024-11-23 17:42:31 +00:00
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.
2024-04-14 16:36:42 +00:00
**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
2020-07-08 00:17:31 +00:00
2024-04-14 16:36:42 +00:00
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
2020-07-08 00:17:31 +00:00
2024-04-14 16:36:42 +00:00
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
2020-07-08 00:17:31 +00:00
2024-04-14 16:36:42 +00:00
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.