Skip to content

Commit e4f8ab1

Browse files
committed
test: add typescript e2e test without babel
Adds a test close to the setup used by the CLI in a TS project without Babel. The existing TS test was moved to `typescript-with-babel`. The new test is a copy of the older one, with all babel dependencies removed, a rewritten component using the Composition API, a test in TS, a TS config close to the CLI one, and a shim file.
1 parent efe0488 commit e4f8ab1

File tree

9 files changed

+147
-14
lines changed

9 files changed

+147
-14
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "vue3-typescript-with-babel",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"private": true,
6+
"scripts": {
7+
"test": "jest --no-cache ./sub-project/test.js"
8+
},
9+
"dependencies": {
10+
"@vue/compiler-sfc": "^3.0.3",
11+
"vue": "^3.0.3"
12+
},
13+
"devDependencies": {
14+
"@babel/core": "^7.9.0",
15+
"@babel/preset-env": "^7.9.0",
16+
"jest": "^26.0.0",
17+
"ts-jest": "^26.4.4",
18+
"typescript": "^4.1.2",
19+
"vue3-jest": "^26.0.0-alpha.10"
20+
},
21+
"jest": {
22+
"testEnvironment": "jsdom",
23+
"globals": {
24+
"vue-jest": {
25+
"tsConfig": "./sub-project/tsconfig.json"
26+
}
27+
},
28+
"moduleFileExtensions": [
29+
"js",
30+
"json",
31+
"vue"
32+
],
33+
"transform": {
34+
"^.+\\.js$": "babel-jest",
35+
"^.+\\.vue$": "vue3-jest"
36+
}
37+
},
38+
"babel": {
39+
"presets": [
40+
"@babel/env"
41+
]
42+
}
43+
}

e2e/3.x/typescript/package.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,32 @@
44
"license": "MIT",
55
"private": true,
66
"scripts": {
7-
"test": "jest --no-cache ./sub-project/test.js"
7+
"test": "jest --no-cache ./src/test.ts"
88
},
99
"dependencies": {
1010
"@vue/compiler-sfc": "^3.0.3",
1111
"vue": "^3.0.3"
1212
},
1313
"devDependencies": {
14-
"@babel/core": "^7.9.0",
15-
"@babel/preset-env": "^7.9.0",
14+
"@types/jest": "16.0.10",
1615
"jest": "^26.0.0",
1716
"ts-jest": "^26.4.4",
1817
"typescript": "^4.1.2",
1918
"vue3-jest": "^26.0.0-alpha.10"
2019
},
2120
"jest": {
22-
"globals": {
23-
"vue-jest": {
24-
"tsConfig": "./sub-project/tsconfig.json"
25-
}
26-
},
2721
"moduleFileExtensions": [
2822
"js",
23+
"ts",
2924
"json",
3025
"vue"
3126
],
27+
"moduleNameMapper": {
28+
"^@/(.*)$": "<rootDir>/src/$1"
29+
},
3230
"transform": {
33-
"^.+\\.js$": "babel-jest",
31+
"^.+\\.ts$": "ts-jest",
3432
"^.+\\.vue$": "vue3-jest"
3533
}
36-
},
37-
"babel": {
38-
"presets": [
39-
"@babel/env"
40-
]
4134
}
4235
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<template>
2+
<div class="hello">
3+
<h1 :class="headingClasses">{{ msg }}</h1>
4+
</div>
5+
</template>
6+
7+
<style module="css">
8+
.testA {
9+
background-color: red;
10+
}
11+
</style>
12+
<style module>
13+
.testB {
14+
background-color: blue;
15+
}
16+
</style>
17+
<style>
18+
.testC {
19+
background-color: blue;
20+
}
21+
</style>
22+
23+
<script lang="ts">
24+
import { computed, defineComponent, ref } from 'vue'
25+
26+
export default defineComponent({
27+
name: 'basic',
28+
setup() {
29+
const msg = 'Welcome to Your Vue.js App'
30+
const isCrazy = ref(false)
31+
const headingClasses = computed(() => ({
32+
red: isCrazy,
33+
blue: !isCrazy,
34+
shadow: isCrazy
35+
}))
36+
const toggleClass = () => (isCrazy.value = !isCrazy.value)
37+
return {
38+
msg,
39+
isCrazy,
40+
headingClasses,
41+
toggleClass
42+
}
43+
}
44+
})
45+
</script>

e2e/3.x/typescript/src/shims-vue.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.vue' {
2+
import type { DefineComponent } from 'vue';
3+
const component: DefineComponent<{}, {}, any>;
4+
export default component;
5+
}

e2e/3.x/typescript/src/test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createApp, h } from 'vue'
2+
3+
import Basic from '@/components/Basic.vue'
4+
5+
function mount(Component: any) {
6+
document.getElementsByTagName('html')[0].innerHTML = ''
7+
const el = document.createElement('div')
8+
el.id = 'app'
9+
document.body.appendChild(el)
10+
const Parent = {
11+
render() {
12+
return h(Component)
13+
}
14+
}
15+
createApp(Parent).mount(el)
16+
}
17+
18+
test('processes .vue files', () => {
19+
mount(Basic)
20+
expect(document.querySelector('h1')!.textContent).toBe(
21+
'Welcome to Your Vue.js App'
22+
)
23+
})

e2e/3.x/typescript/tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"skipLibCheck": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"useDefineForClassFields": true,
14+
"sourceMap": true,
15+
"baseUrl": ".",
16+
"types": ["webpack-env", "jest"],
17+
"paths": {
18+
"@/*": ["src/*"]
19+
},
20+
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
21+
},
22+
"include": ["src/**/*.ts", "src/**/*.vue"],
23+
"exclude": ["node_modules"]
24+
}

0 commit comments

Comments
 (0)