testit-js-commons 5.1.1 → 5.1.2
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/lib/common/utils/utils.d.ts +2 -0
- package/lib/common/utils/utils.js +6 -1
- package/lib/common/utils/utils.test.d.ts +1 -0
- package/lib/common/utils/utils.test.js +17 -0
- package/lib/services/autotests/autotests.converter.js +2 -1
- package/lib/services/autotests/autotests.converter.test.js +13 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
export declare namespace Utils {
|
|
3
3
|
function getHash(input: string): string;
|
|
4
|
+
/** Normalize path separators to `/` so namespaces match across Windows and Unix. */
|
|
5
|
+
function toPosixPath(file: string): string;
|
|
4
6
|
function getDir(file: string): string;
|
|
5
7
|
function removeDir(path: string): void;
|
|
6
8
|
function getFileName(file: string): string;
|
|
@@ -44,8 +44,13 @@ var Utils;
|
|
|
44
44
|
return (0, crypto_1.createHash)("md5").update(input).digest("hex");
|
|
45
45
|
}
|
|
46
46
|
Utils.getHash = getHash;
|
|
47
|
+
/** Normalize path separators to `/` so namespaces match across Windows and Unix. */
|
|
48
|
+
function toPosixPath(file) {
|
|
49
|
+
return file.replace(/\\/g, "/");
|
|
50
|
+
}
|
|
51
|
+
Utils.toPosixPath = toPosixPath;
|
|
47
52
|
function getDir(file) {
|
|
48
|
-
return
|
|
53
|
+
return path_1.posix.dirname(toPosixPath(file));
|
|
49
54
|
}
|
|
50
55
|
Utils.getDir = getDir;
|
|
51
56
|
function removeDir(path) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
describe("Utils.toPosixPath", () => {
|
|
5
|
+
it("replaces backslashes with forward slashes", () => {
|
|
6
|
+
expect(utils_1.Utils.toPosixPath("api\\users\\v1")).toBe("api/users/v1");
|
|
7
|
+
});
|
|
8
|
+
it("keeps forward slashes", () => {
|
|
9
|
+
expect(utils_1.Utils.toPosixPath("api/users/v1")).toBe("api/users/v1");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe("Utils.getDir", () => {
|
|
13
|
+
it("returns directory with posix separators", () => {
|
|
14
|
+
expect(utils_1.Utils.getDir("api\\users\\test.spec.ts")).toBe("api/users");
|
|
15
|
+
expect(utils_1.Utils.getDir("api/users/test.spec.ts")).toBe("api/users");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -41,10 +41,11 @@ class AutotestConverter extends common_1.BaseConverter {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
baseAutotestFields(autotest) {
|
|
44
|
+
var _a;
|
|
44
45
|
return {
|
|
45
46
|
externalId: autotest.externalId,
|
|
46
47
|
name: autotest.name,
|
|
47
|
-
namespace: autotest.namespace,
|
|
48
|
+
namespace: (_a = autotest.namespace) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, "/"),
|
|
48
49
|
classname: autotest.classname,
|
|
49
50
|
steps: autotest.steps,
|
|
50
51
|
setup: autotest.setup,
|
|
@@ -37,3 +37,16 @@ describe("AutotestConverter layer", () => {
|
|
|
37
37
|
expect(withoutLayer.layer).toBeUndefined();
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
|
+
describe("AutotestConverter namespace", () => {
|
|
41
|
+
const converter = new autotests_converter_1.AutotestConverter(makeConfig());
|
|
42
|
+
it("normalizes backslashes to forward slashes on create/update", () => {
|
|
43
|
+
const create = converter.toOriginAutotestCreate(makeAutotest({ namespace: "api\\users" }));
|
|
44
|
+
expect(create.namespace).toBe("api/users");
|
|
45
|
+
const update = converter.toOriginAutotestUpdate(makeAutotest({ namespace: "api\\users\\v1" }));
|
|
46
|
+
expect(update.namespace).toBe("api/users/v1");
|
|
47
|
+
});
|
|
48
|
+
it("keeps posix namespace unchanged", () => {
|
|
49
|
+
const model = converter.toOriginAutotestCreate(makeAutotest({ namespace: "api/users" }));
|
|
50
|
+
expect(model.namespace).toBe("api/users");
|
|
51
|
+
});
|
|
52
|
+
});
|