-
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
4 changed files
with
73 additions
and
6 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
4 changes: 4 additions & 0 deletions
4
packages/allure-cucumberjs/test/samples/features/duration.feature
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,4 @@ | ||
Feature: duration | ||
|
||
Scenario: scenario with sleep | ||
Given a sleep |
14 changes: 14 additions & 0 deletions
14
packages/allure-cucumberjs/test/samples/support/duration.cjs
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,14 @@ | ||
const { Given, Before } = require("@cucumber/cucumber"); | ||
|
||
const sleep = (ms) => | ||
new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
|
||
Before(async () => { | ||
await sleep(80); | ||
}); | ||
|
||
Given("a sleep", async () => { | ||
await sleep(100); | ||
}); |
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,44 @@ | ||
import { expect, it } from "vitest"; | ||
import { runCucumberInlineTest } from "../utils.js"; | ||
|
||
it("should set correct timings for tests", async () => { | ||
const before = new Date().getTime(); | ||
const { tests } = await runCucumberInlineTest(["duration"], ["duration"]); | ||
const after = new Date().getTime(); | ||
|
||
expect(tests).toHaveLength(1); | ||
const [tr] = tests; | ||
expect(tr.name).toEqual("scenario with sleep"); | ||
expect(tr.start).toBeGreaterThanOrEqual(before); | ||
expect(tr.start).toBeLessThanOrEqual(after); | ||
expect(tr.stop).toBeGreaterThanOrEqual(tr.start!); | ||
}); | ||
|
||
it("should set correct timings for steps", async () => { | ||
const before = new Date().getTime(); | ||
const { tests } = await runCucumberInlineTest(["duration"], ["duration"]); | ||
const after = new Date().getTime(); | ||
|
||
expect(tests).toHaveLength(1); | ||
const [tr] = tests; | ||
const [s1] = tr.steps; | ||
expect(s1.name).toEqual("Given a sleep"); | ||
expect(s1.start).toBeGreaterThanOrEqual(before); | ||
expect(s1.start).toBeLessThanOrEqual(after); | ||
expect(s1.stop).toBeGreaterThanOrEqual(s1.start!); | ||
expect(s1.stop! - s1.start!).toBeGreaterThanOrEqual(100); | ||
}); | ||
|
||
it("should set correct timings for hooks", async () => { | ||
const before = new Date().getTime(); | ||
const { groups } = await runCucumberInlineTest(["duration"], ["duration"]); | ||
const after = new Date().getTime(); | ||
|
||
expect(groups).toHaveLength(1); | ||
const [trc] = groups; | ||
const [f1] = trc.befores; | ||
expect(f1.start).toBeGreaterThanOrEqual(before); | ||
expect(f1.start).toBeLessThanOrEqual(after); | ||
expect(f1.stop).toBeGreaterThanOrEqual(f1.start!); | ||
expect(f1.stop! - f1.start!).toBeGreaterThanOrEqual(80); | ||
}); |