Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit c0b2bb3

Browse files
authored
fix: add Example cli TypeScript project (#356)
- remove double plugin insert
1 parent 0a16be5 commit c0b2bb3

File tree

22 files changed

+267
-6
lines changed

22 files changed

+267
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ cypress/screenshots
88
.nyc_output
99
coverage
1010
*.tgz
11+
examples/*/cypress/videos/

examples/cli-ts/.browserslistrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> 1%
2+
last 2 versions
3+
not dead

examples/cli-ts/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
pnpm-debug.log*
14+
15+
# Editor directories and files
16+
.idea
17+
.vscode
18+
*.suo
19+
*.ntvs*
20+
*.njsproj
21+
*.sln
22+
*.sw?

examples/cli-ts/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/cli-ts/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# cli-ts
2+
3+
Application scaffolded with Vue CLI v3 and tested using `Cypress` + `cypress-vue-unit-test`
4+
5+
![Scaffold settings](images/scaffold.png)

examples/cli-ts/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

examples/cli-ts/cypress.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"experimentalComponentTesting": true,
3+
"componentFolder": "src",
4+
"testFiles": "**/*.spec.ts",
5+
"fixturesFolder": false
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
it('has placeholder e2e test', () => {})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const preprocessor = require('cypress-vue-unit-test/dist/plugins/webpack')
2+
module.exports = (on, config) => {
3+
preprocessor(on, config)
4+
// IMPORTANT return the config object
5+
return config
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'cypress-vue-unit-test/dist/support'

examples/cli-ts/images/scaffold.png

227 KB
Loading

examples/cli-ts/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "cli-ts",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve",
7+
"build": "vue-cli-service build",
8+
"cy:open": "../../node_modules/.bin/cypress open",
9+
"cy:run": "../../node_modules/.bin/cypress run"
10+
},
11+
"dependencies": {
12+
"core-js": "^3.6.5",
13+
"vue": "^2.6.11",
14+
"vue-class-component": "^7.2.3",
15+
"vue-property-decorator": "^8.4.2"
16+
},
17+
"devDependencies": {
18+
"@vue/cli-plugin-babel": "~4.4.0",
19+
"@vue/cli-plugin-typescript": "~4.4.0",
20+
"@vue/cli-service": "~4.4.0",
21+
"cypress-vue-unit-test": "file:../..",
22+
"typescript": "~3.9.3",
23+
"vue-template-compiler": "^2.6.11"
24+
}
25+
}

examples/cli-ts/src/App.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template>
2+
<div id="app">
3+
<img alt="Vue logo" src="./assets/logo.png">
4+
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
5+
</div>
6+
</template>
7+
8+
<script lang="ts">
9+
import { Component, Vue } from 'vue-property-decorator';
10+
import HelloWorld from './components/HelloWorld.vue';
11+
12+
@Component({
13+
components: {
14+
HelloWorld,
15+
},
16+
})
17+
export default class App extends Vue {}
18+
</script>
19+
20+
<style>
21+
#app {
22+
font-family: Avenir, Helvetica, Arial, sans-serif;
23+
-webkit-font-smoothing: antialiased;
24+
-moz-osx-font-smoothing: grayscale;
25+
text-align: center;
26+
color: #2c3e50;
27+
margin-top: 60px;
28+
}
29+
</style>

examples/cli-ts/src/assets/logo.png

6.69 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { mount } from 'cypress-vue-unit-test'
2+
import HelloWorld from './HelloWorld.vue'
3+
4+
describe('HelloWorld', () => {
5+
it('shows links', () => {
6+
// @ts-ignore
7+
mount(HelloWorld)
8+
// there are a lot of links
9+
cy.get('li').should('have.length.gt', 10)
10+
})
11+
})
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<div class="hello">
3+
<h1>{{ msg }}</h1>
4+
<p>
5+
For a guide and recipes on how to configure / customize this project,<br>
6+
check out the
7+
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
8+
</p>
9+
<h3>Installed CLI Plugins</h3>
10+
<ul>
11+
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
12+
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript" target="_blank" rel="noopener">typescript</a></li>
13+
</ul>
14+
<h3>Essential Links</h3>
15+
<ul>
16+
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
17+
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
18+
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
19+
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
20+
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
21+
</ul>
22+
<h3>Ecosystem</h3>
23+
<ul>
24+
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
25+
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
26+
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
27+
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
28+
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
29+
</ul>
30+
</div>
31+
</template>
32+
33+
<script lang="ts">
34+
import { Component, Prop, Vue } from 'vue-property-decorator';
35+
36+
@Component
37+
export default class HelloWorld extends Vue {
38+
@Prop() private msg!: string;
39+
}
40+
</script>
41+
42+
<!-- Add "scoped" attribute to limit CSS to this component only -->
43+
<style scoped>
44+
h3 {
45+
margin: 40px 0 0;
46+
}
47+
ul {
48+
list-style-type: none;
49+
padding: 0;
50+
}
51+
li {
52+
display: inline-block;
53+
margin: 0 10px;
54+
}
55+
a {
56+
color: #42b983;
57+
}
58+
</style>

examples/cli-ts/src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
4+
Vue.config.productionTip = false
5+
6+
new Vue({
7+
render: h => h(App),
8+
}).$mount('#app')

examples/cli-ts/src/shims-tsx.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Vue, { VNode } from 'vue'
2+
3+
declare global {
4+
namespace JSX {
5+
// tslint:disable no-empty-interface
6+
interface Element extends VNode {}
7+
// tslint:disable no-empty-interface
8+
interface ElementClass extends Vue {}
9+
interface IntrinsicElements {
10+
[elem: string]: any
11+
}
12+
}
13+
}

examples/cli-ts/src/shims-vue.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.vue' {
2+
import Vue from 'vue'
3+
export default Vue
4+
}

examples/cli-ts/tsconfig.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"experimentalDecorators": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"types": [
15+
"webpack-env"
16+
],
17+
"paths": {
18+
"@/*": [
19+
"src/*"
20+
]
21+
},
22+
"lib": [
23+
"esnext",
24+
"dom",
25+
"dom.iterable",
26+
"scripthost"
27+
]
28+
},
29+
"include": [
30+
"src/**/*.ts",
31+
"src/**/*.tsx",
32+
"src/**/*.vue",
33+
"tests/**/*.ts",
34+
"tests/**/*.tsx"
35+
],
36+
"exclude": [
37+
"node_modules"
38+
]
39+
}

examples/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# cli-example
22

3-
Application scaffolded with Vue CLI v3
3+
Application scaffolded with Vue CLI v3 and tested using `Cypress` + `cypress-vue-unit-test`

src/preprocessor/webpack.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import util from 'util'
66
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
77
const debug = require('debug')('cypress-vue-unit-test')
88
const VueLoaderPlugin = require('vue-loader/lib/plugin')
9+
// const { VueLoaderPlugin } = require('vue-loader')
910
const fw = require('find-webpack')
1011

1112
// Preventing chunks because we don't serve static assets
@@ -51,6 +52,20 @@ function compileTemplate(options = {}) {
5152
options.resolve.alias['vue$'] = 'vue/dist/vue.esm.js'
5253
}
5354

55+
/**
56+
* Warning: modifies the input object
57+
* @param {WebpackOptions} options
58+
*/
59+
60+
function removeForkTsCheckerWebpackPlugin(options) {
61+
if (!Array.isArray(options.plugins)) {
62+
return
63+
}
64+
options.plugins = options.plugins.filter((plugin) => {
65+
return plugin.typescript === undefined
66+
})
67+
}
68+
5469
/**
5570
* Warning: modifies the input object
5671
* @param {Cypress.ConfigOptions} config
@@ -100,9 +115,11 @@ function insertBabelLoader(config, options) {
100115
options.module.rules.push(babelRule)
101116
options.plugins = options.plugins || []
102117

103-
const pluginFound = options.plugins.some(
104-
(plugin) => plugin.constructor === VueLoaderPlugin,
105-
)
118+
const pluginFound = options.plugins.find((plugin) => {
119+
return (
120+
plugin.constructor && plugin.constructor.name === VueLoaderPlugin.name
121+
)
122+
})
106123
if (!pluginFound) {
107124
debug('inserting VueLoaderPlugin')
108125
options.plugins.push(new VueLoaderPlugin())
@@ -127,12 +144,18 @@ const onFileDefaultPreprocessor = (config) => {
127144
compileTemplate(webpackOptions)
128145
insertBabelLoader(config, webpackOptions)
129146

147+
// if I remove it, then get another message
148+
// [VueLoaderPlugin Error] No matching use for vue-loader is found.
149+
// removeForkTsCheckerWebpackPlugin(webpackOptions)
150+
130151
if (debug.enabled) {
131152
console.error('final webpack')
132-
console.error(util.inspect(webpackOptions, false, 10, true))
153+
console.error(util.inspect(webpackOptions, false, 2, true))
133154
}
134155

135-
return webpackPreprocessor({ webpackOptions })
156+
return webpackPreprocessor({
157+
webpackOptions,
158+
})
136159
}
137160

138161
/**

0 commit comments

Comments
 (0)