Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest2vitest

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest2vitest - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

6

CHANGELOG.md
# jest2vitest
## 0.0.3
### Patch Changes
- 80f0724: Handle it.each and test.each
## 0.0.2

@@ -4,0 +10,0 @@

2

package.json
{
"name": "jest2vitest",
"version": "0.0.2",
"version": "0.0.3",
"description": "Migrate from Jest to Vitest (mostly)",

@@ -5,0 +5,0 @@ "author": "Eddy Nguyen <ch@eddeee888.me>",

@@ -20,3 +20,3 @@ "use strict";

project.getSourceFiles().forEach((sourceFile) => {
const functionsToImportFromVitestMap = {};
const importsFromVitestMap = {};
// Clean up all `import {...} from 'vitest'` for idempotency

@@ -34,6 +34,5 @@ sourceFile.getImportDeclarations().forEach((importDeclaration) => {

if (testBasicImports[expressionName]) {
functionsToImportFromVitestMap[expressionName] = true;
importsFromVitestMap[expressionName] = true;
}
});
// Replace jest.something with vi.something
sourceFile

@@ -45,10 +44,23 @@ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)

.asKind(ts_morph_1.SyntaxKind.Identifier);
// Replace jest.something/vi.something with vi.something
if (identifier && ['jest', 'vi'].includes(identifier.getText())) {
functionsToImportFromVitestMap['vi'] = true;
importsFromVitestMap['vi'] = true;
identifier.replaceWithText('vi');
}
// If there's `it.each` or `test.each`, import `it` or `test`
switch (node.getText()) {
case 'it.each':
importsFromVitestMap['it'] = true;
break;
case 'test.each':
importsFromVitestMap['test'] = true;
break;
default:
break;
}
});
const functionsToImportFromVitest = Object.keys(functionsToImportFromVitestMap);
if (functionsToImportFromVitest.length > 0) {
sourceFile.insertStatements(0, `import { ${functionsToImportFromVitest.join(', ')} } from 'vitest';`);
// Import required functions
const importsFromVitest = Object.keys(importsFromVitestMap);
if (importsFromVitest.length > 0) {
sourceFile.insertStatements(0, `import { ${importsFromVitest.join(', ')} } from 'vitest';`);
sourceFile.saveSync();

@@ -55,0 +67,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc