nx-demo-testing
v2.0.1
Published
Helpers to standardize demo/testing scaffolding, logging, evidence, env validation, Space (S3-compatible) checks, and safe timeouts.
Readme
nx-demo-testing
A tiny toolkit that standardizes demo/testing flows across packages:
- Config init + env placeholder validation
- Per-demo logger (console + file)
- Demo I/O directories (
io/input,io/output,io/debug) - Evidence validation (required files exist)
- Safe timeouts for async operations
- Per-service status files
- (Optional) Space connectivity check
Install
npm i nx-demo-testing
# peer deps assumed available in your mono-repo:
# @aws-sdk/client-s3, logs-gateway, nx-config2Quick Start
import {
initDemoConfig, validateEnvironment,
ensureDemoStructure, createDemoLogger,
saveInput, saveOutput, loadInput,
validateDemoEvidence, withTimeout,
createSpaceClient, testSpaceConnection, saveStatus
} from 'nx-demo-testing';
const config = initDemoConfig('./nxconfig.demo.js');
validateEnvironment();
const demoPath = process.cwd() + '/demos/' + config.name;
ensureDemoStructure(demoPath);
const logger = createDemoLogger(config.name, `${demoPath}/io/debug/demo.log`);
logger.info('Demo start');
const space = createSpaceClient(config);
await testSpaceConnection(space, config.space.bucket);
saveInput(demoPath, 'request.json', { hello: 'world' });
// ... do work with withTimeout(...)
saveOutput(demoPath, 'result.json', { ok: true });
validateDemoEvidence(demoPath, ['input/request.json', 'output/result.json', 'debug/demo.log']);
saveStatus(demoPath, 'space-check', 'success', { action: 'HeadBucket' });API Surface
initDemoConfig(path): load & validate config vianx-config2.validateEnvironment(): fails if env contains placeholders likeyour-,changeme, etc.createDemoLogger(name, logPath): standard JSON logger + file append.ensureDemoStructure(demoPath): createsio/input,io/output,io/debug.saveInput(demoPath, filename, data)/saveOutput(...): write JSON.loadInput(filename): read./demos/data/inputs/<filename>.validateDemoEvidence(demoPath, requiredFiles): assert files exist underio/.withTimeout(promise, timeoutMs, onTimeout?): reject with codeTIMEOUT.createSpaceClient(config)/testSpaceConnection(client, bucket): Space head-bucket.
Conventions
- Demo artifacts live under
<demoPath>/io/.... - Each service writes
io/output/<service>/status.jsonviasaveStatus. - Always guard network/IO with
withTimeout.
License
MIT
