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

vue with vue-testing-librray example #42

Merged
merged 10 commits into from
Jun 21, 2022
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
24 changes: 24 additions & 0 deletions examples/vue/.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?
3 changes: 3 additions & 0 deletions examples/vue/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["johnsoncodehk.volar"]
}
7 changes: 7 additions & 0 deletions examples/vue/README-vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vue 3 + Vite

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
9 changes: 9 additions & 0 deletions examples/vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Vue 3 + Vite + Jest Preview

## Installation and Usage

Please refer to [Installation](../../README.md#installation) and [Usage](../../README.md#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/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'],
};
13 changes: 13 additions & 0 deletions examples/vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/vue/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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',
],
};
28 changes: 28 additions & 0 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "vite-vue",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "jest --watch",
"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/public/favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/vue/src/App.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, fireEvent } from '@testing-library/vue';
import App from './App.vue';
import { debug } from 'jest-preview';

test('increments value on click', async () => {
render(App);
debug();
});
23 changes: 23 additions & 0 deletions examples/vue/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>
3 changes: 3 additions & 0 deletions examples/vue/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.imported-css {
color: orange;
}
Binary file added examples/vue/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.
40 changes: 40 additions & 0 deletions examples/vue/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/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')
22 changes: 22 additions & 0 deletions examples/vue/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '@testing-library/jest-dom/extend-expect';
import { jestPreviewConfigure } from 'jest-preview';

jestPreviewConfigure({
autoPreview: true,
});

window.matchMedia = (query) => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
addListener: jest.fn(),
removeListener: jest.fn(),
});

Object.defineProperty(URL, 'createObjectURL', {
writable: true,
value: jest.fn(),
});
7 changes: 7 additions & 0 deletions examples/vue/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()]
})
7 changes: 7 additions & 0 deletions website/docs/examples/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_position: 6
---

# Vue

See more at [Vue Example](https://github.com/nvh95/jest-preview/tree/main/examples/vue)