Skip to content

Commit

Permalink
test: replace vitest with uvu
Browse files Browse the repository at this point in the history
  • Loading branch information
screendriver committed Dec 10, 2022
1 parent 0940603 commit 6e6d828
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 12 additions & 9 deletions test/integration/verify.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 "";
});
Expand All @@ -21,15 +22,15 @@ 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 () => {
let assertionCalled = false;

const server = micro(async (req) => {
const valid = await verifySecret(req, "wrong-secret");
assert.isFalse(valid);
assert.equal(valid, false);
assertionCalled = true;
return "";
});
Expand All @@ -46,15 +47,15 @@ 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 () => {
let assertionCalled = false;

const server = micro(async (req) => {
const valid = await verifySecret(req, "my-secret");
assert.isTrue(valid);
assert.equal(valid, true);
assertionCalled = true;
return "";
});
Expand All @@ -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 () => {
Expand All @@ -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 "";
});
Expand All @@ -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();
13 changes: 8 additions & 5 deletions test/unit/verify.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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();

0 comments on commit 6e6d828

Please sign in to comment.