# @anderjason/tests

> A simple, lightweight test system for Typescript projects.

Latest version **2.0.0** (published 2021-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @anderjason/tests
pnpm add @anderjason/tests
yarn add @anderjason/tests
bun add @anderjason/tests
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-10-26 |
| First published | 2020-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jason Anderson |
| Maintainers | anderjason |

## Links

- npm: https://www.npmjs.com/package/@anderjason/tests
- Repository: https://github.com/anderjason/tests
- Homepage: https://github.com/anderjason/tests#readme
- Issues: https://github.com/anderjason/tests/issues
- npm.io page: https://npm.io/package/@anderjason/tests

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.4.4

## Recent versions

- 2.0.0 (latest) — 2021-10-26
- 1.0.1 — 2020-10-04
- 1.0.0 — 2020-09-06

## README

# @anderjason/tests

A simple, lightweight test system for Typescript projects.

## Installation

`npm install --save @anderjason/tests`

### Setting up the test system for your project

The instructions below assume that you already have a Typescript project.

Step 1: In your `tsconfig.json` file, exclude any test files (which will end with `.test.ts`) from your main build:

```
{
  "exclude": ["src/**/*.test.ts"],
  "include": ["src/**/*"]
}
```

Step 2: Add a `tsconfig.test.json` file in the root of your project with these contents:

```
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "declaration": false,
    "outDir": "./test/",
    "sourceMap": false
  },
  "exclude": []
}
```

Step 3: Add a script entry to your `package.json` file:

```
  "scripts": {
    "test": "tsc -p tsconfig.test.json && node test/index.test && rm -rf test"
  },
```

Step 4: Create a file at `src/index.test.ts` with the following contents:

```
import { Test } from "@anderjason/tests";
// TODO: Import your test files here

Test.runAll()
  .then(() => {
    console.log("Tests complete");
  })
  .catch((err) => {
    console.error(err);
    console.error("Tests failed");
  });
```

### Adding a simple example test

Step 1: Create a file containing one or more tests. The file can be anywhere in your project, and the filename should end with `.test.ts`

```
import { Test } from "@anderjason/tests";

Test.define("Hello has 5 characters", () => {
  Test.assert("hello".length === 5);
});

Test.define("Hello has 3 characters", () => {
  // this test will fail
  Test.assert("hello".length === 3);
});

// You can use async tests too
Test.define("This callback returns Promise<void>", async () => {

});
```

Step 2: From your root test file (`src/index.test.ts`) import the test file you created in the previous step:

```
import { Test } from "@anderjason/tests";
import "./mytest.test"

Test.runAll()
  .then(() => {
    console.log("Tests complete");
  })
  .catch((err) => {
    console.error(err);
    console.error("Tests failed");
  });
```

### Running tests

Run your tests using npm test:

```
$ npm test
```

---
_Source: https://npm.io/package/@anderjason/tests · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
