Skip to content

fix(unit-jest, unit-mocha): ensure EOL in existing tsconfig.json #6006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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'])
})
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
})
}
Expand Down
18 changes: 18 additions & 0 deletions packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js
Original file line number Diff line number Diff line change
@@ -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([
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-unit-jest/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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([
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-unit-mocha/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
})
}
Expand Down