Global handleSummary


I have many test files and I want to define a global handleSummary function to avoid duplicate code.

As far as I know, there’s no build-in way.

Any ideas?

Thanks in advance!

Hello @mohamadkh75,

Welcome to the forum :tada:

I am not sure if I fully get what you’re looking for, but I’d suggest trying to do something like:

// file: shared/handleSummary.js
export function handleSummary() {
	console.log("Here's your shared 'handleSummary'")

// file: script1.js
export {handleSummary} from './shared/handleSummary.js'

export default function () {
	console.log("Here's one of your scripts")

// file: script2.js
export {handleSummary} from './shared/handleSummary.js'

export default function () {
	console.log("Here's another of your scripts")

So, by following that example, you only have a single definition of your handleSummary function, that will be used/defined for both test scripts.

I just tested this example, and it works as expected. Have you tested something like this? Have you encountered any issue with that approach? Does it cover what you’re looking for?

I hope that helps!

Thanks! :bowing_man:

1 Like

Hey @joanlopez

It would be better if there were a built-in global way to set it once (and avoid the export too) but for now, it works!


Hey @mohamadkh75,

Do you mean something like a configuration option that let you point to where the handleSummary function is defined at?

If so, feel free to open a feature request issue in the GitHub repository, with all the details, and the team will evaluate whether worth the effort or not.

Also, this way other people can express their interest on such feature by adding their :+1:


1 Like