forked from Azure/azure-rest-api-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeSpecRequirement] Add tests (Azure#29639)
- Loading branch information
1 parent
5700885
commit 87a08b9
Showing
17 changed files
with
754 additions
and
395 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,23 @@ | ||
name: TypeSpec Requirement - Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- package-lock.json | ||
- package.json | ||
- tsconfig.json | ||
- .github/workflows/_reusable-eng-tools-test.yaml | ||
- .github/workflows/typespec-requirement-test.yaml | ||
- eng/scripts/** | ||
- eng/tools/package.json | ||
- eng/tools/tsconfig.json | ||
- eng/tools/typespec-requirement/** | ||
|
||
jobs: | ||
typespec-requirement: | ||
uses: ./.github/workflows/_reusable-eng-tools-test.yaml | ||
with: | ||
package: typespec-requirement |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@azure-tools/typespec-requirement", | ||
"private": true, | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/node": "^18.19.31", | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"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 --coverage --reporter=verbose" | ||
}, | ||
"engines": { | ||
"node": ">= 18.0.0" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
eng/tools/typespec-requirement/test/specification/empty/placeholder.txt
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 @@ | ||
Test |
2 changes: 2 additions & 0 deletions
2
...itten/resource-manager/Microsoft.HandWritten/preview/2024-01-01-preview/hand-written.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,2 @@ | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
...onfig/resource-manager/Microsoft.NoTspConfig/preview/2024-01-01-preview/no-tspconfig.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,9 @@ | ||
{ | ||
"info": { | ||
"x-typespec-generated": [ | ||
{ | ||
"emitter": "@azure-tools/typespec-autorest" | ||
} | ||
] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...e-error/resource-manager/Microsoft.ParseError/preview/2024-01-01-preview/parse-error.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 @@ | ||
{ |
2 changes: 2 additions & 0 deletions
2
...ession/resource-manager/Microsoft.Suppression/preview/2024-01-01-preview/suppression.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,2 @@ | ||
{ | ||
} |
3 changes: 3 additions & 0 deletions
3
eng/tools/typespec-requirement/test/specification/suppression/suppressions.yaml
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,3 @@ | ||
- tool: TypeSpecRequirement | ||
path: ./resource-manager/Microsoft.Suppression/preview/2024-01-01-preview/*.json | ||
reason: Test |
1 change: 1 addition & 0 deletions
1
...st/specification/typespec-generated/Microsoft.TypeSpecGenerated.Management/tspconfig.yaml
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 @@ | ||
# Test |
9 changes: 9 additions & 0 deletions
9
...erated/resource-manager/Microsoft.TypeSpecGenerated/preview/2024-01-01-preview/valid.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,9 @@ | ||
{ | ||
"info": { | ||
"x-typespec-generated": [ | ||
{ | ||
"emitter": "@azure-tools/typespec-autorest" | ||
} | ||
] | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
eng/tools/typespec-requirement/test/typespec-requirement.test.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,83 @@ | ||
import { execa } from 'execa'; | ||
import { join } from 'path'; | ||
import { test } from 'vitest'; | ||
|
||
async function checkAllUnder(path: string, responseCache?: string) { | ||
const repoRoot = join(__dirname, '..', '..', '..', '..'); | ||
const script = join('eng', 'scripts', 'TypeSpec-Requirement.ps1'); | ||
|
||
let command = `${script} -CheckAllUnder ${join(__dirname, path)}`; | ||
if (responseCache) { | ||
command += ` -_ResponseCache ${responseCache}`; | ||
} | ||
|
||
return await execa("pwsh", ["-Command", command], { cwd: repoRoot, reject: false }); | ||
} | ||
|
||
test.concurrent("No files to check", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder("specification/empty"); | ||
|
||
expect(stdout).toMatchInlineSnapshot(`"No OpenAPI files found to check"`); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
test.concurrent("Suppression", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder("specification/suppression"); | ||
|
||
expect(stdout).toContain("Suppressed"); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
test.concurrent("Parse error", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder("specification/parse-error"); | ||
|
||
expect(stdout).toContain("cannot be parsed as JSON"); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
test.concurrent("No tspconfig.yaml", async ({ expect }) => { | ||
const { stderr, exitCode } = await checkAllUnder("specification/no-tspconfig"); | ||
|
||
expect(stderr).toContain("no files named 'tspconfig.yaml'"); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
test.concurrent("Generated from TypeSpec", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder("specification/typespec-generated"); | ||
|
||
expect(stdout).toContain("was generated from TypeSpec"); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
test.concurrent("Hand-written, exists in main", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder( | ||
"specification/hand-written", | ||
'@{"https://github.com/Azure/azure-rest-api-specs/tree/main/specification/hand-written/resource-manager/Microsoft.HandWritten/stable"=200}' | ||
); | ||
|
||
expect(stdout).toContain("was not generated from TypeSpec"); | ||
expect(stdout).toContain("'main' contains path"); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
test.concurrent("Hand-written, does not exist in main", async ({ expect }) => { | ||
const { stdout, exitCode } = await checkAllUnder( | ||
"specification/hand-written", | ||
'@{"https://github.com/Azure/azure-rest-api-specs/tree/main/specification/hand-written/resource-manager/Microsoft.HandWritten/stable"=404}' | ||
); | ||
|
||
expect(stdout).toContain("was not generated from TypeSpec"); | ||
expect(stdout).toContain("'main' does not contain path"); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
test.concurrent("Hand-written, unexpected response checking main", async ({ expect }) => { | ||
const { stdout, stderr, exitCode } = await checkAllUnder( | ||
"specification/hand-written", | ||
'@{"https://github.com/Azure/azure-rest-api-specs/tree/main/specification/hand-written/resource-manager/Microsoft.HandWritten/stable"=519}' | ||
); | ||
|
||
expect(stdout).toContain("was not generated from TypeSpec"); | ||
expect(stderr).toContain("Unexpected response"); | ||
expect(exitCode).toBe(1); | ||
}); |
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,8 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
// Default timeout of 5 seconds is too low | ||
testTimeout: 20000 | ||
} | ||
}) |
Oops, something went wrong.