Testing Babel Configuration Prompt Module in Vue CLI
This test suite validates the Babel configuration module in Vue CLI, focusing on prompt interactions and TypeScript integration scenarios. It verifies proper plugin installation and configuration options across different setup combinations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
vuejs/vue-cli
packages/@vue/cli/lib/promptModules/__tests__/babel.spec.js
jest.mock('fs')
jest.mock('inquirer')
const assertPromptModule = require('@vue/cli-test-utils/assertPromptModule')
const moduleToTest = require('../babel')
test('should pass', async () => {
const expectedPrompts = [
{
message: 'features',
check: [0]
}
]
const expectedOptions = {
plugins: {
'@vue/cli-plugin-babel': {}
}
}
await assertPromptModule(
moduleToTest,
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})
test('with TS', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.useTsWithBabel = true
answers.features.push('ts')
})
}
const expectedPrompts = [
{
message: 'features',
check: [] // no need to check if "useTsWithBabel" is explicitly true
}
]
const expectedOptions = {
plugins: {
'@vue/cli-plugin-babel': {}
}
}
await assertPromptModule(
[mockTSModule, moduleToTest],
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})
test('with TS, no Babel', async () => {
const mockTSModule = api => {
api.onPromptComplete(answers => {
answers.features.push('ts')
})
}
const expectedPrompts = [
{
message: 'features',
check: []
}
]
const expectedOptions = {
plugins: {}
}
await assertPromptModule(
[mockTSModule, moduleToTest],
expectedPrompts,
expectedOptions,
{ pluginsOnly: true }
)
})