Testing plugins from foreman core

TLDR: Deprecating “theforeman/test”, plugin test and lint can be run from core instead.

Following: Do we want to keep foreman-js?

Hi, we are working on improving the front-end development experience.

We are removing Foreman’s usage of “theforeman/test” and using Ruby’s approach where the plugins will be tested from Foreman core.

The command to test plugins from foreman is: npm run test:plugins or npm run test:plugins PLUGIN_NAME

This allows a few improvements,
one less repo to take care of, and also plugins won’t have to mock foreman components, instead the components will be available from foreman.
Katello already uses foreman for tests so a lot of the new approach is inspired by Katellos code.

Plugins can run tests from their directory if they want, by keeping “theforeman/test”, but it won’t be maintained anymore. (foreman-js test deprecation pr)

Or alternatively they can copy Katellos testing code.

to ease the process in ci plugins are encouraged to create a pr with 2 main changes:

  1. Remove the “@theforeman/test” package and replace the imports to foreman

  2. Use the generic github actions

example pr on how to use the generic github actions: use @theforeman/actions for JS tests too by evgeni · Pull Request #964 · theforeman/foreman_remote_execution · GitHub (Thanks Evgeni)

some changes that might be needed in some plugins that I saw are updating snapshots (foreman_webhooks for example) as some plugins didnt need any pf5 updates to their js code, but the snapshots are using pf4 still.

Lint
The new changes include running lint from foreman, in a similar way.

The command to run lint on plugins is: npm run lint:plugins or npm run lint:plugins PLUGIN_NAME

Some plugins are already using the rule that makes sure PF components that support ouia-id are using the prop.

This change will make all plugins use this prop (unless the plugin specifies a lint script in package.json, then that script will run instead), so please add it where the lint complains

There are no hard breaking changes for now, but there will be warning messages after foreman-js test is deprecated.

2 Likes

I like being able to run npx jest <path_to_test_file> in the Katello directory, will there be an equivalent after this change?

like with npm test -- <path> before (in core and some plugins), you can run npm run test:plugins katello -- <path>

1 Like

The tests PR was merged. Please use npm run test:plugins from the core repo from now!

1 Like