From 93a2e926dbf954efc050cdea76cfbb229580a874 Mon Sep 17 00:00:00 2001 From: Tobias Davis Date: Tue, 15 Mar 2022 12:29:46 -0500 Subject: [PATCH 1/2] change: switch from tape to uvu --- package.json | 6 +-- test/index.js | 106 +++++++++++++++++++++++--------------------------- 2 files changed, 51 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index 9d37b99..eede84f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.0", "repository": "lukeed/templite", "description": "Lightweight templating in 154 bytes", + "type": "module", "module": "dist/templite.mjs", "main": "dist/templite.js", "types": "index.d.ts", @@ -14,7 +15,7 @@ "scripts": { "build": "node builder", "pretest": "npm run build", - "test": "tape test/*.js | tap-spec" + "test": "uvu test" }, "keywords": [ "inject", @@ -25,7 +26,6 @@ "devDependencies": { "mk-dirs": "^1.0.0", "rewrite-imports": "^1.1.1", - "tap-spec": "^5.0.0", - "tape": "^4.9.1" + "uvu": "^0.5.3" } } diff --git a/test/index.js b/test/index.js index 98b2188..c3477ec 100644 --- a/test/index.js +++ b/test/index.js @@ -1,54 +1,49 @@ -const test = require('tape'); -const fn = require('../dist/templite'); +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import fn from '../src/index.js'; -test('exports', t => { - t.is(typeof fn, 'function', '~> a function'); - t.end(); +test('exports', () => { + assert.is(typeof fn, 'function', '~> a function'); }); -test('basic :: object', t => { +test('basic :: object', () => { let x = 'Hello, {{name}}!'; let y = { name: 'world' }; - t.is(fn(x, y), 'Hello, world!'); - t.same(x, 'Hello, {{name}}!', '~> input string intact'); - t.same(y, { name: 'world' }, '~> input object intact'); - t.end(); + assert.is(fn(x, y), 'Hello, world!'); + assert.equal(x, 'Hello, {{name}}!', '~> input string intact'); + assert.equal(y, { name: 'world' }, '~> input object intact'); }); -test('basic :: array', t => { +test('basic :: array', () => { let x = 'Hello, {{0}}!'; let y = ['world']; - t.is(fn(x, y), 'Hello, world!'); - t.same(x, 'Hello, {{0}}!', '~> input string intact'); - t.same(y, ['world'], '~> input array intact'); - t.end(); + assert.is(fn(x, y), 'Hello, world!'); + assert.equal(x, 'Hello, {{0}}!', '~> input string intact'); + assert.equal(y, ['world'], '~> input array intact'); }); -test('repeats', t => { - t.is(fn('{{0}}{{0}}{{0}}', ['🎉']), '🎉🎉🎉'); - t.is(fn('{{x}}{{x}}{{x}}', { x: 'hi~' }), 'hi~hi~hi~'); - t.end(); +test('repeats', () => { + assert.is(fn('{{0}}{{0}}{{0}}', ['🎉']), '🎉🎉🎉'); + assert.is(fn('{{x}}{{x}}{{x}}', { x: 'hi~' }), 'hi~hi~hi~'); }); -test('invalid key ~> empty string', t => { +test('invalid key ~> empty string', () => { let obj = { a:1, b:2 }; - t.is(fn('{{a}}{{d}}{{b}}', obj), '12'); - t.is(fn('{{d}}', obj), ''); + assert.is(fn('{{a}}{{d}}{{b}}', obj), '12'); + assert.is(fn('{{d}}', obj), ''); let arr = [1, 2]; - t.is(fn('{{0}}{{9}}{{1}}', arr), '12'); - t.is(fn('{{9}}', arr), ''); - t.end(); + assert.is(fn('{{0}}{{9}}{{1}}', arr), '12'); + assert.is(fn('{{9}}', arr), ''); }); -test('null keys', t => { +test('null keys', () => { let obj = { a:null, b:undefined }; - t.is(fn('{{a}}~{{b}}', obj), '~'); + assert.is(fn('{{a}}~{{b}}', obj), '~'); let arr = [ null, , undefined ]; - t.is(fn('{{0}}~{{1}}~{{2}}', arr), '~~'); - t.end(); + assert.is(fn('{{0}}~{{1}}~{{2}}', arr), '~~'); }); -test('nested keys', t => { +test('nested keys', () => { let obj = { name: 'John', foo: { @@ -58,57 +53,52 @@ test('nested keys', t => { } }; let arr = ['John', [[['Smith']]]]; - t.is(fn('{{name}} {{foo.bar.baz}}', obj), 'John Smith'); - t.is(fn('{{0}} {{1.0.0}}', arr), 'John Smith'); - t.end(); + assert.is(fn('{{name}} {{foo.bar.baz}}', obj), 'John Smith'); + assert.is(fn('{{0}} {{1.0.0}}', arr), 'John Smith'); }); -test('nested keys (invalid)', t => { +test('nested keys (invalid)', () => { let obj = { foo:123 }; - t.is(fn('{{foo.bar}}', obj), ''); - t.is(fn('{{foo.bar.baz}}', obj), ''); + assert.is(fn('{{foo.bar}}', obj), ''); + assert.is(fn('{{foo.bar.baz}}', obj), ''); let arr = [123]; - t.is(fn('{{0.1}}', arr), ''); - t.is(fn('{{0.1.2}}', arr), ''); - t.end(); + assert.is(fn('{{0.1}}', arr), ''); + assert.is(fn('{{0.1.2}}', arr), ''); }); -test('trim keys (whitespace)', t => { +test('trim keys (whitespace)', () => { let obj = { foo:123, bar:{ baz:456 } }; - t.is(fn('{{ foo }}', obj), '123'); - t.is(fn('{{ bar.baz }}', obj), '456'); + assert.is(fn('{{ foo }}', obj), '123'); + assert.is(fn('{{ bar.baz }}', obj), '456'); let arr = [123, [456]]; - t.is(fn('{{ 0 }}', arr), '123'); - t.is(fn('{{ 1.0 }}', arr), '456'); - t.end(); + assert.is(fn('{{ 0 }}', arr), '123'); + assert.is(fn('{{ 1.0 }}', arr), '456'); }); -test('multiline string', t => { +test('multiline string', () => { let obj = { foo:123, bar:456 }; - t.is(fn('\nApples: {{foo}}\n\nOranges: {{bar}}', obj), '\nApples: 123\n\nOranges: 456'); - t.is(fn(` + assert.is(fn('\nApples: {{foo}}\n\nOranges: {{bar}}', obj), '\nApples: 123\n\nOranges: 456'); + assert.is(fn(` Apples: {{foo}} Oranges: {{bar}} `, obj), '\n\t\tApples: 123\n\t\tOranges: 456\n\t'); - t.end(); }); -test('mixed datatype', t => { +test('mixed datatype', () => { let arr = [4, 5, 6]; arr.foo = 'hello'; arr.bar = 'world'; - t.is(fn('{{foo}}, {{bar}}! {{0}}{{1}}{{2}}', arr), 'hello, world! 456'); - t.end(); + assert.is(fn('{{foo}}, {{bar}}! {{0}}{{1}}{{2}}', arr), 'hello, world! 456'); }); -test('allows "0" value', t => { - t.is(fn('{{0}} & {{1}}', [0, -1]), '0 & -1'); - t.end(); +test('allows "0" value', () => { + assert.is(fn('{{0}} & {{1}}', [0, -1]), '0 & -1'); }); -test('currying', t => { +test('currying', () => { let x = fn.bind(null, 'Hello, {{name}}'); let arr = ['Jack', 'Jill', 'John'].map(name => x({ name })); - t.same(arr, ['Hello, Jack', 'Hello, Jill', 'Hello, John']); - t.end(); + assert.equal(arr, ['Hello, Jack', 'Hello, Jill', 'Hello, John']); }); + +test.run(); From 5d16a953d81e450df4f44b97c8b766f3cb9e9e1f Mon Sep 17 00:00:00 2001 From: Tobias Davis Date: Tue, 15 Mar 2022 12:30:24 -0500 Subject: [PATCH 2/2] change: switch build to use bundt --- builder.js | 13 ------------- package.json | 5 ++--- 2 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 builder.js diff --git a/builder.js b/builder.js deleted file mode 100644 index a0f39b6..0000000 --- a/builder.js +++ /dev/null @@ -1,13 +0,0 @@ -const fs = require('fs'); -const mkdir = require('mk-dirs'); -const imports = require('rewrite-imports'); -const pkg = require('./package'); - -let data = fs.readFileSync('src/index.js', 'utf8'); - -mkdir('dist').then(_ => { - // Copy as is for ESM - fs.writeFileSync(pkg.module, data); - // Rewrite ESM ~> CJS - fs.writeFileSync(pkg.main, imports(data).replace('export default', 'module.exports =')); -}); diff --git a/package.json b/package.json index eede84f..d8ff253 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "index.d.ts" ], "scripts": { - "build": "node builder", + "build": "bundt", "pretest": "npm run build", "test": "uvu test" }, @@ -24,8 +24,7 @@ "template" ], "devDependencies": { - "mk-dirs": "^1.0.0", - "rewrite-imports": "^1.1.1", + "bundt": "^1.1.5", "uvu": "^0.5.3" } }