@@ -179,24 +179,27 @@ it("keeps correct hooks structure when something failed", async () => {
179179it ( "should hook steps have attachments" , async ( ) => {
180180 const results = await runPlaywrightInlineTest ( {
181181 "sample.test.js" : `
182- const {test} = require("@playwright/test");
182+ const { test } = require("@playwright/test");
183183 const allure = require("allure-js-commons");
184+
184185 test.beforeAll(async () => {
185- await allure.attachment('attachment outside step beforeAll', 'test value', 'application/json');
186- await allure.step('i am beforeAll step', async () => {
187- await allure.attachment('attachment in beforeAll step', 'test value', 'application/json');
188- });
186+ await allure.attachment('attachment outside step beforeAll', 'test value', 'application/json');
187+ await allure.step('i am beforeAll step', async () => {
188+ await allure.attachment('attachment in beforeAll step', 'test value', 'application/json');
189+ });
189190 });
191+
190192 test.afterAll(async () => {
191- await allure.attachment('attachment outside step afterAll', 'test value', 'application/json');
192- await allure.step('i am afterAll', async () => {
193- await allure.attachment('test key afterall', 'test value', 'application/json');
194- });
193+ await allure.attachment('attachment outside step afterAll', 'test value', 'application/json');
194+ await allure.step('i am afterAll', async () => {
195+ await allure.attachment('test key afterall', 'test value', 'application/json');
196+ });
195197 });
198+
196199 test("sample test", async () => {
197- await allure.step("step 1", async () => {
198- await allure.attachment('attach in step 1', 'test value', 'application/json');
199- });
200+ await allure.step("step 1", async () => {
201+ await allure.attachment('attach in step 1', 'test value', 'application/json');
202+ });
200203 });
201204 ` ,
202205 "playwright.config.js" : `
@@ -222,11 +225,13 @@ it("should hook steps have attachments", async () => {
222225 ` ,
223226 } ) ;
224227 const steps = results . tests [ 0 ] . steps ;
228+
225229 expect ( steps ) . toHaveLength ( 3 ) ;
230+
226231 const beforeHooks = steps [ 0 ] ;
227232 const beforeAllHook = beforeHooks . steps [ 0 ] ;
228- expect ( beforeAllHook . name ) . equal ( "beforeAll hook" ) ;
229233
234+ expect ( beforeAllHook . name ) . equal ( "beforeAll hook" ) ;
230235 expect ( beforeAllHook . steps ) . toEqual ( [
231236 expect . objectContaining ( {
232237 name : "attachment outside step beforeAll" ,
@@ -254,8 +259,8 @@ it("should hook steps have attachments", async () => {
254259 ] ) ;
255260
256261 const step1Attachment = steps [ 1 ] ;
257- expect ( step1Attachment . name ) . toEqual ( "step 1" ) ;
258262
263+ expect ( step1Attachment . name ) . toEqual ( "step 1" ) ;
259264 expect ( step1Attachment . steps ) . toEqual ( [
260265 expect . objectContaining ( {
261266 name : "attach in step 1" ,
@@ -269,6 +274,7 @@ it("should hook steps have attachments", async () => {
269274 ] ) ;
270275
271276 const afterHooks = steps [ 2 ] ;
277+
272278 expect ( afterHooks . steps [ 0 ] . steps ) . toEqual ( [
273279 expect . objectContaining ( {
274280 name : "attachment outside step afterAll" ,
@@ -295,3 +301,69 @@ it("should hook steps have attachments", async () => {
295301 } ) ,
296302 ] ) ;
297303} ) ;
304+
305+ it ( "should not loose tests metadata when when there are hooks in the test" , async ( ) => {
306+ const results = await runPlaywrightInlineTest ( {
307+ "sample.test.js" : `
308+ import test from '@playwright/test';
309+ import * as allure from "allure-js-commons";
310+
311+ test.beforeAll(async () => {
312+ await allure.label("hook", "1");
313+ });
314+
315+ test.beforeEach(async () => {
316+ await allure.label("hook", "2");
317+ });
318+
319+ test.afterAll(async () => {
320+ await allure.label("hook", "3");
321+ });
322+
323+ test.afterEach(async () => {
324+ await allure.label("hook", "4");
325+ });
326+
327+ test("should contain label", async ({ page }) => {
328+ await allure.label("hook", "5");
329+ });
330+ ` ,
331+ } ) ;
332+
333+ expect ( results . tests ) . toHaveLength ( 1 ) ;
334+ expect ( results . tests [ 0 ] . labels ) . toEqual (
335+ expect . arrayContaining ( [
336+ {
337+ name : "hook" ,
338+ value : "1" ,
339+ } ,
340+ {
341+ name : "hook" ,
342+ value : "2" ,
343+ } ,
344+ {
345+ name : "hook" ,
346+ value : "3" ,
347+ } ,
348+ {
349+ name : "hook" ,
350+ value : "4" ,
351+ } ,
352+ {
353+ name : "hook" ,
354+ value : "5" ,
355+ } ,
356+ ] ) ,
357+ ) ;
358+ expect ( results . tests [ 0 ] . steps ) . toHaveLength ( 2 ) ;
359+ expect ( results . tests [ 0 ] . steps ) . toEqual (
360+ expect . arrayContaining ( [
361+ expect . objectContaining ( {
362+ name : "Before Hooks" ,
363+ } ) ,
364+ expect . objectContaining ( {
365+ name : "After Hooks" ,
366+ } ) ,
367+ ] ) ,
368+ ) ;
369+ } ) ;
0 commit comments