-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TCGC broken with latest compiler and add e2e tests (#818)
fix #817 --------- Co-authored-by: iscai-msft <[email protected]> Co-authored-by: Timothee Guerin <[email protected]> Co-authored-by: Timothee Guerin <[email protected]>
- Loading branch information
1 parent
e7ff7d8
commit 4af68a2
Showing
10 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: fix | ||
packages: | ||
- "@azure-tools/typespec-client-generator-core" | ||
--- | ||
|
||
Fix: Crash due to using api from next version of the compiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ jobs: | |
displayName: Cadl Ranch e2e tests | ||
|
||
- script: pnpm test:e2e | ||
displayName: UI Tests | ||
displayName: E2E Tests |
4 changes: 4 additions & 0 deletions
4
packages/typespec-client-generator-core/e2e/basic-latest/main.tsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import "@typespec/rest"; | ||
import "@azure-tools/typespec-client-generator-core"; | ||
|
||
op ping(): void; |
15 changes: 15 additions & 0 deletions
15
packages/typespec-client-generator-core/e2e/basic-latest/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@azure-tools/tcgc-test-basic-latest", | ||
"dependencies": { | ||
"@typespec/compiler": "latest", | ||
"@typespec/rest": "latest", | ||
"@typespec/http": "latest", | ||
"@typespec/versioning": "latest", | ||
"@typespec/openapi": "latest", | ||
"@typespec/openapi3": "latest", | ||
"@azure-tools/typespec-azure-core": "latest", | ||
"@azure-tools/typespec-autorest": "latest", | ||
"@azure-tools/typespec-azure-resource-manager": "latest" | ||
}, | ||
"private": true | ||
} |
84 changes: 84 additions & 0 deletions
84
packages/typespec-client-generator-core/e2e/check-latest.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { findTestPackageRoot } from "@typespec/compiler/testing"; | ||
import { SpawnOptions, spawn } from "child_process"; | ||
import { cp, readdir, rm } from "fs/promises"; | ||
import { join, resolve } from "path"; | ||
import { beforeAll, it } from "vitest"; | ||
|
||
const packageRoot = await findTestPackageRoot(import.meta.url); | ||
const tempDir = join(packageRoot, "temp/e2e"); | ||
|
||
let tgzFile: string; | ||
beforeAll(async () => { | ||
await rm(tempDir, { recursive: true, force: true }); | ||
|
||
await execSuccessAsync("pnpm", ["pack", "--pack-destination", tempDir]); | ||
const files = await readdir(tempDir); | ||
|
||
const filename = files.find((x) => x.startsWith("azure-tools-typespec-client-generator-core-")); | ||
if (filename === undefined) { | ||
throw new Error( | ||
`Cannot resolve package starting with "azure-tools-typespec-client-generator-core-"` | ||
); | ||
} | ||
tgzFile = join(tempDir, filename); | ||
}); | ||
|
||
// Make sure it works with the latest version of dependencies and not just the local build. | ||
it("works with latest version of packages", async () => { | ||
const dir = await setupScenario("basic-latest"); | ||
await execSuccessAsync("npm", ["install", tgzFile], { cwd: dir }); | ||
await execSuccessAsync("npx", ["tsp", "compile", "."], { cwd: dir }); | ||
}); | ||
|
||
async function setupScenario(name: string): Promise<string> { | ||
const target = resolve(tempDir, name); | ||
await cp(resolve(packageRoot, "e2e", name), target, { | ||
recursive: true, | ||
}); | ||
return target; | ||
} | ||
|
||
async function execSuccessAsync(command: string, args: string[] = [], options: SpawnOptions = {}) { | ||
const result = await execAsync(command, args, options); | ||
if (result.exitCode !== 0) { | ||
throw new Error( | ||
`Command '${command} ${args.join(" ")}' failed with exit code ${result.exitCode}\n` + | ||
result.stdio | ||
); | ||
} | ||
return result; | ||
} | ||
async function execAsync( | ||
command: string, | ||
args: string[] = [], | ||
options: SpawnOptions = {} | ||
): Promise<{ exitCode: number; stdio: string; stdout: string; stderr: string; proc: any }> { | ||
const child = spawn(command, args, options); | ||
|
||
return new Promise((resolve, reject) => { | ||
child.on("error", (error) => { | ||
reject(error); | ||
}); | ||
const stdio: Buffer[] = []; | ||
const stdout: Buffer[] = []; | ||
const stderr: Buffer[] = []; | ||
child.stdout?.on("data", (data) => { | ||
stdout.push(data); | ||
stdio.push(data); | ||
}); | ||
child.stderr?.on("data", (data) => { | ||
stderr.push(data); | ||
stdio.push(data); | ||
}); | ||
|
||
child.on("exit", (exitCode) => { | ||
resolve({ | ||
exitCode: exitCode ?? -1, | ||
stdio: Buffer.concat(stdio).toString(), | ||
stdout: Buffer.concat(stdout).toString(), | ||
stderr: Buffer.concat(stderr).toString(), | ||
proc: child, | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/typespec-client-generator-core/vitest.config.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
environment: "node", | ||
testTimeout: 60_000, | ||
isolate: false, | ||
coverage: { | ||
reporter: ["cobertura", "json", "text"], | ||
}, | ||
outputFile: { | ||
junit: "./test-results.xml", | ||
}, | ||
|
||
include: ["e2e/**/*.e2e.ts"], | ||
}, | ||
}); |