Skip to content

Commit

Permalink
[rest libs] Precise Typechecking (#32176)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
- @azure-rest/confidential-ledger
- @azure-rest/developer-devcenter
- @azure-rest/iot-device-update
- @azure-rest/defender-easm
- @azure-rest/load-testing

### Issues associated with this PR
N/A

### Describe the problem that is addressed by this PR
Tests are not being typechecked and linting isn't configured correctly.
This PR migrates those libraries to precise typechecking setup
introduced in #31786

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?

### Are there test cases added in this PR? _(If not, why?)_
N/A

### Provide a list of related PRs _(if any)_
#31786

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
deyaaeldeen authored Dec 12, 2024
1 parent 0a3136f commit 137528c
Show file tree
Hide file tree
Showing 48 changed files with 259 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ 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",
},
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
3 changes: 2 additions & 1 deletion sdk/confidentialledger/confidential-ledger-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"esm",
"commonjs"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
15 changes: 6 additions & 9 deletions sdk/confidentialledger/confidential-ledger-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure-rest/confidential-ledger": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": ["src/**/*.ts", "src/**/*.mts", "src/**/*.cts", "samples-dev/**/*.ts", "test/**/*.ts"]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure-rest/confidential-ledger": ["./dist/esm"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
testTimeout: 600000,
hookTimeout: 600000,
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
include: ["test/**/*.spec.ts"],
hookTimeout: 60000,
testTimeout: 600000,
},
}),
);
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
);
15 changes: 8 additions & 7 deletions sdk/devcenter/developer-devcenter-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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-package-json-module": "off",
"@azure/azure-sdk/ts-package-json-files-required": "off",
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
},
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
3 changes: 2 additions & 1 deletion sdk/devcenter/developer-devcenter-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"type": "module",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function createDevBox() {

const projectList = await client.path("/projects").get();
if (isUnexpected(projectList)) {
throw new Error(projectList.body.error);
throw projectList.body.error;
}

let project: ProjectOutput = projectList.body.value[0];
Expand All @@ -31,7 +31,7 @@ async function createDevBox() {

const poolList = await client.path("/projects/{projectName}/pools", projectName).get();
if (isUnexpected(poolList)) {
throw new Error(poolList.body.error);
throw poolList.body.error;
}

let pool: PoolOutput = poolList.body.value[0];
Expand Down Expand Up @@ -60,6 +60,9 @@ async function createDevBox() {

const devBoxCreatePoller = await getLongRunningPoller(client, devBoxCreateResponse);
const devBoxCreateResult = await devBoxCreatePoller.pollUntilDone();
if (isUnexpected(devBoxCreateResult)) {
throw devBoxCreateResult.body.error;
}

console.log(`Provisioned dev box with state ${devBoxCreateResult.body.provisioningState}.`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CatalogOutput,
EnvironmentTypeOutput,
EnvironmentDefinitionOutput,
CreateOrUpdateEnvironmentParameters,
getLongRunningPoller,
} from "@azure-rest/developer-devcenter";
import createClient from "@azure-rest/developer-devcenter";
Expand All @@ -22,7 +21,7 @@ async function createEnvironment() {

const projectList = await client.path("/projects").get();
if (isUnexpected(projectList)) {
throw new Error(projectList.body.error.message);
throw projectList.body.error;
}

let project: ProjectOutput = projectList.body.value[0];
Expand All @@ -33,7 +32,7 @@ async function createEnvironment() {

const catalogList = await client.path("/projects/{projectName}/catalogs", projectName).get();
if (isUnexpected(catalogList)) {
throw new Error(catalogList.body.error);
throw catalogList.body.error;
}

const catalog: CatalogOutput = catalogList.body.value[0];
Expand All @@ -48,7 +47,7 @@ async function createEnvironment() {
.get();

if (isUnexpected(environmentDefinitionsList)) {
throw new Error(environmentDefinitionsList.body.error);
throw environmentDefinitionsList.body.error;
}

const environmentDefinition: EnvironmentDefinitionOutput = environmentDefinitionsList.body.value[0];
Expand All @@ -58,15 +57,15 @@ async function createEnvironment() {
.path("/projects/{projectName}/environmentTypes", projectName)
.get();
if (isUnexpected(environmentTypeList)) {
throw new Error(environmentTypeList.body.error.message);
throw environmentTypeList.body.error;
}

let environmentType: EnvironmentTypeOutput = environmentTypeList.body.value[0];
if (environmentType === undefined || environmentType.name === undefined) {
throw new Error("No environment types found.");
}

const environmentsCreateParameters: CreateOrUpdateEnvironmentParameters = {
const environmentsCreateParameters = {
contentType: "application/json",
body: {
environmentDefinitionName: environmentDefinitionName,
Expand All @@ -88,11 +87,14 @@ async function createEnvironment() {
)
.put(environmentsCreateParameters);
if (isUnexpected(environmentCreateResponse)) {
throw new Error(environmentCreateResponse.body.error.message);
throw environmentCreateResponse.body.error;
}

const environmentCreatePoller = await getLongRunningPoller(client, environmentCreateResponse);
const environmentCreateResult = await environmentCreatePoller.pollUntilDone();
if (isUnexpected(environmentCreateResult)) {
throw environmentCreateResult.body.error;
}
console.log(
`Provisioned environment with state ${environmentCreateResult.body.provisioningState}.`
);
Expand All @@ -107,7 +109,7 @@ async function createEnvironment() {
)
.delete();
if (isUnexpected(environmentDeleteResponse)) {
throw new Error(environmentDeleteResponse.body.error.message);
throw environmentDeleteResponse.body.error;
}

const environmentDeletePoller = await getLongRunningPoller(client, environmentDeleteResponse);
Expand Down
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"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
12 changes: 6 additions & 6 deletions sdk/devcenter/developer-devcenter-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": ["./src/**/*.ts", "./src/**/*.mts", "./src/**/*.cts", "test/**/*.ts", "./test/**/*.ts"]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/devcenter/developer-devcenter-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/developer-devcenter": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/devcenter/developer-devcenter-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/devcenter/developer-devcenter-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"]
}
6 changes: 6 additions & 0 deletions sdk/devcenter/developer-devcenter-rest/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
reporters: ["basic", "junit"],
outputFile: {
junit: "test-results.xml",
Expand All @@ -16,6 +21,7 @@ export default defineConfig({
include: ["test/**/*.spec.ts"],
exclude: ["test/**/browser/*.spec.ts"],
testTimeout: 12000000,
hookTimeout: 600000,
coverage: {
include: ["src/**/*.ts"],
exclude: [
Expand Down
11 changes: 11 additions & 0 deletions sdk/devcenter/developer-devcenter-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
);
12 changes: 8 additions & 4 deletions sdk/deviceupdate/iot-device-update-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ 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",
},
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/deviceupdate/iot-device-update-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"generate:client": "autorest --typescript swagger/README.md && npm run format",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"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 Expand Up @@ -115,7 +115,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "dotenv/config";
const endpoint = process.env["ENDPOINT"] || "";
const instanceId = process.env["INSTANCE_ID"] || "";

async function main(): Promsie<void> {
async function main(): Promise<void> {
console.log("== Get device ==");
const groupId = process.env["DEVICEUPDATE_DEVICE_GROUP"] || "";

Expand Down
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/deviceupdate/iot-device-update-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure-rest/iot-device-update": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"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": []
}
Loading

0 comments on commit 137528c

Please sign in to comment.