Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
92 changes: 41 additions & 51 deletions tools/tsp-client/test/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { doesFileExist } from "../src/network.js";
import { TspLocation } from "../src/typespec.js";
import { writeTspLocationYaml } from "../src/utils.js";
import { dirname, resolve } from "node:path";
import { afterEach } from "node:test";

describe.sequential("Verify commands", () => {
let repoRoot: string;
Expand All @@ -30,6 +31,10 @@ describe.sequential("Verify commands", () => {
await mkdir(joinPaths(cwd(), "test/examples/initGlobalConfigNoMatch/"), { recursive: true });
});

afterEach(async () => {
await rm(resolve(joinPaths(repoRoot, "/sdk/contosowidgetmanager")), { recursive: true });
});

afterAll(async () => {
await rm(joinPaths(repoRoot, "eng", "emitter-package.json"));

Expand All @@ -39,14 +44,13 @@ describe.sequential("Verify commands", () => {
await rm(emitterPackageLock);
}

await rm("./test/examples/sdk/local-spec-sdk/TempTypeSpecFiles/", { recursive: true });
await rm("./test/examples/initGlobalConfig/", { recursive: true });
await rm("./test/examples/initGlobalConfigNoMatch/", { recursive: true });
await rm(
"./test/examples/sdk/contosowidgetmanager/contosowidgetmanager-rest/TempTypeSpecFiles/",
{ recursive: true },
);
await rm("./test/examples/sdk/local-spec-sdk/TempTypeSpecFiles/", { recursive: true });
await rm("./test/examples/initGlobalConfig/", { recursive: true });
await rm("./test/examples/initGlobalConfigNoMatch/", { recursive: true });
await rm(joinPaths(repoRoot, "sdk/contosowidgetmanager"), { recursive: true });
});

it("Generate lock file", async () => {
Expand Down Expand Up @@ -100,38 +104,30 @@ describe.sequential("Verify commands", () => {
assert.isTrue(dir.isDirectory());
});

it("Sync example sdk with local spec", async () => {
it("Sync and generate example sdk with local spec", async () => {
const args = {
"output-dir": joinPaths(cwd(), "./test/examples/sdk/local-spec-sdk"),
"local-spec-repo": "./test/examples/specification/contosowidgetmanager/Contoso.WidgetManager",
"save-inputs": true,
};
try {
const args = {
"output-dir": joinPaths(cwd(), "./test/examples/sdk/local-spec-sdk"),
"local-spec-repo":
"./test/examples/specification/contosowidgetmanager/Contoso.WidgetManager",
};
await syncCommand(args);
} catch (error) {
assert.fail(`Failed to sync files. Error: ${error}`);
}
const dir = await stat("./test/examples/sdk/local-spec-sdk/TempTypeSpecFiles/");
assert.isTrue(dir.isDirectory());
});

it("Generate example sdk", async () => {
assert.isTrue(
(await stat("./test/examples/sdk/local-spec-sdk/TempTypeSpecFiles/")).isDirectory(),
);
try {
const args = {
"output-dir": joinPaths(
cwd(),
"./test/examples/sdk/contosowidgetmanager/contosowidgetmanager-rest",
),
"save-inputs": true,
};
await generateCommand(args);
} catch (error) {
assert.fail(`Failed to generate. Error: ${error}`);
}
const dir = await stat(
"./test/examples/sdk/contosowidgetmanager/contosowidgetmanager-rest/tsp-location.yaml",
assert.isTrue(
(
await stat(joinPaths(repoRoot, "sdk/contosowidgetmanager/contosowidgetmanager-rest/"))
).isDirectory(),
);
assert.isTrue(dir.isFile());
});

it("Generate with alternate entrypoint", async () => {
Expand Down Expand Up @@ -159,10 +155,10 @@ describe.sequential("Verify commands", () => {
"save-inputs": true,
};
await updateCommand(args);
assert.isDefined(
await stat(
"./test/examples/sdk/contosowidgetmanager/contosowidgetmanager-rest/tsp-location.yaml",
),
assert.isTrue(
(
await stat(joinPaths(repoRoot, "sdk/contosowidgetmanager/contoso-widgetmanager/"))
).isDirectory(),
);

// Explicitly assert that we're not appending the current directory to the output path which would happen
Expand Down Expand Up @@ -348,7 +344,7 @@ describe.sequential("Verify commands", () => {
}
});

it("Init with legacy package path resolution", async () => {
it.skip("Init with legacy package path resolution", async () => {
try {
const args = {
"output-dir": joinPaths(cwd(), "./test/examples/init/"),
Expand Down Expand Up @@ -382,7 +378,7 @@ describe.sequential("Verify commands", () => {
}
});

it("Init with --update-if-exists", async () => {
it.skip("Init with --update-if-exists", async () => {
try {
const libraryPath = joinPaths(repoRoot, "sdk/contosowidgetmanager/contosowidgetmanager-rest");
const args = {
Expand Down Expand Up @@ -473,7 +469,7 @@ describe.sequential("Verify commands", () => {
}
});

it("Init with --update-if-exists with undefined emitterPackageJsonPath in tsp-location.yaml", async () => {
it.skip("Init with --update-if-exists with undefined emitterPackageJsonPath in tsp-location.yaml", async () => {
try {
const libraryPath = joinPaths(repoRoot, "sdk/contosowidgetmanager/contosowidgetmanager-rest");
const args = {
Expand Down Expand Up @@ -583,14 +579,13 @@ describe.sequential("Verify commands", () => {
const args = {
"package-json": joinPaths(cwd(), "test", "examples", "package.json"),
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package.json")));
const emitterJson = JSON.parse(
await readFile(joinPaths(repoRoot, "eng", "emitter-package.json"), "utf8"),
);
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");
assert.isUndefined(emitterJson["overrides"]);
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package-lock.json")));
} catch (error: any) {
Expand All @@ -613,12 +608,11 @@ describe.sequential("Verify commands", () => {
"package-json": joinPaths(cwd(), "test", "examples", "package.json"),
"emitter-package-json-path": packageJsonPath,
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
assert.isTrue(await doesFileExist(packageJsonPath));
const emitterJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");
assert.isUndefined(emitterJson["overrides"]);
assert.isTrue(
await doesFileExist(
Expand All @@ -640,11 +634,10 @@ describe.sequential("Verify commands", () => {
"package-json": joinPaths(cwd(), "test", "examples", "package.json"),
"emitter-package-json-path": emitterPackageJsonPath,
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
const emitterJson = JSON.parse(await readFile(emitterPackageJsonPath, "utf8"));
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");
//Check that the manual dependency version remains unchanged
assert.equal(emitterJson["devDependencies"]["vitest"], "3.1.0");
assert.isUndefined(emitterJson["overrides"]);
Expand All @@ -670,11 +663,10 @@ describe.sequential("Verify commands", () => {
"package-json": joinPaths(cwd(), "test", "examples", "package.json"),
"emitter-package-json-path": emitterPackageJsonPath,
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
const emitterJson = JSON.parse(await readFile(emitterPackageJsonPath, "utf8"));
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");
//Check that the manual regular dependency version remains unchanged
assert.equal(emitterJson["dependencies"]["lodash"], "4.17.21");
//Check that the manual dev dependency version remains unchanged
Expand All @@ -698,13 +690,12 @@ describe.sequential("Verify commands", () => {
"package-json": joinPaths(cwd(), "test", "examples", "package.json"),
overrides: joinPaths(cwd(), "test", "examples", "overrides.json"),
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package.json")));
const emitterJson = JSON.parse(
await readFile(joinPaths(repoRoot, "eng", "emitter-package.json"), "utf8"),
);
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.exists(emitterJson["overrides"]);
assert.equal(emitterJson["overrides"]["prettier"], "3.5.3");
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package-lock.json")));
Expand All @@ -718,15 +709,14 @@ describe.sequential("Verify commands", () => {
const args = {
"package-json": joinPaths(cwd(), "test", "examples", "package-sdk-pinning.json"),
};
repoRoot = await getRepoRoot(cwd());
await generateConfigFilesCommand(args);
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package.json")));
const emitterJson = JSON.parse(
await readFile(joinPaths(repoRoot, "eng", "emitter-package.json"), "utf8"),
);
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(Object.keys(emitterJson["devDependencies"]).length, 2);
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");
assert.isTrue(await doesFileExist(joinPaths(repoRoot, "eng", "emitter-package-lock.json")));
} catch (error: any) {
assert.fail("Failed to generate tsp-client config files. Error: " + error);
Expand All @@ -752,8 +742,8 @@ describe.sequential("Verify commands", () => {
const emitterJson = JSON.parse(await readFile(emitterPackageJsonPath, "utf8"));

// Check that dependencies and devDependencies are updated
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.38.4");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "~0.67.0");
assert.equal(emitterJson["dependencies"]["@azure-tools/typespec-ts"], "0.46.1");
assert.equal(emitterJson["devDependencies"]["@typespec/compiler"], "^1.6.0");

// Check that all other fields are preserved
assert.equal(emitterJson["name"], "test-emitter");
Expand Down
52 changes: 27 additions & 25 deletions tools/tsp-client/test/examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-ts",
"version": "0.38.4",
"version": "0.46.1",
"description": "tsp-client testing",
"main": "dist/src/index.js",
"type": "module",
Expand All @@ -18,14 +18,15 @@
"license": "MIT",
"devDependencies": {
"@azure-rest/core-client": "^2.3.1",
"@typespec/http-specs": "0.1.0-alpha.11",
"@typespec/spector": "0.1.0-alpha.8",
"@typespec/spec-api": "0.1.0-alpha.1",
"@azure-tools/azure-http-specs": "0.1.0-alpha.7",
"@azure-tools/typespec-autorest": "0.53.0",
"@azure-tools/typespec-azure-core": "0.53.0",
"@azure-tools/typespec-azure-resource-manager": "0.53.0",
"@azure-tools/typespec-client-generator-core": "0.53.0",
"@typespec/http-specs": "0.1.0-alpha.29-dev.2",
"@typespec/spector": "0.1.0-alpha.21-dev.1",
"@typespec/spec-api": "0.1.0-alpha.11-dev.0",
"@typespec/tspd": "0.73.1",
"@azure-tools/azure-http-specs": "0.1.0-alpha.33-dev.0",
"@azure-tools/typespec-autorest": "^0.62.0",
"@azure-tools/typespec-azure-core": "^0.62.0",
"@azure-tools/typespec-azure-resource-manager": "^0.62.0",
"@azure-tools/typespec-client-generator-core": "^0.62.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.6.0",
"@azure/core-lro": "^3.1.0",
Expand All @@ -38,14 +39,14 @@
"@types/lodash": "^4.17.4",
"@types/mocha": "^10.0.6",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@typespec/compiler": "~0.67.0",
"@typespec/http": "~0.67.0",
"@typespec/openapi": "~0.67.0",
"@typespec/rest": "~0.67.0",
"@typespec/ts-http-runtime": "0.1.0",
"@typespec/versioning": "~0.67.0",
"@typescript-eslint/eslint-plugin": "^8.28.0",
"@typescript-eslint/parser": "^8.28.0",
"@typespec/compiler": "^1.6.0",
"@typespec/http": "^1.6.0",
"@typespec/openapi": "^1.6.0",
"@typespec/rest": "^0.76.0",
"@typespec/ts-http-runtime": "^0.1.0",
"@typespec/versioning": "^0.76.0",
"chai": "^4.3.6",
"chalk": "^4.0.0",
"cross-env": "^7.0.3",
Expand All @@ -57,7 +58,8 @@
"prettier": "^3.3.3",
"rimraf": "^5.0.0",
"ts-node": "~10.9.1",
"typescript": "~5.7.2",
"typescript": "~5.8.2",
"vitest": "~1.6.0",
"@vitest/coverage-v8": "~1.6.0",
"@vitest/coverage-istanbul": "~1.6.0",
"@microsoft/api-extractor": "^7.47.5",
Expand All @@ -66,15 +68,15 @@
"js-yaml": "^4.1.0"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.52.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.52.0 <1.0.0",
"@typespec/compiler": ">=0.66.0 <1.0.0",
"@typespec/http": ">=0.66.0 <1.0.0",
"@typespec/rest": ">=0.66.0 <1.0.0",
"@typespec/versioning": ">=0.66.0 <1.0.0"
"@azure-tools/typespec-azure-core": "^0.62.0",
"@azure-tools/typespec-client-generator-core": "^0.62.0",
"@typespec/compiler": "^1.6.0",
"@typespec/http": "^1.6.0",
"@typespec/rest": "^0.76.0",
"@typespec/versioning": "^0.76.0",
"@typespec/xml": "^0.76.0"
},
"dependencies": {
"@azure-tools/rlc-common": "workspace:^0.38.4",
"fs-extra": "^11.1.0",
"lodash": "^4.17.21",
"prettier": "^3.3.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
directory: specification/contosowidgetmanager/Contoso.WidgetManager
commit: 45924e49834c4e01c0713e6b7ca21f94be17e396
commit: d007b3b3344fedd4f0c5f9c60fd660f9df4f39b2
repo: Azure/azure-rest-api-specs
additionalDirectories:
- specification/contosowidgetmanager/Contoso.WidgetManager.Shared
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ namespace Azure.Contoso.WidgetManager;
@doc("Versions info.")
enum Versions {
@doc("The 2022-11-01-preview version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_11_01_Preview: "2022-11-01-preview",

@doc("The 2022-12-01 version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_12_01: "2022-12-01",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ namespace Azure.Contoso.WidgetManager;
@doc("Versions info.")
enum Versions {
@doc("The 2022-11-01-preview version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_11_01_Preview: "2022-11-01-preview",

@doc("The 2022-12-01 version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_12_01: "2022-12-01",
}

Expand Down
Loading
Loading