-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
667 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import test from "@playwright/test"; | ||
import { Label, LabelName, Link, LinkType } from "allure-js-commons"; | ||
|
||
|
||
export const ALLURE_METADATA_CONTENT_TYPE = "application/vnd.allure.metadata+json"; | ||
export interface Metadata { | ||
labels?: Label[]; | ||
links?: Link[]; | ||
} | ||
|
||
export class allure { | ||
static addMetadataAttachment(metadata: Metadata) { | ||
test.info().attach("allure-metadata.json",{ | ||
contentType: ALLURE_METADATA_CONTENT_TYPE, | ||
body: Buffer.from(JSON.stringify(metadata), "utf8"), | ||
}); | ||
} | ||
|
||
static label(label: Label | Label[]) { | ||
this.addMetadataAttachment({ | ||
labels: Array.isArray(label) ? label : [label], | ||
}); | ||
} | ||
|
||
static link(link: Link) { | ||
this.addMetadataAttachment({ | ||
links: Array.isArray(link) ? link : [link], | ||
}); | ||
} | ||
|
||
static id(id: string) { | ||
this.label({ | ||
value: id, | ||
name: LabelName.AS_ID, | ||
}); | ||
} | ||
|
||
static epic(epic: string) { | ||
this.label({ | ||
name: LabelName.EPIC, | ||
value: epic, | ||
}); | ||
} | ||
|
||
static feature(epic: string) { | ||
this.label({ | ||
name: LabelName.FEATURE, | ||
value: epic, | ||
}); | ||
} | ||
|
||
static story(story: string): void { | ||
this.label({ | ||
name: LabelName.STORY, | ||
value: story, | ||
}); | ||
} | ||
|
||
static suite(name: string): void { | ||
this.label({ | ||
name: LabelName.SUITE, | ||
value: name, | ||
}); | ||
} | ||
|
||
static parentSuite(name: string) { | ||
this.label({ | ||
name: LabelName.PARENT_SUITE, | ||
value: name, | ||
}); | ||
} | ||
|
||
static subSuite(name: string) { | ||
this.label({ | ||
name: LabelName.SUB_SUITE, | ||
value: name, | ||
}); | ||
} | ||
|
||
static owner(owner: string) { | ||
this.label({ | ||
name: LabelName.OWNER, | ||
value: owner, | ||
}); | ||
} | ||
|
||
static severity(severity: string) { | ||
this.label({ | ||
name: LabelName.SEVERITY, | ||
value: severity, | ||
}); | ||
} | ||
|
||
static tag(tag: string) { | ||
this.label({ | ||
name: LabelName.TAG, | ||
value: tag, | ||
}); | ||
} | ||
|
||
static issue(issueData: Omit<Link, "type">) { | ||
this.link({ | ||
url: issueData.url, | ||
name: issueData.name, | ||
type: LinkType.ISSUE, | ||
}); | ||
} | ||
|
||
static tms(issueData: Omit<Link, "type">) { | ||
this.link({ | ||
url: issueData.url, | ||
name: issueData.name, | ||
type: LinkType.TMS, | ||
}); | ||
} | ||
} | ||
|
||
export {LabelName} from "allure-js-commons"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Label, LabelName } from "allure-js-commons"; | ||
import { test, expect } from "./fixtures"; | ||
|
||
test("should have label", async ({ runInlineTest }) => { | ||
const result: Label[] = await runInlineTest( | ||
{ | ||
"a.test.ts": ` | ||
import { test, expect } from '@playwright/test'; | ||
import { allure, LabelName } from '../../dist/index' | ||
test('should add epic label', async ({}, testInfo) => { | ||
allure.label({name:LabelName.EPIC,value:'Test epic label'}); | ||
}); | ||
`, | ||
}, | ||
(writer) => { | ||
return writer.tests.map((t) => t.labels); | ||
}, | ||
); | ||
expect(result[0]).toContainEqual({ name: LabelName.EPIC, value: "Test epic label" }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Label } from "allure-js-commons"; | ||
import { test, expect } from "./fixtures"; | ||
test("should have link", async ({ runInlineTest }) => { | ||
const result: Label[] = await runInlineTest( | ||
{ | ||
"a.test.ts": ` | ||
import { test } from '@playwright/test'; | ||
import { allure } from '../../dist/index' | ||
test('should add epic link', async ({}, testInfo) => { | ||
allure.link({url:"https://playwright.dev/docs/api/class-page#page-workers"}); | ||
}); | ||
`, | ||
}, | ||
(writer) => { | ||
return writer.tests.map(val => val.links); | ||
}, | ||
); | ||
|
||
expect(result[0]).toContainEqual({ | ||
url: "https://playwright.dev/docs/api/class-page#page-workers", | ||
}); | ||
}); |
Oops, something went wrong.