Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
@openverse/k6
This is an internal, non-distributable package.
This package houses Openverse's k6 scripts.
Refer to k6 documentation to learn more about the tool and its capabilities.
To run k6 scripts, use the just recipe:
ov run {namespace} {scenario} [EXTRA_ARGS]
For example, to run all frontend scenarios:
ov run frontend all
When developing and testing changes, it's recommended to run k6 scripts only against your local services. For this reason, the scripts default to using localhost URLs for the service in test.
To prevent your local frontend from experiencing throttling, run it alongside talkback. Start and leave talkback running in one terminal like so:
ov just p frontend talkback
And in another terminal, build and run the frontend, with the API URL option pointed at the talkback instance:
ov just p frontend build && ov env NUXT_PUBLIC_API_URL=http://localhost:49153/ just p frontend start
Development tips and guidelines
- Code is written in TypeScript. k6's
jslibpackages do not have TypeScript definitions, so you must@ts-expect-errorthose. Rollup processes the TypeScript, and then we execute the transpiled code with k6. - Follow typical Openverse JavaScript code style and development procedures, but
keep in mind k6's special requirements, and the fact that
it doesn't have a "normal" JavaScript execution environment.
- An important example of these special requirements are that k6 depends on
the scenario functions being exported from the executed test script. This
is why the frontend
.test.tsfiles allexport * from "./scenarios", otherwise the functions referenced by name in the generated scenarios would not be available for execution by k6 from the test file.
- An important example of these special requirements are that k6 depends on
the scenario functions being exported from the executed test script. This
is why the frontend
- Test suites should be placed in namespaced directories, and then named in the
pattern
{scenario}.test.ts. This format is mandatory for build and execution scripts to function as intended. For example,src/frontend/search-en.test.tshas thefrontendnamespace andsearch-enis the scenario name. "Scenario name" may also refer to a group of scenarios, as it does in the case ofsrc/frontend/all.test.ts, which executes all frontend scenarios. - Use
k6
-eto pass environment variables that test code relies on to create flexible tests. For example, use this method to write tests that can target any hostname where the target service might be hosted.