Compare commits

...

5 Commits

Author SHA1 Message Date
Bauke 30fc15fb8d
Version 0.2.2! 2024-01-27 13:10:20 +01:00
Bauke 82d68f8066
Update dependencies and fix linting issues. 2024-01-27 13:06:54 +01:00
Bauke 967c709b85
Use top-level await everywhere. 2024-01-27 13:04:24 +01:00
Bauke 50d5b71d03
Switch from npm scripts to cargo-make tasks. 2024-01-27 13:00:48 +01:00
Bauke 373d85a17b
Add Nix flake and direnv files. 2024-01-27 12:53:52 +01:00
13 changed files with 2818 additions and 1868 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.direnv/
build/ build/
node_modules/ node_modules/

45
Makefile.toml Normal file
View File

@ -0,0 +1,45 @@
# Build the package.
[tasks.build]
clear = true
dependencies = ["clean", "lint", "test", "build-types", "build-js"]
# Build the JavaScript.
[tasks.build-js]
clear = true
command = "pnpm"
args = ["tsx", "esbuild.ts"]
# Build the TypeScript type declarations.
[tasks.build-types]
clear = true
command = "pnpm"
args = ["tsc"]
# Clean the build directory.
[tasks.clean]
clear = true
command = "pnpm"
args = ["trash", "build/"]
# Run the full set of linting and testing.
[tasks.lint]
clear = true
dependencies = ["lint-js", "test"]
# Lint the TypeScript using XO.
[tasks.lint-js]
clear = true
command = "pnpm"
args = ["xo"]
# Run the tests.
[tasks.test]
clear = true
command = "pnpm"
args = ["tsx", "tests/index.ts"]
# Start a live-reloading server that watches for changes.
[tasks.watch]
clear = true
command = "pnpm"
args = ["vite"]

View File

@ -9,7 +9,7 @@ import {setup} from "@holllo/test";
const add = (a: number, b: number): number => a + b; const add = (a: number, b: number): number => a + b;
void setup("add", async (group) => { await setup("add", async (group) => {
group.test("1 + 1", async (test) => { group.test("1 + 1", async (test) => {
test.equals(add(1, 1), 2); test.equals(add(1, 1), 2);
}); });

59
flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706173671,
"narHash": "sha256-lciR7kQUK2FCAYuszyd7zyRRmTaXVeoZsCyK6QFpGdk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4fddc9be4eaf195d631333908f2a454b03628ee5",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

13
flake.nix Normal file
View File

@ -0,0 +1,13 @@
{
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

View File

@ -2,12 +2,8 @@
"name": "@holllo/test", "name": "@holllo/test",
"description": "Tiny testing library designed to run anywhere.", "description": "Tiny testing library designed to run anywhere.",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"version": "0.2.1", "version": "0.2.2",
"homepage": "https://git.bauke.xyz/Holllo/test", "homepage": "https://git.bauke.xyz/Holllo/test",
"bugs": {
"email": "helllo@holllo.org",
"url": "https://github.com/Holllo/test/issues"
},
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
@ -17,20 +13,15 @@
"files": [ "files": [
"build/" "build/"
], ],
"scripts": {
"build": "tsx esbuild.ts && tsc",
"dev": "vite",
"lint": "xo",
"test": "pnpm run build && tsx tests/index.ts && tsx tests/example.ts"
},
"devDependencies": { "devDependencies": {
"@bauke/eslint-config": "^0.1.2", "@bauke/eslint-config": "^0.1.5",
"@bauke/prettier-config": "^0.1.2", "@bauke/prettier-config": "^0.1.5",
"esbuild": "^0.16.10", "esbuild": "^0.19.12",
"tsx": "^3.12.1", "trash-cli": "^5.0.0",
"typescript": "^4.9.4", "tsx": "^4.7.0",
"vite": "^4.0.2", "typescript": "^5.3.3",
"xo": "^0.53.1" "vite": "^5.0.12",
"xo": "^0.56.0"
}, },
"prettier": "@bauke/prettier-config", "prettier": "@bauke/prettier-config",
"xo": { "xo": {

File diff suppressed because it is too large Load Diff

7
shell.nix Normal file
View File

@ -0,0 +1,7 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell rec {
packages = [ cargo-make nodejs nodePackages.pnpm ];
}

View File

@ -27,7 +27,10 @@ export class Group implements GroupOptions {
private _afterAll: (() => Promise<void>) | undefined; private _afterAll: (() => Promise<void>) | undefined;
private _beforeAll: (() => Promise<void>) | undefined; private _beforeAll: (() => Promise<void>) | undefined;
constructor(public name: string, options?: GroupOptions) { constructor(
public name: string,
options?: GroupOptions,
) {
this.parallel = options?.parallel ?? false; this.parallel = options?.parallel ?? false;
} }
@ -65,7 +68,6 @@ export class Group implements GroupOptions {
} else { } else {
results = []; results = [];
for (const test of this.tests) { for (const test of this.tests) {
// eslint-disable-next-line no-await-in-loop
results.push(await test.run(this.context)); results.push(await test.run(this.context));
} }
} }

View File

@ -1,8 +1,8 @@
import {setup} from "../build/index.js"; import {setup} from "../source/index.js";
const add = (a: number, b: number): number => a + b; const add = (a: number, b: number): number => a + b;
void setup("add", async (group) => { await setup("Example add", async (group) => {
group.test("1 + 1", async (test) => { group.test("1 + 1", async (test) => {
test.equals(add(1, 1), 2); test.equals(add(1, 1), 2);
}); });

View File

@ -16,7 +16,6 @@
<body> <body>
<script src="index.ts" type="module"></script> <script src="index.ts" type="module"></script>
<script src="example.ts" type="module"></script>
</body> </body>
</html> </html>

View File

@ -1,6 +1,7 @@
import {setup} from "../source/index.js"; import {setup} from "../source/index.js";
await import("./assertions.js"); await import("./assertions.js");
await import("./example.js");
async function add(a: number, b: number): Promise<number> { async function add(a: number, b: number): Promise<number> {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -22,7 +23,7 @@ async function subtract(a: number, b: number): Promise<number> {
return a - b; return a - b;
} }
void setup("add", async (group) => { await setup("add", async (group) => {
group.test("add(1, 1) = 2", async (test) => { group.test("add(1, 1) = 2", async (test) => {
test.equals(await add(1, 1), 2); test.equals(await add(1, 1), 2);
}); });
@ -36,7 +37,7 @@ void setup("add", async (group) => {
}); });
}); });
void setup( await setup(
"subtract", "subtract",
async (group) => { async (group) => {
group.beforeAll(async () => { group.beforeAll(async () => {