From b03769bf65f93bcb7cca80010f170c109f9bbc68 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 16 Jul 2021 17:47:35 -0700 Subject: [PATCH] feat(allure-playwright): initial implementation for allure-playwright --- README.md | 4 + packages/allure-playwright/.gitignore | 1 + packages/allure-playwright/.npmignore | 5 + packages/allure-playwright/LICENSE.txt | 201 ++++++++++++++++++ packages/allure-playwright/README.md | 42 ++++ packages/allure-playwright/package.json | 34 +++ packages/allure-playwright/src/index.ts | 123 +++++++++++ packages/allure-playwright/test/fixtures.ts | 108 ++++++++++ .../allure-playwright/test/labels.spec.ts | 97 +++++++++ .../test/status-details.spec.ts | 33 +++ .../allure-playwright/test/status.spec.ts | 40 ++++ packages/allure-playwright/test/stdio.spec.ts | 38 ++++ packages/allure-playwright/tsconfig.json | 14 ++ 13 files changed, 740 insertions(+) create mode 100644 packages/allure-playwright/.gitignore create mode 100644 packages/allure-playwright/.npmignore create mode 100644 packages/allure-playwright/LICENSE.txt create mode 100644 packages/allure-playwright/README.md create mode 100644 packages/allure-playwright/package.json create mode 100644 packages/allure-playwright/src/index.ts create mode 100644 packages/allure-playwright/test/fixtures.ts create mode 100644 packages/allure-playwright/test/labels.spec.ts create mode 100644 packages/allure-playwright/test/status-details.spec.ts create mode 100644 packages/allure-playwright/test/status.spec.ts create mode 100644 packages/allure-playwright/test/stdio.spec.ts create mode 100644 packages/allure-playwright/tsconfig.json diff --git a/README.md b/README.md index 2ea7d934a..a4dc34f33 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ This project aggregates Allure Javascript commons and reporters. [Read more](/packages/allure-mocha/README.md) +### Playwright +[Read more](/packages/allure-playwright/README.md) + + ## Development ### allure-js-commons diff --git a/packages/allure-playwright/.gitignore b/packages/allure-playwright/.gitignore new file mode 100644 index 000000000..5b8b3b6fc --- /dev/null +++ b/packages/allure-playwright/.gitignore @@ -0,0 +1 @@ +test-results \ No newline at end of file diff --git a/packages/allure-playwright/.npmignore b/packages/allure-playwright/.npmignore new file mode 100644 index 000000000..20a1c2ec3 --- /dev/null +++ b/packages/allure-playwright/.npmignore @@ -0,0 +1,5 @@ +* +!dist/** +!package.json +!*.md +!*.txt diff --git a/packages/allure-playwright/LICENSE.txt b/packages/allure-playwright/LICENSE.txt new file mode 100644 index 000000000..b5ed4ecec --- /dev/null +++ b/packages/allure-playwright/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + 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. diff --git a/packages/allure-playwright/README.md b/packages/allure-playwright/README.md new file mode 100644 index 000000000..0539a80da --- /dev/null +++ b/packages/allure-playwright/README.md @@ -0,0 +1,42 @@ +# allure-playwright + +This project implements Allure integration with [Playwright Test](https://playwright.dev) framework. + +## Installation + +```bash +npm i -D @playwright/test allure-playwright +``` +or via yarn: +```bash +yarn add @playwright/test allure-playwright --dev +``` + +## Usage + +Either add **allure-playwright** into **playwright.config.ts**: + +```js +{ + reporter: 'allure-playwright' +} +``` + +Or pass the same value via command line: + +```bash +npx playwright test --reporter=line,allure-playwright +``` + +Specify location for allure results: + +Mac / Linux +```bash +ALLURE_RESULTS_DIR=my-allure-results npx playwright test --reporter=line,allure-playwright +``` + +Windows +```bash +set ALLURE_RESULTS_DIR=my-allure-results +npx playwright test --reporter=line,allure-playwright +``` diff --git a/packages/allure-playwright/package.json b/packages/allure-playwright/package.json new file mode 100644 index 000000000..8c694b28e --- /dev/null +++ b/packages/allure-playwright/package.json @@ -0,0 +1,34 @@ +{ + "name": "allure-playwright", + "version": "2.0.0-beta.10", + "description": "Allure Playwright integration", + "license": "Apache-2.0", + "author": { + "name": "Microsoft Corporation" + }, + "repository": "https://github.com/allure-framework/allure-playwright", + "keywords": [ + "playwright", + "allure" + ], + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "scripts": { + "clean": "rimraf ./dist ./out", + "compile": "tsc", + "prepublishOnly": "npm run clean && npm run build", + "build": "npm run compile", + "generate-report": "allure generate ./out/allure-results -o ./out/allure-report --clean", + "allure-report": "allure serve ./out/allure-results", + "test": "playwright test -c test", + "lint": "eslint ./src ./test --ext .ts", + "lint-fix": "eslint ./src ./test ./index.ts --ext .ts --fix" + }, + "devDependencies": { + "@playwright/test": "=1.13.0-1626733671000" + }, + "dependencies": { + "allure-js-commons": "^2.0.0-beta.10", + "@types/node": "^15.14.1" + } +} diff --git a/packages/allure-playwright/src/index.ts b/packages/allure-playwright/src/index.ts new file mode 100644 index 000000000..8b79e30da --- /dev/null +++ b/packages/allure-playwright/src/index.ts @@ -0,0 +1,123 @@ +/** + * 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 path from 'path'; +import { AllureGroup, AllureRuntime, InMemoryAllureWriter, LabelName, Status } from 'allure-js-commons'; +import { FullConfig, TestStatus } from '@playwright/test'; +import { Suite, Reporter } from '@playwright/test/reporter'; + +class AllureReporter implements Reporter { + config!: FullConfig; + suite!: Suite; + + onBegin(config: FullConfig, suite: Suite) { + this.config = config; + this.suite = suite; + } + + onTimeout() { + this.onEnd(); + } + + async onEnd() { + const writerForTest = process.env.PW_ALLURE_POST_PROCESSOR_FOR_TEST ? new InMemoryAllureWriter() : undefined; + const resultsDir = process.env.ALLURE_RESULTS_DIR || path.join(process.cwd(), 'allure-results'); + const runtime = new AllureRuntime({ resultsDir, writer: writerForTest }); + const processSuite = (suite: Suite, parent: AllureGroup | AllureRuntime) => { + const groupName = 'Root'; + const group = parent.startGroup(groupName); + for (const test of suite.tests) { + for (const result of test.results) { + const startTime = result.startTime.getTime(); + const endTime = startTime + result.duration; + const allureTest = group.startTest(test.title, startTime); + allureTest.addLabel(LabelName.LANGUAGE, 'JavaScript'); + allureTest.addLabel(LabelName.FRAMEWORK, 'Playwright'); + const [, projectSuiteTitle, fileSuiteTitle, ...suiteTitles] = suite.titlePath(); + if (projectSuiteTitle) + allureTest.addLabel(LabelName.PARENT_SUITE, projectSuiteTitle); + if (fileSuiteTitle) + allureTest.addLabel(LabelName.SUITE, fileSuiteTitle); + if (suiteTitles.length > 0) + allureTest.addLabel(LabelName.SUB_SUITE, suiteTitles.join(' > ')); + + allureTest.historyId = test.titlePath().slice(1).join(' '); + allureTest.fullName = test.title; + allureTest.status = statusToAllureStats(result.status!); + + if (result.error) { + const message = result.error.message && stripAscii(result.error.message); + let trace = result.error.stack && stripAscii(result.error.stack); + if (trace && message && trace.startsWith('Error: ' + message)) + trace = trace.substr(message.length + 'Error: '.length); + allureTest.statusDetails = { + message, + trace, + }; + } + + for (const attachment of result.attachments) { + let fileName = attachment.path; + if (attachment.body) + fileName = runtime.writeAttachment(attachment.body, attachment.contentType); + allureTest.addAttachment(attachment.name, attachment.contentType, fileName!); + if (attachment.name === 'diff') + allureTest.addLabel('testType', 'screenshotDiff'); + } + + for (const stdout of result.stdout) + allureTest.addAttachment('stdout', 'text/plain', runtime.writeAttachment(stdout, 'text/plain')); + for (const stderr of result.stderr) + allureTest.addAttachment('stderr', 'text/plain', runtime.writeAttachment(stderr, 'text/plain')); + allureTest.endTest(endTime); + } + } + for (const child of suite.suites) + processSuite(child, group); + group.endGroup(); + }; + processSuite(this.suite, runtime); + + if (process.env.PW_ALLURE_POST_PROCESSOR_FOR_TEST) { + try { + const postProcess = eval(process.env.PW_ALLURE_POST_PROCESSOR_FOR_TEST); + console.log(JSON.stringify(postProcess(writerForTest))); + } catch (e) { + console.log(JSON.stringify({ error: e.toString() })); + } + } + } +} + +function statusToAllureStats(status: TestStatus): Status { + switch (status) { + case 'failed': + return Status.FAILED; + case 'passed': + return Status.PASSED; + case 'skipped': + return Status.SKIPPED; + case 'timedOut': + return Status.BROKEN; + } +} + +export default AllureReporter; + +const asciiRegex = new RegExp('[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))', 'g'); +export function stripAscii(str: string): string { + return str.replace(asciiRegex, ''); +} diff --git a/packages/allure-playwright/test/fixtures.ts b/packages/allure-playwright/test/fixtures.ts new file mode 100644 index 000000000..398e5b9e5 --- /dev/null +++ b/packages/allure-playwright/test/fixtures.ts @@ -0,0 +1,108 @@ +/** + * 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 { test as base, TestInfo } from '@playwright/test'; +import type { InMemoryAllureWriter } from 'allure-js-commons'; +import { spawn } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +export { expect } from '@playwright/test'; + +type RunResult = any; + +type Files = { [key: string]: string | Buffer }; +type Params = { [key: string]: string | number | boolean | string[] }; +type Env = { [key: string]: string | number | boolean | undefined }; + +async function writeFiles(testInfo: TestInfo, files: Files) { + const baseDir = testInfo.outputPath(); + + const hasConfig = Object.keys(files).some(name => name.includes('.config.')); + if (!hasConfig) { + files = { + ...files, + 'playwright.config.ts': ` + module.exports = { projects: [ { name: 'project' } ] }; + `, + }; + } + + await Promise.all(Object.keys(files).map(async name => { + const fullName = path.join(baseDir, name); + await fs.promises.mkdir(path.dirname(fullName), { recursive: true }); + await fs.promises.writeFile(fullName, files[name]); + })); + + return baseDir; +} + +async function runPlaywrightTest(baseDir: string, postProcess: (writer: InMemoryAllureWriter) => any, params: any, env: NodeJS.ProcessEnv): Promise { + const paramList = []; + let additionalArgs = ''; + for (const key of Object.keys(params)) { + if (key === 'args') { + additionalArgs = params[key]; + continue; + } + for (const value of Array.isArray(params[key]) ? params[key] : [params[key]]) { + const k = key.startsWith('-') ? key : '--' + key; + paramList.push(params[key] === true ? `${k}` : `${k}=${value}`); + } + } + const outputDir = path.join(baseDir, 'test-results'); + const args = [require.resolve('@playwright/test/lib/cli/cli.js'), 'test']; + args.push( + '--output=' + outputDir, + '--reporter=' + require.resolve('../dist/index.js'), + '--workers=2', + ...paramList + ); + if (additionalArgs) + args.push(...additionalArgs); + const testProcess = spawn('node', args, { + env: { + ...process.env, + ...env, + PW_ALLURE_POST_PROCESSOR_FOR_TEST: String(postProcess) + }, + cwd: baseDir + }); + let output = ''; + testProcess.stdout.on('data', chunk => { + output += String(chunk); + if (process.env.PW_RUNNER_DEBUG) + process.stdout.write(String(chunk)); + }); + await new Promise(x => testProcess.on('close', x)); + return JSON.parse(output.toString()); +} + +type Fixtures = { + runInlineTest: (files: Files, postProcess: (writer: InMemoryAllureWriter) => any, params?: Params, env?: Env) => Promise; +}; + +export const test = base.extend({ + runInlineTest: async ({}, use, testInfo: TestInfo) => { + let runResult: RunResult | undefined; + await use(async (files: Files, postProcess, params: Params = {}, env: NodeJS.ProcessEnv = {}) => { + const baseDir = await writeFiles(testInfo, files); + runResult = await runPlaywrightTest(baseDir, postProcess, params, env); + return runResult; + }); + if (testInfo.status !== testInfo.expectedStatus && runResult && !process.env.PW_RUNNER_DEBUG) + console.log(runResult.output); + } +}); diff --git a/packages/allure-playwright/test/labels.spec.ts b/packages/allure-playwright/test/labels.spec.ts new file mode 100644 index 000000000..c08115062 --- /dev/null +++ b/packages/allure-playwright/test/labels.spec.ts @@ -0,0 +1,97 @@ +/** + * 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 { test, expect } from './fixtures'; + +test('should report structure', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import test from '@playwright/test'; + test.describe('suite', () => { + test('should work', async ({}) => {}); + });`, + 'b.test.ts': ` + import test from '@playwright/test'; + test.describe('parent suite 2', () => { + test.describe('suite 2', () => { + test.describe('sub suite 2', () => { + test('should work 2', async ({}) => {}); + }); + }); + }); + ` + }, writer => { + return writer.tests.map(t => ({ + name: t.name, + fullName: t.fullName, + historyId: t.historyId, + labels: t.labels + })); + }); + expect(result).toEqual([ + { + name: 'should work', + fullName: 'should work', + historyId: 'project a.test.ts suite should work', + labels: [ + { + 'name': 'language', + 'value': 'JavaScript' + }, + { + 'name': 'framework', + 'value': 'Playwright' + }, + { + 'name': 'parentSuite', + 'value': 'project' + }, + { + 'name': 'suite', + 'value': 'a.test.ts' + }, { + 'name': 'subSuite', + 'value': 'suite' + } + ], + }, + { + name: 'should work 2', + fullName: 'should work 2', + historyId: 'project b.test.ts parent suite 2 suite 2 sub suite 2 should work 2', + labels: [ + { + 'name': 'language', + 'value': 'JavaScript' + }, + { + 'name': 'framework', + 'value': 'Playwright' + }, + { + 'name': 'parentSuite', + 'value': 'project' + }, { + 'name': 'suite', + 'value': 'b.test.ts' + }, { + 'name': 'subSuite', + 'value': 'parent suite 2 > suite 2 > sub suite 2' + } + ] + } + ]); +}); diff --git a/packages/allure-playwright/test/status-details.spec.ts b/packages/allure-playwright/test/status-details.spec.ts new file mode 100644 index 000000000..f355268ae --- /dev/null +++ b/packages/allure-playwright/test/status-details.spec.ts @@ -0,0 +1,33 @@ +/** + * 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 { test, expect } from './fixtures'; + +test('should report test status details', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('should fail', async ({}) => { + expect(true).toBe(false); + }); + ` + }, writer => { + return writer.tests[0].statusDetails; + }); + expect(result.message).toContain('Object.is equality'); + expect(result.trace).toContain('at '); + expect(result.trace.trim().startsWith('at ')).toBeTruthy(); +}); diff --git a/packages/allure-playwright/test/status.spec.ts b/packages/allure-playwright/test/status.spec.ts new file mode 100644 index 000000000..5767329ea --- /dev/null +++ b/packages/allure-playwright/test/status.spec.ts @@ -0,0 +1,40 @@ +/** + * 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 { test, expect } from './fixtures'; + +test('should report test status', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('should pass', async ({}) => { + }); + test('should fail', async ({}) => { + expect(true).toBe(false); + }); + test('should break', async ({}) => { + test.setTimeout(1); + await new Promise(() => {}); + }); + test('should skip', async ({}) => { + test.skip(true); + }); + ` + }, writer => { + return writer.tests.map(t => t.status); + }); + expect(result).toEqual(['passed', 'failed', 'broken', 'skipped']); +}); diff --git a/packages/allure-playwright/test/stdio.spec.ts b/packages/allure-playwright/test/stdio.spec.ts new file mode 100644 index 000000000..448f8b1f0 --- /dev/null +++ b/packages/allure-playwright/test/stdio.spec.ts @@ -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 { test, expect } from './fixtures'; + +test('should report stdout and stderr', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import test from '@playwright/test'; + test('stdout should work', async ({}) => { + console.log('System out'); + console.error('System err'); + }); + ` + }, writer => { + return writer.tests[0].attachments.map(a => { + const buffer = writer.attachments[a.source]; + return { name: a.name, type: a.type, buffer }; + }); + }); + expect(result).toEqual([ + { name: 'stdout', type: 'text/plain', buffer: 'System out\n' }, + { name: 'stderr', type: 'text/plain', buffer: 'System err\n' }, + ]); +}); diff --git a/packages/allure-playwright/tsconfig.json b/packages/allure-playwright/tsconfig.json new file mode 100644 index 000000000..522058547 --- /dev/null +++ b/packages/allure-playwright/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "./src/**/*", + ], + "exclude": [ + "./test/**/*", + ], + "compilerOptions": { + "lib": ["esnext", "dom", "DOM.Iterable"], + "rootDir": "./src", + "outDir": "./dist" + } +}