Hello 👋 I have the following decorator
import { backOff, BackoffOptions } from "exponential-backoff";
/**
* A decorator that allow to rety a function based on the provided options
* @param {IBackOffOptions} options The retrial options
*/
export function reattempt(options: BackoffOptions) {
// eslint-disable-next-line
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor){
// eslint-disable-next-line
const originalFunction = descriptor.value as Function;
// eslint-disable-next-line
descriptor.value = async function(...args: any[]){
return backOff(() => originalFunction(...args), options);
};
};
}
When I decorate a method that makes an API call with it, and try running the test, I get this
Error: C:\Users\AmrouBellalouna\source\repos\ExpensyaWebE2E\PlayWright\src\apiWrappers\transaction\transactionSimulatorClient.ts: Support for the experimental syntax 'decorators' isn't currently enabled (27:2):
Add @babel/plugin-proposal-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators) to the 'plugins' section of your Babel config to enabtion of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators) to the 'plugins' section to enable parsing.
This only happen when I run the test with playwright, meaning if I have a .ts
file with a basic script that uses this decorator, I don't get the error.
experimental decorators are enabled in my tsconfig file
This thread is trying to answer question "Why does an error occur when running a test with playwright that uses a decorator in a method making an API call, and how can this issue be resolved?"
You can try compiling tests yourself https://playwright.dev/docs/next/test-typescript#manually-compile-tests-with-typescript and then running, not sure if it will help
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].