Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/index.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
59 changes: 59 additions & 0 deletions dist/index.test.js

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

1 change: 1 addition & 0 deletions dist/index.test.js.map

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

74 changes: 74 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { test } from 'node:test';
import assert from 'node:assert';

import * as api from './index.js';

// package.json "main" points at dist/index.js — this file is the public API
// surface consumers get from `import ... from '@hivecommons/promptargs'`.
// Pin every runtime export so a refactor of the barrel (or of a re-exported
// module) that drops or renames a symbol fails the suite instead of shipping
// a silent breaking change.

const EXPECTED_FUNCTION_EXPORTS = [
'parseVars',
'expand',
'autodetect',
'autodetectAll',
'loadTemplates',
'findTemplate',
'resolve',
'renderStatus',
].sort();

test('index exports exactly the documented runtime API', () => {
const actual = Object.keys(api).sort();
const expected = [...EXPECTED_FUNCTION_EXPORTS, 'AUTODETECT_VARS'].sort();
assert.deepStrictEqual(actual, expected);
});

test('every function export is callable', () => {
for (const name of EXPECTED_FUNCTION_EXPORTS) {
assert.strictEqual(
typeof (api as Record<string, unknown>)[name],
'function',
`expected export "${name}" to be a function`,
);
}
});

test('AUTODETECT_VARS is a non-empty list of var names', () => {
assert.ok(Array.isArray(api.AUTODETECT_VARS));
assert.ok(api.AUTODETECT_VARS.length > 0);
for (const v of api.AUTODETECT_VARS) {
assert.strictEqual(typeof v, 'string');
assert.ok(v.length > 0);
}
});

test('entry-point exports are the same objects as their source modules', async () => {
const parser = await import('./parser.js');
const autodetectMod = await import('./autodetect.js');
const loader = await import('./loader.js');
const resolver = await import('./resolver.js');
const status = await import('./status.js');

assert.strictEqual(api.parseVars, parser.parseVars);
assert.strictEqual(api.expand, parser.expand);
assert.strictEqual(api.autodetect, autodetectMod.autodetect);
assert.strictEqual(api.autodetectAll, autodetectMod.autodetectAll);
assert.strictEqual(api.AUTODETECT_VARS, autodetectMod.AUTODETECT_VARS);
assert.strictEqual(api.loadTemplates, loader.loadTemplates);
assert.strictEqual(api.findTemplate, loader.findTemplate);
assert.strictEqual(api.resolve, resolver.resolve);
assert.strictEqual(api.renderStatus, status.renderStatus);
});

test('smoke: exported parseVars + expand round-trip through the entry point', () => {
const vars = api.parseVars('Hello {{name}}, focus on {{focus}}');
assert.deepStrictEqual(
vars.map((v: { name: string }) => v.name),
['name', 'focus'],
);
const out = api.expand('Hello {{name}}', { name: 'World' });
assert.strictEqual(out, 'Hello World');
});
Loading