@argos-ci/util 2.1.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/browser.d.ts +4 -3
- package/dist/browser.js +10 -0
- package/dist/chunk-SBIRPBRC.js +26 -0
- package/dist/index.d.ts +8 -54
- package/dist/index.js +88 -0
- package/package.json +7 -8
- package/dist/browser.mjs +0 -27
- package/dist/index.mjs +0 -112
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/github-readme-logo-dark.png">
|
|
5
|
+
<img alt="Argos" src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/github-readme-logo-light.png" width="360" height="70">
|
|
6
|
+
</picture>
|
|
4
7
|
</a>
|
|
5
8
|
</p>
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
<p align="center"><strong>The open source visual testing plaform for modern engineering teams.</strong></p>
|
|
8
11
|
|
|
9
12
|
# Argos Utilities
|
|
10
13
|
|
package/dist/browser.d.ts
CHANGED
|
@@ -31,7 +31,6 @@ type ScreenshotMetadata = {
|
|
|
31
31
|
name: string;
|
|
32
32
|
version: string;
|
|
33
33
|
};
|
|
34
|
-
// Metdata used to pass informations later removed from metadata.
|
|
35
34
|
transient?: {
|
|
36
35
|
threshold?: number;
|
|
37
36
|
baseName?: string;
|
|
@@ -41,15 +40,17 @@ type ScreenshotMetadata = {
|
|
|
41
40
|
* Get metadata path from screenshot path.
|
|
42
41
|
*/
|
|
43
42
|
declare function getMetadataPath(screenshotPath: string): string;
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Build a screenshot name from a test name and options.
|
|
46
46
|
*/
|
|
47
47
|
declare function getScreenshotName(name: string, options?: {
|
|
48
48
|
viewportWidth?: number;
|
|
49
49
|
}): string;
|
|
50
|
+
|
|
50
51
|
/**
|
|
51
52
|
* Validates the threshold value.
|
|
52
53
|
*/
|
|
53
54
|
declare function validateThreshold(threshold: number): void;
|
|
54
|
-
|
|
55
|
-
export type
|
|
55
|
+
|
|
56
|
+
export { type ScreenshotMetadata, getMetadataPath, getScreenshotName, validateThreshold };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/metadata.ts
|
|
2
|
+
function getMetadataPath(screenshotPath) {
|
|
3
|
+
return screenshotPath + ".argos.json";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/name.ts
|
|
7
|
+
function getScreenshotName(name, options = {}) {
|
|
8
|
+
let parts = [name];
|
|
9
|
+
if (options.viewportWidth) {
|
|
10
|
+
parts.push(`vw-${options.viewportWidth}`);
|
|
11
|
+
}
|
|
12
|
+
return parts.join(" ");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/threshold.ts
|
|
16
|
+
function validateThreshold(threshold) {
|
|
17
|
+
if (threshold < 0 || threshold > 1) {
|
|
18
|
+
throw new Error("The threshold must be between 0 and 1.");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
getMetadataPath,
|
|
24
|
+
getScreenshotName,
|
|
25
|
+
validateThreshold
|
|
26
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,16 @@
|
|
|
1
|
+
import { ScreenshotMetadata } from './browser.js';
|
|
2
|
+
export { getMetadataPath, getScreenshotName, validateThreshold } from './browser.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Get the top level of the git repository.
|
|
3
6
|
*/
|
|
4
7
|
declare function getGitRepositoryPath(): Promise<string | null>;
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* Read the version from a package.json file.
|
|
7
11
|
*/
|
|
8
12
|
declare function readVersionFromPackage(pkgPath: string): Promise<string>;
|
|
9
|
-
|
|
10
|
-
url?: string;
|
|
11
|
-
viewport?: {
|
|
12
|
-
width: number;
|
|
13
|
-
height: number;
|
|
14
|
-
};
|
|
15
|
-
colorScheme?: "light" | "dark";
|
|
16
|
-
mediaType?: "screen" | "print";
|
|
17
|
-
test: {
|
|
18
|
-
id?: string;
|
|
19
|
-
title: string;
|
|
20
|
-
titlePath: string[];
|
|
21
|
-
retries?: number;
|
|
22
|
-
retry?: number;
|
|
23
|
-
repeat?: number;
|
|
24
|
-
location?: {
|
|
25
|
-
file: string;
|
|
26
|
-
line: number;
|
|
27
|
-
column: number;
|
|
28
|
-
};
|
|
29
|
-
} | null;
|
|
30
|
-
browser?: {
|
|
31
|
-
name: string;
|
|
32
|
-
version: string;
|
|
33
|
-
};
|
|
34
|
-
automationLibrary: {
|
|
35
|
-
name: string;
|
|
36
|
-
version: string;
|
|
37
|
-
};
|
|
38
|
-
sdk: {
|
|
39
|
-
name: string;
|
|
40
|
-
version: string;
|
|
41
|
-
};
|
|
42
|
-
// Metdata used to pass informations later removed from metadata.
|
|
43
|
-
transient?: {
|
|
44
|
-
threshold?: number;
|
|
45
|
-
baseName?: string;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Get metadata path from screenshot path.
|
|
50
|
-
*/
|
|
51
|
-
declare function getMetadataPath(screenshotPath: string): string;
|
|
13
|
+
|
|
52
14
|
/**
|
|
53
15
|
* Write screenshot metadata to disk.
|
|
54
16
|
*/
|
|
@@ -58,19 +20,11 @@ declare function writeMetadata(screenshotPath: string, metadata: ScreenshotMetad
|
|
|
58
20
|
* If not found, returns null.
|
|
59
21
|
*/
|
|
60
22
|
declare function readMetadata(screenshotPath: string): Promise<ScreenshotMetadata | null>;
|
|
61
|
-
|
|
62
|
-
* Build a screenshot name from a test name and options.
|
|
63
|
-
*/
|
|
64
|
-
declare function getScreenshotName(name: string, options?: {
|
|
65
|
-
viewportWidth?: number;
|
|
66
|
-
}): string;
|
|
23
|
+
|
|
67
24
|
/**
|
|
68
25
|
* Get playwright trace from screenshot path.
|
|
69
26
|
* If not found, returns null.
|
|
70
27
|
*/
|
|
71
28
|
declare function getPlaywrightTracePath(screenshotPath: string): Promise<string | null>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*/
|
|
75
|
-
declare function validateThreshold(threshold: number): void;
|
|
76
|
-
export { getGitRepositoryPath, readVersionFromPackage, ScreenshotMetadata, getMetadataPath, writeMetadata, readMetadata, getScreenshotName, getPlaywrightTracePath, validateThreshold };
|
|
29
|
+
|
|
30
|
+
export { ScreenshotMetadata, getGitRepositoryPath, getPlaywrightTracePath, readMetadata, readVersionFromPackage, writeMetadata };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMetadataPath,
|
|
3
|
+
getScreenshotName,
|
|
4
|
+
validateThreshold
|
|
5
|
+
} from "./chunk-SBIRPBRC.js";
|
|
6
|
+
|
|
7
|
+
// src/git.ts
|
|
8
|
+
import { exec } from "node:child_process";
|
|
9
|
+
var cached;
|
|
10
|
+
function getGitRepositoryPath() {
|
|
11
|
+
if (!cached) {
|
|
12
|
+
cached = new Promise((resolve) => {
|
|
13
|
+
exec("git rev-parse --show-toplevel", (error, stdout, stderr) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
resolve(null);
|
|
16
|
+
}
|
|
17
|
+
if (stderr) {
|
|
18
|
+
resolve(null);
|
|
19
|
+
}
|
|
20
|
+
resolve(stdout.trim());
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return cached;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/introspection.ts
|
|
28
|
+
import { readFile } from "node:fs/promises";
|
|
29
|
+
var versionCache = /* @__PURE__ */ new Map();
|
|
30
|
+
function readVersionFromPackage(pkgPath) {
|
|
31
|
+
const readVersion = async () => {
|
|
32
|
+
const { version } = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
33
|
+
if (typeof version !== "string") {
|
|
34
|
+
throw new Error("Invalid version");
|
|
35
|
+
}
|
|
36
|
+
return version;
|
|
37
|
+
};
|
|
38
|
+
if (!versionCache.has(pkgPath)) {
|
|
39
|
+
versionCache.set(pkgPath, readVersion());
|
|
40
|
+
}
|
|
41
|
+
const fromCache = versionCache.get(pkgPath);
|
|
42
|
+
if (!fromCache) {
|
|
43
|
+
throw new Error("Invariant violation: version not in cache");
|
|
44
|
+
}
|
|
45
|
+
return fromCache;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/metadata-io.ts
|
|
49
|
+
import { readFile as readFile2, writeFile } from "node:fs/promises";
|
|
50
|
+
async function writeMetadata(screenshotPath, metadata) {
|
|
51
|
+
await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata));
|
|
52
|
+
}
|
|
53
|
+
async function readMetadata(screenshotPath) {
|
|
54
|
+
try {
|
|
55
|
+
const metadata = await readFile2(getMetadataPath(screenshotPath), "utf8");
|
|
56
|
+
return JSON.parse(metadata);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Failed to read metadata", { cause: error });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/playwright-trace.ts
|
|
66
|
+
import { access } from "node:fs/promises";
|
|
67
|
+
function getTracePath(screenshotPath) {
|
|
68
|
+
return screenshotPath + ".pw-trace.zip";
|
|
69
|
+
}
|
|
70
|
+
async function getPlaywrightTracePath(screenshotPath) {
|
|
71
|
+
try {
|
|
72
|
+
const tracePath = getTracePath(screenshotPath);
|
|
73
|
+
await access(tracePath);
|
|
74
|
+
return tracePath;
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
getGitRepositoryPath,
|
|
81
|
+
getMetadataPath,
|
|
82
|
+
getPlaywrightTracePath,
|
|
83
|
+
getScreenshotName,
|
|
84
|
+
readMetadata,
|
|
85
|
+
readVersionFromPackage,
|
|
86
|
+
validateThreshold,
|
|
87
|
+
writeMetadata
|
|
88
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/util",
|
|
3
3
|
"description": "Set of utilities used across all Argos SDKs.",
|
|
4
|
-
"version": "2.1
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"import": "./dist/index.
|
|
28
|
-
"default": "./dist/index.
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
29
|
},
|
|
30
30
|
"./browser": {
|
|
31
31
|
"types": "./dist/browser.d.ts",
|
|
32
|
-
"import": "./dist/browser.
|
|
33
|
-
"default": "./dist/browser.
|
|
32
|
+
"import": "./dist/browser.js",
|
|
33
|
+
"default": "./dist/browser.js"
|
|
34
34
|
},
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
@@ -38,11 +38,10 @@
|
|
|
38
38
|
"node": ">=18.0.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"
|
|
42
|
-
"build": "rollup -c"
|
|
41
|
+
"build": "tsup"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/node": "^18.19.44"
|
|
46
45
|
},
|
|
47
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "1dd8b4240b76b0756d8784e3320b7f57d915aeaf"
|
|
48
47
|
}
|
package/dist/browser.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get metadata path from screenshot path.
|
|
3
|
-
*/ function getMetadataPath(screenshotPath) {
|
|
4
|
-
return screenshotPath + ".argos.json";
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Build a screenshot name from a test name and options.
|
|
9
|
-
*/ function getScreenshotName(name, options = {}) {
|
|
10
|
-
let parts = [
|
|
11
|
-
name
|
|
12
|
-
];
|
|
13
|
-
if (options.viewportWidth) {
|
|
14
|
-
parts.push(`vw-${options.viewportWidth}`);
|
|
15
|
-
}
|
|
16
|
-
return parts.join(" ");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Validates the threshold value.
|
|
21
|
-
*/ function validateThreshold(threshold) {
|
|
22
|
-
if (threshold < 0 || threshold > 1) {
|
|
23
|
-
throw new Error("The threshold must be between 0 and 1.");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { getMetadataPath, getScreenshotName, validateThreshold };
|
package/dist/index.mjs
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { exec } from 'node:child_process';
|
|
2
|
-
import { readFile, writeFile, access } from 'node:fs/promises';
|
|
3
|
-
|
|
4
|
-
let cached;
|
|
5
|
-
/**
|
|
6
|
-
* Get the top level of the git repository.
|
|
7
|
-
*/ function getGitRepositoryPath() {
|
|
8
|
-
if (!cached) {
|
|
9
|
-
cached = new Promise((resolve)=>{
|
|
10
|
-
exec("git rev-parse --show-toplevel", (error, stdout, stderr)=>{
|
|
11
|
-
if (error) {
|
|
12
|
-
resolve(null);
|
|
13
|
-
}
|
|
14
|
-
if (stderr) {
|
|
15
|
-
resolve(null);
|
|
16
|
-
}
|
|
17
|
-
resolve(stdout.trim());
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return cached;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Cache the version to avoid reading the file multiple times.
|
|
25
|
-
const versionCache = new Map();
|
|
26
|
-
/**
|
|
27
|
-
* Read the version from a package.json file.
|
|
28
|
-
*/ function readVersionFromPackage(pkgPath) {
|
|
29
|
-
const readVersion = async ()=>{
|
|
30
|
-
const { version } = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
31
|
-
if (typeof version !== "string") {
|
|
32
|
-
throw new Error("Invalid version");
|
|
33
|
-
}
|
|
34
|
-
return version;
|
|
35
|
-
};
|
|
36
|
-
if (!versionCache.has(pkgPath)) {
|
|
37
|
-
versionCache.set(pkgPath, readVersion());
|
|
38
|
-
}
|
|
39
|
-
const fromCache = versionCache.get(pkgPath);
|
|
40
|
-
if (!fromCache) {
|
|
41
|
-
throw new Error("Invariant violation: version not in cache");
|
|
42
|
-
}
|
|
43
|
-
return fromCache;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get metadata path from screenshot path.
|
|
48
|
-
*/ function getMetadataPath(screenshotPath) {
|
|
49
|
-
return screenshotPath + ".argos.json";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Write screenshot metadata to disk.
|
|
54
|
-
*/ async function writeMetadata(screenshotPath, metadata) {
|
|
55
|
-
await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata));
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Read screenshot metadata from disk.
|
|
59
|
-
* If not found, returns null.
|
|
60
|
-
*/ async function readMetadata(screenshotPath) {
|
|
61
|
-
try {
|
|
62
|
-
const metadata = await readFile(getMetadataPath(screenshotPath), "utf8");
|
|
63
|
-
return JSON.parse(metadata);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
throw new Error("Failed to read metadata", {
|
|
69
|
-
cause: error
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Build a screenshot name from a test name and options.
|
|
76
|
-
*/ function getScreenshotName(name, options = {}) {
|
|
77
|
-
let parts = [
|
|
78
|
-
name
|
|
79
|
-
];
|
|
80
|
-
if (options.viewportWidth) {
|
|
81
|
-
parts.push(`vw-${options.viewportWidth}`);
|
|
82
|
-
}
|
|
83
|
-
return parts.join(" ");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get trace path from screenshot path.
|
|
88
|
-
*/ function getTracePath(screenshotPath) {
|
|
89
|
-
return screenshotPath + ".pw-trace.zip";
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get playwright trace from screenshot path.
|
|
93
|
-
* If not found, returns null.
|
|
94
|
-
*/ async function getPlaywrightTracePath(screenshotPath) {
|
|
95
|
-
try {
|
|
96
|
-
const tracePath = getTracePath(screenshotPath);
|
|
97
|
-
await access(tracePath);
|
|
98
|
-
return tracePath;
|
|
99
|
-
} catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Validates the threshold value.
|
|
106
|
-
*/ function validateThreshold(threshold) {
|
|
107
|
-
if (threshold < 0 || threshold > 1) {
|
|
108
|
-
throw new Error("The threshold must be between 0 and 1.");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export { getGitRepositoryPath, getMetadataPath, getPlaywrightTracePath, getScreenshotName, readMetadata, readVersionFromPackage, validateThreshold, writeMetadata };
|