Skip to content

Commit

Permalink
add a generic crypto functions to commons
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Mar 11, 2024
1 parent fa53ecb commit 7339e5d
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 6 deletions.
41 changes: 41 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/allure-js-commons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export {
getStatusFromError,
getSuitesLabels,
isAnyStepFailed,
randomUUID,
md5,
readImageAsBase64,
serialize,
Expand Down
2 changes: 2 additions & 0 deletions packages/allure-js-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
"test": "ts-node --project test/tsconfig.json test/runner.ts"
},
"dependencies": {
"md5": "^2.3.0",
"properties": "^1.2.1",
"strip-ansi": "^5.2.0"
},
"devDependencies": {
"@types/chai": "^4.3.6",
"@types/eslint": "^8",
"@types/md5": "^2",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.3",
"@types/sinon": "^17.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-js-commons/src/AllureRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { randomUUID } from "crypto";
import { PathLike } from "fs";
import { AllureConfig } from "./AllureConfig";
import { AllureGroup } from "./AllureGroup";
import { AttachmentOptions, Category, ContentType, TestResult, TestResultContainer } from "./model";
import { randomUUID } from "./utils";
import { AllureWriter, FileSystemAllureWriter, typeToExtension } from "./writers";

const buildAttachmentFileName = (options: ContentType | string | AttachmentOptions): string => {
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-js-commons/src/constructors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomUUID } from "crypto";
import { FixtureResult, Stage, Status, StepResult, TestResult, TestResultContainer } from "./model";
import { randomUUID } from "./utils";

export const testResultContainer = (): TestResultContainer => {
return {
Expand Down
20 changes: 17 additions & 3 deletions packages/allure-js-commons/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { createHash } from "crypto";
import { readFile } from "fs/promises";
import md5lib from "md5";
import path from "path";
import { env } from "process";
import { ExecutableItem, Label, LabelName, Status } from "./model";

export const md5 = (data: string) => createHash("md5").update(data).digest("hex");
export const randomUUID = () => {
if (globalThis?.crypto?.randomUUID) {
return globalThis.crypto.randomUUID();
}

// eslint-disable-next-line
return require("node:crypto").randomUUID();
};

export const md5 = (data: string) => md5lib(data);

export const getLabelsFromEnv = (): Label[] => {
const envKeys = Object.keys(env);
Expand Down Expand Up @@ -143,7 +152,12 @@ export const serialize = (val: unknown): string => {
return (val as any).toString();
};

export const extractMetadataFromString = (title: string): { labels: Label[]; cleanTitle: string } => {
export const extractMetadataFromString = (
title: string,
): {
labels: Label[];
cleanTitle: string;
} => {
const labels = [] as Label[];

title.split(" ").forEach((val) => {
Expand Down
36 changes: 35 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,13 @@ __metadata:
languageName: node
linkType: hard

"@types/md5@npm:^2":
version: 2.3.5
resolution: "@types/md5@npm:2.3.5"
checksum: a86baf0521006e3072488bd79089b84831780866102e5e4b4f7afabfab17e0270a3791f3331776b73efb2cc9317efd56a334fd3d2698c7929e9b18593ca3fd39
languageName: node
linkType: hard

"@types/minimatch@npm:^5.1.2":
version: 5.1.2
resolution: "@types/minimatch@npm:5.1.2"
Expand Down Expand Up @@ -3390,6 +3397,7 @@ __metadata:
dependencies:
"@types/chai": ^4.3.6
"@types/eslint": ^8
"@types/md5": ^2
"@types/mocha": ^10.0.1
"@types/node": ^20.6.3
"@types/sinon": ^17.0.0
Expand All @@ -3406,6 +3414,7 @@ __metadata:
eslint-plugin-prefer-arrow: ^1.2.3
expect: ^29.5.0
glob: ^10.3.5
md5: ^2.3.0
mocha: ^10.2.0
mocha-multi-reporters: ^1.5.1
properties: ^1.2.1
Expand Down Expand Up @@ -4972,6 +4981,13 @@ __metadata:
languageName: node
linkType: hard

"charenc@npm:0.0.2":
version: 0.0.2
resolution: "charenc@npm:0.0.2"
checksum: 81dcadbe57e861d527faf6dd3855dc857395a1c4d6781f4847288ab23cffb7b3ee80d57c15bba7252ffe3e5e8019db767757ee7975663ad2ca0939bb8fcaf2e5
languageName: node
linkType: hard

"charset@npm:^1.0.0":
version: 1.0.1
resolution: "charset@npm:1.0.1"
Expand Down Expand Up @@ -5884,6 +5900,13 @@ __metadata:
languageName: node
linkType: hard

"crypt@npm:0.0.2":
version: 0.0.2
resolution: "crypt@npm:0.0.2"
checksum: baf4c7bbe05df656ec230018af8cf7dbe8c14b36b98726939cef008d473f6fe7a4fad906cfea4062c93af516f1550a3f43ceb4d6615329612c6511378ed9fe34
languageName: node
linkType: hard

"crypto-browserify@npm:^3.0.0":
version: 3.12.0
resolution: "crypto-browserify@npm:3.12.0"
Expand Down Expand Up @@ -9535,7 +9558,7 @@ __metadata:
languageName: node
linkType: hard

"is-buffer@npm:^1.1.0, is-buffer@npm:^1.1.5":
"is-buffer@npm:^1.1.0, is-buffer@npm:^1.1.5, is-buffer@npm:~1.1.6":
version: 1.1.6
resolution: "is-buffer@npm:1.1.6"
checksum: 4a186d995d8bbf9153b4bd9ff9fd04ae75068fe695d29025d25e592d9488911eeece84eefbd8fa41b8ddcc0711058a71d4c466dcf6f1f6e1d83830052d8ca707
Expand Down Expand Up @@ -11489,6 +11512,17 @@ __metadata:
languageName: node
linkType: hard

"md5@npm:^2.3.0":
version: 2.3.0
resolution: "md5@npm:2.3.0"
dependencies:
charenc: 0.0.2
crypt: 0.0.2
is-buffer: ~1.1.6
checksum: a63cacf4018dc9dee08c36e6f924a64ced735b37826116c905717c41cebeb41a522f7a526ba6ad578f9c80f02cb365033ccd67fe186ffbcc1a1faeb75daa9b6e
languageName: node
linkType: hard

"memorystream@npm:^0.3.1":
version: 0.3.1
resolution: "memorystream@npm:0.3.1"
Expand Down

0 comments on commit 7339e5d

Please sign in to comment.