Skip to content

Commit d03169c

Browse files
authored
fix: ensure EOL in existing tsconfig.json (#6006)
Fixes #5948 Ensure EOL in existing tsconfig.json when invoking unit-jest, unit-mocha, e2e-webdriverio
1 parent 2373df1 commit d03169c

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
jest.setTimeout(process.env.APPVEYOR ? 120000 : 60000)
2+
3+
const create = require('@vue/cli-test-utils/createTestProject')
4+
5+
test('should add types to existing tsconfig.json', async () => {
6+
const { dir, read, write } = await create('e2e-webdriverio-tsconfig', {
7+
plugins: {
8+
'@vue/cli-plugin-typescript': {},
9+
'@vue/cli-plugin-e2e-webdriverio': {
10+
webdrivers: ['chrome']
11+
}
12+
}
13+
})
14+
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
15+
16+
const invoke = require('@vue/cli/lib/invoke')
17+
await invoke('e2e-webdriverio', { webdrivers: ['chrome'] }, dir)
18+
19+
const tsconfig = await read('tsconfig.json')
20+
expect(tsconfig).toMatch(/\r?\n$/)
21+
expect(JSON.parse(tsconfig)['compilerOptions']['types'])
22+
.toEqual(['some-type', 'mocha', '@wdio/mocha-framework', '@wdio/sync'])
23+
})

Diff for: packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const applyTS = module.exports.applyTS = (api, invoking) => {
2121
}
2222
}
2323
}
24-
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
24+
files['tsconfig.json'] = JSON.stringify(parsed, null, 2) + '\n'
2525
}
2626
})
2727
}

Diff for: 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)

Diff for: 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
}

Diff for: 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)

Diff for: 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)