Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vajahath/testeves
A workaround testing strategy for highly coupled legacy codebase.
https://github.com/vajahath/testeves
Last synced: about 13 hours ago
JSON representation
A workaround testing strategy for highly coupled legacy codebase.
- Host: GitHub
- URL: https://github.com/vajahath/testeves
- Owner: vajahath
- License: mit
- Created: 2019-10-29T07:11:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T23:45:19.000Z (about 2 years ago)
- Last Synced: 2025-01-14T02:06:24.995Z (6 days ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@vaju/testeves
- Size: 1.35 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# testeves
![](https://github.com/vajahath/testeves/workflows/Build-and-test/badge.svg) [![Greenkeeper badge](https://badges.greenkeeper.io/vajahath/testeves.svg)](https://greenkeeper.io/)
A workaround testing strategy for highly coupled legacy codebase.
## Why
Sometimes you need to test some legacy code which is not actually testable. Refactoring the codebase to write testable code may be hard or it doesn't worth.
## How
It's important to learn how testeves works. It is a simple concept.
You emit events at critical points in the codebase. The test agent will listen for these events and execute expectations.## Install
Requires Node >= 8.
From npm:
```sh
npm install @vaju/testeves
```From [Github Package Registry](https://github.com/vajahath/testeves/packages). ([Guide](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages)).
_(✔ Type definitions included for TypeScript)_
## Usage
The tests for this repo ([inside the `/tests` dir](https://github.com/vajahath/testeves/tree/master/tests)) is an ideal example.
The code you need to test: `foo.js`
```js
const { Testeves } = require('@vaju/testeves');
// or
import { Testeves } from '@vaju/testeves';// create a hook
const hook = new Testeves();// ... somewhere in the actual codebase we want to test ...
function foo() {
['a', 'b', 'c'].forEach(item => {
// emit events
hook.emit({ [item]: true });
});
// when the flow is complete, call finishProcess().
return hook.finishProcess();
}module.exports = { foo, hook };
```Then the test file: `foo.spec.js`
```js
const { foo, hook } = require('./foo');// Start the observer. Here is where
// the emitted events are stored.
const observer = hook.listen();// Before running into actual tests, wait for
// the entire flow to complete.
beforeAll(() => {
// invoke the function.
foo();
// hook.isFinished returns a promise, which is
// resolved when the hook.finishProcess() is called
// in the testing code.
return hook.isFinished;
});describe('testing', () => {
test('testing a', () => {
// the observer object stores the emitted
// events and their values.
expect(observer.a).toBe(true);
});
test('testing b', () => {
expect(observer.b).toBe(true);
});
test('testing c', () => {
expect(observer.c).toBe(true);
});
});
```## Licence
MIT © [Vajahath Ahmed](https://twitter.com/vajahath7)