From d6938e22b68102d074a7ff5df21e9a6e1b2cc3d9 Mon Sep 17 00:00:00 2001 From: Vitaliy Potapov Date: Thu, 10 Oct 2024 10:27:44 +0400 Subject: [PATCH] chore: tiny fixes in typings and examples --- examples/basic-cjs/package.json | 2 +- examples/basic-esm/package.json | 2 +- src/reporter/cucumber/attachments/external.ts | 17 ++--------------- src/reporter/cucumber/attachments/trace.ts | 2 ++ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/examples/basic-cjs/package.json b/examples/basic-cjs/package.json index 21a1c72f..5509f585 100644 --- a/examples/basic-cjs/package.json +++ b/examples/basic-cjs/package.json @@ -2,7 +2,7 @@ "type": "commonjs", "scripts": { "test": "npx bddgen && npx playwright test", - "show-report": "npx http-server ./cucumber-report -o index.html", + "show-report": "npx http-server ./cucumber-report -c-1 -o index.html", "watch:bdd": "nodemon -w ./features -w ./steps -e feature,js,ts --exec \"npx bddgen\"", "watch:pw": "playwright test --ui", "watch": "run-p watch:*" diff --git a/examples/basic-esm/package.json b/examples/basic-esm/package.json index 1bc17f1b..c29a521b 100644 --- a/examples/basic-esm/package.json +++ b/examples/basic-esm/package.json @@ -2,6 +2,6 @@ "type": "module", "scripts": { "test": "npx bddgen && npx playwright test", - "show-report": "npx http-server ./cucumber-report -o index.html" + "show-report": "npx http-server ./cucumber-report -c-1 -o index.html" } } diff --git a/src/reporter/cucumber/attachments/external.ts b/src/reporter/cucumber/attachments/external.ts index 9fe5b47d..4476451f 100644 --- a/src/reporter/cucumber/attachments/external.ts +++ b/src/reporter/cucumber/attachments/external.ts @@ -47,7 +47,8 @@ export function toExternalAttachment( const fileName = calculateSha1(buffer) + '.' + extension; const filePath = path.join(attachmentsDir, fileName); // todo: save file async? - fs.writeFileSync(filePath, buffer); + // without converting to Uint8Array TS complains about buffer type + fs.writeFileSync(filePath, new Uint8Array(buffer)); return { ...attachment, @@ -72,17 +73,3 @@ function getAttachmentExtension(attachment: messages.Attachment) { export function isTextAttachment(attachment: messages.Attachment) { return /^(text\/|application\/json)/.test(attachment.mediaType); } - -// function createMissingAttachmentError(attachmentPath: string) { -// const attachmentDir = path.join(path.dirname(attachmentPath)); -// const attachmentDirExists = fs.existsSync(attachmentDir); -// const files = attachmentDirExists ? fs.readdirSync(attachmentDir) : []; -// const errorMsg = [ -// `Attachment file is not found:`, -// attachmentPath, -// `Attachment dir ${attachmentDirExists ? 'exists' : 'does not exist'}.`, -// ...(attachmentDirExists ? [`Available files (${files.length}):`, ...files] : []), -// '', -// ].join('\n'); -// return new Error(errorMsg); -// } diff --git a/src/reporter/cucumber/attachments/trace.ts b/src/reporter/cucumber/attachments/trace.ts index 09558767..f14185f3 100644 --- a/src/reporter/cucumber/attachments/trace.ts +++ b/src/reporter/cucumber/attachments/trace.ts @@ -45,5 +45,7 @@ export function isTraceAttachment(attachment: messages.Attachment) { } export function generateTraceUrl(attachment: messages.Attachment) { + // In PW trace url is generated dynamically in JS with location.href: + // https://github.com/microsoft/playwright/blob/8f3353865d8d98e9b40c15497e60d5e2583410b6/packages/html-reporter/src/links.tsx#L102 return `trace/index.html?trace=${attachment.url}`; }