Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link's order of arguments #989

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"compile": "run-s 'compile:*'",
"compile:esm": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
"compile:cjs": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:types": "tsc --declaration --emitDeclarationOnly",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint ./src ./test --ext .ts --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const allureCodeceptJsLegacyApi: AllureCodeceptJsLegacyApi = {
/**
* @deprecated please use import { link } from "allure-js-commons" instead.
*/
link: (type, url, name) => Promise.resolve(allure.link(url, type, name)),
link: (type, url, name) => Promise.resolve(allure.link(url, name, type)),
/**
* @deprecated please use import { parameter } from "allure-js-commons" instead.
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/allure-codeceptjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"include": ["./src/**/*"],
"compilerOptions": {
"skipLibCheck": true,
"declaration": true,
"emitDeclarationOnly": true,
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",
"lib": ["dom", "esnext"],
"types": ["node", "jasmine"],
"outDir": "./dist"
"outDir": "./dist/types"
}
}
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"compile": "run-s 'compile:*'",
"compile:esm": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
"compile:cjs": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:types": "tsc --declaration --emitDeclarationOnly",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint --fix ./src ./test --ext .ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cucumberjs/src/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AllureCucumberWorld extends World implements AllureCucumberLegacyAp
/**
* @deprecated please use import { link } from "allure-js-commons" instead.
*/
link = (type: string, url: string, name?: string) => allure.link(url, type, name);
link = (type: string, url: string, name?: string) => allure.link(url, name, type);
/**
* @deprecated please use import { parameter } from "allure-js-commons" instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { link, issue, tms } = require("allure-js-commons");
Given("a step", () => {});

Given("a step with runtime link", async () => {
await link("https://example.com", "custom", "Custom link");
await link("https://example.com", "Custom link", "custom");
});

Given("a step with runtime issue links", async () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/allure-cucumberjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"include": ["./src/**/*"],
"compilerOptions": {
"skipLibCheck": true,
"declaration": true,
"emitDeclarationOnly": true,
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",
"lib": ["dom", "esnext"],
"types": ["node"],
"outDir": "./dist"
"outDir": "./dist/types"
}
}
2 changes: 1 addition & 1 deletion packages/allure-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"compile:cjs-node": "babel --config-file ./babel.cjs.json ./src --ignore './src/index.ts' --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:esm-browser": "esbuild ./src/index.ts --bundle --minify --sourcemap --format=esm --outfile=./dist/esm/index.js --external:allure-playwright",
"compile:cjs-browser": "esbuild ./src/index.ts --bundle --minify --sourcemap --format=cjs --outfile=./dist/cjs/index.js --external:allure-playwright",
"compile:types": "tsc --declaration --emitDeclarationOnly",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint ./src ./test --ext .ts --fix",
Expand Down
20 changes: 1 addition & 19 deletions packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stage, Status } from "allure-js-commons";
import type { ContentType, Label, LabelName, Link, LinkType, ParameterMode, ParameterOptions } from "allure-js-commons";
import type { ContentType, Label, Link, ParameterMode, ParameterOptions } from "allure-js-commons";
import type { RuntimeMessage } from "allure-js-commons/sdk";
import { getUnfinishedStepsMessages, hasStepMessage } from "allure-js-commons/sdk";
import type { TestRuntime } from "allure-js-commons/sdk/runtime";
Expand All @@ -8,15 +8,6 @@ import type { CypressRuntimeMessage } from "./model.js";
import { getSuitePath, normalizeAttachmentContentEncoding, uint8ArrayToBase64 } from "./utils.js";

export class AllureCypressTestRuntime implements TestRuntime {
label(name: LabelName | string, value: string) {
return this.sendMessageAsync({
type: "metadata",
data: {
labels: [{ name, value }],
},
});
}

labels(...labels: Label[]) {
return this.sendMessageAsync({
type: "metadata",
Expand All @@ -26,15 +17,6 @@ export class AllureCypressTestRuntime implements TestRuntime {
});
}

link(url: string, type?: LinkType | string, name?: string) {
return this.sendMessageAsync({
type: "metadata",
data: {
links: [{ type, url, name }],
},
});
}

links(...links: Link[]) {
return this.sendMessageAsync({
type: "metadata",
Expand Down
4 changes: 2 additions & 2 deletions packages/allure-cypress/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type Cypress from "cypress";
import { readFileSync } from "node:fs";
import { ContentType, LabelName, Stage } from "allure-js-commons";
import { extractMetadataFromString } from "allure-js-commons/sdk";
import { FileSystemWriter, ReporterRuntime, getSuitesLabels } from "allure-js-commons/sdk/reporter";
import { FileSystemWriter, ReporterRuntime, getSuiteLabels } from "allure-js-commons/sdk/reporter";
import type { CypressRuntimeMessage, CypressTestEndRuntimeMessage, CypressTestStartRuntimeMessage } from "./model.js";

export type AllureCypressConfig = {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class AllureCypress {
throw new Error("INTERNAL ERROR: Invalid message sequence");
}

const suiteLabels = getSuitesLabels(startMessage.data.specPath.slice(0, -1));
const suiteLabels = getSuiteLabels(startMessage.data.specPath.slice(0, -1));
const testTitle = startMessage.data.specPath[startMessage.data.specPath.length - 1];
const titleMetadata = extractMetadataFromString(testTitle);
const testUuid = this.runtime.startTest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ it("adds all the possible links", async () => {

expect(tests).toHaveLength(1);
expect(tests[0].links).toContainEqual({
name: "bar",
type: "foo",
name: "foo",
type: "bar",
url: "https://allurereport.org",
});
expect(tests[0].links).toContainEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ it("adds all the possible links", async () => {

expect(tests).toHaveLength(1);
expect(tests[0].links).toContainEqual({
name: "bar",
type: "foo",
name: "foo",
type: "bar",
url: "https://allurereport.org",
});
expect(tests[0].links).toContainEqual({
Expand Down
4 changes: 3 additions & 1 deletion packages/allure-cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"extends": "../../tsconfig.json",
"include": ["./src/**/*"],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"skipLibCheck": true,
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",
"lib": ["dom", "esnext"],
"types": ["node"],
"outDir": "./dist",
"outDir": "./dist/types",
"isolatedModules": true
}
}
2 changes: 1 addition & 1 deletion packages/allure-jasmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"compile": "run-s 'compile:*'",
"compile:esm-babel": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
"compile:cjs-babel": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./dist/types",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint ./src ./test --ext .ts --fix",
Expand Down
4 changes: 3 additions & 1 deletion packages/allure-jasmine/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"extends": "../../tsconfig.json",
"include": ["./src/**/*"],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"skipLibCheck": true,
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",
"lib": ["dom", "esnext"],
"types": ["node", "jasmine"],
"outDir": "./dist"
"outDir": "./dist/types"
}
}
2 changes: 1 addition & 1 deletion packages/allure-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"compile": "run-s 'compile:*'",
"compile:esm-babel": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
"compile:cjs-babel": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./dist/types",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint ./src ./test --ext .ts --fix",
Expand Down
4 changes: 2 additions & 2 deletions packages/allure-jest/src/environmentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as allure from "allure-js-commons";
import { LabelName, Stage, Status } from "allure-js-commons";
import type { RuntimeMessage } from "allure-js-commons/sdk";
import { getMessageAndTraceFromError, getStatusFromError } from "allure-js-commons/sdk";
import { FileSystemWriter, MessageWriter, ReporterRuntime, getSuitesLabels } from "allure-js-commons/sdk/reporter";
import { FileSystemWriter, MessageWriter, ReporterRuntime, getSuiteLabels } from "allure-js-commons/sdk/reporter";
import { setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
import { AllureJestTestRuntime } from "./AllureJestTestRuntime.js";
import type { AllureJestConfig, AllureJestEnvironment } from "./model.js";
Expand Down Expand Up @@ -159,7 +159,7 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>
result.labels.push({ name: LabelName.HOST, value: hostLabel });
}

result.labels.push(...getSuitesLabels(newTestSuitesPath));
result.labels.push(...getSuiteLabels(newTestSuitesPath));
}, testUuid);

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/allure-jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"extends": "../../tsconfig.json",
"include": ["./src/**/*"],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "bundler",
"lib": ["dom", "esnext"],
"types": ["node"],
"outDir": "./dist"
"outDir": "./dist/types"
}
}
2 changes: 1 addition & 1 deletion packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"compile": "run-s 'compile:*'",
"compile:esm": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
"compile:cjs": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
"compile:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./dist/types",
"compile:types": "tsc",
"compile:fixup": "node ./scripts/fixup.mjs",
"lint": "eslint ./src ./test --ext .ts",
"lint:fix": "eslint ./src ./test --ext .ts --fix",
Expand Down
6 changes: 3 additions & 3 deletions packages/allure-js-commons/src/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const labels = (...labelsList: Label[]) => {
return callRuntimeMethod("labels", ...labelsList);
};

export const link = (url: string, type?: LinkType | string, name?: string) => {
export const link = (url: string, name?: string, type?: LinkType | string) => {
// const runtime = await getGlobalTestRuntimeWithAutoconfig();
//
// return runtime.links({ url, type, name });
Expand Down Expand Up @@ -123,9 +123,9 @@ export const step = <T = void>(name: string, body: (context: StepContext) => T |
return callRuntimeMethod("step", name, () => body(stepContext()));
};

export const issue = (url: string, name?: string) => link(url, LinkType.ISSUE, name);
export const issue = (url: string, name?: string) => link(url, name, LinkType.ISSUE);

export const tms = (url: string, name?: string) => link(url, LinkType.TMS, name);
export const tms = (url: string, name?: string) => link(url, name, LinkType.TMS);

export const allureId = (value: string) => label(LabelName.ALLURE_ID, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { MutableAllureContextHolder, StaticContextProvider } from "./context/Sta
import type { AllureContextProvider } from "./context/types.js";
import { createFixtureResult, createStepResult, createTestResult } from "./factory.js";
import type { Config, FixtureType, FixtureWrapper, LinkConfig, TestScope, WellKnownWriters, Writer } from "./types.js";
import { deepClone, getGlobalLabels, randomUuid, typeToExtension } from "./utils.js";
import { deepClone, randomUuid, typeToExtension } from "./utils.js";
import { getTestResultHistoryId, getTestResultTestCaseId, resolveWriter } from "./utils.js";
import * as wellKnownCommonWriters from "./writer/wellKnownCommonWriters.js";

Expand Down Expand Up @@ -779,7 +779,6 @@ export class ReporterRuntime {
return {
...createTestResult(uuid),
start: Date.now(),
labels: getGlobalLabels(),
...deepClone(result),
};
}
Expand Down
17 changes: 0 additions & 17 deletions packages/allure-js-commons/src/sdk/reporter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createHash, randomUUID } from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { env } from "process";
import properties from "properties";
import type { AttachmentOptions, ContentType, Status, StepResult, TestResult } from "../../model.js";
import { LabelName, StatusByPriority } from "../../model.js";
Expand Down Expand Up @@ -126,20 +125,6 @@ const requireWriterCtor = (modulePath: string): (new (...args: readonly unknown[
return require(modulePath);
};

export const getGlobalLabels = () => {
const ENV_NAME_PREFIX = "ALLURE_LABEL_";
let globalLabels: Label[];
const initGlobalLabels: () => Label[] = () =>
Object.keys(env)
.filter((varname) => varname.startsWith(ENV_NAME_PREFIX))
.map((varname) => ({
name: varname.substring(ENV_NAME_PREFIX.length),
value: env[varname] ?? "",
}))
.filter((l) => l.name && l.value);
return (globalLabels ??= initGlobalLabels());
};

const getProjectRoot = (() => {
let cachedProjectRoot: string | null = null;

Expand Down Expand Up @@ -242,8 +227,6 @@ export const getSuiteLabels = (suites: readonly string[]): Label[] => {
return labels;
};

export const getSuitesLabels = getSuiteLabels;

const suiteLabelNames: readonly string[] = [LabelName.PARENT_SUITE, LabelName.SUITE, LabelName.SUB_SUITE];

export const ensureSuiteLabels = (test: Partial<TestResult>, defaultSuites: readonly string[]) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/allure-js-commons/test/sdk/reporter/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { LabelName } from "../../../src/model.js";
import { getSuitesLabels, serialize, typeToExtension } from "../../../src/sdk/reporter/utils.js";
import { getSuiteLabels, serialize, typeToExtension } from "../../../src/sdk/reporter/utils.js";

describe("typeToExtension", () => {
it("should respect provided file extension", () => {
Expand Down Expand Up @@ -46,16 +46,16 @@ describe("typeToExtension", () => {
});
});

describe("getSuitesLabels", () => {
describe("getSuiteLabels", () => {
describe("with empty suites", () => {
it("returns empty array", () => {
expect(getSuitesLabels([])).toEqual([]);
expect(getSuiteLabels([])).toEqual([]);
});
});

describe("with single suite", () => {
it("returns parent suite label as the first element", () => {
expect(getSuitesLabels(["foo"])).toEqual([
expect(getSuiteLabels(["foo"])).toEqual([
{
name: LabelName.PARENT_SUITE,
value: "foo",
Expand All @@ -66,7 +66,7 @@ describe("getSuitesLabels", () => {

describe("with two suites", () => {
it("returns parent suite and suite labels as the first two elements", () => {
expect(getSuitesLabels(["foo", "bar"])).toEqual([
expect(getSuiteLabels(["foo", "bar"])).toEqual([
{
name: LabelName.PARENT_SUITE,
value: "foo",
Expand All @@ -81,7 +81,7 @@ describe("getSuitesLabels", () => {

describe("with three or more suites", () => {
it("returns list of three elements where last one is a sub suite label", () => {
expect(getSuitesLabels(["foo", "bar", "baz", "beep", "boop"])).toEqual([
expect(getSuiteLabels(["foo", "bar", "baz", "beep", "boop"])).toEqual([
{
name: LabelName.PARENT_SUITE,
value: "foo",
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-js-commons/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"lib": ["dom", "esnext"],
"types": [
"node"
],
"outDir": "./dist/esm",
"outDir": "./dist/types",
"module": "es2020",
"moduleResolution": "bundler",
"target": "es2020"
Expand Down
Loading
Loading