vitest 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)
4
4
 
5
- A blazing fast test runner powered by Vite.
5
+ A blazing fast unit test framework powered by Vite.
6
6
 
7
7
  ## Features
8
8
 
@@ -155,8 +155,8 @@ describe('suite', () => {
155
155
  - [x] Task filter
156
156
  - [x] Mock
157
157
  - [x] Global Mode & Types
158
- - [ ] Parallel Executing
159
- - [ ] CLI Help (Use yargs)
158
+ - [ ] Concurrent Executing
159
+ - [x] CLI Help
160
160
  - [x] JSDom
161
161
  - [x] Watch
162
162
  - [ ] Source Map
package/bin/vitest.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
3
 
4
- import '../dist/entry.js'
4
+ import '../dist/cli.js'
package/dist/cli.d.ts CHANGED
@@ -1 +1,10 @@
1
- export {};
1
+ import type { UserOptions } from './types';
2
+ declare global {
3
+ namespace NodeJS {
4
+ interface Process {
5
+ __vitest__: {
6
+ options: Required<UserOptions>;
7
+ };
8
+ }
9
+ }
10
+ }
package/dist/cli.js CHANGED
@@ -1,29 +1,56 @@
1
- import minimist from 'minimist';
2
- import c from 'picocolors';
3
- import { run } from './run';
4
- const { log } = console;
5
- const argv = minimist(process.argv.slice(2), {
6
- alias: {
7
- u: 'update',
8
- w: 'watch',
9
- },
10
- string: ['root', 'config'],
11
- boolean: ['update', 'dev', 'global', 'watch', 'jsdom'],
12
- unknown(name) {
13
- if (name[0] === '-') {
14
- console.error(c.red(`Unknown argument: ${name}`));
15
- help();
16
- process.exit(1);
17
- }
18
- return true;
19
- },
20
- });
21
- if (!process.__vite_node__)
22
- throw new Error('Vite can only run in Vite environment, please use the CLI to start the process');
23
- const server = process.__vite_node__.server;
24
- const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
25
- const testOptions = viteConfig.test || {};
26
- await run(Object.assign(Object.assign(Object.assign({}, argv), testOptions), { server, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
27
- function help() {
28
- log('Help: finish help');
29
- }
1
+ import { fileURLToPath } from 'url';
2
+ import { resolve, dirname } from 'path';
3
+ import { findUp } from 'find-up';
4
+ import sade from 'sade';
5
+ import { run as startViteNode } from './node/index.js';
6
+ // TODO: use bundler
7
+ const version = '0.0.0';
8
+ sade('vitest [filter]', true)
9
+ .version(version)
10
+ .describe('A blazing fast unit test framework powered by Vite.')
11
+ .option('-r, --root', 'root path', process.cwd())
12
+ .option('-c, --config', 'path to config file')
13
+ .option('-w, --watch', 'watch mode', false)
14
+ .option('-u, --update', 'update snapshot', false)
15
+ .option('--global', 'inject apis globally', false)
16
+ .option('--dev', 'dev mode', false)
17
+ .option('--jsdom', 'mock browser api using JSDOM', false)
18
+ .action(async (filters, options) => {
19
+ process.env.VITEST = 'true';
20
+ const __dirname = dirname(fileURLToPath(import.meta.url));
21
+ const root = resolve(options.root || process.cwd());
22
+ const configPath = options.config
23
+ ? resolve(root, options.config)
24
+ : await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
25
+ options.config = configPath;
26
+ options.root = root;
27
+ options.filters = filters
28
+ ? Array.isArray(filters)
29
+ ? filters
30
+ : [filters]
31
+ : undefined;
32
+ process.__vitest__ = {
33
+ options,
34
+ };
35
+ await startViteNode({
36
+ root,
37
+ files: [
38
+ resolve(__dirname, options.dev ? '../src/entry.ts' : './entry.js'),
39
+ ],
40
+ config: configPath,
41
+ defaultConfig: {
42
+ optimizeDeps: {
43
+ exclude: [
44
+ 'vitest',
45
+ ],
46
+ },
47
+ },
48
+ shouldExternalize(id) {
49
+ if (id.includes('/node_modules/vitest/'))
50
+ return false;
51
+ else
52
+ return id.includes('/node_modules/');
53
+ },
54
+ });
55
+ })
56
+ .parse(process.argv);
package/dist/entry.js CHANGED
@@ -1,38 +1,6 @@
1
- import { fileURLToPath } from 'url';
2
- import { resolve, dirname } from 'path';
3
- import minimist from 'minimist';
4
- import { findUp } from 'find-up';
5
- import { run } from './node/index.js';
6
- process.env.VITEST = 'true';
7
- const argv = minimist(process.argv.slice(2), {
8
- alias: {
9
- c: 'config',
10
- },
11
- string: ['root', 'config'],
12
- boolean: ['dev'],
13
- });
14
- const __dirname = dirname(fileURLToPath(import.meta.url));
15
- const root = resolve(argv.root || process.cwd());
16
- const configPath = argv.config
17
- ? resolve(root, argv.config)
18
- : await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
19
- await run({
20
- root,
21
- files: [
22
- resolve(__dirname, argv.dev ? '../src/cli.ts' : './cli.js'),
23
- ],
24
- config: configPath,
25
- defaultConfig: {
26
- optimizeDeps: {
27
- exclude: [
28
- 'vitest',
29
- ],
30
- },
31
- },
32
- shouldExternalize(id) {
33
- if (id.includes('/node_modules/vitest/'))
34
- return false;
35
- else
36
- return id.includes('/node_modules/');
37
- },
38
- });
1
+ import { run } from './run';
2
+ if (!process.__vite_node__ || !process.__vitest__)
3
+ throw new Error('Vitest can only run in vite-node environment, please use the CLI to start the process');
4
+ const inlineOptions = process.__vite_node__.server.config.test || {};
5
+ const cliOptions = process.__vitest__.options || {};
6
+ await run(Object.assign(Object.assign({}, inlineOptions), cliOptions));
@@ -1,2 +1,2 @@
1
- import { Config } from 'vitest';
2
- export declare function setupChai(config: Config): Promise<void>;
1
+ import { ResolvedConfig } from 'vitest';
2
+ export declare function setupChai(config: ResolvedConfig): Promise<void>;
@@ -5,8 +5,5 @@ import { SnapshotPlugin } from './snapshot';
5
5
  export async function setupChai(config) {
6
6
  chai.use(SinonChai);
7
7
  chai.use(JestChaiExpect());
8
- chai.use(await SnapshotPlugin({
9
- rootDir: config.rootDir || process.cwd(),
10
- update: config.updateSnapshot,
11
- }));
8
+ chai.use(await SnapshotPlugin(config));
12
9
  }
@@ -1,7 +1,7 @@
1
1
  import { ChaiPlugin } from '../types';
2
2
  import { SnapshotManager } from './manager';
3
3
  export interface SnapshotOptions {
4
- rootDir: string;
4
+ root: string;
5
5
  update?: boolean;
6
6
  }
7
7
  export declare function getSnapshotManager(): SnapshotManager;
@@ -6,7 +6,7 @@ export function getSnapshotManager() {
6
6
  return _manager;
7
7
  }
8
8
  export async function SnapshotPlugin(options) {
9
- const { rootDir } = options;
9
+ const { root: rootDir } = options;
10
10
  _manager = new SnapshotManager({
11
11
  rootDir,
12
12
  update: options.update,
@@ -1,8 +1,8 @@
1
- import { File, Config, Task, RunnerContext, Suite } from '../types';
1
+ import { File, ResolvedConfig, Task, RunnerContext, Suite } from '../types';
2
2
  export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
3
3
  export declare function collectFiles(paths: string[]): Promise<Record<string, File>>;
4
4
  export declare function runSite(suite: Suite, ctx: RunnerContext): Promise<void>;
5
5
  export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
6
6
  export declare function runFiles(filesMap: Record<string, File>, ctx: RunnerContext): Promise<void>;
7
- export declare function run(config: Config): Promise<void>;
7
+ export declare function run(config: ResolvedConfig): Promise<void>;
8
8
  export declare function startWatcher(ctx: RunnerContext): Promise<void>;
package/dist/run/index.js CHANGED
@@ -143,12 +143,12 @@ export async function run(config) {
143
143
  // collect files
144
144
  let testFilepaths = await fg(config.includes || defaultIncludes, {
145
145
  absolute: true,
146
- cwd: config.rootDir,
146
+ cwd: config.root,
147
147
  ignore: config.excludes || defaultExcludes,
148
148
  });
149
149
  // if name filters are provided by the CLI
150
- if ((_a = config.nameFilters) === null || _a === void 0 ? void 0 : _a.length)
151
- testFilepaths = testFilepaths.filter(i => config.nameFilters.some(f => i.includes(f)));
150
+ if ((_a = config.filters) === null || _a === void 0 ? void 0 : _a.length)
151
+ testFilepaths = testFilepaths.filter(i => config.filters.some(f => i.includes(f)));
152
152
  if (!testFilepaths.length) {
153
153
  console.error('No test files found');
154
154
  process.exitCode = 1;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { ViteDevServer } from 'vite';
2
1
  export declare type Awaitable<T> = Promise<T> | T;
3
2
  export interface UserOptions {
4
3
  includes?: string[];
@@ -21,13 +20,22 @@ export interface UserOptions {
21
20
  * @default false
22
21
  */
23
22
  parallel?: boolean;
24
- }
25
- export interface Config extends UserOptions {
26
- rootDir?: string;
27
- updateSnapshot?: boolean;
28
- nameFilters?: string[];
29
- server: ViteDevServer;
23
+ /**
24
+ * Update snapshot files
25
+ *
26
+ * @default false
27
+ */
28
+ update?: boolean;
29
+ /**
30
+ * Watch mode
31
+ *
32
+ * @default false
33
+ */
30
34
  watch?: boolean;
35
+ root?: string;
36
+ }
37
+ export interface ResolvedConfig extends Required<UserOptions> {
38
+ filters?: string[];
31
39
  }
32
40
  export declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
33
41
  export declare type TaskState = RunMode | 'pass' | 'fail';
@@ -82,7 +90,7 @@ export interface RunnerContext {
82
90
  files: File[];
83
91
  suites: Suite[];
84
92
  tasks: Task[];
85
- config: Config;
93
+ config: ResolvedConfig;
86
94
  reporter: Reporter;
87
95
  }
88
96
  export interface GlobalContext {
@@ -90,7 +98,7 @@ export interface GlobalContext {
90
98
  currentSuite: SuiteCollector | null;
91
99
  }
92
100
  export interface Reporter {
93
- onStart?: (userOptions: Config) => Awaitable<void>;
101
+ onStart?: (userOptions: ResolvedConfig) => Awaitable<void>;
94
102
  onCollected?: (files: File[], ctx: RunnerContext) => Awaitable<void>;
95
103
  onFinished?: (ctx: RunnerContext) => Awaitable<void>;
96
104
  onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.22",
4
- "description": "",
5
- "keywords": [],
3
+ "version": "0.0.23",
4
+ "description": "A blazing fast unit test framework powered by Vite",
5
+ "keywords": [
6
+ "vite",
7
+ "vite-node",
8
+ "test",
9
+ "jest"
10
+ ],
6
11
  "homepage": "https://github.com/antfu/vitest#readme",
7
12
  "bugs": {
8
13
  "url": "https://github.com/antfu/vitest/issues"
@@ -44,9 +49,8 @@
44
49
  "jest-util": "^27.4.2",
45
50
  "jsdom": "^19.0.0",
46
51
  "listr": "^0.14.3",
47
- "minimist": "^1.2.5",
48
- "ora": "^6.0.1",
49
52
  "picocolors": "^1.0.0",
53
+ "sade": "^1.7.4",
50
54
  "sinon": "^12.0.1",
51
55
  "sinon-chai": "^3.7.0"
52
56
  },
@@ -55,8 +59,8 @@
55
59
  "@antfu/ni": "^0.11.0",
56
60
  "@types/jsdom": "^16.2.13",
57
61
  "@types/listr": "^0.14.4",
58
- "@types/minimist": "^1.2.2",
59
62
  "@types/node": "^16.11.11",
63
+ "@types/sade": "^1.7.3",
60
64
  "@types/sinon": "^10.0.6",
61
65
  "bumpp": "^7.1.1",
62
66
  "eslint": "^8.3.0",