-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[tsp-client] Add acceptance tests #29811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7d13790
Remove coverage, since no source JS files
mikeharder 2cef63a
Add starter project tsp-client-tests
mikeharder 176490d
Add GH Action
mikeharder ffb9b42
Rename job
mikeharder 4fc3917
Add usage test
mikeharder 1bc8cb7
Increase timeout to 30s
mikeharder 605ac4e
Add test for keyvault/data-plane
mikeharder f89fd21
Update lockfile
mikeharder c895ef7
Verify generated files exist
mikeharder a62d712
Add logs, verify folder deleted
mikeharder dcedf0b
Add test for sphere/resource-manager
mikeharder 6725661
Add sparse-checkout-paths
mikeharder 5a42646
Merge branch 'main' into tsp-client-tests
mikeharder fae4852
Add paths to PR trigger
mikeharder 4fae6f5
Checkout all of spec folder
mikeharder 59df497
Disable sparse checkout
mikeharder 3d4ac77
enable git long paths
mikeharder 206d78c
Only enable longpaths on windows
mikeharder 8c0761b
Revert "Disable sparse checkout"
mikeharder 064339d
Show full output if exit code is nonzero
mikeharder e5e6213
Narrow sparse checkout
mikeharder cb07ea5
Add common-types to sparse checkout
mikeharder 35a1dcc
Increase timeout to 2 minutes
mikeharder 2e3bcfe
Add comment
mikeharder e799cca
Revert disable parallelism in package.json
mikeharder 89781de
Increase timeout to 4 minutes
mikeharder 8f60e52
Add comment
mikeharder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,26 @@ | ||
| 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 |
This file contains hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| 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, { 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, exitCode } = await tspClient( | ||
| "convert", | ||
| "--no-prompt", | ||
| "--swagger-readme", | ||
| readme, | ||
| "-o", | ||
| outputFolder, | ||
| readme.includes("resource-manager") ? "--arm" : "", | ||
| ); | ||
|
|
||
| expect(stdout).toContain("Converting"); | ||
| expect(exitCode).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(); | ||
| } | ||
|
|
||
| test.concurrent("Usage", async ({ expect }) => { | ||
| const { stdout, exitCode } = await tspClient(); | ||
|
|
||
| expect(stdout).toContain("Usage"); | ||
| expect(exitCode).not.toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("Convert keyvault/data-plane", async ({ expect }) => { | ||
| await convert(expect, "specification/keyvault/data-plane/readme.md"); | ||
| }); | ||
|
|
||
| test.concurrent("Convert sphere/resource-manager", async ({ expect }) => { | ||
| await convert(expect, "specification/sphere/resource-manager/readme.md"); | ||
| }); | ||
This file contains hidden or 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 hidden or 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,8 @@ | ||
| import { defineConfig } from "vite"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| // Default timeout of 5 seconds is too low | ||
| testTimeout: 60000, | ||
| }, | ||
| }); |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.