Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[batch] Precise Typechecking #32146

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions sdk/batch/batch-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import azsdkEslint from "@azure/eslint-plugin-azure-sdk";
export default azsdkEslint.config([
{
rules: {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn",
"@azure/azure-sdk/ts-modules-only-named": "warn",
},
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
3 changes: 2 additions & 1 deletion sdk/batch/batch-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"sideEffects": false,
"autoPublish": false,
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand Down Expand Up @@ -96,7 +97,7 @@
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\"",
"generate:client": "echo skipped",
"integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"integration-test:node": "dev-tool run test:vitest",
"integration-test:node": "dev-tool run test:vitest --esm",
"lint": "eslint package.json api-extractor.json src test",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down
5 changes: 4 additions & 1 deletion sdk/batch/batch-rest/src/paginateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ function checkPagingRequest(response: PathUncheckedResponse): void {
/**
* Extracts the itemName and nextLinkName from the initial response to use them for pagination
*/
function getPaginationProperties(initialResponse: PathUncheckedResponse) {
function getPaginationProperties(initialResponse: PathUncheckedResponse): {
itemName: string;
nextLinkName: string | undefined;
} {
// Build a set with the passed custom nextLinkNames
const nextLinkNames = new Set(["nextLink", "odata.nextLink"]);

Expand Down
6 changes: 3 additions & 3 deletions sdk/batch/batch-rest/test/computeNodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
UploadBatchServiceLogsContent,
UploadNodeLogsParameters,
} from "../src/index.js";
import { isUnexpected } from "../src/index.js";
import { isUnexpected, type ListNodes200Response, type BatchNodeOutput } from "../src/index.js";
import { fakeTestPasswordPlaceholder1 } from "./utils/fakeTestSecrets.js";
import { getResourceName, waitForNotNull } from "./utils/helpers.js";
import { describe, it, beforeAll, afterAll, beforeEach, afterEach, assert } from "vitest";
Expand Down Expand Up @@ -97,7 +97,7 @@ describe("Compute node operations", async () => {
it("should list compute nodes successfully", async () => {
const poolId = recorder.variable("BASIC_POOL", BASIC_POOL);

const getListNodesResult = async () => {
const getListNodesResult = async (): Promise<ListNodes200Response | null> => {
const res = await batchClient.path("/pools/{poolId}/nodes", poolId).get();
if (isUnexpected(res)) {
assert.fail(`Received unexpected status code from getting pool: ${res.status}
Expand Down Expand Up @@ -275,7 +275,7 @@ describe("Compute node operations", async () => {
.post({ contentType: "application/json; odata=minimalmetadata" });
assert.equal(deallocateNodeResult.status, "202");

const checkIfDeallocated = async () => {
const checkIfDeallocated = async (): Promise<BatchNodeOutput | null> => {
const nodes = await batchClient.path("/pools/{poolId}/nodes", poolId).get();
if (isUnexpected(nodes)) {
assert.fail(`Received unexpected status code from listing nodes: ${nodes.status}
Expand Down
4 changes: 2 additions & 2 deletions sdk/batch/batch-rest/test/poolScaling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
EnablePoolAutoScaleParameters,
EvaluatePoolAutoScaleParameters,
} from "../src/index.js";
import { isUnexpected } from "../src/index.js";
import { isUnexpected, type GetPool200Response } from "../src/index.js";
import { fakeTestPasswordPlaceholder1 } from "./utils/fakeTestSecrets.js";
import { getResourceName, waitForNotNull } from "./utils/helpers.js";
import moment from "moment";
Expand Down Expand Up @@ -64,7 +64,7 @@ describe("Autoscale operations", async () => {
Unable to provision resource needed for Job Testing.
Response Body: ${poolPostResult.body.message}`);
}
const getSteadyPool = async () => {
const getSteadyPool = async (): Promise<GetPool200Response | null> => {
const getPoolResult = await batchClient.path("/pools/{poolId}", BASIC_POOL).get();
if (isUnexpected(getPoolResult)) {
assert.fail(`Received unexpected status code from getting pool: ${getPoolResult.status}
Expand Down
14 changes: 9 additions & 5 deletions sdk/batch/batch-rest/test/pools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import type {
ReplacePoolPropertiesParameters,
ResizePoolParameters,
} from "../src/index.js";
import { isUnexpected, paginate } from "../src/index.js";
import {
isUnexpected,
paginate,
type GetPool200Response,
type BatchPoolNodeCountsOutput,
} from "../src/index.js";
import { fakeTestPasswordPlaceholder1 } from "./utils/fakeTestSecrets.js";
import { wait } from "./utils/wait.js";
import { getResourceName, POLLING_INTERVAL, waitForNotNull } from "./utils/helpers.js";
Expand Down Expand Up @@ -137,7 +142,7 @@ describe("Pool Operations Test", () => {
it("should get a pool reference successfully", async () => {
const poolId = recorder.variable("BASIC_POOL", BASIC_POOL);

const getSteadyPool = async () => {
const getSteadyPool = async (): Promise<GetPool200Response | null> => {
const res = await batchClient.path("/pools/{poolId}", poolId).get();
if (isUnexpected(res)) {
assert.fail(`Received unexpected status code from getting pool: ${res.status}
Expand Down Expand Up @@ -419,9 +424,8 @@ describe("Pool Operations Test", () => {
it("should get pool node counts successfully", async () => {
// let poolList = [];
const poolId = recorder.variable("ENDPOINT_POOL", ENDPOINT_POOL);
// eslint-disable-next-line no-constant-condition

const listNodeCounts = async () => {
const listNodeCounts = async (): Promise<BatchPoolNodeCountsOutput[] | null> => {
const poolList = [];
const listNodeCountResult = await batchClient.path("/nodecounts").get();
if (isUnexpected(listNodeCountResult)) {
Expand Down Expand Up @@ -495,7 +499,7 @@ describe("Pool Operations Test", () => {

it("should start pool resizing successfully", async () => {
const poolId = recorder.variable("TEST_POOL3", TEST_POOL3);
const getSteadyPool = async () => {
const getSteadyPool = async (): Promise<GetPool200Response | null> => {
const res = await batchClient.path("/pools/{poolId}", poolId).get();
if (isUnexpected(res)) {
assert.fail(`Received unexpected status code from getting pool: ${res.status}
Expand Down
4 changes: 2 additions & 2 deletions sdk/batch/batch-rest/test/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
CreatePoolParameters,
CreateTaskParameters,
} from "../src/index.js";
import { isUnexpected, paginate } from "../src/index.js";
import { isUnexpected, paginate, type GetTask200Response } from "../src/index.js";
import { fakeTestPasswordPlaceholder1 } from "./utils/fakeTestSecrets.js";
import { getResourceName, waitForNotNull } from "./utils/helpers.js";
import { describe, it, beforeAll, afterAll, beforeEach, afterEach, assert } from "vitest";
Expand Down Expand Up @@ -458,7 +458,7 @@ describe("Task Operations Test", () => {
const taskAddResult = await batchClient.path("/jobs/{jobId}/tasks", jobId).post(taskAddParams);
assert.equal(taskAddResult.status, "201");

const getExecutedTask = async () => {
const getExecutedTask = async (): Promise<GetTask200Response | null> => {
const getTaskResult = await batchClient
.path("/jobs/{jobId}/tasks/{taskId}", jobId, taskAddParams.body.id!)
.get();
Expand Down
2 changes: 1 addition & 1 deletion sdk/batch/batch-rest/test/utils/envTokenCredential.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { TokenCredential } from "@azure/identity";
import type { TokenCredential } from "@azure/identity";

/**
* A TokenCredential implementation that gets the token from the environment variable
Expand Down
4 changes: 2 additions & 2 deletions sdk/batch/batch-rest/test/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT License.

import { assert } from "vitest";
import { BatchClient } from "../../src/clientDefinitions.js";
import type { BatchClient } from "../../src/clientDefinitions.js";
import { isUnexpected } from "../../src/isUnexpected.js";
import { paginate } from "../../src/paginateHelper.js";
import { waitForNotNull } from "./helpers.js";
import { BatchNodeOutput } from "../../src/outputModels.js";
import type { BatchNodeOutput } from "../../src/outputModels.js";

export function waitForNodesToStart(
poolId: string,
Expand Down
9 changes: 1 addition & 8 deletions sdk/batch/batch-rest/tsconfig.browser.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
23 changes: 6 additions & 17 deletions sdk/batch/batch-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": ".",
"paths": {
"@azure-rest/batch": ["./src/index"]
}
},
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts",
"test/**/*.cts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/batch/batch-rest/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure-rest/batch": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/batch/batch-rest/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/batch/batch-rest/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
5 changes: 5 additions & 0 deletions sdk/batch/batch-rest/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default mergeConfig(
include: ["test/**/*.spec.ts"],
hookTimeout: 500000,
testTImeout: 500000,
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/batch/batch-rest/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
Loading