GithubHelp home page GithubHelp logo

tanay-pingalkar / oral Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 106 KB

a decorator based testing framework for typescript

License: MIT License

JavaScript 0.35% TypeScript 99.65%
typescript testing testing-tools testing-framework typescript-decorators tdd unit-test oral

oral's Introduction

@ral

an open source decorator based testing framework for typescript

features

  • decorator based testing
  • watch mode
  • async tests with not efforts

install

currently this repo is not released yet so you have to fork and clone the repo before using it.
run npm install
run cd examples && npm install
run oral

how to write tests in oral

writing tests in oral is same as writing tests in other framework but in oral, there is no describe and no it, instead of that, it usesname of you class as description of you tests. To get started with it
touch oral.config.ts && mkdir tests

  • oral.config.ts
module.export = {
  testDir: "/tests",
};

cd tests && touch firstTest.test.ts

inside firstTest.test.ts

import { Suit, Equal } from "oral";

@Suite()
export class myFirstTest {
  @Equal("this should pass")
  thisShouldPass() {
    return "this should pass";
  }

  @Equal(5)
  thisShouldFail() {
    return 2 + 2;
  }
}

save and run oral --watch

output

and here you go..

cli options

oral location of config file --watch --testDir /tests/ --clear --noclear --help --version --notify --file name_of_file
all cli options can be inclue in oral.config.ts

Api

@Equal()
@Suite()
@Contain()
@Match()
@True()
@False()
@GreaterThan()
@LessThan()
@Instanceof()
@Typeof()
@Extend()
@Before()
@After()
@Util()
@BeforeEach()
@AfterEach()
more coming soon.
detailed examples in example/tests folder...
continue reading to know more...

@Before() and @After()

import { Suite, Before, After, Equal } from "oral";
@Suite()
export class beforeAfterTest {
  name: string;
  @Before()
  before() {
    this.name = "a name";
    // create connection
  }

  @Equal("a name")
  shouldReturnName() {
    return this.name;
  }

  @After()
  after() {
    this.name = undefied;
    // drop database
  }
}

@Util()

import { Util, Suit, GreaterThan } from "oral";
@Suite()
export class utilTest {
  @Util()
  @GreaterThan(5)
  aUtil(num1: number, num2: number) {
    return num1 + num2;
  }

  realTest() {
    this.aUtil();
  }
}

beforeEveryone & afterEveryone

do not support in new version currenly, available soon !!! git checkout old to use this

  • oral.config.ts
function Afunc() {
  // create database
  return "a global string";
}
module.export = {
  beforeEveryone: Afunc,
};
  • aTest.test.ts
import { Suite, Equal } from "oral";
@Suite()
export class aTest {
  str: string;
  constructure(str: string) {
    this.str = str; // aFunc's returned value
  }

  @Equal()
  checkIfStrExist() {
    return this.str;
  }
}

@Extend()

import { Extend, Suite } from "oral";

const decoratorFunc = (val: string) => {
  if (val === "a string") return true;
  return false;
};

@Suite()
export class extendDecoratorTest {
  @Extend("my own decorator", decoratorFunc)
  extendDecoratorTesting() {
    return "a string";
  }

  @Extend("my own decorator", decoratorFunc)
  extendDecoratorTestingFail() {
    return "a false string";
  }
}

@BeforeEach() & @AfterEach()

import { Suite, Equal, BeforeEach, AfterEach } from "oral";

@Suite()
export class beforeEveryone {
  num = 0;
  @BeforeEach()
  beforeEach() {
    this.num = this.num + 1;
  }
  @AfterEach()
  beforeEach() {
    this.num = 0;
  }
  @Equal(1)
  checkIfEqualOne() {
    return this.num;
  }

  @Equal(1)
  checkIfEqualOneAgain() {
    return this.num;
  }
}

philosophy

Hello i am tanay pingalkar. I like to code things that helps other and are open and free. I have created this testing framework for using the power of decorators and to give testers a complete new exciting workflow. This framework is typescript specific and dedicated to it. This framework believe that every assertion counts the quality of software and thats why every method in a class is a assertion. I currently dont have a good name but I call it "oral" (@ral) for some reason. Suggestion for name is needed. This project is open source and Licensed under MIT License. I will like to see feedback and ideas on github issues to make it better.

contribution

this porject is open source and will always live open source. Contributer's are highly welcome and appreciated. You can read CONTRIBUTING.md and CODE_OF_CONDUCT.md to know more about contribution process.

oral's People

Contributors

tanay-pingalkar avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

gitter-badger

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.