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

fix: add Example cli TypeScript project #356

Merged
merged 5 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cypress/screenshots
.nyc_output
coverage
*.tgz
examples/*/cypress/videos/
3 changes: 3 additions & 0 deletions examples/cli-ts/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead
22 changes: 22 additions & 0 deletions examples/cli-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.DS_Store
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions examples/cli-ts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions examples/cli-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cli-ts

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

![Scaffold settings](images/scaffold.png)
5 changes: 5 additions & 0 deletions examples/cli-ts/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
6 changes: 6 additions & 0 deletions examples/cli-ts/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"experimentalComponentTesting": true,
"componentFolder": "src",
"testFiles": "**/*.spec.ts",
"fixturesFolder": false
}
1 change: 1 addition & 0 deletions examples/cli-ts/cypress/integration/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it('has placeholder e2e test', () => {})
6 changes: 6 additions & 0 deletions examples/cli-ts/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const preprocessor = require('cypress-vue-unit-test/dist/plugins/webpack')
module.exports = (on, config) => {
preprocessor(on, config)
// IMPORTANT return the config object
return config
}
1 change: 1 addition & 0 deletions examples/cli-ts/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'cypress-vue-unit-test/dist/support'
Binary file added examples/cli-ts/images/scaffold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/cli-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "cli-ts",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"cy:open": "../../node_modules/.bin/cypress open",
"cy:run": "../../node_modules/.bin/cypress run"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-property-decorator": "^8.4.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-typescript": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"cypress-vue-unit-test": "file:../..",
"typescript": "~3.9.3",
"vue-template-compiler": "^2.6.11"
}
}
29 changes: 29 additions & 0 deletions examples/cli-ts/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
</div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import HelloWorld from './components/HelloWorld.vue';

@Component({
components: {
HelloWorld,
},
})
export default class App extends Vue {}
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
Binary file added examples/cli-ts/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/cli-ts/src/components/HelloWorld.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { mount } from 'cypress-vue-unit-test'
import HelloWorld from './HelloWorld.vue'

describe('HelloWorld', () => {
it('shows links', () => {
// @ts-ignore
mount(HelloWorld)
// there are a lot of links
cy.get('li').should('have.length.gt', 10)
})
})
58 changes: 58 additions & 0 deletions examples/cli-ts/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript" target="_blank" rel="noopener">typescript</a></li>
</ul>
<h3>Essential Links</h3>
<ul>
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
</ul>
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class HelloWorld extends Vue {
@Prop() private msg!: string;
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
8 changes: 8 additions & 0 deletions examples/cli-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

new Vue({
render: h => h(App),
}).$mount('#app')
13 changes: 13 additions & 0 deletions examples/cli-ts/src/shims-tsx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Vue, { VNode } from 'vue'

declare global {
namespace JSX {
// tslint:disable no-empty-interface
interface Element extends VNode {}
// tslint:disable no-empty-interface
interface ElementClass extends Vue {}
interface IntrinsicElements {
[elem: string]: any
}
}
}
4 changes: 4 additions & 0 deletions examples/cli-ts/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}
39 changes: 39 additions & 0 deletions examples/cli-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
2 changes: 1 addition & 1 deletion examples/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# cli-example

Application scaffolded with Vue CLI v3
Application scaffolded with Vue CLI v3 and tested using `Cypress` + `cypress-vue-unit-test`
33 changes: 28 additions & 5 deletions src/preprocessor/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import util from 'util'
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
const debug = require('debug')('cypress-vue-unit-test')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
// const { VueLoaderPlugin } = require('vue-loader')
const fw = require('find-webpack')

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

/**
* Warning: modifies the input object
* @param {WebpackOptions} options
*/

function removeForkTsCheckerWebpackPlugin(options) {
if (!Array.isArray(options.plugins)) {
return
}
options.plugins = options.plugins.filter((plugin) => {
return plugin.typescript === undefined
})
}

/**
* Warning: modifies the input object
* @param {Cypress.ConfigOptions} config
Expand Down Expand Up @@ -100,9 +115,11 @@ function insertBabelLoader(config, options) {
options.module.rules.push(babelRule)
options.plugins = options.plugins || []

const pluginFound = options.plugins.some(
(plugin) => plugin.constructor === VueLoaderPlugin,
)
const pluginFound = options.plugins.find((plugin) => {
return (
plugin.constructor && plugin.constructor.name === VueLoaderPlugin.name
)
})
if (!pluginFound) {
debug('inserting VueLoaderPlugin')
options.plugins.push(new VueLoaderPlugin())
Expand All @@ -127,12 +144,18 @@ const onFileDefaultPreprocessor = (config) => {
compileTemplate(webpackOptions)
insertBabelLoader(config, webpackOptions)

// if I remove it, then get another message
// [VueLoaderPlugin Error] No matching use for vue-loader is found.
// removeForkTsCheckerWebpackPlugin(webpackOptions)

if (debug.enabled) {
console.error('final webpack')
console.error(util.inspect(webpackOptions, false, 10, true))
console.error(util.inspect(webpackOptions, false, 2, true))
}

return webpackPreprocessor({ webpackOptions })
return webpackPreprocessor({
webpackOptions,
})
}

/**
Expand Down