Skip to content

Commit

Permalink
Use slightly modified "uvu" as test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Sep 25, 2023
1 parent b0b02b7 commit 260062b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 103 deletions.
3 changes: 2 additions & 1 deletion apps/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "nxjs-tests",
"version": "0.0.0",
"private": true,
"type": "module",
"description": "nx.js API tests",
"scripts": {
"build": "esbuild --bundle --target=es2020 src/main.ts --outfile=romfs/main.js",
Expand All @@ -14,6 +15,6 @@
"nxjs-runtime": "workspace:^"
},
"dependencies": {
"kleur": "github:TooTallNate/kleur#rgb"
"uvu": "github:TooTallNate/uvu#master"
}
}
85 changes: 44 additions & 41 deletions apps/tests/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import { assert, test } from './runner';
import { test } from 'uvu';
import * as assert from 'uvu/assert';

const ctx = Switch.screen.getContext('2d');

test('`Switch.entrypoint` is a string', () => {
assert(typeof Switch.entrypoint === 'string');
assert(Switch.entrypoint.length > 0);
assert.type(Switch.entrypoint, 'string');
assert.ok(Switch.entrypoint.length > 0);
});

test('`Switch.cwd()` is a URL string representation', () => {
test('`Switch.cwd()` is a URL string representation', async () => {
const cwd = Switch.cwd();
assert(typeof cwd === 'string');
assert(cwd.startsWith('sdmc:/'));
assert(cwd.endsWith('/'));
assert.type(cwd, 'string');
assert.ok(cwd.startsWith('sdmc:/'));
assert.ok(cwd.endsWith('/'));
});

test('`Switch.readDirSync()` works on relative path', () => {
const files = Switch.readDirSync('.');
assert(Array.isArray(files));
assert(files.length > 0);
assert.ok(Array.isArray(files));
assert.ok(files.length > 0);
});

test('`Switch.readDirSync()` works on `sdmc:/` path', () => {
const files = Switch.readDirSync('sdmc:/');
assert(Array.isArray(files));
assert(files.length > 0);
assert.ok(Array.isArray(files));
assert.ok(files.length > 0);
});

test('`Switch.readDirSync()` works on `romfs:/` path', () => {
const files = Switch.readDirSync('romfs:/');
assert(Array.isArray(files));
assert(files.length > 0);
assert.ok(Array.isArray(files));
assert.ok(files.length > 0);
});

test('`Switch.readDirSync()` throws error when directory does not exist', () => {
Expand All @@ -39,13 +40,13 @@ test('`Switch.readDirSync()` throws error when directory does not exist', () =>
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.ok(err);
});

test('`Switch.resolveDns()` works', async () => {
const result = await Switch.resolveDns('n8.io');
assert(Array.isArray(result));
assert(result.length > 0);
assert.ok(Array.isArray(result));
assert.ok(result.length > 0);
});

test('`Switch.resolveDns()` rejects with invalid hostname', async () => {
Expand All @@ -55,19 +56,19 @@ test('`Switch.resolveDns()` rejects with invalid hostname', async () => {
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.ok(err);
});

test('`Switch.readFile()` works with string path', async () => {
const data = await Switch.readFile('romfs:/runtime.js');
assert(data instanceof ArrayBuffer);
assert(data.byteLength > 0);
assert.ok(data instanceof ArrayBuffer);
assert.ok(data.byteLength > 0);
});

test('`Switch.readFile()` works with URL path', async () => {
const data = await Switch.readFile(new URL(Switch.entrypoint));
assert(data instanceof ArrayBuffer);
assert(data.byteLength > 0);
assert.ok(data instanceof ArrayBuffer);
assert.ok(data.byteLength > 0);
});

test('`Switch.readFile()` rejects when file does not exist', async () => {
Expand All @@ -77,7 +78,7 @@ test('`Switch.readFile()` rejects when file does not exist', async () => {
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.ok(err);
});

test('`Switch.readFile()` rejects when attempting to read a directory', async () => {
Expand All @@ -87,12 +88,12 @@ test('`Switch.readFile()` rejects when attempting to read a directory', async ()
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.ok(err);
});

test('`Switch.stat()` returns file information', async () => {
const stat = await Switch.stat(Switch.entrypoint);
assert(stat.size > 0);
assert.ok(stat.size > 0);
});

test('`Switch.stat()` rejects when file does not exist', async () => {
Expand All @@ -102,41 +103,41 @@ test('`Switch.stat()` rejects when file does not exist', async () => {
} catch (_err) {
err = _err as Error;
}
assert(err);
assert.ok(err);
});

test('`CanvasContext2D#getImageData()`', () => {
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 1, 1);
const data = ctx.getImageData(0, 0, 1, 1);
assert(data.data[0] === 255);
assert(data.data[1] === 0);
assert(data.data[2] === 0);
assert(data.data[3] === 255);
assert.equal(data.data[0], 255);
assert.equal(data.data[1], 0);
assert.equal(data.data[2], 0);
assert.equal(data.data[3], 255);
});

test('FormData', async () => {
const file = new File(['conte', new Blob(['nts'])], 'file.txt', {
type: 'text/plain',
});
assert(file.name === 'file.txt');
assert(file.type === 'text/plain');
assert.equal(file.name, 'file.txt');
assert.equal(file.type, 'text/plain');

const form = new FormData();
form.append('file', file);
form.append('string', 'string-value');

const r = new Response(form);
const form2 = await r.formData();
assert(form2 instanceof FormData);
assert(form2.get('string') === 'string-value');
assert(form2.get('missing') === null);
assert.ok(form2 instanceof FormData);
assert.ok(form2.get('string') === 'string-value');
assert.ok(form2.get('missing') === null);

const file2 = form2.get('file');
assert(file2 instanceof File);
assert(file2.name === 'file.txt');
assert(file2.type === 'text/plain');
assert((await file2.text()) === 'contents');
assert.ok(file2 instanceof File);
assert.ok(file2.name === 'file.txt');
assert.ok(file2.type === 'text/plain');
assert.ok((await file2.text()) === 'contents');
});

test('Request - no `body` for `GET`', () => {
Expand All @@ -146,7 +147,9 @@ test('Request - no `body` for `GET`', () => {
} catch (_err: any) {
err = _err;
}
assert(err);
assert(err.name === 'TypeError');
assert(err.message === 'Body not allowed for GET or HEAD requests');
assert.ok(err);
assert.equal(err.name, 'TypeError');
assert.equal(err.message, 'Body not allowed for GET or HEAD requests');
});

test.run();
57 changes: 0 additions & 57 deletions apps/tests/src/runner.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
Expand Down
42 changes: 39 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 260062b

Please sign in to comment.