thunderclient / thunder-client-support

Thunder Client is a lightweight Rest API Client Extension for VS Code.
https://www.thunderclient.com
Other
3.64k stars 132 forks source link

Import JS Files not working for me #1607

Closed iAmcDiddy closed 2 months ago

iAmcDiddy commented 2 months ago

Since the use of Custom Scripts is being deprecated (which is unfortunate because we use it extensively) we are trying to migrate the functions from our custom script file to the solution provided here

I have created a simple project (using the RESTful Booker API) to demonstrate what I have tried, I will attach it. Create folder in project 'scripts' and create file there 'booking.js' Add a simple function (called 'validateBookingID') to booking.js that just returns true. In my collection I have a folder where I load booking.js in the "Pre Run, Scripting" tab. (I have tried loading it from other places, but could never get it to work). In that folder I have a working Request and contains 2 Tests. The first test validates the value returned by the function validateBookingID is true.

I expect the Test to Pass, but instead it says "filter is not defined - validateBookingID". Next I loaded booking.js directly through the Scripting tab of the Request's Test tab. Run again and get same (not defined) result.

I have tried on Windows 10 and 11 VSCode version 1.93.1 ThunderClient version 2.25.0

We are using the paid version TC_DeprecatedCustomScripts.zip

rangav commented 2 months ago

With the deprecation of the customer filter, 95% of users have already migrated to inline scripting. Maintaining both formats moving forward will be challenging.

You cannot use the custom filter directly in the Tests tab.

For this use case you have use the post-req scripting tab.

const { validateBookingID } = require("scripts/booking.js");

let json = tc.response.json;

var result = validateBookingID(json);
console.log(result);

tc.test('json validation', function() { 
  expect(result).to.equal(true);
});

Delete the custom filter Test in the Tests tab

Screenshot 2024-09-18 at 21 46 07
iAmcDiddy commented 2 months ago

Thank you for clearing that up. I have verified the functionality in the sample project I will work on my real projects next, I assume the new way supports async functions.

Also, I'm creating another github account (because I don't want to be associated with a criminal). The new name will be 3rdTimeCharm.