-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tsp-client] Add acceptance tests (#29811)
- Loading branch information
1 parent
1aa9126
commit ac1f4e8
Showing
9 changed files
with
164 additions
and
4 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
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,28 @@ | ||
name: tsp-client - Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- package-lock.json | ||
- package.json | ||
- tsconfig.json | ||
- .github/workflows/_reusable-eng-tools-test.yaml | ||
- .github/workflows/tsp-client-test.yaml | ||
- eng/tools/package.json | ||
- eng/tools/tsconfig.json | ||
- eng/tools/tsp-client/** | ||
- specification/keyvault | ||
- specification/sphere | ||
|
||
jobs: | ||
tsp-client: | ||
uses: ./.github/workflows/_reusable-eng-tools-test.yaml | ||
with: | ||
package: tsp-client-tests | ||
sparse-checkout-paths: | | ||
specification/common-types | ||
specification/keyvault | ||
specification/sphere |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@azure-tools/tsp-client-tests", | ||
"private": true, | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/node": "^18.19.31", | ||
"execa": "^9.3.0", | ||
"typescript": "~5.4.5", | ||
"vitest": "^1.6.0" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"postinstall": "npm run build", | ||
"test": "vitest", | ||
"test:ci": "vitest run --reporter=verbose" | ||
}, | ||
"engines": { | ||
"node": ">= 18.0.0" | ||
} | ||
} |
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,72 @@ | ||
import { execa } from "execa"; | ||
import { access, constants, mkdir, rm } from "fs/promises"; | ||
import { dirname, join } from "path"; | ||
import { ExpectStatic, test } from "vitest"; | ||
|
||
const repoRoot = join(__dirname, "..", "..", "..", ".."); | ||
|
||
async function tspClient(...args: string[]) { | ||
const allArgs = ["exec", "--no", "--", "tsp-client"].concat(args); | ||
|
||
console.log(`${repoRoot}$ npm ${allArgs.join(" ")}`); | ||
|
||
return await execa("npm", allArgs, { all: true, cwd: repoRoot, reject: false }); | ||
} | ||
|
||
async function convert(expect: ExpectStatic, readme: string) { | ||
const specFolder = dirname(dirname(join(repoRoot, readme))); | ||
const outputFolder = join(specFolder, "Test.TspClientConvert"); | ||
|
||
try { | ||
await mkdir(outputFolder); | ||
} catch { | ||
// Delete and retry | ||
await rm(outputFolder, { recursive: true, force: true }); | ||
await mkdir(outputFolder); | ||
} | ||
|
||
try { | ||
const { stdout, all, exitCode } = await tspClient( | ||
"convert", | ||
"--no-prompt", | ||
"--swagger-readme", | ||
readme, | ||
"-o", | ||
outputFolder, | ||
readme.includes("resource-manager") ? "--arm" : "", | ||
); | ||
|
||
expect(stdout).toContain("Converting"); | ||
expect(exitCode, all).toBe(0); | ||
|
||
const tspConfigYaml = join(outputFolder, "tspconfig.yaml"); | ||
await access(tspConfigYaml, constants.R_OK); | ||
console.log(`File exists: ${tspConfigYaml}`); | ||
|
||
const mainTsp = join(outputFolder, "main.tsp"); | ||
await access(mainTsp, constants.R_OK); | ||
console.log(`File exists: ${mainTsp}`); | ||
} finally { | ||
await rm(outputFolder, { recursive: true, force: true }); | ||
} | ||
|
||
// Ensure outputFolder is deleted | ||
expect(() => access(outputFolder)).rejects.toThrowError(); | ||
} | ||
|
||
// TODO: Convert to `test.concurrent()` once Azure/azure-sdk-tools#8610 is merged, | ||
// which should fix race condition bug calling `npx autorest`. | ||
test("Usage", async ({ expect }) => { | ||
const { stdout, exitCode } = await tspClient(); | ||
|
||
expect(stdout).toContain("Usage"); | ||
expect(exitCode).not.toBe(0); | ||
}); | ||
|
||
test("Convert keyvault/data-plane", async ({ expect }) => { | ||
await convert(expect, "specification/keyvault/data-plane/readme.md"); | ||
}); | ||
|
||
test("Convert sphere/resource-manager", async ({ expect }) => { | ||
await convert(expect, "specification/sphere/resource-manager/readme.md"); | ||
}); |
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,6 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
} | ||
} |
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 @@ | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
testTimeout: 240000, | ||
}, | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.