diff --git a/sdk/batch/batch-rest/eslint.config.mjs b/sdk/batch/batch-rest/eslint.config.mjs index 699816467a91..bbdf14373db4 100644 --- a/sdk/batch/batch-rest/eslint.config.mjs +++ b/sdk/batch/batch-rest/eslint.config.mjs @@ -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"], + }, }, }, ]); diff --git a/sdk/batch/batch-rest/package.json b/sdk/batch/batch-rest/package.json index 0586dbb16a2b..c88a6305ca66 100644 --- a/sdk/batch/batch-rest/package.json +++ b/sdk/batch/batch-rest/package.json @@ -8,6 +8,7 @@ "sideEffects": false, "autoPublish": false, "tshy": { + "project": "./tsconfig.src.json", "exports": { "./package.json": "./package.json", ".": "./src/index.ts" @@ -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", diff --git a/sdk/batch/batch-rest/src/paginateHelper.ts b/sdk/batch/batch-rest/src/paginateHelper.ts index e6b7b5a0b41c..a2182df24e56 100644 --- a/sdk/batch/batch-rest/src/paginateHelper.ts +++ b/sdk/batch/batch-rest/src/paginateHelper.ts @@ -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"]); diff --git a/sdk/batch/batch-rest/test/computeNodes.spec.ts b/sdk/batch/batch-rest/test/computeNodes.spec.ts index a8bb0b77af12..2975f1b2f0b0 100644 --- a/sdk/batch/batch-rest/test/computeNodes.spec.ts +++ b/sdk/batch/batch-rest/test/computeNodes.spec.ts @@ -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"; @@ -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 => { const res = await batchClient.path("/pools/{poolId}/nodes", poolId).get(); if (isUnexpected(res)) { assert.fail(`Received unexpected status code from getting pool: ${res.status} @@ -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 => { const nodes = await batchClient.path("/pools/{poolId}/nodes", poolId).get(); if (isUnexpected(nodes)) { assert.fail(`Received unexpected status code from listing nodes: ${nodes.status} diff --git a/sdk/batch/batch-rest/test/poolScaling.spec.ts b/sdk/batch/batch-rest/test/poolScaling.spec.ts index e36b15eaf7c8..4660bd978f24 100644 --- a/sdk/batch/batch-rest/test/poolScaling.spec.ts +++ b/sdk/batch/batch-rest/test/poolScaling.spec.ts @@ -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"; @@ -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 => { const getPoolResult = await batchClient.path("/pools/{poolId}", BASIC_POOL).get(); if (isUnexpected(getPoolResult)) { assert.fail(`Received unexpected status code from getting pool: ${getPoolResult.status} diff --git a/sdk/batch/batch-rest/test/pools.spec.ts b/sdk/batch/batch-rest/test/pools.spec.ts index 7fde55755a62..47bc81da08e8 100644 --- a/sdk/batch/batch-rest/test/pools.spec.ts +++ b/sdk/batch/batch-rest/test/pools.spec.ts @@ -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"; @@ -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 => { const res = await batchClient.path("/pools/{poolId}", poolId).get(); if (isUnexpected(res)) { assert.fail(`Received unexpected status code from getting pool: ${res.status} @@ -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 => { const poolList = []; const listNodeCountResult = await batchClient.path("/nodecounts").get(); if (isUnexpected(listNodeCountResult)) { @@ -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 => { const res = await batchClient.path("/pools/{poolId}", poolId).get(); if (isUnexpected(res)) { assert.fail(`Received unexpected status code from getting pool: ${res.status} diff --git a/sdk/batch/batch-rest/test/tasks.spec.ts b/sdk/batch/batch-rest/test/tasks.spec.ts index d82080837b65..72d841c3cf3b 100644 --- a/sdk/batch/batch-rest/test/tasks.spec.ts +++ b/sdk/batch/batch-rest/test/tasks.spec.ts @@ -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"; @@ -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 => { const getTaskResult = await batchClient .path("/jobs/{jobId}/tasks/{taskId}", jobId, taskAddParams.body.id!) .get(); diff --git a/sdk/batch/batch-rest/test/utils/envTokenCredential.ts b/sdk/batch/batch-rest/test/utils/envTokenCredential.ts index 07c5660016cc..7c74f2f2ca63 100644 --- a/sdk/batch/batch-rest/test/utils/envTokenCredential.ts +++ b/sdk/batch/batch-rest/test/utils/envTokenCredential.ts @@ -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 diff --git a/sdk/batch/batch-rest/test/utils/pool.ts b/sdk/batch/batch-rest/test/utils/pool.ts index f8e741a2dce3..f147e244e655 100644 --- a/sdk/batch/batch-rest/test/utils/pool.ts +++ b/sdk/batch/batch-rest/test/utils/pool.ts @@ -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, diff --git a/sdk/batch/batch-rest/tsconfig.browser.config.json b/sdk/batch/batch-rest/tsconfig.browser.config.json index f772e6eb3b76..75871518e3a0 100644 --- a/sdk/batch/batch-rest/tsconfig.browser.config.json +++ b/sdk/batch/batch-rest/tsconfig.browser.config.json @@ -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"] } diff --git a/sdk/batch/batch-rest/tsconfig.json b/sdk/batch/batch-rest/tsconfig.json index 1998492a3f1c..b186a5a177d8 100644 --- a/sdk/batch/batch-rest/tsconfig.json +++ b/sdk/batch/batch-rest/tsconfig.json @@ -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": [] } diff --git a/sdk/batch/batch-rest/tsconfig.samples.json b/sdk/batch/batch-rest/tsconfig.samples.json new file mode 100644 index 000000000000..5f4cd89a557f --- /dev/null +++ b/sdk/batch/batch-rest/tsconfig.samples.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.samples.base.json", + "compilerOptions": { + "paths": { + "@azure-rest/batch": ["./dist/esm"] + } + } +} diff --git a/sdk/batch/batch-rest/tsconfig.src.json b/sdk/batch/batch-rest/tsconfig.src.json new file mode 100644 index 000000000000..bae70752dd38 --- /dev/null +++ b/sdk/batch/batch-rest/tsconfig.src.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../tsconfig.lib.json" +} diff --git a/sdk/batch/batch-rest/tsconfig.test.json b/sdk/batch/batch-rest/tsconfig.test.json new file mode 100644 index 000000000000..290ca214aebc --- /dev/null +++ b/sdk/batch/batch-rest/tsconfig.test.json @@ -0,0 +1,3 @@ +{ + "extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"] +} diff --git a/sdk/batch/batch-rest/vitest.config.ts b/sdk/batch/batch-rest/vitest.config.ts index dd0df7bb85c0..fcc539c7e81d 100644 --- a/sdk/batch/batch-rest/vitest.config.ts +++ b/sdk/batch/batch-rest/vitest.config.ts @@ -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"], + }, }, }), ); diff --git a/sdk/batch/batch-rest/vitest.esm.config.ts b/sdk/batch/batch-rest/vitest.esm.config.ts new file mode 100644 index 000000000000..2f6e757a54f7 --- /dev/null +++ b/sdk/batch/batch-rest/vitest.esm.config.ts @@ -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 +);