@adonis-agora/media
Version:
Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a
32 lines • 1.23 kB
JavaScript
/**
* Deterministic {@link Transformer} for tests — the transformer counterpart of
* `FakeImageProcessor`. It records every context it is called with and writes/declares exactly
* what it was configured to, so eager/deferred behaviour, artifact bookkeeping and rollback can be
* asserted without a media engine.
*/
export class FakeTransformer {
name;
eager;
calls = [];
options;
constructor(options) {
this.name = options.name;
this.eager = options.eager ?? false;
this.options = options;
}
async transform(context) {
this.calls.push(context);
if (this.options.behavior)
return this.options.behavior(context);
const artifacts = Object.entries(this.options.artifacts ?? {});
for (const [path, content] of artifacts) {
await context.write(path, Buffer.from(content, 'utf8'));
}
const entry = this.options.entry === null ? undefined : (this.options.entry ?? artifacts[0]?.[0]);
return {
...(entry !== undefined ? { entry } : {}),
...(this.options.meta !== undefined ? { meta: this.options.meta } : {}),
};
}
}
//# sourceMappingURL=fake_transformer.js.map