diff --git a/examples/esbuild/package.json b/examples/esbuild/package.json new file mode 100644 index 0000000..7726c8d --- /dev/null +++ b/examples/esbuild/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "scripts": { + "test": "uvu -r esbuild-register tests" + }, + "devDependencies": { + "esbuild": "0.12.15", + "esbuild-register": "2.6.0", + "uvu": "^0.5.1" + } +} diff --git a/examples/esbuild/src/math.ts b/examples/esbuild/src/math.ts new file mode 100644 index 0000000..fcaee67 --- /dev/null +++ b/examples/esbuild/src/math.ts @@ -0,0 +1,11 @@ +export function sum(a: number, b: number): number { + return a + b; +} + +export function div(a: number, b: number): number { + return a / b; +} + +export function mod(a: number, b: number): number { + return a % b; +} diff --git a/examples/esbuild/src/utils.ts b/examples/esbuild/src/utils.ts new file mode 100644 index 0000000..8d6a1f6 --- /dev/null +++ b/examples/esbuild/src/utils.ts @@ -0,0 +1,7 @@ +export function capitalize(str: string): string { + return str[0].toUpperCase() + str.substring(1); +} + +export function dashify(str: string): string { + return str.replace(/([a-zA-Z])(?=[A-Z\d])/g, '$1-').toLowerCase(); +} diff --git a/examples/esbuild/tests/math.ts b/examples/esbuild/tests/math.ts new file mode 100644 index 0000000..c888400 --- /dev/null +++ b/examples/esbuild/tests/math.ts @@ -0,0 +1,26 @@ +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import * as math from '../src/math'; + +test('sum', () => { + assert.type(math.sum, 'function'); + assert.is(math.sum(1, 2), 3); + assert.is(math.sum(-1, -2), -3); + assert.is(math.sum(-1, 1), 0); +}); + +test('div', () => { + assert.type(math.div, 'function'); + assert.is(math.div(1, 2), 0.5); + assert.is(math.div(-1, -2), 0.5); + assert.is(math.div(-1, 1), -1); +}); + +test('mod', () => { + assert.type(math.mod, 'function'); + assert.is(math.mod(1, 2), 1); + assert.is(math.mod(-3, -2), -1); + assert.is(math.mod(7, 4), 3); +}); + +test.run(); diff --git a/examples/esbuild/tests/utils.ts b/examples/esbuild/tests/utils.ts new file mode 100644 index 0000000..1fc3ee4 --- /dev/null +++ b/examples/esbuild/tests/utils.ts @@ -0,0 +1,18 @@ +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import * as utils from '../src/utils'; + +test('capitalize', () => { + assert.type(utils.capitalize, 'function'); + assert.is(utils.capitalize('hello'), 'Hello'); + assert.is(utils.capitalize('foo bar'), 'Foo bar'); +}); + +test('dashify', () => { + assert.type(utils.dashify, 'function'); + assert.is(utils.dashify('fooBar'), 'foo-bar'); + assert.is(utils.dashify('FooBar'), 'foo-bar'); + assert.is(utils.dashify('foobar'), 'foobar'); +}); + +test.run(); diff --git a/examples/esbuild/tsconfig.json b/examples/esbuild/tsconfig.json new file mode 100644 index 0000000..682f13b --- /dev/null +++ b/examples/esbuild/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "outDir": "build", + "target": "esnext", + "module": "esnext", + "noImplicitAny": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true + }, + "include": [ + "@types/**/*", + "src/**/*" + ], + "exclude": [ + "node_modules" + ] +}