Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest-Preview + Vue 3 + Vue-CLI + Vue-Test-Utils #257

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions examples/vue-testing-library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/vue-testing-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Vue

See the full example at <https://github.com/nvh95/jest-preview/tree/main/examples/vue>

## Installation and Usage

Please refer to [Installation](https://www.jest-preview.com/docs/getting-started/installation/) and [Usage](https://www.jest-preview.com/docs/getting-started/usage/).

## Caveats

Currently, the [Scoped CSS](https://vuejs.org/api/sfc-css-features.html#scoped-css) is not supported yet. We are working to support soon in the future release.
5 changes: 5 additions & 0 deletions examples/vue-testing-library/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Not sure why default babel settings does not work
// https://github.com/vuejs/vue-jest/issues/461
module.exports = {
presets: ['@babel/preset-env'],
};
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/vue-testing-library/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @type {import('@jest/types').Config.InitialOptions} */

module.exports = {
roots: ['<rootDir>/src'],
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
moduleFileExtensions: ['js', 'ts', 'json', 'vue'],
transform: {
'^.+\\.(js|ts)$': 'ts-jest',
'^.+\\.vue$': '@vue/vue3-jest',
'^.+\\.css$': 'jest-preview/transforms/css',
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json|vue)$)':
'jest-preview/transforms/file',
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
],
testEnvironment: 'jsdom',
moduleFileExtensions: [
'js',
'tsx',
'ts',
'web.js',
'web.ts',
'web.tsx',
'json',
'web.jsx',
'jsx',
'node',
],
};
29 changes: 29 additions & 0 deletions examples/vue-testing-library/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "vite-vue",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "jest --watch",
"test:ci": "jest",
"test:nc": "jest --watch --no-cache",
"jest-preview": "jest-preview"
},
"dependencies": {
"@babel/preset-env": "^7.16.11",
"vue": "^3.2.25"
},
"devDependencies": {
"@testing-library/vue": "^6.5.1",
"@types/jest": "^27.4.1",
"@vitejs/plugin-vue": "^2.3.0",
"@vue/test-utils": "^2.0.0-rc.18",
"@vue/vue3-jest": "^27.0.0-alpha.4",
"jest": "^27.5.1",
"jest-preview": "file:../..",
"ts-jest": "^27.1.4",
"vite": "^2.9.0"
}
}
Binary file added examples/vue-testing-library/public/favicon.ico
Binary file not shown.
23 changes: 23 additions & 0 deletions examples/vue-testing-library/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue';
import logo from './assets/logo.png';
import './app.css';
</script>

<template>
<img alt="Vue logo" :src="logo" />
<HelloWorld msg="Hello Vue 3 + Vite" />
</template>

<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>
File renamed without changes.
40 changes: 40 additions & 0 deletions examples/vue-testing-library/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script setup>
import { ref } from 'vue';

defineProps({
msg: String,
});

const count = ref(0);
</script>

<template>
<h1>{{ msg }}</h1>
<p class="imported-css">This message is styled by imported CSS</p>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>

<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Documentation
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
</p>

<button type="button" @click="count++">count is: {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>

<style scoped>
a {
color: #42b983;
}
</style>
4 changes: 4 additions & 0 deletions examples/vue-testing-library/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
4 changes: 4 additions & 0 deletions examples/vue/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> 1%
last 2 versions
not dead
not ie 11
23 changes: 11 additions & 12 deletions examples/vue/.gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Logs
logs
*.log
.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*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
.vscode
*.suo
*.ntvs*
*.njsproj
Expand Down
16 changes: 10 additions & 6 deletions examples/vue/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Vue
# Jest-Preview + Vue + Vue-CLI + Vue-Test-Utils

See the full example at <https://github.com/nvh95/jest-preview/tree/main/examples/vue>
**Running Locally:**

## Installation and Usage
* `npm install && npm start`

Please refer to [Installation](https://www.jest-preview.com/docs/getting-started/installation/) and [Usage](https://www.jest-preview.com/docs/getting-started/usage/).

## Caveats
**Running Unit tests:**

Currently, the [Scoped CSS](https://vuejs.org/api/sfc-css-features.html#scoped-css) is not supported yet. We are working to support soon in the future release.
* `npm run unit`


**Running Jest-Preview**

* `npm run jest`
6 changes: 3 additions & 3 deletions examples/vue/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Not sure why default babel settings does not work
// https://github.com/vuejs/vue-jest/issues/461
module.exports = {
presets: ['@babel/preset-env'],
presets: [
'@vue/cli-plugin-babel/preset'
]
};
48 changes: 24 additions & 24 deletions examples/vue/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/** @type {import('@jest/types').Config.InitialOptions} */
process.env.VUE_CLI_BABEL_TARGET_NODE = true;
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true;

module.exports = {
roots: ['<rootDir>/src'],
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
moduleFileExtensions: ['js', 'ts', 'json', 'vue'],
preset: '@vue/cli-plugin-unit-jest',
testURL: 'http://localhost/',
testEnvironment: 'jest-environment-jsdom-global',
transformIgnorePatterns: ['/node_modules/(?!babel/runtime)'],
snapshotSerializers: ['jest-serializer-vue-tjw'],
setupFilesAfterEnv: ['<rootDir>/tests/unit/setup.js'],
coverageDirectory: '<rootDir>/tests/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!**/node_modules/**'
],
testMatch: [
'**/tests/unit/**/*.test.js'
],
moduleNameMapper: {
'^@@/(.*)$': '<rootDir>/tests/$1',
'^@/(.*)$': '<rootDir>/src/$1'
},
// Used by jest-preview
transform: {
'^.+\\.(js|ts)$': 'ts-jest',
'^.+\\.vue$': '@vue/vue3-jest',
'^.+\\.css$': 'jest-preview/transforms/css',
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json|vue)$)':
'jest-preview/transforms/file',
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
],
testEnvironment: 'jsdom',
moduleFileExtensions: [
'js',
'tsx',
'ts',
'web.js',
'web.ts',
'web.tsx',
'json',
'web.jsx',
'jsx',
'node',
],
'^(?!.*\\.(js|css|json|vue)$)': 'jest-preview/transforms/file'
}
};
19 changes: 19 additions & 0 deletions examples/vue/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}
44 changes: 24 additions & 20 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
{
"name": "vite-vue",
"name": "jest-prevue",
"version": "0.1.0",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "jest --watch",
"test:ci": "jest",
"test:nc": "jest --watch --no-cache",
"jest-preview": "jest-preview"
"start": "npm run serve",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"unit": "vue-cli-service test:unit",
"jest": "concurrently \"jest-preview\" \"wait-on http://localhost:3336 && npm run unit\""
},
"dependencies": {
"@babel/preset-env": "^7.16.11",
"vue": "^3.2.25"
"vue": "^3.2.38"
},
"devDependencies": {
"@testing-library/vue": "^6.5.1",
"@types/jest": "^27.4.1",
"@vitejs/plugin-vue": "^2.3.0",
"@vue/test-utils": "^2.0.0-rc.18",
"@vue/vue3-jest": "^27.0.0-alpha.4",
"jest": "^27.5.1",
"jest-preview": "file:../..",
"ts-jest": "^27.1.4",
"vite": "^2.9.0"
"@babel/core": "7.18.10",
"@testing-library/vue": "^6.6.1",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-unit-jest": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"@vue/test-utils": "^2.0.2",
"@vue/vue3-jest": "27.0.0",
"babel-jest": "27.5.1",
"concurrently": "^7.3.0",
"core-js": "^3.25.0",
"jest": "27.5.1",
"jest-environment-jsdom-global": "^4.0.0",
"jest-preview": "^0.3.1",
"jest-serializer-vue-tjw": "^3.19.0",
"ts-jest": "27.1.5",
"wait-on": "^6.0.1"
}
}
6 changes: 6 additions & 0 deletions examples/vue/public/global-css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
font-family: sans-serif;
}
.hello {
color: #F00;
}
18 changes: 18 additions & 0 deletions examples/vue/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="">
<head>
<title><%= htmlWebpackPlugin.options.title %></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="stylesheet" href="global-css.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Loading