Skip to content

Commit

Permalink
feat: added the vitest configs
Browse files Browse the repository at this point in the history
  • Loading branch information
gokh4nozturk authored and Gökhan Öztürk committed Aug 18, 2022
1 parent b8088e7 commit bcadd19
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 26 deletions.
6 changes: 6 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent<{}, {}, any>;
export default component;
}
3 changes: 1 addition & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import HelloWorld from '../src/components/HelloWorld.vue';
import Button from '../src/components/Button/Button.vue';

export { HelloWorld, Button };
export { Button };
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dev": "vite",
"build": "run-p type-check build-only",
"preview": "vite preview --port 4173",
"test:unit": "vitest --environment jsdom",
"test:unit": "vitest",
"test:coverage": "vitest run --coverage",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
Expand All @@ -42,10 +43,11 @@
"@storybook/vue3": "^6.5.10",
"@types/jsdom": "^20.0.0",
"@types/node": "^16.11.48",
"@vitejs/plugin-vue": "^3.0.1",
"@vitejs/plugin-vue": "^3.0.3",
"@vitest/coverage-c8": "^0.22.1",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"@vue/test-utils": "^2.0.2",
"@vue/test-utils": "^2.0.0",
"@vue/tsconfig": "^0.1.3",
"autoprefixer": "^10.4.8",
"babel-loader": "^8.2.5",
Expand All @@ -62,8 +64,8 @@
"prettier": "^2.7.1",
"tailwindcss": "^3.1.8",
"typescript": "~4.7.4",
"vite": "^3.0.4",
"vitest": "^0.21.0",
"vite": "^3.0.8",
"vitest": "^0.22.1",
"vue-loader": "^16.8.3",
"vue-tsc": "^0.39.5"
},
Expand Down
11 changes: 11 additions & 0 deletions src/components/Button/Button.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, it, expect } from 'vitest';

import { mount } from '@vue/test-utils';
import Button from './Button.vue';

describe('Button', () => {
it('renders properly', () => {
const wrapper = mount(Button, { props: { label: 'Hello Vitest' } });
expect(wrapper.text()).toContain('Hello Vitest');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MyButton from './Button.vue';
import type { Meta, StoryFn } from '@storybook/vue3';

// More on default export: https://storybook.js.org/docs/vue/writing-stories/introduction#default-export
export default {
Expand All @@ -22,22 +23,17 @@ export default {
icon: { control: 'text' },
onClick: {},
},
};
} as Meta<typeof MyButton>;

// More on component templates: https://storybook.js.org/docs/vue/writing-stories/introduction#using-args
const Template = (args) => ({
// Components used in your story `template` are defined in the `components` object
const Template: StoryFn<typeof MyButton> = (args) => ({
components: { MyButton },
// The story's `args` need to be mapped into the template through the `setup()` method
setup() {
return { args };
},
// And then the `args` are bound to your component with `v-bind="args"`
template: '<my-button v-bind="args" />',
});

export const Primary = Template.bind({});
// More on args: https://storybook.js.org/docs/vue/writing-stories/args
Primary.args = {
role: 'primary',
label: 'Primary Button',
Expand Down
11 changes: 0 additions & 11 deletions src/components/__tests__/HelloWorld.spec.ts

This file was deleted.

9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
{
"path": "./tsconfig.vitest.json"
}
]
],
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
"types": ["vitest/globals"]
}
}
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ export default defineConfig({
},
},
},
test: {
collectCoverage: true,
},
});
12 changes: 12 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import Vue from '@vitejs/plugin-vue';

export default defineConfig({
plugins: [Vue()],
test: {
globals: true,
environment: 'jsdom',
},
});

0 comments on commit bcadd19

Please sign in to comment.