Socket
Socket
Sign inDemoInstall

vitest

Package Overview
Dependencies
13
Maintainers
1
Versions
357
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.12 to 0.0.13

dist/cli-entry.d.ts

9

dist/chai.d.ts

@@ -0,1 +1,3 @@

import { Config } from 'vitest';
export declare function setupChai(config: Config): Promise<void>;
export { assert, should, expect } from 'chai';

@@ -7,2 +9,9 @@ declare global {

matchSnapshot(message?: string): Assertion;
toEqual(expected: any): void;
toStrictEqual(expected: any): void;
toContain(item: any): void;
toBeNaN(): void;
toBeUndefined(): void;
toBeNull(): void;
toBeDefined(): void;
}

@@ -9,0 +18,0 @@ interface ExpectStatic {

@@ -0,1 +1,37 @@

import chai from 'chai';
import SinonChai from 'sinon-chai';
import { SnapshotPlugin } from './snapshot';
export async function setupChai(config) {
chai.use(SinonChai);
chai.use(await SnapshotPlugin({
rootDir: config.rootDir || process.cwd(),
update: config.updateSnapshot,
}));
// Jest Compact
// TODO: add more https://jestjs.io/docs/expect
chai.use((chai, utils) => {
const proto = chai.Assertion.prototype;
utils.addMethod(proto, 'toEqual', function (expected) {
return this.eql(expected);
});
utils.addMethod(proto, 'toStrictEqual', function (expected) {
return this.equal(expected);
});
utils.addMethod(proto, 'toContain', function (item) {
return this.contain(item);
});
utils.addMethod(proto, 'toBeNaN', function () {
return this.be.NaN;
});
utils.addMethod(proto, 'toBeUndefined', function () {
return this.be.undefined;
});
utils.addMethod(proto, 'toBeNull', function () {
return this.be.null;
});
utils.addMethod(proto, 'toBeDefined', function () {
return this.not.be.undefined;
});
});
}
export { assert, should, expect } from 'chai';

50

dist/cli.js

@@ -1,28 +0,36 @@

var _a;
import { fileURLToPath } from 'url';
import { resolve, dirname } from 'path';
import minimist from 'minimist';
import c from 'picocolors';
import { run } from './run';
const { log } = console;
import { findUp } from 'find-up';
import { run } from './node.js';
process.env.VITEST = 'true';
const argv = minimist(process.argv.slice(2), {
alias: {
u: 'update',
c: 'config',
},
string: ['root', 'config'],
boolean: ['update', 'dev'],
unknown(name) {
if (name[0] === '-') {
console.error(c.red(`Unknown argument: ${name}`));
help();
process.exit(1);
}
return true;
boolean: ['dev'],
});
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(argv.root || process.cwd());
const configPath = argv.config ? resolve(root, argv.config) : await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
await run({
root,
files: [
resolve(__dirname, argv.dev ? '../src/cli-entry.ts' : './cli-entry.js'),
],
config: configPath,
defaultConfig: {
optimizeDeps: {
exclude: [
'vitest',
],
},
},
shouldExternalize(id) {
if (id.includes('/node_modules/vitest/'))
return false;
else
return id.includes('/node_modules/');
},
});
// @ts-expect-error
const server = (_a = process === null || process === void 0 ? void 0 : process.__vite_node__) === null || _a === void 0 ? void 0 : _a.server;
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
const testOptions = viteConfig.test || {};
await run(Object.assign(Object.assign({}, testOptions), { server, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
function help() {
log('Help: finish help');
}
export declare const defaultIncludes: string[];
export declare const defaultExcludes: string[];
export declare const globalApis: string[];
export const defaultIncludes = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'];
export const defaultExcludes = ['**/node_modules/**', '**/dist/**'];
export const globalApis = [
'suite',
'test',
'describe',
'it',
'expect',
'assert',
'spy',
'mock',
'stub',
'sinon',
'beforeAll',
'afterAll',
'beforeEach',
'afterEach',
'beforeFile',
'afterFile',
'beforeSuite',
'afterSuite',
];

@@ -1,8 +0,6 @@

import chai from 'chai';
import fg from 'fast-glob';
import SinonChai from 'sinon-chai';
import { setupChai } from './chai';
import { clearContext, defaultSuite } from './suite';
import { context } from './context';
import { afterEachHook, afterFileHook, afterAllHook, afterSuiteHook, beforeEachHook, beforeFileHook, beforeAllHook, beforeSuiteHook } from './hooks';
import { SnapshotPlugin } from './snapshot';
import { DefaultReporter } from './reporters/default';

@@ -97,9 +95,4 @@ import { defaultIncludes, defaultExcludes } from './constants';

var _a, _b, _c, _d;
const { rootDir = process.cwd() } = config;
// setup chai
chai.use(await SnapshotPlugin({
rootDir,
update: config.updateSnapshot,
}));
chai.use(SinonChai);
await setupChai(config);
// collect files

@@ -120,2 +113,4 @@ let paths = await fg(config.includes || defaultIncludes, {

await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
if (config.global)
(await import('./global')).registerApiGlobally();
const files = await collectFiles(paths);

@@ -122,0 +117,0 @@ const ctx = {

@@ -7,2 +7,3 @@ /**

*/
// @ts-ignore
import Test from '@jest/test-result';

@@ -9,0 +10,0 @@ const { makeEmptyAggregatedTestResult, } = Test;

@@ -6,2 +6,8 @@ import { ViteDevServer } from 'vite';

excludes?: string[];
/**
* Register apis globally
*
* @default false
*/
global?: string;
}

@@ -8,0 +14,0 @@ export interface Config extends UserOptions {

{
"name": "vitest",
"version": "0.0.12",
"type": "module",
"version": "0.0.13",
"description": "",

@@ -18,2 +17,3 @@ "keywords": [],

"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"type": "module",
"exports": {

@@ -29,21 +29,10 @@ ".": {

"types": "./dist/index.d.ts",
"bin": {
"vitest": "./bin/vitest.mjs"
},
"files": [
"dist",
"bin"
"bin",
"*.d.ts"
],
"bin": {
"vitest": "./bin/vitest.mjs"
},
"devDependencies": {
"@antfu/eslint-config": "^0.11.1",
"@antfu/ni": "^0.11.0",
"@types/minimist": "^1.2.2",
"@types/node": "^16.11.11",
"@types/sinon": "^10.0.6",
"bumpp": "^7.1.1",
"eslint": "^8.3.0",
"esno": "^0.12.1",
"typescript": "^4.5.2",
"vite": "^2.6.14"
},
"dependencies": {

@@ -62,13 +51,25 @@ "@jest/test-result": "^27.4.2",

"sinon": "^12.0.1",
"sinon-chai": "^3.7.0",
"vite-node": "^0.1.10"
"sinon-chai": "^3.7.0"
},
"devDependencies": {
"@antfu/eslint-config": "^0.11.1",
"@antfu/ni": "^0.11.0",
"@types/minimist": "^1.2.2",
"@types/node": "^16.11.11",
"@types/sinon": "^10.0.6",
"bumpp": "^7.1.1",
"eslint": "^8.3.0",
"esno": "^0.12.1",
"rimraf": "^3.0.2",
"typescript": "^4.5.2",
"vite": "^2.6.14"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"build": "rimraf dist && tsc -p src/tsconfig.json",
"lint": "eslint \"{src,test}/**/*.ts\"",
"release": "bumpp --commit --push --tag && pnpm publish",
"test": "node bin/vitest.mjs --dev",
"test:update": "nr test -u"
"test:update": "nr test -u",
"watch": "tsc -p src/tsconfig.json --watch"
}
}

@@ -61,2 +61,30 @@ # vitest

## Global APIs
By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--global` option to CLI or add `global: true` in the config.
```ts
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
test: {
global: true
}
})
```
To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
```json
// tsconfig.json
{
"compilerOptions": {
"types": [
"vitest/global"
]
}
}
```
## Filtering

@@ -128,3 +156,3 @@

- [x] Mock
- [ ] Global Mode & Types
- [x] Global Mode & Types
- [ ] Parallel Executing

@@ -131,0 +159,0 @@ - [ ] CLI Help

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc