kubernetes-fluent-client 3.0.5 → 3.1.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.
Files changed (78) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +68 -0
  4. package/dist/fetch.d.ts +22 -0
  5. package/dist/fetch.d.ts.map +1 -0
  6. package/dist/fetch.js +82 -0
  7. package/dist/fetch.test.d.ts +2 -0
  8. package/dist/fetch.test.d.ts.map +1 -0
  9. package/dist/fetch.test.js +97 -0
  10. package/dist/fileSystem.d.ts +11 -0
  11. package/dist/fileSystem.d.ts.map +1 -0
  12. package/dist/fileSystem.js +42 -0
  13. package/dist/fileSystem.test.d.ts +2 -0
  14. package/dist/fileSystem.test.d.ts.map +1 -0
  15. package/dist/fileSystem.test.js +75 -0
  16. package/dist/fluent/http2-watch.spec.d.ts +2 -0
  17. package/dist/fluent/http2-watch.spec.d.ts.map +1 -0
  18. package/dist/fluent/http2-watch.spec.js +284 -0
  19. package/dist/fluent/index.d.ts +12 -0
  20. package/dist/fluent/index.d.ts.map +1 -0
  21. package/dist/fluent/index.js +228 -0
  22. package/dist/fluent/index.test.d.ts +2 -0
  23. package/dist/fluent/index.test.d.ts.map +1 -0
  24. package/dist/fluent/index.test.js +193 -0
  25. package/dist/fluent/types.d.ts +187 -0
  26. package/dist/fluent/types.d.ts.map +1 -0
  27. package/dist/fluent/types.js +16 -0
  28. package/dist/fluent/utils.d.ts +41 -0
  29. package/dist/fluent/utils.d.ts.map +1 -0
  30. package/dist/fluent/utils.js +153 -0
  31. package/dist/fluent/utils.test.d.ts +2 -0
  32. package/dist/fluent/utils.test.d.ts.map +1 -0
  33. package/dist/fluent/utils.test.js +215 -0
  34. package/dist/fluent/watch.d.ts +88 -0
  35. package/dist/fluent/watch.d.ts.map +1 -0
  36. package/dist/fluent/watch.js +546 -0
  37. package/dist/fluent/watch.spec.d.ts +2 -0
  38. package/dist/fluent/watch.spec.d.ts.map +1 -0
  39. package/dist/fluent/watch.spec.js +261 -0
  40. package/dist/generate.d.ts +84 -0
  41. package/dist/generate.d.ts.map +1 -0
  42. package/dist/generate.js +208 -0
  43. package/dist/generate.test.d.ts +2 -0
  44. package/dist/generate.test.d.ts.map +1 -0
  45. package/dist/generate.test.js +320 -0
  46. package/dist/helpers.d.ts +33 -0
  47. package/dist/helpers.d.ts.map +1 -0
  48. package/dist/helpers.js +103 -0
  49. package/dist/helpers.test.d.ts +2 -0
  50. package/dist/helpers.test.d.ts.map +1 -0
  51. package/dist/helpers.test.js +37 -0
  52. package/dist/index.d.ts +14 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +60 -0
  55. package/dist/kinds.d.ts +16 -0
  56. package/dist/kinds.d.ts.map +1 -0
  57. package/dist/kinds.js +570 -0
  58. package/dist/kinds.test.d.ts +2 -0
  59. package/dist/kinds.test.d.ts.map +1 -0
  60. package/dist/kinds.test.js +155 -0
  61. package/dist/patch.d.ts +7 -0
  62. package/dist/patch.d.ts.map +1 -0
  63. package/dist/patch.js +2 -0
  64. package/dist/postProcessing.d.ts +246 -0
  65. package/dist/postProcessing.d.ts.map +1 -0
  66. package/dist/postProcessing.js +497 -0
  67. package/dist/postProcessing.test.d.ts +2 -0
  68. package/dist/postProcessing.test.d.ts.map +1 -0
  69. package/dist/postProcessing.test.js +550 -0
  70. package/dist/types.d.ts +32 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +16 -0
  73. package/dist/upstream.d.ts +4 -0
  74. package/dist/upstream.d.ts.map +1 -0
  75. package/dist/upstream.js +56 -0
  76. package/package.json +1 -1
  77. package/src/fluent/http2-watch.spec.ts +335 -0
  78. package/src/fluent/watch.ts +174 -35
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const helpers_1 = require("yargs/helpers");
10
+ const yargs_1 = __importDefault(require("yargs/yargs"));
11
+ const generate_1 = require("./generate");
12
+ const package_json_1 = require("../package.json");
13
+ const postProcessing_1 = require("./postProcessing");
14
+ const fileSystem_1 = require("./fileSystem"); // Import your new file system
15
+ void (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
16
+ .version("version", "Display version number", `kubernetes-fluent-client v${package_json_1.version}`)
17
+ .alias("version", "V")
18
+ .command("crd [source] [directory]", "generate usable types from a K8s CRD", yargs => {
19
+ return yargs
20
+ .positional("source", {
21
+ describe: "the yaml file path, remote url, or K8s CRD name",
22
+ type: "string",
23
+ })
24
+ .positional("directory", {
25
+ describe: "the directory to output the generated types to",
26
+ type: "string",
27
+ })
28
+ .option("plain", {
29
+ alias: "p",
30
+ type: "boolean",
31
+ description: "generate plain types without binding to the fluent client, automatically enabled when an alternate language is specified",
32
+ })
33
+ .option("language", {
34
+ alias: "l",
35
+ type: "string",
36
+ default: "ts",
37
+ description: "the language to generate types in, see https://github.com/glideapps/quicktype#target-languages for a list of supported languages",
38
+ })
39
+ .option("noPost", {
40
+ alias: "x",
41
+ type: "boolean",
42
+ default: false,
43
+ description: "disable post-processing after generating the types",
44
+ })
45
+ .demandOption(["source", "directory"]);
46
+ }, async (argv) => {
47
+ const opts = argv;
48
+ opts.logFn = console.log;
49
+ // Pass the `post` flag to opts
50
+ opts.noPost = argv.noPost;
51
+ // Use NodeFileSystem as the file system for post-processing
52
+ const fileSystem = new fileSystem_1.NodeFileSystem(); // Create an instance of NodeFileSystem
53
+ if (!opts.noPost) {
54
+ console.log("\n✅ Post-processing has been enabled.\n");
55
+ }
56
+ try {
57
+ // Capture the results returned by generate
58
+ const allResults = await (0, generate_1.generate)(opts);
59
+ // If noPost is false, run post-processing
60
+ if (!opts.noPost) {
61
+ await (0, postProcessing_1.postProcessing)(allResults, opts, fileSystem); // Pass the file system to postProcessing
62
+ }
63
+ }
64
+ catch (e) {
65
+ console.log(`\n❌ ${e.message}`);
66
+ }
67
+ })
68
+ .parse();
@@ -0,0 +1,22 @@
1
+ import { RequestInfo, RequestInit } from "node-fetch";
2
+ export type FetchResponse<T> = {
3
+ data: T;
4
+ ok: boolean;
5
+ status: number;
6
+ statusText: string;
7
+ };
8
+ /**
9
+ * Perform an async HTTP call and return the parsed JSON response, optionally
10
+ * as a specific type.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * fetch<string[]>("https://example.com/api/foo");
15
+ * ```
16
+ *
17
+ * @param url The URL or Request object to fetch
18
+ * @param init Additional options for the request
19
+ * @returns The parsed JSON response
20
+ */
21
+ export declare function fetch<T>(url: URL | RequestInfo, init?: RequestInit): Promise<FetchResponse<T>>;
22
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAiB,EAAc,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAwC3B"}
package/dist/fetch.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.fetch = fetch;
29
+ const http_status_codes_1 = require("http-status-codes");
30
+ const node_fetch_1 = __importStar(require("node-fetch"));
31
+ /**
32
+ * Perform an async HTTP call and return the parsed JSON response, optionally
33
+ * as a specific type.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * fetch<string[]>("https://example.com/api/foo");
38
+ * ```
39
+ *
40
+ * @param url The URL or Request object to fetch
41
+ * @param init Additional options for the request
42
+ * @returns The parsed JSON response
43
+ */
44
+ async function fetch(url, init) {
45
+ let data = undefined;
46
+ try {
47
+ const resp = await (0, node_fetch_1.default)(url, init);
48
+ const contentType = resp.headers.get("content-type") || "";
49
+ // Parse the response as JSON if the content type is JSON
50
+ if (contentType.includes("application/json")) {
51
+ data = await resp.json();
52
+ }
53
+ else {
54
+ // Otherwise, return however the response was read
55
+ data = (await resp.text());
56
+ }
57
+ return {
58
+ data,
59
+ ok: resp.ok,
60
+ status: resp.status,
61
+ statusText: resp.statusText,
62
+ };
63
+ }
64
+ catch (e) {
65
+ if (e instanceof node_fetch_1.FetchError) {
66
+ // Parse the error code from the FetchError or default to 400 (Bad Request)
67
+ const status = parseInt(e.code || "400");
68
+ return {
69
+ data,
70
+ ok: false,
71
+ status,
72
+ statusText: e.message,
73
+ };
74
+ }
75
+ return {
76
+ data,
77
+ ok: false,
78
+ status: http_status_codes_1.StatusCodes.BAD_REQUEST,
79
+ statusText: "Unknown error",
80
+ };
81
+ }
82
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fetch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../src/fetch.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const globals_1 = require("@jest/globals");
9
+ const http_status_codes_1 = require("http-status-codes");
10
+ const nock_1 = __importDefault(require("nock"));
11
+ const fetch_1 = require("./fetch");
12
+ (0, globals_1.beforeEach)(() => {
13
+ (0, nock_1.default)("https://jsonplaceholder.typicode.com")
14
+ .get("/todos/1")
15
+ .reply(200, {
16
+ userId: 1,
17
+ id: 1,
18
+ title: "Example title",
19
+ completed: false,
20
+ })
21
+ .post("/todos", {
22
+ title: "test todo",
23
+ userId: 1,
24
+ completed: false,
25
+ })
26
+ .reply(200, (uri, requestBody) => requestBody)
27
+ .get("/todos/empty-null")
28
+ .reply(200, undefined)
29
+ .get("/todos/empty-string")
30
+ .reply(200, "")
31
+ .get("/todos/empty-object")
32
+ .reply(200, {})
33
+ .get("/todos/invalid")
34
+ .replyWithError("Something bad happened");
35
+ });
36
+ (0, globals_1.test)("fetch: should return without type data", async () => {
37
+ const url = "https://jsonplaceholder.typicode.com/todos/1";
38
+ const { data, ok } = await (0, fetch_1.fetch)(url);
39
+ (0, globals_1.expect)(ok).toBe(true);
40
+ (0, globals_1.expect)(data["title"]).toBe("Example title");
41
+ });
42
+ (0, globals_1.test)("fetch: should return parsed JSON response as a specific type", async () => {
43
+ const url = "https://jsonplaceholder.typicode.com/todos/1";
44
+ const { data, ok } = await (0, fetch_1.fetch)(url);
45
+ (0, globals_1.expect)(ok).toBe(true);
46
+ (0, globals_1.expect)(data.id).toBe(1);
47
+ (0, globals_1.expect)(typeof data.title).toBe("string");
48
+ (0, globals_1.expect)(typeof data.completed).toBe("boolean");
49
+ });
50
+ (0, globals_1.test)("fetch: should handle additional request options", async () => {
51
+ const url = "https://jsonplaceholder.typicode.com/todos";
52
+ const requestOptions = {
53
+ method: "POST",
54
+ body: JSON.stringify({
55
+ title: "test todo",
56
+ userId: 1,
57
+ completed: false,
58
+ }),
59
+ headers: {
60
+ "Content-type": "application/json; charset=UTF-8",
61
+ },
62
+ };
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ const { data, ok } = await (0, fetch_1.fetch)(url, requestOptions);
65
+ (0, globals_1.expect)(ok).toBe(true);
66
+ (0, globals_1.expect)(data["title"]).toBe("test todo");
67
+ (0, globals_1.expect)(data["userId"]).toBe(1);
68
+ (0, globals_1.expect)(data["completed"]).toBe(false);
69
+ });
70
+ (0, globals_1.test)("fetch: should handle empty (null) responses", async () => {
71
+ const url = "https://jsonplaceholder.typicode.com/todos/empty-null";
72
+ const resp = await (0, fetch_1.fetch)(url);
73
+ (0, globals_1.expect)(resp.data).toBe("");
74
+ (0, globals_1.expect)(resp.ok).toBe(true);
75
+ (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
76
+ });
77
+ (0, globals_1.test)("fetch: should handle empty (string) responses", async () => {
78
+ const url = "https://jsonplaceholder.typicode.com/todos/empty-string";
79
+ const resp = await (0, fetch_1.fetch)(url);
80
+ (0, globals_1.expect)(resp.data).toBe("");
81
+ (0, globals_1.expect)(resp.ok).toBe(true);
82
+ (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
83
+ });
84
+ (0, globals_1.test)("fetch: should handle empty (object) responses", async () => {
85
+ const url = "https://jsonplaceholder.typicode.com/todos/empty-object";
86
+ const resp = await (0, fetch_1.fetch)(url);
87
+ (0, globals_1.expect)(resp.data).toEqual({});
88
+ (0, globals_1.expect)(resp.ok).toBe(true);
89
+ (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
90
+ });
91
+ (0, globals_1.test)("fetch: should handle failed requests without throwing an error", async () => {
92
+ const url = "https://jsonplaceholder.typicode.com/todos/invalid";
93
+ const resp = await (0, fetch_1.fetch)(url);
94
+ (0, globals_1.expect)(resp.data).toBe(undefined);
95
+ (0, globals_1.expect)(resp.ok).toBe(false);
96
+ (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.BAD_REQUEST);
97
+ });
@@ -0,0 +1,11 @@
1
+ export interface FileSystem {
2
+ readFile(filePath: string): string;
3
+ writeFile(filePath: string, content: string): void;
4
+ readdirSync(directory: string): string[];
5
+ }
6
+ export declare class NodeFileSystem implements FileSystem {
7
+ readFile(filePath: string): string;
8
+ writeFile(filePath: string, content: string): void;
9
+ readdirSync(directory: string): string[];
10
+ }
11
+ //# sourceMappingURL=fileSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileSystem.d.ts","sourceRoot":"","sources":["../src/fileSystem.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1C;AAGD,qBAAa,cAAe,YAAW,UAAU;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIlC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIlD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;CAGzC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.NodeFileSystem = void 0;
29
+ const fs = __importStar(require("fs"));
30
+ /* eslint class-methods-use-this: "off" */
31
+ class NodeFileSystem {
32
+ readFile(filePath) {
33
+ return fs.readFileSync(filePath, "utf8");
34
+ }
35
+ writeFile(filePath, content) {
36
+ fs.writeFileSync(filePath, content, "utf8");
37
+ }
38
+ readdirSync(directory) {
39
+ return fs.readdirSync(directory);
40
+ }
41
+ }
42
+ exports.NodeFileSystem = NodeFileSystem;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fileSystem.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileSystem.test.d.ts","sourceRoot":"","sources":["../src/fileSystem.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ const fs = __importStar(require("fs"));
29
+ const fileSystem_1 = require("./fileSystem");
30
+ const globals_1 = require("@jest/globals");
31
+ // Mock the fs module
32
+ globals_1.jest.mock("fs");
33
+ (0, globals_1.describe)("NodeFileSystem", () => {
34
+ let nodeFileSystem;
35
+ (0, globals_1.beforeEach)(() => {
36
+ nodeFileSystem = new fileSystem_1.NodeFileSystem();
37
+ globals_1.jest.clearAllMocks(); // Clear all mocks before each test
38
+ });
39
+ (0, globals_1.describe)("readFile", () => {
40
+ (0, globals_1.test)("should call fs.readFileSync with correct arguments", () => {
41
+ const mockFilePath = "test-file.txt";
42
+ const mockFileContent = "This is a test file";
43
+ // Mock the fs.readFileSync method to return the mock file content
44
+ fs.readFileSync.mockReturnValue(mockFileContent);
45
+ const result = nodeFileSystem.readFile(mockFilePath);
46
+ // Assert that fs.readFileSync was called with the correct file path and encoding
47
+ (0, globals_1.expect)(fs.readFileSync).toHaveBeenCalledWith(mockFilePath, "utf8");
48
+ // Assert that the returned content matches the mock file content
49
+ (0, globals_1.expect)(result).toBe(mockFileContent);
50
+ });
51
+ });
52
+ (0, globals_1.describe)("writeFile", () => {
53
+ (0, globals_1.test)("should call fs.writeFileSync with correct arguments", () => {
54
+ const mockFilePath = "test-file.txt";
55
+ const mockFileContent = "This is a test file";
56
+ // Call the writeFile method
57
+ nodeFileSystem.writeFile(mockFilePath, mockFileContent);
58
+ // Assert that fs.writeFileSync was called with the correct arguments
59
+ (0, globals_1.expect)(fs.writeFileSync).toHaveBeenCalledWith(mockFilePath, mockFileContent, "utf8");
60
+ });
61
+ });
62
+ (0, globals_1.describe)("readdirSync", () => {
63
+ (0, globals_1.test)("should call fs.readdirSync with correct arguments and return file list", () => {
64
+ const mockDirectoryPath = "test-directory";
65
+ const mockFileList = ["file1.txt", "file2.txt"];
66
+ // Mock the fs.readdirSync method to return the mock file list
67
+ fs.readdirSync.mockReturnValue(mockFileList);
68
+ const result = nodeFileSystem.readdirSync(mockDirectoryPath);
69
+ // Assert that fs.readdirSync was called with the correct directory path
70
+ (0, globals_1.expect)(fs.readdirSync).toHaveBeenCalledWith(mockDirectoryPath);
71
+ // Assert that the returned file list matches the mock file list
72
+ (0, globals_1.expect)(result).toEqual(mockFileList);
73
+ });
74
+ });
75
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http2-watch.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http2-watch.spec.d.ts","sourceRoot":"","sources":["../../src/fluent/http2-watch.spec.ts"],"names":[],"mappings":""}