Please follow the Prerequisite part to install the dependencies.
- Use the following command to clone the Typescript/Javascript SDK generator repository:
git clone https://github.com/Azure/autorest.typescript.git
- Use the following commands to build the SDK generator:
pnpm install
pnpm build
-
There are also 3 test-suites in the RLC generator:
- Unit tests (which could be found at
test/unit/*) - Integration tests (which could be found at
test/integration/*) - Smoke tests (which could be found at
../../packages/typespec-test)
- Unit tests (which could be found at
-
You can run the Unit tests & Integration tests using the following command:
npm run test
Running the command above will do the following things:
- Start TestServer
- Build TypeSpec TS
- Generate all scenarios in parallel (i.e. Dictionary, Extensible Enums, Models, Resiliency)
- Run all the tests under test/integration
- Stop TestServer
Note: If your development environment is Windows, then run the command npm run start-test-server(in a seperate window) before running npm run test and run the command npm run stop-test-server after. (In non windows machines, we could run the test-server in the background automatically. But, in Windows machines, it has to be done manually.)
- You can run the Smoke tests using the following command:
cd ../../packages/typespec-test
npm run smoke-testWhenever you work on adding a feature/fixing a bug, this would probably be your first step. You create a test case and then run it through the generator, see the result, modify the generator, run it again and so on, until you get the desired output.
-
Pick up a typespec as your test input in cadl-ranch. Below are some examples
Let us say your test input is
authentication/api-key/main.tspin @azure-tools/cadl-ranch-specs. -
Now add an entry to the TypeSpecRanchConfig to the file
cadl-ranch-list.ts. In the file, add the following to the array.{ outputPath: "authentication/apiKey", inputPath: "authentication/api-key" },
-
Create a tspconfig.yaml in
./test/integration/generated/authentication/apiKeyfolder and put the following content in it.emit: - "@azure-tools/typespec-ts" options: "@azure-tools/typespec-ts": emitter-output-dir: "{project-root}" generate-metadata: true generate-test: true include-shortcuts: true azure-sdk-for-js: false add-credentials: false is-typespec-test: true title: AuthApiKeyClient package-details: name: "@msinternal/auth-apikey" description: "Auth api key Test Service" version: "1.0.0"
-
Now, You can generate the RLC for your test case with the following command: (Initially, during your development, you do not want to run all the cases during every step of your development, you can comment out other test cases. But, once your code changes are complete for your case, then you need to run the entire suite to ensure that your changes did not cause any unwanted changes.)
npm run generate-tsp-only
-
Once you are satisfied with the generated code, you can add a spec file such as
testUserCaseRest.spec.tsfile here. You can find several examples in the same place.
If you would like to debug the generate-tsp-only step for our test input, Open the repository in VS Code -> Select Generate code for TypeSpec Emitter section -> Click Attach.
If you would like to debug the testUserCase.spec.ts file (after the SDK is generated), Open the repository in VS Code -> Open the testUserCase.spec.ts file -> Select Run and Debug section -> Click IntegrationTests - Current File.
-
In VS Code, We have created a Debugging profile for UnitTests to start debugging:
- Go to the debugger tab
- Select the "[TypeSpec] - Unit Test" Profile
- Click the "Play" button
-
Your breakpoints will start hitting, you can set breakpoints in either Test or Generator code
-
In order to debug integration tests you need to start the test server, by running:
npm run start-test-server:v1 -
Once the Test Server is running
- In VSCode go to the debugger tab
- Select the "[TypeSpec] - Integration Test" profile from the drop down
- Click the "Play" button
-
**IMPORTANT**: Running Integration Tests for debugging, does not re-generate the test clients so make sure that after each change you do:
-
Re-generate all the test swaggers
npm run generate-tsp-only -- --build -
Re-generate a specific swagger
npm run generate-tsp-only -- -i bodyComplexRest -b
-