Validating TypeScript-ESLint Integration in Vue CLI
This test suite validates the integration between TypeScript and ESLint in Vue CLI projects, focusing on proper semicolon handling and code formatting. It ensures that the TypeScript plugin works correctly with ESLint configuration and maintains consistent code style across different file types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
vuejs/vue-cli
packages/@vue/cli-plugin-typescript/__tests__/tsPluginESLint.spec.js
jest.setTimeout(60000)
const create = require('@vue/cli-test-utils/createTestProject')
test('should work', async () => {
const project = await create('ts-eslint', {
plugins: {
'@vue/cli-plugin-eslint': {
config: 'prettier'
},
'@vue/cli-plugin-typescript': {
classComponent: true
}
}
})
const { read, write, run } = project
const main = await read('src/main.ts')
expect(main).toMatch(';')
const app = await read('src/App.vue')
expect(main).toMatch(';')
// remove semicolons
const updatedMain = main.replace(/;/g, '')
await write('src/main.ts', updatedMain)
// for Vue file, only remove semis in script section
const updatedApp = app.replace(/<script(.|\n)*\/script>/, $ => {
return $.replace(/;/g, '')
})
await write('src/App.vue', updatedApp)
// lint
await run('vue-cli-service lint')
expect(await read('src/main.ts')).toMatch(';')
const lintedApp = await read('src/App.vue')
expect(lintedApp).toMatch(';')
// test if ESLint is fixing vue files properly
expect(lintedApp).toBe(app)
})