@typespec/http-client-js 0.16.0 → 0.16.1-dev.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/.turbo/turbo-build.log +2 -5
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/{calculate-coverage.js → calculate-coverage.ts} +5 -8
- package/eng/scripts/{emit-e2e.js → emit-e2e.ts} +2 -6
- package/eng/scripts/{run-e2e-tests.js → run-e2e-tests.ts} +16 -12
- package/eng/scripts/{upload-spector-results.js → upload-spector-results.ts} +28 -9
- package/package.json +17 -17
- package/src/testing/index.ts +1 -0
- package/test/e2e/http/payload/multipart/main.test.ts +1 -3
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
3
|
import { readFile } from "fs/promises";
|
|
4
|
-
import {
|
|
4
|
+
import { join } from "path";
|
|
5
5
|
import pc from "picocolors";
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = dirname(__filename);
|
|
10
6
|
|
|
11
7
|
const coverageFilePath = join(
|
|
12
|
-
|
|
8
|
+
import.meta.dirname,
|
|
13
9
|
"../../temp",
|
|
14
10
|
"tsp-spector-coverage-javascript-standard.json",
|
|
15
11
|
);
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
/** Calculates and prints Spector coverage from the local coverage artifact. */
|
|
14
|
+
export async function calculateCoverage(): Promise<void> {
|
|
18
15
|
try {
|
|
19
16
|
console.log(pc.blue(`Reading coverage file from: ${coverageFilePath}`));
|
|
20
17
|
const data = await readFile(coverageFilePath, "utf8");
|
|
21
18
|
|
|
22
|
-
const coverage = JSON.parse(data)
|
|
19
|
+
const coverage = JSON.parse(data) as Array<{ results: Record<string, string> }>;
|
|
23
20
|
|
|
24
21
|
const results = coverage[0].results;
|
|
25
22
|
const totalTests = Object.keys(results).length;
|
|
@@ -7,13 +7,9 @@ import ora from "ora";
|
|
|
7
7
|
import pLimit from "p-limit";
|
|
8
8
|
import { basename, dirname, join, resolve } from "path";
|
|
9
9
|
import pc from "picocolors";
|
|
10
|
-
import { fileURLToPath } from "url";
|
|
11
10
|
import { hideBin } from "yargs/helpers";
|
|
12
11
|
import yargs from "yargs/yargs";
|
|
13
12
|
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = dirname(__filename);
|
|
16
|
-
|
|
17
13
|
async function pathExists(path) {
|
|
18
14
|
return access(path).then(
|
|
19
15
|
() => true,
|
|
@@ -21,8 +17,8 @@ async function pathExists(path) {
|
|
|
21
17
|
);
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
const projectRoot = join(
|
|
25
|
-
const tspConfig = join(
|
|
20
|
+
const projectRoot = join(import.meta.dirname, "../..");
|
|
21
|
+
const tspConfig = join(import.meta.dirname, "tspconfig.yaml");
|
|
26
22
|
|
|
27
23
|
const basePath = join(projectRoot, "node_modules", "@typespec", "http-specs", "specs");
|
|
28
24
|
const ignoreFilePath = join(projectRoot, ".testignore");
|
|
@@ -8,8 +8,8 @@ import pc from "picocolors";
|
|
|
8
8
|
import { promisify } from "util";
|
|
9
9
|
import yargs from "yargs";
|
|
10
10
|
import { hideBin } from "yargs/helpers";
|
|
11
|
-
import { calculateCoverage } from "./calculate-coverage.
|
|
12
|
-
import { runCoverageUpload } from "./upload-spector-results.
|
|
11
|
+
import { calculateCoverage } from "./calculate-coverage.ts";
|
|
12
|
+
import { runCoverageUpload } from "./upload-spector-results.ts";
|
|
13
13
|
|
|
14
14
|
const execPromise = promisify(exec);
|
|
15
15
|
const spinner = ora();
|
|
@@ -18,7 +18,7 @@ const SERVER_URL = "http://localhost:3000/routes/in-interface/fixed";
|
|
|
18
18
|
// ✅ Setup logging to a file
|
|
19
19
|
const logFile = path.join(process.cwd(), "script.log");
|
|
20
20
|
const logStream = fs.createWriteStream(logFile, { flags: "a" });
|
|
21
|
-
const log = (message) => {
|
|
21
|
+
const log = (message: string): void => {
|
|
22
22
|
console.log(message);
|
|
23
23
|
logStream.write(`${new Date().toISOString()} - ${message}\n`);
|
|
24
24
|
};
|
|
@@ -53,10 +53,10 @@ if (testPath) {
|
|
|
53
53
|
/**
|
|
54
54
|
* Waits until the mock server responds with HTTP 204 on /routes
|
|
55
55
|
*/
|
|
56
|
-
const waitForServer = async (url, retries = 20, delay = 2000) => {
|
|
56
|
+
const waitForServer = async (url: string, retries = 20, delay = 2000): Promise<void> => {
|
|
57
57
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
58
58
|
try {
|
|
59
|
-
const res = await new Promise((resolve, reject) => {
|
|
59
|
+
const res = await new Promise<http.IncomingMessage>((resolve, reject) => {
|
|
60
60
|
http.get(url, resolve).on("error", reject);
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -66,7 +66,7 @@ const waitForServer = async (url, retries = 20, delay = 2000) => {
|
|
|
66
66
|
} else {
|
|
67
67
|
log(pc.yellow(`⚠️ Attempt ${attempt}: Received ${res.statusCode}, retrying...`));
|
|
68
68
|
}
|
|
69
|
-
} catch
|
|
69
|
+
} catch {
|
|
70
70
|
log(pc.gray(`🔄 Attempt ${attempt}: Server not ready yet...`));
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -80,7 +80,7 @@ const waitForServer = async (url, retries = 20, delay = 2000) => {
|
|
|
80
80
|
/**
|
|
81
81
|
* Main function to start the server, run tests, and stop the server
|
|
82
82
|
*/
|
|
83
|
-
const runE2eTests = async () => {
|
|
83
|
+
const runE2eTests = async (): Promise<void> => {
|
|
84
84
|
log(pc.blue(pc.bold("\n🚀 Starting mock server...")));
|
|
85
85
|
spinner.start("Launching mock server...");
|
|
86
86
|
|
|
@@ -97,12 +97,12 @@ const runE2eTests = async () => {
|
|
|
97
97
|
);
|
|
98
98
|
|
|
99
99
|
// ✅ Ensure cleanup on exit
|
|
100
|
-
const stopServer = async () => {
|
|
100
|
+
const stopServer = async (): Promise<void> => {
|
|
101
101
|
spinner.start("Shutting down mock server...");
|
|
102
102
|
try {
|
|
103
103
|
await execPromise("pnpm stop:server");
|
|
104
104
|
spinner.succeed(pc.green("✅ Mock server stopped successfully."));
|
|
105
|
-
} catch
|
|
105
|
+
} catch {
|
|
106
106
|
spinner.fail(pc.red("❌ Failed to stop the server gracefully."));
|
|
107
107
|
}
|
|
108
108
|
};
|
|
@@ -121,7 +121,7 @@ const runE2eTests = async () => {
|
|
|
121
121
|
log(pc.cyan(`> ${vitestArgs.join(" ")}`));
|
|
122
122
|
|
|
123
123
|
// ✅ Run Vitest and stream output live
|
|
124
|
-
await new Promise((resolve, reject) => {
|
|
124
|
+
await new Promise<void>((resolve, reject) => {
|
|
125
125
|
const testProcess = spawn("npx", vitestArgs, { stdio: "inherit", shell: true });
|
|
126
126
|
|
|
127
127
|
testProcess.on("exit", async (code) => {
|
|
@@ -137,11 +137,15 @@ const runE2eTests = async () => {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
} catch (err) {
|
|
140
|
-
log(pc.red(
|
|
140
|
+
log(pc.red(`\n❌ Error: ${getErrorMessage(err)}`));
|
|
141
141
|
await stopServer();
|
|
142
142
|
process.exit(1);
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
|
+
|
|
146
|
+
function getErrorMessage(error: unknown): string {
|
|
147
|
+
return error instanceof Error ? error.message : String(error);
|
|
148
|
+
}
|
|
145
149
|
const startTime = process.hrtime.bigint(); // ✅ High precision time tracking
|
|
146
150
|
let exitCode = 0; // ✅ Track exit status
|
|
147
151
|
|
|
@@ -149,7 +153,7 @@ try {
|
|
|
149
153
|
await runE2eTests();
|
|
150
154
|
await runCoverageUpload({ force: forceUpload });
|
|
151
155
|
} catch (error) {
|
|
152
|
-
log(pc.red(`❌ Fatal Error: ${error
|
|
156
|
+
log(pc.red(`❌ Fatal Error: ${getErrorMessage(error)}`));
|
|
153
157
|
exitCode = 1; // ✅ Mark as failure but do NOT exit yet
|
|
154
158
|
} finally {
|
|
155
159
|
// ✅ Ensure time is always logged
|
|
@@ -5,7 +5,15 @@ import path from "path";
|
|
|
5
5
|
import pc from "picocolors";
|
|
6
6
|
|
|
7
7
|
/* eslint-disable no-console */
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
type CoverageUploadOptions = {
|
|
10
|
+
force?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Uploads Spector coverage when CI environment conditions allow it. */
|
|
14
|
+
export async function runCoverageUpload({
|
|
15
|
+
force = false,
|
|
16
|
+
}: CoverageUploadOptions = {}): Promise<void> {
|
|
9
17
|
console.log(pc.blue("\n🔍 Checking conditions before uploading coverage..."));
|
|
10
18
|
|
|
11
19
|
// Retrieve environment variables
|
|
@@ -46,7 +54,10 @@ export async function runCoverageUpload({ force = false } = {}) {
|
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
// Extract generator details
|
|
49
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
|
|
57
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")) as {
|
|
58
|
+
name?: string;
|
|
59
|
+
version?: string;
|
|
60
|
+
};
|
|
50
61
|
const generatorName = packageJson.name;
|
|
51
62
|
const generatorVersion = packageJson.version;
|
|
52
63
|
|
|
@@ -88,15 +99,19 @@ export async function runCoverageUpload({ force = false } = {}) {
|
|
|
88
99
|
}).start();
|
|
89
100
|
|
|
90
101
|
try {
|
|
91
|
-
await new Promise((resolve, reject) => {
|
|
92
|
-
const
|
|
102
|
+
await new Promise<void>((resolve, reject) => {
|
|
103
|
+
const uploadProcess = spawn("npx", args, { stdio: "pipe", shell: true });
|
|
93
104
|
|
|
94
105
|
// Capture output and errors
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
uploadProcess.stdout.on("data", (data) =>
|
|
107
|
+
console.log(pc.gray(`📄 ${data.toString().trim()}`)),
|
|
108
|
+
);
|
|
109
|
+
uploadProcess.stderr.on("data", (data) =>
|
|
110
|
+
console.error(pc.red(`❌ ${data.toString().trim()}`)),
|
|
111
|
+
);
|
|
97
112
|
|
|
98
113
|
// Handle process completion
|
|
99
|
-
|
|
114
|
+
uploadProcess.on("close", (code) => {
|
|
100
115
|
if (code === 0) {
|
|
101
116
|
spinner.succeed(pc.green("🎉 Coverage upload successful!"));
|
|
102
117
|
resolve();
|
|
@@ -107,14 +122,18 @@ export async function runCoverageUpload({ force = false } = {}) {
|
|
|
107
122
|
});
|
|
108
123
|
|
|
109
124
|
// Handle unexpected errors
|
|
110
|
-
|
|
125
|
+
uploadProcess.on("error", (error) => {
|
|
111
126
|
spinner.fail(pc.red("❌ An error occurred while uploading coverage."));
|
|
112
127
|
console.error(pc.red(error.message));
|
|
113
128
|
reject(error);
|
|
114
129
|
});
|
|
115
130
|
});
|
|
116
131
|
} catch (error) {
|
|
117
|
-
console.error(pc.red(`❌ Error: ${error
|
|
132
|
+
console.error(pc.red(`❌ Error: ${getErrorMessage(error)}`));
|
|
118
133
|
process.exit(1);
|
|
119
134
|
}
|
|
120
135
|
}
|
|
136
|
+
|
|
137
|
+
function getErrorMessage(error: unknown): string {
|
|
138
|
+
return error instanceof Error ? error.message : String(error);
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://typespec.io",
|
|
6
6
|
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
|
|
@@ -28,22 +28,27 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@typespec/compiler": "^1.14.0",
|
|
32
|
-
"@typespec/http": "^1.14.0",
|
|
33
|
-
"@typespec/rest": "^0.84.0"
|
|
31
|
+
"@typespec/compiler": "^1.14.0 || >= 1.15.0-dev.7",
|
|
32
|
+
"@typespec/http": "^1.14.0 || >= 1.15.0-dev.3",
|
|
33
|
+
"@typespec/rest": "^0.84.0 || >= 0.85.0-dev.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@alloy-js/core": "^0.24.1",
|
|
37
37
|
"@alloy-js/typescript": "^0.24.0",
|
|
38
|
-
"
|
|
39
|
-
"@typespec/
|
|
40
|
-
"
|
|
38
|
+
"@typespec/emitter-framework": "^0.19.0 || >= 0.20.0-dev.2",
|
|
39
|
+
"@typespec/http-client": "^0.16.0 || >= 0.16.1-dev.0",
|
|
40
|
+
"prettier": "^3.9.5"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@alloy-js/cli": "^0.24.0",
|
|
44
44
|
"@alloy-js/rollup-plugin": "^0.1.2",
|
|
45
45
|
"@types/yargs": "^17.0.35",
|
|
46
|
-
"@typespec/
|
|
46
|
+
"@typespec/http": "^1.14.0 || >= 1.15.0-dev.3",
|
|
47
|
+
"@typespec/http-specs": "^0.1.0-alpha.40 || >= 0.1.0-alpha.41-dev.0",
|
|
48
|
+
"@typespec/spector": "^0.1.0-alpha.27 || >= 0.1.0-alpha.28-dev.2",
|
|
49
|
+
"@typespec/ts-http-runtime": "0.3.7",
|
|
50
|
+
"@typespec/tspd": "^0.76.0 || >= 0.77.0-dev.4",
|
|
51
|
+
"@typespec/versioning": "^0.84.0 || >= 0.85.0-dev.0",
|
|
47
52
|
"@vitest/ui": "^4.1.3",
|
|
48
53
|
"change-case": "^5.4.4",
|
|
49
54
|
"concurrently": "^10.0.0",
|
|
@@ -56,12 +61,7 @@
|
|
|
56
61
|
"typescript": "~6.0.2",
|
|
57
62
|
"uri-template": "^2.0.0",
|
|
58
63
|
"vitest": "^4.1.3",
|
|
59
|
-
"yargs": "^18.0.0"
|
|
60
|
-
"@typespec/http": "^1.14.0",
|
|
61
|
-
"@typespec/http-specs": "^0.1.0-alpha.39",
|
|
62
|
-
"@typespec/tspd": "^0.76.0",
|
|
63
|
-
"@typespec/spector": "^0.1.0-alpha.26",
|
|
64
|
-
"@typespec/versioning": "^0.84.0"
|
|
64
|
+
"yargs": "^18.0.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"build": "alloy build",
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"test:watch": "vitest -w",
|
|
75
75
|
"test:regen": "cross-env RECORD=true vitest run",
|
|
76
76
|
"test:ci": "vitest run --coverage --reporter=junit --reporter=default",
|
|
77
|
-
"test:e2e": "pnpm emit:e2e && pnpm build:test && node eng/scripts/run-e2e-tests.
|
|
77
|
+
"test:e2e": "pnpm emit:e2e && pnpm build:test && node eng/scripts/run-e2e-tests.ts",
|
|
78
78
|
"format": "prettier . --write",
|
|
79
79
|
"build:test": "tsc -p tsconfig.test.json",
|
|
80
80
|
"start:server": "npx tsp-spector server start node_modules/@typespec/http-specs/specs --coverageFile ./temp/tsp-spector-coverage-javascript-standard.json --debug",
|
|
81
81
|
"stop:server": "npx tsp-spector server stop",
|
|
82
|
-
"run:e2e": "node eng/scripts/run-e2e-tests.
|
|
82
|
+
"run:e2e": "node eng/scripts/run-e2e-tests.ts",
|
|
83
83
|
"regen-docs": "tspd doc . --enable-experimental --output-dir ../../website/src/content/docs/docs/emitters/clients/http-client-js/reference --skip-js",
|
|
84
|
-
"emit:e2e": "node eng/scripts/emit-e2e.
|
|
84
|
+
"emit:e2e": "node eng/scripts/emit-e2e.ts"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testi
|
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
|
|
5
5
|
/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
6
7
|
export const HttpClientJavascriptEmitterTestLibrary: TypeSpecTestLibrary = createTestLibrary({
|
|
7
8
|
name: "@typespec/http-client-js",
|
|
8
9
|
packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../"),
|