Skip to content

Commit

Permalink
use rollup to build cypress integraiton
Browse files Browse the repository at this point in the history
make cypress integration compatible with both cjs and esm modules
move some common utilities from node to framework directory
change commons build workflow
use absolute imports instead of relative ones in cypress tests
use new commons for cypress integration
  • Loading branch information
epszaw committed Mar 14, 2024
1 parent d1b80a4 commit 3ea083d
Show file tree
Hide file tree
Showing 69 changed files with 865 additions and 612 deletions.
251 changes: 161 additions & 90 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { readFileSync, rmSync, existsSync } = require("node:fs");
const { join, relative } = require("node:path");
const { globSync } = require("glob");
const { allureCypress } = require("./dist/reporter");
const { allureCypress } = require("allure-cypress/reporter");

module.exports = {
experimentalInteractiveRunEvents: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/attachments.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { attachment } from "../../dist"
import { attachment } from "allure-cypress"

describe("primitive data", () => {
describe("text", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/description.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { description, descriptionHtml } from "../../dist";
import { description, descriptionHtml } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/displayName.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { displayName } from "../../dist";
import { displayName } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/historyId.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { historyId } from "../../dist";
import { historyId } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/labels.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
subSuite,
suite,
tag,
} from "../../dist";
} from "allure-cypress";

describe("custom", () => {
after(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/links.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { link, issue, tms } from "../../dist";
import { link, issue, tms } from "allure-cypress";

describe("custom", () => {
after(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/parameters.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parameter } from "../../dist";
import { parameter } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/steps.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { step } from "../../dist";
import { step } from "allure-cypress";

describe("single", () => {
after(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/testCaseId.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { testCaseId } from "../../dist";
import { testCaseId } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/e2e/titleMetadata.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { label } from "../../dist";
import { label } from "allure-cypress";

after(() => {
cy.task("readLastTestResult").then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-cypress/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../dist/commands";
import "allure-cypress/commands";

Cypress.Commands.add("matches", { prevSubject: true }, (subject, object) => {
cy.wrap(subject).then((subject) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/allure-cypress/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ import { glob } from "glob";
platform: "node",
sourcemap: true,
entryPoints: [file],
outfile: join(__dirname, "dist", basename(file).replace(/\.ts$/, ".cjs")),
});
await esbuild.build({
bundle: true,
format: "esm",
platform: "node",
sourcemap: true,
entryPoints: [file],
outfile: join(__dirname, "dist", basename(file).replace(/\.ts$/, ".js")),
});
}

for (const file of browserFiles) {
await esbuild.build({
bundle: true,
format: "cjs",
platform: "browser",
sourcemap: true,
entryPoints: [file],
outfile: join(__dirname, "dist", basename(file).replace(/\.ts$/, ".cjs")),
});
await esbuild.build({
bundle: true,
format: "cjs",
Expand Down
23 changes: 17 additions & 6 deletions packages/allure-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@
"author": "Qameta Software <[email protected]> (https://qameta.io/)",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"./commands": {
"require": "./dist/commands.js",
"import": "./dist/commands.mjs",
"require": "./dist/commands.cjs",
"types": "./dist/commands.d.ts"
},
"./reporter": {
"require": "./dist/reporter.js",
"import": "./dist/reporter.mjs",
"require": "./dist/reporter.cjs",
"types": "./dist/reporter.d.ts"
}
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"directories": {
"test": "test"
Expand All @@ -42,7 +46,9 @@
],
"scripts": {
"clean": "rimraf ./dist ./out",
"compile": "ts-node ./esbuild.ts && tsc --emitDeclarationOnly",
"compile": "run-p 'compile:*'",
"compile:lib": "rollup -c",
"compile:types": "tsc --project ./tsconfig.json",
"coverage": "codecov",
"lint": "eslint ./src --ext .ts",
"lint:fix": "eslint ./src --ext .ts --fix",
Expand All @@ -53,6 +59,9 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/eslint": "^8",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.12",
Expand All @@ -63,7 +72,6 @@
"allure-jest": "workspace:*",
"cypress": "^13.6.0",
"enquirer": "^2.3.6",
"esbuild": "^0.20.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-cypress": "^2.15.1",
Expand All @@ -73,9 +81,12 @@
"eslint-plugin-prefer-arrow": "^1.2.3",
"glob": "^10.3.5",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.1",
"rollup": "^4.13.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
}
}
95 changes: 95 additions & 0 deletions packages/allure-cypress/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import typescriptPlugin from "@rollup/plugin-typescript";
import commonjsPlugin from "@rollup/plugin-commonjs";
import resolvePlugin from "@rollup/plugin-node-resolve";
import { glob } from "glob";
import { join, relative } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "rollup";

const dirname = fileURLToPath(new URL(".", import.meta.url));

const createNodeEntry = (inputFile) => {
const outputFileBase = inputFile.replace(/^src/, "dist");
const external = ["node:fs", "allure-js-commons/new", "allure-js-commons/new/node"];

return [
defineConfig({
input: inputFile,
output: {
file: join(dirname, outputFileBase.replace(/\.ts$/, ".mjs")),
format: "esm",
exports: "named",
sourcemap: true,
},
plugins: [
typescriptPlugin({
tsconfig: "./tsconfig.rollup.json",
}),
],
external,
}),
defineConfig({
input: inputFile,
output: {
file: join(dirname, outputFileBase.replace(/\.ts$/, ".cjs")),
format: "cjs",
exports: "named",
sourcemap: true,
},
plugins: [
typescriptPlugin({
tsconfig: "./tsconfig.rollup.json",
}),
],
external,
}),
];
};
const createBrowserEntry = (inputFile) => {
const outputFileBase = inputFile.replace(/^src/, "dist");

return [
defineConfig({
input: inputFile,
output: {
file: join(dirname, outputFileBase.replace(/\.ts$/, ".mjs")),
format: "esm",
exports: "named",
sourcemap: true,
},
plugins: [
typescriptPlugin({
tsconfig: "./tsconfig.rollup.json",
}),
resolvePlugin(),
commonjsPlugin(),
],
// external,
}),
defineConfig({
input: inputFile,
output: {
file: join(dirname, outputFileBase.replace(/\.ts$/, ".cjs")),
format: "cjs",
exports: "named",
sourcemap: true,
},
plugins: [
typescriptPlugin({
tsconfig: "./tsconfig.rollup.json",
}),
resolvePlugin(),
commonjsPlugin(),
],
// external,
}),
];
};

export default () => {
return [
createBrowserEntry("src/index.ts"),
createBrowserEntry("src/commands.ts"),
createNodeEntry("src/reporter.ts"),
].flat();
};
6 changes: 4 additions & 2 deletions packages/allure-cypress/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { MessageType, type ReportFinalMessage, Stage, Status } from "./model";
import { Stage, Status } from "allure-js-commons/new";
import { MessageType, type ReportFinalMessage, type ReporterMessage } from "./model";

const createFinalMesage = () =>
// @ts-ignore
({
startMessage: undefined,
endMessage: undefined,
Expand Down Expand Up @@ -44,7 +46,7 @@ const getStepsMessagesPair = (reportMessage: ReportFinalMessage) =>
acc[unfinishedStepIdx].push(message);

return acc;
}, []);
}, [] as ReporterMessage[][]);

// @ts-ignore
Cypress.mocha
Expand Down
5 changes: 3 additions & 2 deletions packages/allure-cypress/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LabelName, LinkType, MessageType, type ParameterOptions, Stage, Status } from "./model";
import { LabelName, LinkType, ParameterOptions, Stage, Status } from "allure-js-commons/new";
import { MessageType } from "./model";
import { pushReportMessage } from "./utils";

export type CypressWrappedAttachment = { type: string; data: unknown };
Expand All @@ -12,7 +13,7 @@ export const uint8ArrayToBase64 = (data: unknown) => {
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return btoa(String.fromCharCode.apply(null, data));
return btoa(String.fromCharCode.apply(null, data as number[]));
};

export const normalizeAttachmentContentEncoding = (data: unknown, encoding: BufferEncoding): BufferEncoding => {
Expand Down
Loading

0 comments on commit 3ea083d

Please sign in to comment.