Skip to content

Commit 61133cc

Browse files
committed
feature: @putout/plugin-vitest: add
1 parent cc85d7c commit 61133cc

23 files changed

+419
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@ Next packages not bundled with 🐊**Putout** but can be installed separately.
22952295
| [`@putout/plugin-cloudcmd`](/packages/plugin-cloudcmd#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-cloudcmd.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-cloudcmd) |
22962296
| [`@putout/plugin-postcss`](/packages/plugin-postcss#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-postcss.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-postcss) |
22972297
| [`@putout/plugin-jest`](/packages/plugin-jest#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-jest.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-jest) |
2298+
| [`@putout/plugin-vitest`](/packages/plugin-vitest#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-vitest.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-vitest) |
22982299
| [`@putout/plugin-travis`](/packages/plugin-travis#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-travis.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-travis) |
22992300
| [`@putout/plugin-convert-throw`](/packages/plugin-convert-throw#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-convert-throw.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-convert-throw) |
23002301
| [`@putout/plugin-printer`](/packages/plugin-printer#readme) | [![npm](https://img.shields.io/npm/v/@putout/plugin-printer.svg?maxAge=86400)](https://www.npmjs.com/package/@putout/plugin-printer) |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:n/recommended",
4+
"plugin:putout/recommended"
5+
],
6+
"plugins": [
7+
"n",
8+
"putout"
9+
]
10+
}

packages/plugin-vitest/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*.swp
3+
yarn-error.log
4+
5+
coverage
6+
.idea

packages/plugin-vitest/.madrun.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {run} from 'madrun';
2+
3+
export default {
4+
'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`,
5+
'watch:test': async () => `nodemon -w lib -x ${await run('test')}`,
6+
'lint': () => `putout .`,
7+
'fresh:lint': () => run('lint', '--fresh'),
8+
'lint:fresh': () => run('lint', '--fresh'),
9+
'fix:lint': () => run('lint', '--fix'),
10+
'coverage': async () => `c8 ${await run('test')}`,
11+
'report': () => 'c8 report --reporter=lcov',
12+
};

packages/plugin-vitest/.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.*
2+
*.spec.js
3+
test
4+
fixture
5+
yarn-error.log
6+
7+
coverage
8+
*.config.*

packages/plugin-vitest/.nycrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"check-coverage": true,
3+
"all": true,
4+
"exclude": [
5+
"**/*.spec.*",
6+
"**/fixture",
7+
"test",
8+
".*.*",
9+
"**/*.config.*"
10+
],
11+
"branches": 100,
12+
"lines": 100,
13+
"functions": 100,
14+
"statements": 100
15+
}

packages/plugin-vitest/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/plugin-vitest/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# @putout/plugin-vitest [![NPM version][NPMIMGURL]][NPMURL]
2+
3+
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-vitest.svg?style=flat&longCache=true
4+
[NPMURL]: https://npmjs.org/package/@putout/plugin-vitest "npm"
5+
6+
> A Vite-native testing framework. It's fast!
7+
>
8+
> (c) [vitest.dev](https://vitest.dev/)
9+
10+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin helps to migrate to [migrate to latest version of vitest](https://vitest.dev/guide/migration.html#migration-guide).
11+
12+
## Install
13+
14+
```
15+
npm i @putout/plugin-vitest -D
16+
```
17+
18+
## Rules
19+
20+
-[v3-apply-options-as-second-argument](#v3-apply-options-as-second-argument);
21+
-[v3-apply-browser-instances](#v3-apply-browser-instances);
22+
23+
## Config
24+
25+
```json
26+
{
27+
"rules": {
28+
"vitest": "on"
29+
}
30+
}
31+
```
32+
33+
## v3-apply-options-as-second-argument
34+
35+
> Vitest 3.0 prints a warning if you pass down an object as a third argument to test or describe functions.
36+
> Vitest 4.0 will throw an error if the third argument is an object.
37+
>
38+
> (c) [vitest.dev](https://vitest.dev/guide/migration.html#test-options-as-a-third-argument)
39+
40+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/908b58a6478a26c5ef14c5ee793bf59e/31712984095bcf59ccf9a1a2619e1a1c19f69891).
41+
42+
### ❌ Example of incorrect code
43+
44+
```js
45+
test('validation works', () => {
46+
// ...
47+
}, {
48+
retry: 3,
49+
});
50+
```
51+
52+
### ✅ Example of correct code
53+
54+
```js
55+
test('validation works', {retry: 3}, () => {
56+
// ...
57+
});
58+
```
59+
60+
## v3-apply-browser-instances
61+
62+
> Both `browser.name` and `browser.providerOptions` will be removed in Vitest 4. Instead of them, use the new `browser.instances` option.
63+
>
64+
> (c) [vitest.dev](https://vitest.dev/guide/migration.html#test-options-as-a-third-argument)
65+
66+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1ffbaec363b8094137bb02f561ce2bd2/a3563e8c8ae9b18733d369f5669402e2da59d542).
67+
68+
### ❌ Example of incorrect code
69+
70+
```js
71+
export default defineConfig({
72+
test: {
73+
browser: {
74+
name: 'chromium',
75+
providerOptions: {
76+
launch: {
77+
devtools: true,
78+
},
79+
},
80+
},
81+
},
82+
});
83+
```
84+
85+
### ✅ Example of correct code
86+
87+
```js
88+
export default defineConfig({
89+
test: {
90+
browser: {
91+
instances: [{
92+
name: 'chromium',
93+
providerOptions: {
94+
launch: {
95+
devtools: true,
96+
},
97+
},
98+
}],
99+
},
100+
},
101+
});
102+
```
103+
104+
## License
105+
106+
MIT
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const v3ApplyOptionsAsSecondArgument = require('./v3-apply-options-as-second-argument');
4+
const v3ApplyBrowserInstances = require('./v3-apply-browser-instances');
5+
6+
module.exports.rules = {
7+
'v3-apply-options-as-second-argument': v3ApplyOptionsAsSecondArgument,
8+
'v3-apply-browser-instances': v3ApplyBrowserInstances,
9+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default defineConfig({
2+
test: {
3+
browser: {
4+
instances: [{
5+
instances: [{
6+
name: 'chromium',
7+
providerOptions: {
8+
launch: {
9+
devtools: true,
10+
},
11+
},
12+
}],
13+
}],
14+
},
15+
},
16+
});

0 commit comments

Comments
 (0)