-
Notifications
You must be signed in to change notification settings - Fork 137
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
Request for mjs support for scripting #1508
Comments
One more question about this topic. Where I can find test's results? I saw them only in console, but this one doesn't look right? Test was broken and better to see that after every request. |
|
const z = await tc.loadModule('zod');
const schema = z.object({
id: z.string().nullable(),
});
const result = schema.strict().safeParse(tc.response.json.data);
expect(result.success).to.equal(true);
|
{
"type": "object",
"additionalProperties": false,
"properties": {
"fraction": {
"type": "number"
},
"balance": {
"type": "number"
},
"bignumber": {
"type": "integer"
},
"isNumber": {
"type": "null"
}
},
"required": [
"balance",
"bignumber",
"fraction",
"isNumber"
],
"title": "Welcome4"
} |
So I have file const z = require('zod');
console.log({ z });
const deliveryAddressesCitySchema = z.object({
id: z.string().nullable(),
});
module.exports = {
deliveryAddressesCitySchema,
}; In console I got
In test I have const { deliveryAddressesCitySchema } = require('./app/test-schema.js');
tc.test("Doesn't match schema", function () {
const result = deliveryAddressesCitySchema.strict().safeParse(tc.response.json.data);
expect(result.success).to.equal(true);
}) |
You need to import third party node modules using below syntax
See docs here |
Please read the full scripting docs carefully to avoid issues |
@rangav but in this case I will be unable to use that files across the project. I want to have the same schemas for using in code and for tests in TC |
You can use those files across the project Please share code what is the issue? |
How I can use that across the project If I replace That validation schemas should be used in JS runtime. |
The code will be executed at runtime and please test and then let us know if any issues. |
You don't understand. How my typescript environment will find your local |
Typescript is not supported, you have to create javascript files and import them into TC scripts See docs here |
Goal — have same validation rules for backend and for frontend.
I tried to use Zod schemas for response validation and I can't because I can't import
.ts
or.mjs
or.js (with import inside)
files. I'm trying to achieve DRY and have automatic test for the API.Tests / Scripting
As an alternative I can create schemas in openAPI format and convert it to zod schema automatically and at the same time use them as argument for test.
![image](https://private-user-images.githubusercontent.com/1213198/315525389-af2218e9-caa8-466c-8d91-0adef78aa3aa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NzMwOTUsIm5iZiI6MTczOTU3Mjc5NSwicGF0aCI6Ii8xMjEzMTk4LzMxNTUyNTM4OS1hZjIyMThlOS1jYWE4LTQ2NmMtOGQ5MS0wYWRlZjc4YWEzYWEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMjIzOTU1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmFjNDZhNjUzNWE0Y2YzNzAwNzVhMWY1OTQ0MzkxNWY4NzU1YmRlZjk0ODFiYzFhNTBiOTBjZGJiMzlhNTZkYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.pDw_Fm5OAhTmaQEh-bP2ZAXROqyfx_tQo39aHVrKx8g)
May I ask you to suggest another possible solutions?
Paid version
The text was updated successfully, but these errors were encountered: