playwright-bdd
Version:
BDD Testing with Playwright runner
49 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptFixture = void 0;
exports.isPromptAttachmentContentType = isPromptAttachmentContentType;
const promptBuilder_1 = require("./promptBuilder");
const PROMPT_ATTACHMENT_NAME = '🤖 Fix with AI: copy prompt and paste to AI chat';
const PROMPT_ATTACHMENT_CONTENT_TYPE = 'text/plain+prompt';
class PromptFixture {
constructor(bddContext) {
this.bddContext = bddContext;
}
get bddConfig() {
return this.bddContext.config;
}
get testInfo() {
return this.bddContext.testInfo;
}
setPage(page) {
this.page = page;
}
async attach() {
if (!this.bddConfig.aiFix?.promptAttachment)
return;
if (!this.page)
return;
if (!this.isFailedTest())
return;
const prompt = await new promptBuilder_1.PromptBuilder(this.bddContext, this.page).build();
if (!prompt)
return;
await this.testInfo.attach(this.getAttachmentName(), {
body: prompt,
contentType: PROMPT_ATTACHMENT_CONTENT_TYPE,
});
}
isFailedTest() {
const { testInfo } = this;
const willBeRetried = testInfo.retry < testInfo.project.retries;
return Boolean(testInfo.error && !willBeRetried);
}
getAttachmentName() {
return this.bddConfig.aiFix?.promptAttachmentName || PROMPT_ATTACHMENT_NAME;
}
}
exports.PromptFixture = PromptFixture;
function isPromptAttachmentContentType(contentType) {
return contentType === PROMPT_ATTACHMENT_CONTENT_TYPE;
}
//# sourceMappingURL=promptAttachment.js.map