diff --git a/packages/@vue/cli-plugin-e2e-webdriverio/__tests__/wdioGenerator.spec.js b/packages/@vue/cli-plugin-e2e-webdriverio/__tests__/wdioGenerator.spec.js new file mode 100644 index 0000000000..fbc6cdbb56 --- /dev/null +++ b/packages/@vue/cli-plugin-e2e-webdriverio/__tests__/wdioGenerator.spec.js @@ -0,0 +1,23 @@ +jest.setTimeout(process.env.APPVEYOR ? 120000 : 60000) + +const create = require('@vue/cli-test-utils/createTestProject') + +test('should add types to existing tsconfig.json', async () => { + const { dir, read, write } = await create('e2e-webdriverio-tsconfig', { + plugins: { + '@vue/cli-plugin-typescript': {}, + '@vue/cli-plugin-e2e-webdriverio': { + webdrivers: ['chrome'] + } + } + }) + await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }})) + + const invoke = require('@vue/cli/lib/invoke') + await invoke('e2e-webdriverio', { webdrivers: ['chrome'] }, dir) + + const tsconfig = await read('tsconfig.json') + expect(tsconfig).toMatch(/\r?\n$/) + expect(JSON.parse(tsconfig)['compilerOptions']['types']) + .toEqual(['some-type', 'mocha', '@wdio/mocha-framework', '@wdio/sync']) +}) diff --git a/packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js b/packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js index 69879d0611..13032a93d7 100644 --- a/packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js +++ b/packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js @@ -21,7 +21,7 @@ const applyTS = module.exports.applyTS = (api, invoking) => { } } } - files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n' } }) } diff --git a/packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js b/packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js index 0166aae893..adcadc4dc0 100644 --- a/packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js +++ b/packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js @@ -1,4 +1,5 @@ const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') +const create = require('@vue/cli-test-utils/createTestProject') test('base', async () => { const { pkg, files } = await generateWithPlugin([ @@ -141,3 +142,20 @@ test('TS + bare + router', async () => { expect(spec).toMatch(`const wrapper = mount(App,`) expect(spec).toMatch(`expect(wrapper.text()).toMatch(\`Welcome to Your Vue.js App\`)`) }) + +test('add types to existing tsconfig.json', async () => { + const { dir, read, write } = await create('unit-jest-tsconfig', { + plugins: { + '@vue/cli-plugin-typescript': {}, + '@vue/cli-plugin-unit-jest': {} + } + }) + await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }})) + + const invoke = require('@vue/cli/lib/invoke') + await invoke('unit-jest', {}, dir) + + const tsconfig = await read('tsconfig.json') + expect(tsconfig).toMatch(/\r?\n$/) + expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'jest']) +}, 30000) diff --git a/packages/@vue/cli-plugin-unit-jest/generator/index.js b/packages/@vue/cli-plugin-unit-jest/generator/index.js index 843d560850..68873968b8 100644 --- a/packages/@vue/cli-plugin-unit-jest/generator/index.js +++ b/packages/@vue/cli-plugin-unit-jest/generator/index.js @@ -87,7 +87,7 @@ const applyTS = (module.exports.applyTS = (api, invoking) => { ) { parsed.compilerOptions.types.push('jest') } - files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n' } }) } diff --git a/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js b/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js index 6c6368c4d1..3dce859e47 100644 --- a/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js +++ b/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js @@ -1,4 +1,5 @@ const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') +const create = require('@vue/cli-test-utils/createTestProject') test('base', async () => { const { pkg, files } = await generateWithPlugin([ @@ -138,3 +139,20 @@ test('TS + bare + router', async () => { expect(spec).toMatch(`const wrapper = mount(App,`) expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js App\`)`) }) + +test('add types to existing tsconfig.json', async () => { + const { dir, read, write } = await create('unit-mocha-tsconfig', { + plugins: { + '@vue/cli-plugin-typescript': {}, + '@vue/cli-plugin-unit-mocha': {} + } + }) + await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }})) + + const invoke = require('@vue/cli/lib/invoke') + await invoke('unit-mocha', {}, dir) + + const tsconfig = await read('tsconfig.json') + expect(tsconfig).toMatch(/\r?\n$/) + expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'mocha', 'chai']) +}, 30000) diff --git a/packages/@vue/cli-plugin-unit-mocha/generator/index.js b/packages/@vue/cli-plugin-unit-mocha/generator/index.js index 204644955f..ab35e769b0 100644 --- a/packages/@vue/cli-plugin-unit-mocha/generator/index.js +++ b/packages/@vue/cli-plugin-unit-mocha/generator/index.js @@ -66,7 +66,7 @@ const applyTS = module.exports.applyTS = (api, invoking) => { types.push('chai') } } - files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n' } }) }