A Vue CLI plugin that adds Jest unit testing capabilities to Vue.js projects, providing seamless integration with the Vue CLI service through the 'test:unit' command.
—
The UI integration capability provides Vue CLI UI integration that offers a graphical interface for running tests with interactive configuration options.
Registers the test:unit task with Vue CLI UI for graphical test management.
/**
* Vue CLI UI plugin function that describes the test:unit task
* @param api - UI Plugin API for task registration
*/
function uiPlugin(api: UIPluginAPI): void;Usage Example:
// ui.js
module.exports = api => {
api.describeTask({
match: /vue-cli-service test:unit/,
description: 'org.vue.jest.tasks.test.description',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-jest#injected-commands',
prompts: [
{
name: 'watch',
type: 'confirm',
description: 'org.vue.jest.tasks.test.watch'
},
{
name: 'notify',
type: 'confirm',
description: 'org.vue.jest.tasks.test.notify',
when: answers => answers.watch
},
{
name: 'update',
type: 'confirm',
description: 'org.vue.jest.tasks.test.update'
}
],
onBeforeRun: ({ answers, args }) => {
if (answers.watch) args.push('--watch')
if (answers.notify) args.push('--notify')
if (answers.update) args.push('--updateSnapshot')
}
})
}Describes the test:unit task for the Vue CLI UI with interactive prompts and configuration.
/**
* Describe a task for Vue CLI UI
* @param taskDescription - Configuration for UI task representation
*/
describeTask(taskDescription: TaskDescription): void;The UI integration matches commands using regular expressions:
const taskMatch = /vue-cli-service test:unit/;The UI provides three main interactive options:
interface TaskPrompts {
/** Enable watch mode for continuous testing */
watch: ConfirmPrompt;
/** Enable desktop notifications (only when watch is enabled) */
notify: ConditionalConfirmPrompt;
/** Update Jest snapshots */
update: ConfirmPrompt;
}Watch Mode Prompt:
const watchPrompt = {
name: 'watch',
type: 'confirm',
description: 'org.vue.jest.tasks.test.watch'
};Notification Prompt:
const notifyPrompt = {
name: 'notify',
type: 'confirm',
description: 'org.vue.jest.tasks.test.notify',
when: answers => answers.watch // Only show when watch mode is enabled
};Snapshot Update Prompt:
const updatePrompt = {
name: 'update',
type: 'confirm',
description: 'org.vue.jest.tasks.test.update'
};The UI integration translates user selections into Jest command-line arguments:
/**
* Process UI selections and convert to command arguments
* @param context - Task execution context with user answers
*/
onBeforeRun(context: TaskContext): void;Argument Mapping:
watch: true → --watch flagnotify: true → --notify flagupdate: true → --updateSnapshot flagThe UI uses internationalization keys for user-facing text:
interface I18nKeys {
/** Task description key */
'org.vue.jest.tasks.test.description': string;
/** Watch mode option description */
'org.vue.jest.tasks.test.watch': string;
/** Notification option description */
'org.vue.jest.tasks.test.notify': string;
/** Snapshot update option description */
'org.vue.jest.tasks.test.update': string;
}The UI integration links to external documentation for additional help:
const documentationLink = 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-jest#injected-commands';vue-cli-service test:unit commandsonBeforeRun translates selections to CLI argumentsinterface UIPluginAPI {
/** Register a task description with Vue CLI UI */
describeTask(taskDescription: TaskDescription): void;
}
interface TaskDescription {
/** Regular expression to match commands */
match: RegExp;
/** Internationalization key for task description */
description: string;
/** Link to external documentation */
link: string;
/** Interactive prompts for user configuration */
prompts: TaskPrompt[];
/** Callback to process user selections before execution */
onBeforeRun: (context: TaskContext) => void;
}
interface TaskPrompt {
/** Unique identifier for the prompt */
name: string;
/** Prompt type (confirm, input, list, etc.) */
type: string;
/** Internationalization key for prompt description */
description: string;
/** Conditional display logic */
when?: (answers: any) => boolean;
}
interface TaskContext {
/** User answers from interactive prompts */
answers: Record<string, any>;
/** Command arguments array to be modified */
args: string[];
}
interface ConfirmPrompt extends TaskPrompt {
type: 'confirm';
}
interface ConditionalConfirmPrompt extends ConfirmPrompt {
when: (answers: any) => boolean;
}When using the Vue CLI UI:
vue uiThe UI integration provides a user-friendly alternative to remembering Jest command-line options and flags.
Install with Tessl CLI
npx tessl i tessl/npm-vue--cli-plugin-unit-jest