How to generate results with allure-js-commons version 3 from custom framework? #2610
-
We have a custom framework we use in our company that generates test results to JSON files. I would like to create a script that will take these files as input and generate the appropriate allure-results JSON files from that. I am using TypeScript on Node.js with the allure-js-commons package. With version 2.15.1 of the library, I am able to use the following sample code to generate the files: import { AllureRuntime, ExecutableItem, Stage, FileSystemAllureWriter, Status } from 'allure-js-commons'
import _ from "lodash"
import path from 'path'
const oneHourAgo = new Date().getTime() - 60000
const resultsDir = path.resolve(__dirname, "output", "allure-results")
const writer = new FileSystemAllureWriter({ resultsDir })
const runtime = new AllureRuntime({ resultsDir, writer })
const group1 = runtime.startGroup("Group 1")
const test1 = group1.startTest("Test 1", oneHourAgo)
const step1: ExecutableItem = {
name: "Step 1",
status: Status.PASSED,
statusDetails: {},
stage: Stage.FINISHED,
steps: [],
attachments: [],
parameters: [],
start: oneHourAgo + _.random(1000, 4000),
stop: oneHourAgo + _.random(28000, 33000)
}
test1.addStep(step1)
const step2: ExecutableItem = {
name: "Step 2",
status: Status.PASSED,
statusDetails: {},
stage: Stage.FINISHED,
steps: [],
attachments: [],
parameters: [],
start: oneHourAgo + _.random(34000, 37000),
stop: oneHourAgo + _.random(58000, 64000)
}
test1.addStep(step2)
test1.status = Status.PASSED
test1.endTest(oneHourAgo + _.random(87000, 93000))
group1.endGroup() This is just a simple example with one group, one test, and 2 steps. In practice, I would be populating more values, etc. However, with the latest version 3.0.0-beta.3, the API appears to have changed substantially. I see that Are there any code examples I could look at to get me started with rewriting this to work with version 3? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Now, So instead of import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter";
const writer = new FileSystemWriter({ resultsDir: ".out/allure-results"});
const runtime = new ReporterRuntime({ writer });
const rootUuid = runtime.startTest({ name: "Some test name" });
// stepUuid can be undefined in case no test with rootUuid is found
const stepUuid = runtime.startStep(rootUuid, undefined, { name: "some name" });
runtime.updateStep(stepUuid!, (result) => { result.status = Status.PASSED });
runtime.stopStep(stepUuid!);
runtime.stopTest(rootUuid);
runtime.writeTest(rootUuid); For hooks, there is a new abstraction called the scope: const scopeUuid = runtime.startScope();
const hookUuid = runtime.startFixture(scopeUuid, { name: "before"});
const stepUuid = runtime.startStep(hookUuid, undefined, { name: "some name" });
runtime.updateStep(stepUuid!, (result) => { result.status = Status.PASSED });
runtime.stopStep(stepUuid!);
runtime.stopFixture(hookUuid);
// scopes can be linked to tests by last argument in startTest method:
const testUuid = runtime.startTest({}, [ scopeUuid ]);
//...
runtime.writeScope(scopeUuid); |
Beta Was this translation helpful? Give feedback.
Now,
allure-js-commons
is split into two parts: SKD and client. The SDK API is used to create new integrations. The client code can be run in any environment (including browsers). Allure relies on message bus abstraction, which should be implemented by each test runner.So instead of
AllureRuntime
, there is nowReporterRuntime
andTestRuntime
.ReporterRuntime
is the one you're looking for: