Skip to content

Commit

Permalink
Merge pull request #366 from cexbrayat/test/typescript-without-babel
Browse files Browse the repository at this point in the history
test: add typescript e2e test without babel
  • Loading branch information
lmiller1990 committed Jul 19, 2021
2 parents efe0488 + e4f8ab1 commit 9e3b610
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 14 deletions.
43 changes: 43 additions & 0 deletions e2e/3.x/typescript-with-babel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "vue3-typescript-with-babel",
"version": "1.0.0",
"license": "MIT",
"private": true,
"scripts": {
"test": "jest --no-cache ./sub-project/test.js"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2",
"vue3-jest": "^26.0.0-alpha.10"
},
"jest": {
"testEnvironment": "jsdom",
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue3-jest"
}
},
"babel": {
"presets": [
"@babel/env"
]
}
}
File renamed without changes.
21 changes: 7 additions & 14 deletions e2e/3.x/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,32 @@
"license": "MIT",
"private": true,
"scripts": {
"test": "jest --no-cache ./sub-project/test.js"
"test": "jest --no-cache ./src/test.ts"
},
"dependencies": {
"@vue/compiler-sfc": "^3.0.3",
"vue": "^3.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@types/jest": "16.0.10",
"jest": "^26.0.0",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2",
"vue3-jest": "^26.0.0-alpha.10"
},
"jest": {
"globals": {
"vue-jest": {
"tsConfig": "./sub-project/tsconfig.json"
}
},
"moduleFileExtensions": [
"js",
"ts",
"json",
"vue"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.ts$": "ts-jest",
"^.+\\.vue$": "vue3-jest"
}
},
"babel": {
"presets": [
"@babel/env"
]
}
}
45 changes: 45 additions & 0 deletions e2e/3.x/typescript/src/components/Basic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<div class="hello">
<h1 :class="headingClasses">{{ msg }}</h1>
</div>
</template>

<style module="css">
.testA {
background-color: red;
}
</style>
<style module>
.testB {
background-color: blue;
}
</style>
<style>
.testC {
background-color: blue;
}
</style>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
export default defineComponent({
name: 'basic',
setup() {
const msg = 'Welcome to Your Vue.js App'
const isCrazy = ref(false)
const headingClasses = computed(() => ({
red: isCrazy,
blue: !isCrazy,
shadow: isCrazy
}))
const toggleClass = () => (isCrazy.value = !isCrazy.value)
return {
msg,
isCrazy,
headingClasses,
toggleClass
}
}
})
</script>
5 changes: 5 additions & 0 deletions e2e/3.x/typescript/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
23 changes: 23 additions & 0 deletions e2e/3.x/typescript/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createApp, h } from 'vue'

import Basic from '@/components/Basic.vue'

function mount(Component: any) {
document.getElementsByTagName('html')[0].innerHTML = ''
const el = document.createElement('div')
el.id = 'app'
document.body.appendChild(el)
const Parent = {
render() {
return h(Component)
}
}
createApp(Parent).mount(el)
}

test('processes .vue files', () => {
mount(Basic)
expect(document.querySelector('h1')!.textContent).toBe(
'Welcome to Your Vue.js App'
)
})
24 changes: 24 additions & 0 deletions e2e/3.x/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"sourceMap": true,
"baseUrl": ".",
"types": ["webpack-env", "jest"],
"paths": {
"@/*": ["src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["src/**/*.ts", "src/**/*.vue"],
"exclude": ["node_modules"]
}

0 comments on commit 9e3b610

Please sign in to comment.