Page MenuHomePhabricator

Setup a unit test environment in the frontend docs
Closed, ResolvedPublic

Description

The current setup in the docs/frontend vitepress site uses Vue SFC and es6. It would be nice to setup jest to test those components as it's already done with the rest of components in the extension.

Since the setup in the documentation project uses Codex's ES build instead of CommonJS modules it might be worth trying out vitest which simplifies the setup boilerplate for a Vite project to be tested. See also T305515: Consider migrating from Jest to Vitest

Event Timeline

Sgs renamed this task from Setup jest in the frontend documentation to Setup jest in the frontend docs.Feb 7 2023, 11:33 AM
Sgs created this task.

Change 892517 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] WIP setup jest for testing documentation/frontend

https://gerrit.wikimedia.org/r/892517

Sgs renamed this task from Setup jest in the frontend docs to Setup a unit test evironement in the frontend docs.Mar 13 2023, 9:53 AM
Sgs changed the task status from Open to In Progress.
Sgs moved this task from Triaged to Sprint 0 (Growth Team) on the Growth-Team board.
Sgs edited projects, added Growth-Team (Sprint 0 (Growth Team)); removed Growth-Team.
Sgs moved this task from Incoming to In Progress on the Growth-Team (Sprint 0 (Growth Team)) board.

Change 897825 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: setup vitest

https://gerrit.wikimedia.org/r/897825

Sgs renamed this task from Setup a unit test evironement in the frontend docs to Setup a unit test environment in the frontend docs.Mar 13 2023, 11:13 AM

Change 898853 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: break vitest suite on console errors and warns

https://gerrit.wikimedia.org/r/898853

Change 898854 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: test a component that uses a Codex component

https://gerrit.wikimedia.org/r/898854

Change 892517 abandoned by Sergio Gimeno:

[mediawiki/extensions/GrowthExperiments@master] WIP setup jest for testing documentation/frontend

Reason:

https://gerrit.wikimedia.org/r/892517

It seems that tests of components which use Codex components trigger two warnings ( see build without errors and build with errors ):

[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: Invalid VNode type: Symbol(Text) (symbol)
  at <DummyComponent ref="VTU_COMPONENT" >
  at <VTUROOT>

It would be nice to resolve these or at least know where they are coming from before writing unit tests for the prototype components since most of them will use Codex. Do you remember having clean these warns on our jest suite? cc @kostajh

It seems that tests of components which use Codex components trigger two warnings ( see build without errors and build with errors ):

[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: Invalid VNode type: Symbol(Text) (symbol)
  at <DummyComponent ref="VTU_COMPONENT" >
  at <VTUROOT>

It would be nice to resolve these or at least know where they are coming from before writing unit tests for the prototype components since most of them will use Codex. Do you remember having clean these warns on our jest suite? cc @kostajh

No, I don't remember seeing those before.

Change 897825 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: setup vitest

https://gerrit.wikimedia.org/r/897825

Change 898853 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: break vitest suite on console errors and warns

https://gerrit.wikimedia.org/r/898853

Change 901121 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: fix stylelint config to lint the demo components

https://gerrit.wikimedia.org/r/901121

Change 901121 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: fix stylelint config to lint the demo components

https://gerrit.wikimedia.org/r/901121

It seems that tests of components which use Codex components trigger two warnings ( see build without errors and build with errors ):

[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: Invalid VNode type: Symbol(Text) (symbol)
  at <DummyComponent ref="VTU_COMPONENT" >
  at <VTUROOT>

It would be nice to resolve these or at least know where they are coming from before writing unit tests for the prototype components since most of them will use Codex. Do you remember having clean these warns on our jest suite? cc @kostajh

The reason for the errors was missing dependencies that also depend on vue. When importing a module directly from a NodeJS environement, it walks directories up the tree to look for the closest node_modules folder if a dependency is not satisfied in the local directory. This was causing the missing dependencies to be resolved by the parent node_modules including the parent node_modules/@vue module instead of the documentation/frontend/node_modules/@vue. Should be fixed in 898854 PS5.

It seems that tests of components which use Codex components trigger two warnings ( see build without errors and build with errors ):

[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: Invalid VNode type: Symbol(Text) (symbol)
  at <DummyComponent ref="VTU_COMPONENT" >
  at <VTUROOT>

It would be nice to resolve these or at least know where they are coming from before writing unit tests for the prototype components since most of them will use Codex. Do you remember having clean these warns on our jest suite? cc @kostajh

The reason for the errors was missing dependencies that also depend on vue. When importing a module directly from a NodeJS environement, it walks directories up the tree to look for the closest node_modules folder if a dependency is not satisfied in the local directory. This was causing the missing dependencies to be resolved by the parent node_modules including the parent node_modules/@vue module instead of the documentation/frontend/node_modules/@vue. Should be fixed in 898854 PS5.

Nice, thanks for tracking that down.

Change 898854 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: test a component that uses a Codex component

https://gerrit.wikimedia.org/r/898854

Change 904205 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] Frontend documentation: use es2020 in test files

https://gerrit.wikimedia.org/r/904205