@cucumber/cucumber
Advanced tools
Comparing version 10.8.0 to 10.9.0
@@ -13,3 +13,3 @@ "use strict"; | ||
const cleanupFns = []; | ||
async function initializeFormatter(stream, target, specifier) { | ||
async function initializeFormatter(stream, directory, target, specifier) { | ||
if (specifier === 'progress-bar' && !stream.isTTY) { | ||
@@ -38,3 +38,3 @@ logger.warn(`Cannot use 'progress-bar' formatter for output to '${target}' as not a TTY. Switching to 'progress' formatter.`); | ||
else { | ||
await pluginManager.initFormatter(implementation, configuration.options, stream.write.bind(stream)); | ||
await pluginManager.initFormatter(implementation, configuration.options, logger, stream.write.bind(stream), directory); | ||
if (stream !== stdout) { | ||
@@ -45,5 +45,6 @@ cleanupFns.push((0, node_util_1.promisify)(stream.end.bind(stream))); | ||
} | ||
await initializeFormatter(stdout, 'stdout', configuration.stdout); | ||
await initializeFormatter(stdout, undefined, 'stdout', configuration.stdout); | ||
for (const [target, specifier] of Object.entries(configuration.files)) { | ||
await initializeFormatter(await (0, create_stream_1.createStream)(target, onStreamError, cwd, logger), target, specifier); | ||
const { stream, directory } = await (0, create_stream_1.createStream)(target, onStreamError, cwd, logger); | ||
await initializeFormatter(stream, directory, target, specifier); | ||
} | ||
@@ -50,0 +51,0 @@ return async function () { |
@@ -0,6 +1,10 @@ | ||
interface Options { | ||
externalAttachments?: true; | ||
} | ||
declare const _default: { | ||
type: "formatter"; | ||
formatter({ on, write }: import("../../plugin").FormatterPluginContext<any>): () => Promise<void>; | ||
formatter({ on, options, write, directory }: import("../../plugin").FormatterPluginContext<Options>): () => Promise<void>; | ||
documentation: string; | ||
optionsKey: string; | ||
}; | ||
export default _default; |
@@ -8,11 +8,34 @@ "use strict"; | ||
const node_stream_1 = require("node:stream"); | ||
const html_formatter_1 = __importDefault(require("@cucumber/html-formatter")); | ||
const node_fs_1 = require("node:fs"); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const html_formatter_1 = require("@cucumber/html-formatter"); | ||
const resolve_pkg_1 = __importDefault(require("resolve-pkg")); | ||
const mime_1 = __importDefault(require("mime")); | ||
const messages_1 = require("@cucumber/messages"); | ||
exports.default = { | ||
type: 'formatter', | ||
formatter({ on, write }) { | ||
const htmlStream = new html_formatter_1.default((0, resolve_pkg_1.default)('@cucumber/html-formatter', { cwd: __dirname }) + | ||
formatter({ on, options, write, directory }) { | ||
if (!directory && options.externalAttachments) { | ||
throw new Error('Unable to externalise attachments when formatter is not writing to a file'); | ||
} | ||
const newId = messages_1.IdGenerator.uuid(); | ||
const htmlStream = new html_formatter_1.CucumberHtmlStream((0, resolve_pkg_1.default)('@cucumber/html-formatter', { cwd: __dirname }) + | ||
'/dist/main.css', (0, resolve_pkg_1.default)('@cucumber/html-formatter', { cwd: __dirname }) + | ||
'/dist/main.js'); | ||
on('message', (message) => htmlStream.write(message)); | ||
const writeOperations = []; | ||
on('message', (message) => { | ||
if (message.attachment && options.externalAttachments) { | ||
const { attachment, writeOperation } = externaliseAttachment(newId, message.attachment, directory); | ||
htmlStream.write({ | ||
...message, | ||
attachment, | ||
}); | ||
if (writeOperation) { | ||
writeOperations.push(writeOperation); | ||
} | ||
} | ||
else { | ||
htmlStream.write(message); | ||
} | ||
}); | ||
htmlStream.on('data', (chunk) => write(chunk)); | ||
@@ -22,6 +45,34 @@ return async () => { | ||
await (0, node_util_1.promisify)(node_stream_1.finished)(htmlStream); | ||
await Promise.all(writeOperations); | ||
}; | ||
}, | ||
documentation: 'Outputs a HTML report', | ||
optionsKey: 'html', | ||
}; | ||
const alwaysInlinedTypes = ['text/x.cucumber.log+plain', 'text/uri-list']; | ||
const encodingsMap = { | ||
IDENTITY: 'utf-8', | ||
BASE64: 'base64', | ||
}; | ||
function externaliseAttachment(newId, original, directory) { | ||
if (alwaysInlinedTypes.includes(original.mediaType)) { | ||
return { attachment: original }; | ||
} | ||
let filename = `attachment-${newId()}`; | ||
const extension = mime_1.default.getExtension(original.mediaType); | ||
if (extension) { | ||
filename += `.${extension}`; | ||
} | ||
const writeOperation = (0, node_util_1.promisify)(node_fs_1.writeFile)(node_path_1.default.join(directory, filename), Buffer.from(original.body, encodingsMap[original.contentEncoding])); | ||
const updated = { | ||
...original, | ||
contentEncoding: messages_1.AttachmentContentEncoding.IDENTITY, | ||
body: '', | ||
url: `./${filename}`, | ||
}; | ||
return { | ||
attachment: updated, | ||
writeOperation, | ||
}; | ||
} | ||
//# sourceMappingURL=html.js.map |
/// <reference types="node" /> | ||
import { Writable } from 'node:stream'; | ||
import { ILogger } from '../logger'; | ||
export declare function createStream(target: string, onStreamError: () => void, cwd: string, logger: ILogger): Promise<Writable>; | ||
export declare function createStream(target: string, onStreamError: () => void, cwd: string, logger: ILogger): Promise<{ | ||
directory: string; | ||
stream: Writable; | ||
}>; |
@@ -12,4 +12,5 @@ "use strict"; | ||
const absoluteTarget = node_path_1.default.resolve(cwd, target); | ||
const directory = node_path_1.default.dirname(absoluteTarget); | ||
try { | ||
await (0, mkdirp_1.mkdirp)(node_path_1.default.dirname(absoluteTarget)); | ||
await (0, mkdirp_1.mkdirp)(directory); | ||
} | ||
@@ -26,5 +27,8 @@ catch (error) { | ||
}); | ||
return stream; | ||
return { | ||
directory, | ||
stream, | ||
}; | ||
} | ||
exports.createStream = createStream; | ||
//# sourceMappingURL=create_stream.js.map |
@@ -16,2 +16,5 @@ /// <reference types="node" /> | ||
colorsEnabled?: boolean; | ||
html?: { | ||
externalAttachments?: boolean; | ||
}; | ||
rerun?: FormatRerunOptions; | ||
@@ -18,0 +21,0 @@ snippetInterface?: SnippetInterface; |
@@ -8,3 +8,3 @@ import { IRunEnvironment } from '../api'; | ||
private register; | ||
initFormatter<OptionsType>(plugin: FormatterPlugin<OptionsType>, options: OptionsType, write: (buffer: string | Uint8Array) => void): Promise<void>; | ||
initFormatter<OptionsType>(plugin: FormatterPlugin<OptionsType>, options: OptionsType, logger: ILogger, write: (buffer: string | Uint8Array) => void, directory?: string): Promise<void>; | ||
initCoordinator<OptionsType>(operation: Operation, plugin: InternalPlugin<OptionsType>, options: OptionsType, logger: ILogger, environment: Required<IRunEnvironment>): Promise<void>; | ||
@@ -11,0 +11,0 @@ emit<K extends CoordinatorPluginEventKey>(event: K, value: CoordinatorPluginEventValues[K]): void; |
@@ -15,7 +15,11 @@ "use strict"; | ||
} | ||
async initFormatter(plugin, options, write) { | ||
async initFormatter(plugin, options, logger, write, directory) { | ||
const cleanupFn = await plugin.formatter({ | ||
on: (key, handler) => this.register(key, handler), | ||
options, | ||
options: plugin.optionsKey | ||
? options[plugin.optionsKey] ?? {} | ||
: options, | ||
logger, | ||
write, | ||
directory, | ||
}); | ||
@@ -22,0 +26,0 @@ if (typeof cleanupFn === 'function') { |
@@ -42,3 +42,5 @@ import { Envelope } from '@cucumber/messages'; | ||
options: OptionsType; | ||
logger: ILogger; | ||
write: (buffer: string | Uint8Array) => void; | ||
directory?: string; | ||
} | ||
@@ -50,2 +52,3 @@ export type FormatterPluginFunction<OptionsType> = (context: FormatterPluginContext<OptionsType>) => Promisable<PluginCleanup | void>; | ||
documentation: string; | ||
optionsKey?: string; | ||
} |
@@ -25,2 +25,3 @@ /// <reference types="node" /> | ||
export type ICreateLog = (text: string) => void; | ||
export type ICreateLink = (text: string) => void; | ||
export default class AttachmentManager { | ||
@@ -30,2 +31,3 @@ private readonly onAttachment; | ||
log(text: string): void | Promise<void>; | ||
link(...url: string[]): void | Promise<void>; | ||
create(data: Buffer | Readable | string, mediaTypeOrOptions?: string | ICreateAttachmentOptions, callback?: () => void): void | Promise<void>; | ||
@@ -32,0 +34,0 @@ createBufferAttachment(data: Buffer, mediaType: string, fileName?: string): void; |
@@ -40,2 +40,5 @@ "use strict"; | ||
} | ||
link(...url) { | ||
return this.create(url.join('\n'), 'text/uri-list'); | ||
} | ||
create(data, mediaTypeOrOptions, callback) { | ||
@@ -42,0 +45,0 @@ const options = normaliseOptions(mediaTypeOrOptions); |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import { JsonObject } from 'type-fest'; | ||
import { SupportCodeLibrary, ITestCaseHookParameter } from '../support_code_library_builder/types'; | ||
import { ITestCaseHookParameter, SupportCodeLibrary } from '../support_code_library_builder/types'; | ||
import TestCaseHookDefinition from '../models/test_case_hook_definition'; | ||
@@ -9,0 +9,0 @@ import TestStepHookDefinition from '../models/test_step_hook_definition'; |
@@ -88,2 +88,3 @@ "use strict"; | ||
log: this.attachmentManager.log.bind(this.attachmentManager), | ||
link: this.attachmentManager.link.bind(this.attachmentManager), | ||
parameters: structuredClone(this.worldParameters), | ||
@@ -90,0 +91,0 @@ }); |
@@ -1,5 +0,6 @@ | ||
import { ICreateAttachment, ICreateLog } from '../runtime/attachment_manager'; | ||
import { ICreateAttachment, ICreateLink, ICreateLog } from '../runtime/attachment_manager'; | ||
export interface IWorldOptions<ParametersType = any> { | ||
attach: ICreateAttachment; | ||
log: ICreateLog; | ||
link: ICreateLink; | ||
parameters: ParametersType; | ||
@@ -10,2 +11,3 @@ } | ||
readonly log: ICreateLog; | ||
readonly link: ICreateLink; | ||
readonly parameters: ParametersType; | ||
@@ -17,4 +19,5 @@ [key: string]: any; | ||
readonly log: ICreateLog; | ||
readonly link: ICreateLink; | ||
readonly parameters: ParametersType; | ||
constructor({ attach, log, parameters }: IWorldOptions<ParametersType>); | ||
constructor({ attach, log, link, parameters, }: IWorldOptions<ParametersType>); | ||
} |
@@ -6,6 +6,8 @@ "use strict"; | ||
log; | ||
link; | ||
parameters; | ||
constructor({ attach, log, parameters }) { | ||
constructor({ attach, log, link, parameters, }) { | ||
this.attach = attach; | ||
this.log = log; | ||
this.link = link; | ||
this.parameters = parameters; | ||
@@ -12,0 +14,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare const version = "10.8.0"; | ||
export declare const version = "10.9.0"; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = '10.8.0'; | ||
exports.version = '10.9.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "10.8.0", | ||
"version": "10.9.0", | ||
"funding": "https://opencollective.com/cucumber", | ||
@@ -222,3 +222,3 @@ "homepage": "https://github.com/cucumber/cucumber-js", | ||
"@cucumber/gherkin-utils": "9.0.0", | ||
"@cucumber/html-formatter": "21.3.1", | ||
"@cucumber/html-formatter": "21.6.0", | ||
"@cucumber/message-streams": "4.0.1", | ||
@@ -244,2 +244,3 @@ "@cucumber/messages": "24.1.0", | ||
"luxon": "3.2.1", | ||
"mime": "^3.0.0", | ||
"mkdirp": "^2.1.5", | ||
@@ -348,4 +349,3 @@ "mz": "^2.7.0", | ||
"types-test": "tsd", | ||
"unit-test": "mocha 'src/**/*_spec.ts'", | ||
"update-dependencies": "npx npm-check-updates --upgrade" | ||
"unit-test": "mocha 'src/**/*_spec.ts'" | ||
}, | ||
@@ -352,0 +352,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
898003
9154
42
+ Addedmime@^3.0.0
+ Added@cucumber/html-formatter@21.6.0(transitive)
+ Addedmime@3.0.0(transitive)
- Removed@cucumber/html-formatter@21.3.1(transitive)