nole
v3.0.0
Published
Testing Library for Typescript projects
Readme

Nole
Nole is a testing platform just like mocha..
Breaking change at nole v3, plain old classes are better at this task.
Use nole 2.x for ESM and Typescript.
Use nole 1.x for CommonJS. (ability to disable Typescript with -T option)
// test/queue.test.ts
import { Test } from "nole";
export class QueueTest extends Test() {
queue!: Queue;
createInstance() {
this.queue = new Queue();
}
push() {
this.queue.push(10);
}
async pipe() {
await this.queue.pipe(somewhere);
}
}$ nole ./test/**/*.test.ts
(ok) 0.09 ms QueueTest.createInstance()
(ok) 0.11 ms QueueTest.push()
(ok) 1.09 ms QueueTest.pipe()Skip
You can skip tests. Make sure method name starts with skip
// test/queue.test.ts
import { Test } from "nole";
export class QueueTest extends Test() {
skip_Push() {
this.queue.push(10);
}
}$ nole ./**/test/*.test.ts
(skip) QueueTest.skip_Push() {marked as skipped}// test/queue.test.ts
import { Test } from "nole";
export class QueueTest extends Test({
skip: "no need",
}) {
push() {
this.queue.push(10);
}
}$ nole ./**/test/*.test.ts
(skip) QueueTest.skip_Push() {no need}Dependencies
You can include other tests and wait them to complete.
// test/database.test.ts
import { Test } from "nole";
export class Database extends Test() {
connection!: any;
async connect() {
connection = new Connection("...");
await connection.connect();
}
}// test/other.test.ts
import { Test } from "nole";
import { Database } from "./database.test";
export class Other extends Test({
dependencies: {
database: () => Database,
},
}) {
async DoThings() {
await this.database.connection.doStuff();
}
}
- All dependencies will be waited until done
- If dependencies cannot resolve, it will occurr an error after the available tests done.
Wait other tests
// test/redis.test.ts
import { Test } from "nole";
export class A extends Test() {
async doThings() {}
}
export class B extends Test({ before: () => [A] }) {
async doThings() {}
}Hook
Hooks will help you to develop helper methods.
// test/hook.test.ts
import { Test } from "nole";
export class HookTest {
value!: number;
async beforeEach() {
this.value = Math.random();
}
validateNumber() {
if (this.value > 0.5) {
throw new Error("Should not be higher than 0.5");
}
}
}Dynamic Tests
// test/dynamic.test.ts
import { Test, addTest } from "nole";
// not exported, nole cannot auto-bind this class
class DynamicTest extends Test() {
test() {}
}
// adds it anyway
addTest(() => DynamicTest);// test/dynamic2.test.ts
import { Test, addTest } from "nole";
if (something) {
addTest(
() =>
class Special extends Test() {
check() {}
},
);
}// test/dynamic3.test.ts
import { Test, addTest } from "nole";
export class DeepTest extends Test() {
check() {
if (something) {
addTest(() => class Wololo extends Test() {});
}
}
}Test cleanup
There is a special hook that can be used to capture test finishing stage.
Lifecycle:
- (class) Before
- (method) BeforeEach
- (method) Spec
- (method) AfterEach
- (class) After
- (class) CleanUp *called after dependency execution
// test/database-with-cleanup.test.ts
import { Test } from "nole";
export class DatabaseWithCleanup extends Test() {
connection!: any;
async connect() {
this.connection = new Connection("...");
await connection.connect();
}
async cleanUp() {
this.connection.close();
console.log("Connection closed!");
}
}// test/other.test.ts
import { Test } from "nole";
import { Database } from "./database.test";
export class Other extends Test({
dependencies: {
database: () => DatabaseWithCleanup,
},
}) {
async doThings() {
await this.database.connection.doStuff();
}
}$ nole ./test/**/*.test.ts
(ok) 0.09 ms DatabaseWithCleanup.connect()
(ok) 0.11 ms Other.doThings()
Connection closed!Test extending
If they are classes we should be able to extend them right
// test/extending.test.ts
import { Test } from "nole";
// Simple is not exported, so nole wont handle it
class Simple extends Test() {
value = 1;
check() {
if (this.value !== 1) {
// yeah it should be 1 anyway
}
}
}
export class Complex extends Simple {
check() {
if (this.value > 0) {
// maybe it is more than just 1?
}
super.check(); // or
}
}
export class MoreComplex extends Simple {
moreSpecs() {
// mooree
}
}$ nole ./test/**/*.test.ts
(ok) 0.09 ms Complex.check()
(ok) 0.11 ms MoreComplex.check()
(ok) 0.11 ms MoreComplex.moreSpecs()