From 6e6d8283b2a7d65712e01d9ad8399c68232e901f Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Sat, 10 Dec 2022 09:39:05 +0100 Subject: [PATCH] test: replace vitest with uvu --- package.json | 6 +++--- test/integration/verify.test.ts | 21 ++++++++++++--------- test/unit/verify.test.ts | 13 ++++++++----- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 4c972c76..5b7ae6a4 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,9 @@ "scripts": { "compile": "tsc --build", "lint": "eslint . --ext '.ts'", - "test:unit": "vitest --dir test/unit/", - "test:unit:coverage": "vitest run --coverage --dir test/unit/", - "test:integration": "vitest run --dir test/integration/" + "test:unit": "NODE_OPTIONS='--loader tsx --no-warnings' uvu 'test/unit/' '.*\\.test\\.ts$'", + "test:unit:coverage": "c8 npm run test:unit", + "test:integration": "NODE_OPTIONS='--loader tsx --no-warnings' uvu 'test/integration/' '.*\\.test\\.ts$'" }, "dependencies": { "micro": "9.3.4", diff --git a/test/integration/verify.test.ts b/test/integration/verify.test.ts index cfb62b8a..5a04cb5a 100644 --- a/test/integration/verify.test.ts +++ b/test/integration/verify.test.ts @@ -1,4 +1,5 @@ -import { test, assert } from "vitest"; +import { test } from "uvu"; +import * as assert from "uvu/assert"; import micro from "micro"; import listen from "test-listen"; import got from "got"; @@ -9,7 +10,7 @@ test('return "false" when "x-hub-signature" header is missing', async () => { const server = micro(async (req) => { const valid = await verifySecret(req, "my-secret"); - assert.isFalse(valid); + assert.equal(valid, false); assertionCalled = true; return ""; }); @@ -21,7 +22,7 @@ test('return "false" when "x-hub-signature" header is missing', async () => { }); server.close(); - assert.isTrue(assertionCalled); + assert.equal(assertionCalled, true); }); test('return "false" when secret is wrong', async () => { @@ -29,7 +30,7 @@ test('return "false" when secret is wrong', async () => { const server = micro(async (req) => { const valid = await verifySecret(req, "wrong-secret"); - assert.isFalse(valid); + assert.equal(valid, false); assertionCalled = true; return ""; }); @@ -46,7 +47,7 @@ test('return "false" when secret is wrong', async () => { }); server.close(); - assert.isTrue(assertionCalled); + assert.equal(assertionCalled, true); }); test('return "true" when secret is correct', async () => { @@ -54,7 +55,7 @@ test('return "true" when secret is correct', async () => { const server = micro(async (req) => { const valid = await verifySecret(req, "my-secret"); - assert.isTrue(valid); + assert.equal(valid, true); assertionCalled = true; return ""; }); @@ -71,7 +72,7 @@ test('return "true" when secret is correct', async () => { }); server.close(); - assert.isTrue(assertionCalled); + assert.equal(assertionCalled, true); }); test("should not hang when verify is called more than once", async () => { @@ -80,7 +81,7 @@ test("should not hang when verify is called more than once", async () => { const server = micro(async (req) => { const valid = await verifySecret(req, "my-secret"); await verifySecret(req, "my-secret"); - assert.isTrue(valid); + assert.equal(valid, true); assertionCalled = true; return ""; }); @@ -97,5 +98,7 @@ test("should not hang when verify is called more than once", async () => { }); server.close(); - assert.isTrue(assertionCalled); + assert.equal(assertionCalled, true); }); + +test.run(); diff --git a/test/unit/verify.test.ts b/test/unit/verify.test.ts index 1c382c1b..a61ed342 100644 --- a/test/unit/verify.test.ts +++ b/test/unit/verify.test.ts @@ -1,4 +1,5 @@ -import { test, assert } from "vitest"; +import { test } from "uvu"; +import * as assert from "uvu/assert"; import { verify } from "../../src/verify"; const body = JSON.stringify({ @@ -10,23 +11,25 @@ const signature = "sha1=30a233839fe2ddd9233c49fd593e8f1aec68f553"; test('return "false" when signature is missing', () => { const valid = verify(body, "my-secret"); - assert.isFalse(valid); + assert.equal(valid, false); }); test('return "false" when signature is an Array', () => { const valid = verify(body, "wrong-secret", signature); - assert.isFalse(valid); + assert.equal(valid, false); }); test('return "false" when secret is wrong', () => { const valid = verify(body, "wrong-secret", signature); - assert.isFalse(valid); + assert.equal(valid, false); }); test('return "true" when secret is correct', () => { const valid = verify(body, "my-secret", signature); - assert.isTrue(valid); + assert.equal(valid, true); }); + +test.run();