Skip to content

Commit 95ac06b

Browse files
committed
fix(unit-jest, unit-mocha): ensure EOL in existing tsconfig.json
1 parent 2373df1 commit 95ac06b

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

packages/@vue/cli-plugin-unit-jest/__tests__/jestGenerator.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin')
2+
const create = require('@vue/cli-test-utils/createTestProject')
23

34
test('base', async () => {
45
const { pkg, files } = await generateWithPlugin([
@@ -141,3 +142,20 @@ test('TS + bare + router', async () => {
141142
expect(spec).toMatch(`const wrapper = mount(App,`)
142143
expect(spec).toMatch(`expect(wrapper.text()).toMatch(\`Welcome to Your Vue.js App\`)`)
143144
})
145+
146+
test('add types to existing tsconfig.json', async () => {
147+
const { dir, read, write } = await create('unit-jest-tsconfig', {
148+
plugins: {
149+
'@vue/cli-plugin-typescript': {},
150+
'@vue/cli-plugin-unit-jest': {}
151+
}
152+
})
153+
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
154+
155+
const invoke = require('@vue/cli/lib/invoke')
156+
await invoke('unit-jest', {}, dir)
157+
158+
const tsconfig = await read('tsconfig.json')
159+
expect(tsconfig).toMatch(/\r?\n$/)
160+
expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'jest'])
161+
}, 30000)

packages/@vue/cli-plugin-unit-jest/generator/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const applyTS = (module.exports.applyTS = (api, invoking) => {
8787
) {
8888
parsed.compilerOptions.types.push('jest')
8989
}
90-
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
90+
files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n'
9191
}
9292
})
9393
}

packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin')
2+
const create = require('@vue/cli-test-utils/createTestProject')
23

34
test('base', async () => {
45
const { pkg, files } = await generateWithPlugin([
@@ -138,3 +139,20 @@ test('TS + bare + router', async () => {
138139
expect(spec).toMatch(`const wrapper = mount(App,`)
139140
expect(spec).toMatch(`expect(wrapper.text()).to.include(\`Welcome to Your Vue.js App\`)`)
140141
})
142+
143+
test('add types to existing tsconfig.json', async () => {
144+
const { dir, read, write } = await create('unit-mocha-tsconfig', {
145+
plugins: {
146+
'@vue/cli-plugin-typescript': {},
147+
'@vue/cli-plugin-unit-mocha': {}
148+
}
149+
})
150+
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
151+
152+
const invoke = require('@vue/cli/lib/invoke')
153+
await invoke('unit-mocha', {}, dir)
154+
155+
const tsconfig = await read('tsconfig.json')
156+
expect(tsconfig).toMatch(/\r?\n$/)
157+
expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'mocha', 'chai'])
158+
}, 30000)

packages/@vue/cli-plugin-unit-mocha/generator/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const applyTS = module.exports.applyTS = (api, invoking) => {
6666
types.push('chai')
6767
}
6868
}
69-
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
69+
files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n'
7070
}
7171
})
7272
}

0 commit comments

Comments
 (0)