Back to Repositories

Testing TypeScript Plugin Integration with Jest in vue-cli

This test suite validates the TypeScript plugin integration with Jest testing in Vue CLI. It ensures proper functionality of TypeScript-based unit testing setups, both with and without Babel transpilation support.

Test Coverage Overview

The test suite covers core TypeScript integration scenarios with Jest in Vue CLI projects.

Key areas tested include:
  • Basic TypeScript and Jest integration setup
  • TypeScript with Babel and Jest combined configuration
  • Project creation and test execution validation

Implementation Analysis

The testing approach uses Vue CLI’s test utilities to create temporary test projects and verify successful test execution. It implements two main test cases – one for standard TypeScript-Jest setup and another with Babel integration, ensuring compatibility across different build configurations.

Technical patterns include:
  • Async/await test implementation
  • Project fixture creation
  • CLI command execution validation

Technical Details

Testing infrastructure includes:
  • Jest as the test runner
  • @vue/cli-test-utils for project creation
  • TypeScript plugin configuration
  • Optional Babel integration
  • 40-second timeout configuration for CI environments

Best Practices Demonstrated

The test suite exemplifies several testing best practices in the Vue ecosystem.

Notable practices include:
  • Isolated test environments for each configuration
  • Explicit plugin dependency declaration
  • Proper async test handling
  • Clear test case separation for different configurations

vuejs/vue-cli

packages/@vue/cli-plugin-typescript/__tests__/tsPluginUnit.spec.js

            
jest.setTimeout(40000)

const create = require('@vue/cli-test-utils/createTestProject')

test('jest', async () => {
  const project = await create('ts-unit-jest', {
    plugins: {
      '@vue/cli-plugin-typescript': {},
      '@vue/cli-plugin-unit-jest': {}
    }
  })
  await project.run(`vue-cli-service test:unit`)
})

test('jest w/ babel', async () => {
  const project = await create('ts-unit-jest-babel', {
    plugins: {
      '@vue/cli-plugin-typescript': {},
      '@vue/cli-plugin-babel': {},
      '@vue/cli-plugin-unit-jest': {}
    }
  })
  await project.run(`vue-cli-service test:unit`)
})