Page MenuHomePhabricator

Integrate Vitest with Personal Dashboard
Closed, ResolvedPublic3 Estimated Story Points

Description

Since we are working on a brand new project, we have the opportunity to explore some newer libraries and frameworks. Vitest is the recommended testing suite by the maintainers of Vue, and there are quite a few benefits we could have from integrating it into our stack.

The long term goal is to make this a project-agnostic library which other teams working on MediaWiki could add as a plugin and write unit tests similar to how Jest is used now.

Acceptance Criteria:

Event Timeline

Dillon changed the task status from Open to In Progress.Oct 30 2025, 5:12 PM
Dillon updated the task description. (Show Details)
Dillon moved this task from In Progress to Eng review on the Moderator-Tools-Team (Kanban) board.

@Dillon can you link to the repository for review? Thanks!

@Dillon can you link to the repository for review? Thanks!

Done!

@Dillon
I've been encountering this error when trying to mount an app that imports components via commonjs:

SyntaxError: Unexpected token '<'
 ❯ Module.default._load node_modules/vitest-plugin-mediawiki/setup.js:22:22
     20|  }
     21| 
     22|  return loadInternal.call( this, request, parent, isMain );
       |                      ^
     23| }

I created this repo to demonstrate the problem with the vue example app
https://gitlab.wikimedia.org/jsn/vitest-plugin-test

The only change I made was moving imports from es6 style to commonjs

okay, looks like we need a little more mocking:

 FAIL  tests/vitest/ext.personalDashboard.riskyArticleEdits/components/ListCard.test.mjs > mount component
TypeError: mw.Message is not a constructor
 ❯ Proxy.getTag resources/ext.personalDashboard.riskyArticleEdits/components/ListCard.vue:103:16
    101|   getTag: function ( tag ) {
    102|    // eslint-disable-next-line mediawiki/msg-doc
    103|    const msg = new mw.Message( mw.messages, `tag-${ tag }` );
       |                ^
    104|    return msg.exists() ? msg.text() : tag;
    105|   }
 ❯ resources/ext.personalDashboard.riskyArticleEdits/components/ListCard.vue:35:23
 ❯ renderFnWithContext node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:692:13
 ❯ renderSlot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3032:53
 ❯ Proxy._sfc_render$h node_modules/@wikimedia/codex/dist/codex.js:7490:11
 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6545:16
 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5345:46
 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:241:19
 ❯ setupRenderEffect node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5480:5
 ❯ mountComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5254:7

@Dillon
I've been encountering this error when trying to mount an app that imports components via commonjs:

SyntaxError: Unexpected token '<'
 ❯ Module.default._load node_modules/vitest-plugin-mediawiki/setup.js:22:22
     20|  }
     21| 
     22|  return loadInternal.call( this, request, parent, isMain );
       |                      ^
     23| }

I created this repo to demonstrate the problem with the vue example app
https://gitlab.wikimedia.org/jsn/vitest-plugin-test

The only change I made was moving imports from es6 style to commonjs

okay, looks like we need a little more mocking:

 FAIL  tests/vitest/ext.personalDashboard.riskyArticleEdits/components/ListCard.test.mjs > mount component
TypeError: mw.Message is not a constructor
 ❯ Proxy.getTag resources/ext.personalDashboard.riskyArticleEdits/components/ListCard.vue:103:16
    101|   getTag: function ( tag ) {
    102|    // eslint-disable-next-line mediawiki/msg-doc
    103|    const msg = new mw.Message( mw.messages, `tag-${ tag }` );
       |                ^
    104|    return msg.exists() ? msg.text() : tag;
    105|   }
 ❯ resources/ext.personalDashboard.riskyArticleEdits/components/ListCard.vue:35:23
 ❯ renderFnWithContext node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:692:13
 ❯ renderSlot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3032:53
 ❯ Proxy._sfc_render$h node_modules/@wikimedia/codex/dist/codex.js:7490:11
 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6545:16
 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5345:46
 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:241:19
 ❯ setupRenderEffect node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5480:5
 ❯ mountComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5254:7

The above CI issues have since been fixed in the Vitest plugin repo. ✅