Coder Social home page Coder Social logo

aspecto-io / malabi Goto Github PK

View Code? Open in Web Editor NEW
200.0 200.0 6.0 545 KB

Tracing Based JavaScript Assertions

Home Page: https://aspecto-io.github.io/malabi/index.html

License: Apache License 2.0

TypeScript 99.21% JavaScript 0.79%
javascript nodejs opentelemetry testing tracing

malabi's People

Contributors

aspectom avatar blumamir avatar habmic avatar matthewhembree avatar mottibec avatar orgeva10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

malabi's Issues

Support filtering by elasticsearch spans

Currently, we allow to filter by specific databases/orm like mongo/sequelize.

We want to enable this same behavior on elasticsearch, so users could filter by elasticsearch spans easily.

This is an example of usage in sequelize

const sequelizeActivities = spans.sequelize();
expect(sequelizeActivities.length).toBe(1);
expect(sequelizeActivities.first.dbOperation).toBe("SELECT");
expect(Array.isArray(JSON.parse(sequelizeActivities.first.dbResponse))).toBe(true);

We would want to enable something like this:

const esSpans = spans.elasticsearch();
expect(esSpans.length).toBe(1);

It means to implement this filter in SpansRepository class. See how it's implemented for mongo/sequelize etc.

Use test name as tracer name

In 'packages/malabi/src/instrumentation/index.ts', Instead of 'malabiRoot', we should dynamically take the name of the current test (name of the 'it' clause), and use it as tracer name.

This way, if at any time the user is looking at his traces in jaeger, he could know which test they belong to.

API Proposals

Split extract and expect

import { extract, expect, getSpans } from 'malabi';

it('http', () => {
    const spans = getSpans();

    const httpSpan = extract(spans).http().method('post').incoming().first();
    expect(httpSpan).statusCode().toBe(200);
    expect(httpSpan).successStatusCode();
    expect(httpSpan).requestBody().toContain('admin');
    expect(httpSpan).requestHeaders('origin').toBe('http://localhost:3000');
});

it('mongo', () => {
    const spans = getSpans();

    const mongoSpan = extract(spans).mongo().second();
    expect(mongoSpan).operation().toBe('findOne');
    expect(mongoSpan).duration().lessThan(3000);
    expect(mongoSpan).statement().toHaveKey('token');
});

extract + where in single statement

import { expect, getSpans } from 'malabi';

it('http', () => {
    const spans = getSpans();

    expect(spans).http().method('post').incoming().first().where([
        expect.statusCode(200),
        expect.successStatusCode,
        expect.requestBody.contains('admin')
    ])
});

Assert existence in spans array, followed by condition

Style 1 - use where

import { expect, getSpans } from 'malabi';

it('mongo', () => {
    const spans = getSpans();

    expect(spans).toHaveMongo()
        .where([
            expect.operation("findOne"),
            expect.duration.lessThanMs(3000),
            expect.parentSpan.exists(),
            expect.statement.hasKey('token')
        ])
});

Style 2 - conditions object

import { expect, getSpans } from 'malabi';

it('mongo', () => {
    const spans = getSpans();

    expect(spans).toHaveMongo({
        operation: "findOne",
        duration: expect.lessThan(3000),
        parentSpans: expect.exists(),
        statement: expect.hasKey('token')
    });
});

jasmine style option

replace toHaveMongo with jasmine style, ie: expect(spans).to.have.mongo, or expect(spans).to.not.have.mongo

Roadmap issues

Hello @blumamir @aspectom , I really find tracing testing intriguing as it solves many of the problem that we can have for a less buggy production application, I would love to work on such amazing project. Do you have any roadmap for the project and what it needs in the coming future ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.