jest2vitest
Advanced tools
Comparing version 0.0.2 to 0.0.3
# jest2vitest | ||
## 0.0.3 | ||
### Patch Changes | ||
- 80f0724: Handle it.each and test.each | ||
## 0.0.2 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7112
89