@argos-ci/util 0.0.1-alpha.182
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/LICENSE +7 -0
- package/README.md +19 -0
- package/dist/browser.d.ts +33 -0
- package/dist/browser.mjs +19 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.mjs +65 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Smooth Code
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/logo-github-readme.png" alt="Argos" width="300" height="61">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
_Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes._
|
|
8
|
+
|
|
9
|
+
# Argos Utilities
|
|
10
|
+
|
|
11
|
+
Set of utilities used across all Argos SDKs.
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@argos-ci/util)
|
|
14
|
+
[](https://www.npmjs.com/package/@argos-ci/util)
|
|
15
|
+
[](https://www.npmjs.com/package/@argos-ci/util)
|
|
16
|
+
|
|
17
|
+
## Links
|
|
18
|
+
|
|
19
|
+
- [Official Docs](https://argos-ci.com/docs)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type ScreenshotMetadata = {
|
|
2
|
+
url: string;
|
|
3
|
+
viewport: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
colorScheme: "light" | "dark";
|
|
8
|
+
mediaType: "screen" | "print";
|
|
9
|
+
browser: {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
};
|
|
13
|
+
automationLibrary: {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
};
|
|
17
|
+
sdk: {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get metadata path from screenshot path.
|
|
24
|
+
*/
|
|
25
|
+
declare function getMetadataPath(screenshotPath: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Build a screenshot name from a test name and options.
|
|
28
|
+
*/
|
|
29
|
+
declare function getScreenshotName(name: string, options?: {
|
|
30
|
+
viewportWidth?: number;
|
|
31
|
+
}): string;
|
|
32
|
+
export { getMetadataPath, getScreenshotName };
|
|
33
|
+
export type { ScreenshotMetadata };
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export { getMetadataPath, getScreenshotName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the version from a package.json file.
|
|
3
|
+
*/
|
|
4
|
+
declare function readVersionFromPackage(pkgPath: string): Promise<string>;
|
|
5
|
+
type ScreenshotMetadata = {
|
|
6
|
+
url: string;
|
|
7
|
+
viewport: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
colorScheme: "light" | "dark";
|
|
12
|
+
mediaType: "screen" | "print";
|
|
13
|
+
browser: {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
};
|
|
17
|
+
automationLibrary: {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
};
|
|
21
|
+
sdk: {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get metadata path from screenshot path.
|
|
28
|
+
*/
|
|
29
|
+
declare function getMetadataPath(screenshotPath: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Write screenshot metadata to disk.
|
|
32
|
+
*/
|
|
33
|
+
declare function writeMetadata(screenshotPath: string, metadata: ScreenshotMetadata): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Read screenshot metadata from disk.
|
|
36
|
+
* If not found, returns null.
|
|
37
|
+
*/
|
|
38
|
+
declare function readMetadata(screenshotPath: string): Promise<ScreenshotMetadata | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Build a screenshot name from a test name and options.
|
|
41
|
+
*/
|
|
42
|
+
declare function getScreenshotName(name: string, options?: {
|
|
43
|
+
viewportWidth?: number;
|
|
44
|
+
}): string;
|
|
45
|
+
export { readVersionFromPackage, ScreenshotMetadata, getMetadataPath, writeMetadata, readMetadata, getScreenshotName };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
// Cache the version to avoid reading the file multiple times.
|
|
4
|
+
const versionCache = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Read the version from a package.json file.
|
|
7
|
+
*/ function readVersionFromPackage(pkgPath) {
|
|
8
|
+
const readVersion = async ()=>{
|
|
9
|
+
const { version } = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
10
|
+
if (typeof version !== "string") {
|
|
11
|
+
throw new Error("Invalid version");
|
|
12
|
+
}
|
|
13
|
+
return version;
|
|
14
|
+
};
|
|
15
|
+
if (!versionCache.has(pkgPath)) {
|
|
16
|
+
versionCache.set(pkgPath, readVersion());
|
|
17
|
+
}
|
|
18
|
+
const fromCache = versionCache.get(pkgPath);
|
|
19
|
+
if (!fromCache) {
|
|
20
|
+
throw new Error("Invariant violation: version not in cache");
|
|
21
|
+
}
|
|
22
|
+
return fromCache;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get metadata path from screenshot path.
|
|
27
|
+
*/ function getMetadataPath(screenshotPath) {
|
|
28
|
+
return screenshotPath + ".argos.json";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Write screenshot metadata to disk.
|
|
33
|
+
*/ async function writeMetadata(screenshotPath, metadata) {
|
|
34
|
+
await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read screenshot metadata from disk.
|
|
38
|
+
* If not found, returns null.
|
|
39
|
+
*/ async function readMetadata(screenshotPath) {
|
|
40
|
+
try {
|
|
41
|
+
const metadata = await readFile(getMetadataPath(screenshotPath), "utf8");
|
|
42
|
+
return JSON.parse(metadata);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Failed to read metadata", {
|
|
48
|
+
cause: error
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build a screenshot name from a test name and options.
|
|
55
|
+
*/ function getScreenshotName(name, options = {}) {
|
|
56
|
+
let parts = [
|
|
57
|
+
name
|
|
58
|
+
];
|
|
59
|
+
if (options.viewportWidth) {
|
|
60
|
+
parts.push(`vw-${options.viewportWidth}`);
|
|
61
|
+
}
|
|
62
|
+
return parts.join(" ");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { getMetadataPath, getScreenshotName, readMetadata, readVersionFromPackage, writeMetadata };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@argos-ci/util",
|
|
3
|
+
"description": "Set of utilities used across all Argos SDKs",
|
|
4
|
+
"version": "0.0.1-alpha.182+8a2e9db",
|
|
5
|
+
"author": "Smooth Code",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/argos-ci/argos-javascript.git",
|
|
10
|
+
"directory": "packages/util"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./browser": {
|
|
23
|
+
"import": "./dist/browser.mjs",
|
|
24
|
+
"types": "./dist/browser.d.ts",
|
|
25
|
+
"default": "./dist/browser.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=16.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"prebuild": "rm -rf dist",
|
|
34
|
+
"build": "rollup -c"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^16.0.0"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "8a2e9db6427071708c3d701a3230f228b1216893"
|
|
40
|
+
}
|