Primeiro commit do projeto Angular

This commit is contained in:
2026-03-14 20:41:55 +00:00
parent 9bebe1de72
commit 94f4f46395
22413 changed files with 3221690 additions and 0 deletions
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
export declare function addVitestValueImport(imports: Set<string>, importName: string): void;
export declare function addVitestTypeImport(imports: Set<string>, importName: string): void;
export declare function getVitestAutoImports(valueImports: Set<string>, typeImports: Set<string>): ts.ImportDeclaration | undefined;
export declare function createViCallExpression(methodName: string, args?: readonly ts.Expression[], typeArgs?: ts.TypeNode[] | undefined): ts.CallExpression;
export declare function createExpectCallExpression(args: ts.Expression[], typeArgs?: ts.TypeNode[] | undefined): ts.CallExpression;
export declare function createPropertyAccess(expressionOrIndentifierText: ts.Expression | string, name: string | ts.MemberName): ts.PropertyAccessExpression;
@@ -0,0 +1,58 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addVitestValueImport = addVitestValueImport;
exports.addVitestTypeImport = addVitestTypeImport;
exports.getVitestAutoImports = getVitestAutoImports;
exports.createViCallExpression = createViCallExpression;
exports.createExpectCallExpression = createExpectCallExpression;
exports.createPropertyAccess = createPropertyAccess;
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
function addVitestValueImport(imports, importName) {
imports.add(importName);
}
function addVitestTypeImport(imports, importName) {
imports.add(importName);
}
function getVitestAutoImports(valueImports, typeImports) {
if (valueImports.size === 0 && typeImports.size === 0) {
return undefined;
}
const isClauseTypeOnly = valueImports.size === 0 && typeImports.size > 0;
const allSpecifiers = [];
// Add value imports
for (const i of [...valueImports].sort()) {
allSpecifiers.push(typescript_1.default.factory.createImportSpecifier(false, undefined, typescript_1.default.factory.createIdentifier(i)));
}
// Add type imports
for (const i of [...typeImports].sort()) {
// Only set isTypeOnly on individual specifiers if the clause itself is NOT type-only
allSpecifiers.push(typescript_1.default.factory.createImportSpecifier(!isClauseTypeOnly, undefined, typescript_1.default.factory.createIdentifier(i)));
}
allSpecifiers.sort((a, b) => a.name.text.localeCompare(b.name.text));
const importClause = typescript_1.default.factory.createImportClause(isClauseTypeOnly, // Set isTypeOnly on the clause if only type imports
undefined, typescript_1.default.factory.createNamedImports(allSpecifiers));
return typescript_1.default.factory.createImportDeclaration(undefined, importClause, typescript_1.default.factory.createStringLiteral('vitest'));
}
function createViCallExpression(methodName, args = [], typeArgs = undefined) {
const callee = typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier('vi'), methodName);
return typescript_1.default.factory.createCallExpression(callee, typeArgs, args);
}
function createExpectCallExpression(args, typeArgs = undefined) {
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier('expect'), typeArgs, args);
}
function createPropertyAccess(expressionOrIndentifierText, name) {
return typescript_1.default.factory.createPropertyAccessExpression(typeof expressionOrIndentifierText === 'string'
? typescript_1.default.factory.createIdentifier(expressionOrIndentifierText)
: expressionOrIndentifierText, name);
}
//# sourceMappingURL=ast-helpers.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["ast-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAIH,oDAEC;AAED,kDAEC;AAED,oDA2CC;AAED,wDAWC;AAED,gEAKC;AAED,oDAUC;AArFD,qHAAqF;AAErF,SAAgB,oBAAoB,CAAC,OAAoB,EAAE,UAAkB;IAC3E,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,mBAAmB,CAAC,OAAoB,EAAE,UAAkB;IAC1E,O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AAkB,CAAC,aAAa,CAAC,CAC7C,CAAC;IAEF,OAAO,oBAAE,CAAC,OAAO,CAAC,uBAAuB,CACvC,SAAS,EACT,YAAY,EACZ,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CACzC,CAAC;AACJ,CAAC;AAED,SAAgB,sBAAsB,CACpC,UAAkB,EAClB,OAAiC,EAAE,EACnC,WAAsC,SAAS;IAE/C,MAAM,MAAM,GAAG,oBAAE,CAAC,OAAO,CAAC,8BAA8B,CACtD,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EACjC,UAAU,CACX,CAAC;IAEF,OAAO,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAAqB,EACrB,WAAsC,SAAS;IAE/C,OAAO,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAChG,CAAC;AAED,SAAgB,oBAAoB,CAClC,2BAAmD,EACnD,IAA4B;IAE5B,OAAO,oBAAE,CAAC,OAAO,CAAC,8BAA8B,CAC9C,OAAO,2BAA2B,KAAK,QAAQ;QAC7C,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,2BAA2B,CAAC;QAC1D,CAAC,CAAC,2BAA2B,EAC/B,IAAI,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* @fileoverview This file contains helper functions for validating the structure of
* TypeScript AST nodes, particularly for identifying specific patterns in Jasmine tests.
*/
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
/**
* If a node is a `jasmine.method()` call, returns the method name.
* @param node The node to check.
* @returns The name of the method if it's a jasmine call, otherwise undefined.
*/
export declare function getJasmineMethodName(node: ts.Node): string | undefined;
/**
* Checks if a node is a call expression for a specific method on the `jasmine` object.
* @param node The node to check.
* @param methodName The name of the method on the `jasmine` object.
* @returns True if the node is a `jasmine.<methodName>()` call.
*/
export declare function isJasmineCallExpression(node: ts.Node, methodName: string): node is ts.CallExpression;
@@ -0,0 +1,44 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getJasmineMethodName = getJasmineMethodName;
exports.isJasmineCallExpression = isJasmineCallExpression;
/**
* @fileoverview This file contains helper functions for validating the structure of
* TypeScript AST nodes, particularly for identifying specific patterns in Jasmine tests.
*/
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
/**
* If a node is a `jasmine.method()` call, returns the method name.
* @param node The node to check.
* @returns The name of the method if it's a jasmine call, otherwise undefined.
*/
function getJasmineMethodName(node) {
if (!typescript_1.default.isCallExpression(node) || !typescript_1.default.isPropertyAccessExpression(node.expression)) {
return undefined;
}
const pae = node.expression;
if (!typescript_1.default.isIdentifier(pae.expression) || pae.expression.text !== 'jasmine') {
return undefined;
}
return typescript_1.default.isIdentifier(pae.name) ? pae.name.text : undefined;
}
/**
* Checks if a node is a call expression for a specific method on the `jasmine` object.
* @param node The node to check.
* @param methodName The name of the method on the `jasmine` object.
* @returns True if the node is a `jasmine.<methodName>()` call.
*/
function isJasmineCallExpression(node, methodName) {
return getJasmineMethodName(node) === methodName;
}
//# sourceMappingURL=ast-validation.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ast-validation.js","sourceRoot":"","sources":["ast-validation.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAcH,oDAWC;AAQD,0DAKC;AApCD;;;GAGG;AAEH,qHAAqF;AAErF;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAAa;IAChD,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAClF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;IAC5B,IAAI,CAAC,oBAAE,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC1E,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,oBAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,IAAa,EACb,UAAkB;IAElB,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC;AACnD,CAAC"}
@@ -0,0 +1,29 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { TodoCategory, TodoContextMap } from './todo-notes';
type CategoriesWithNoContext = {
[K in TodoCategory]: TodoContextMap[K] extends never ? K : never;
}[TodoCategory];
/**
* Adds a TODO comment to a TypeScript node for manual migration.
* This overload handles categories that do not require a context object.
* @param node The AST node to which the comment will be added.
* @param category The category of the TODO, used to look up the message and URL.
*/
export declare function addTodoComment<T extends CategoriesWithNoContext>(node: ts.Node, category: T): void;
/**
* Adds a TODO comment to a TypeScript node for manual migration.
* This overload handles categories that require a context object, ensuring it is
* provided and correctly typed.
* @param node The AST node to which the comment will be added.
* @param category The category of the TODO, used to look up the message and URL.
* @param context The context object providing dynamic values for the message.
*/
export declare function addTodoComment<T extends TodoCategory>(node: ts.Node, category: T, context: TodoContextMap[T]): void;
export {};
@@ -0,0 +1,37 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addTodoComment = addTodoComment;
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
const todo_notes_1 = require("./todo-notes");
// Implementation that covers both overloads.
function addTodoComment(node, category, context) {
const note = todo_notes_1.TODO_NOTES[category];
// The type assertion is safe here because the overloads guarantee the correct context is passed.
const message = typeof note.message === 'function' ? note.message(context) : note.message;
const url = 'url' in note && note.url ? ` See: ${note.url}` : '';
const commentText = ` TODO: vitest-migration: ${message}${url}`;
let statement = node;
// Traverse up the AST to find the containing statement for the node.
// This ensures that the comment is placed before the entire statement,
// rather than being attached to a deeply nested node. For example, if the
// node is an `Identifier`, we want the comment on the `VariableStatement`
// or `ExpressionStatement` that contains it.
while (statement.parent && !typescript_1.default.isBlock(statement.parent) && !typescript_1.default.isSourceFile(statement.parent)) {
if (typescript_1.default.isExpressionStatement(statement) || typescript_1.default.isVariableStatement(statement)) {
break;
}
statement = statement.parent;
}
typescript_1.default.addSyntheticLeadingComment(statement, typescript_1.default.SyntaxKind.SingleLineCommentTrivia, commentText, true);
}
//# sourceMappingURL=comment-helpers.js.map
@@ -0,0 +1 @@
{"version":3,"file":"comment-helpers.js","sourceRoot":"","sources":["comment-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAiCH,wCAgCC;AA/DD,qHAAqF;AACrF,6CAAwE;AA6BxE,6CAA6C;AAC7C,SAAgB,cAAc,CAC5B,IAAa,EACb,QAAsB,EACtB,OAAiC;IAEjC,MAAM,IAAI,GAAG,uBAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,iGAAiG;IACjG,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IACrF,MAAM,GAAG,GAAG,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,MAAM,WAAW,GAAG,4BAA4B,OAAO,GAAG,GAAG,EAAE,CAAC;IAEhE,IAAI,SAAS,GAAY,IAAI,CAAC;IAE9B,qEAAqE;IACrE,uEAAuE;IACvE,0EAA0E;IAC1E,0EAA0E;IAC1E,6CAA6C;IAC7C,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC,oBAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAE,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/F,IAAI,oBAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,oBAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7E,MAAM;QACR,CAAC;QACD,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,oBAAE,CAAC,0BAA0B,CAC3B,SAAS,EACT,oBAAE,CAAC,UAAU,CAAC,uBAAuB,EACrC,WAAW,EACX,IAAI,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { RefactorReporter } from './refactor-reporter';
/**
* A context object that provides access to shared utilities and state
* throughout the transformation process.
*/
export interface RefactorContext {
/** The root ts.SourceFile node of the file being transformed. */
readonly sourceFile: ts.SourceFile;
/** The reporter for logging changes and TODOs. */
readonly reporter: RefactorReporter;
/** The official context from the TypeScript Transformer API. */
readonly tsContext: ts.TransformationContext;
/** A set of Vitest value imports to be added to the file. */
readonly pendingVitestValueImports: Set<string>;
/** A set of Vitest type imports to be added to the file. */
readonly pendingVitestTypeImports: Set<string>;
}
/**
* A generic transformer function that operates on a specific type of ts.Node.
* @template T The specific type of AST node this transformer works on (e.g., ts.CallExpression).
*/
export type NodeTransformer<T extends ts.Node> = (node: T, refactorCtx: RefactorContext) => ts.Node | readonly ts.Node[];
@@ -0,0 +1,10 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=refactor-context.js.map
@@ -0,0 +1 @@
{"version":3,"file":"refactor-context.js","sourceRoot":"","sources":["refactor-context.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
@@ -0,0 +1,28 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { TodoCategory } from './todo-notes';
export declare class RefactorReporter {
private logger;
private filesScanned;
private filesTransformed;
private readonly todos;
private readonly verboseLogs;
private readonly fileTodos;
constructor(logger: {
info(message: string): void;
warn(message: string): void;
});
get hasTodos(): boolean;
incrementScannedFiles(): void;
incrementTransformedFiles(): void;
recordTodo(category: TodoCategory, sourceFile: ts.SourceFile, node: ts.Node): void;
reportTransformation(sourceFile: ts.SourceFile, node: ts.Node, message: string): void;
generateReportContent(): string;
printSummary(verbose?: boolean): void;
}
@@ -0,0 +1,142 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RefactorReporter = void 0;
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
class RefactorReporter {
logger;
filesScanned = 0;
filesTransformed = 0;
todos = new Map();
verboseLogs = new Map();
fileTodos = new Map();
constructor(logger) {
this.logger = logger;
}
get hasTodos() {
return this.todos.size > 0;
}
incrementScannedFiles() {
this.filesScanned++;
}
incrementTransformedFiles() {
this.filesTransformed++;
}
recordTodo(category, sourceFile, node) {
this.todos.set(category, (this.todos.get(category) ?? 0) + 1);
const { line } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, typescript_1.default.getOriginalNode(node).getStart(sourceFile));
const filePath = sourceFile.fileName;
let fileTodos = this.fileTodos.get(filePath);
if (!fileTodos) {
fileTodos = [];
this.fileTodos.set(filePath, fileTodos);
}
fileTodos.push({ category, line: line + 1 });
}
reportTransformation(sourceFile, node, message) {
const { line } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, typescript_1.default.getOriginalNode(node).getStart(sourceFile));
const filePath = sourceFile.fileName;
let logs = this.verboseLogs.get(filePath);
if (!logs) {
logs = [];
this.verboseLogs.set(filePath, logs);
}
logs.push(`L${line + 1}: ${message}`);
}
generateReportContent() {
const lines = [];
lines.push('# Jasmine to Vitest Refactoring Report');
lines.push('');
lines.push(`Date: ${new Date().toISOString()}`);
lines.push('');
const summaryEntries = [
{ label: 'Files Scanned', value: this.filesScanned },
{ label: 'Files Transformed', value: this.filesTransformed },
{ label: 'Files Skipped', value: this.filesScanned - this.filesTransformed },
{ label: 'Total TODOs', value: [...this.todos.values()].reduce((a, b) => a + b, 0) },
];
const firstColPad = Math.max(...summaryEntries.map(({ label }) => label.length));
const secondColPad = 5;
lines.push('## Summary');
lines.push('');
lines.push(`| ${' '.padEnd(firstColPad)} | ${'Count'.padStart(secondColPad)} |`);
lines.push(`|:${'-'.repeat(firstColPad + 1)}|${'-'.repeat(secondColPad + 1)}:|`);
for (const { label, value } of summaryEntries) {
lines.push(`| ${label.padEnd(firstColPad)} | ${String(value).padStart(secondColPad)} |`);
}
lines.push('');
if (this.todos.size > 0) {
lines.push('## TODO Overview');
lines.push('');
const todoEntries = [...this.todos.entries()];
const firstColPad = Math.max('Category'.length, ...todoEntries.map(([category]) => category.length));
const secondColPad = 5;
lines.push(`| ${'Category'.padEnd(firstColPad)} | ${'Count'.padStart(secondColPad)} |`);
lines.push(`|:${'-'.repeat(firstColPad + 1)}|${'-'.repeat(secondColPad + 1)}:|`);
for (const [category, count] of todoEntries) {
lines.push(`| ${category.padEnd(firstColPad)} | ${String(count).padStart(secondColPad)} |`);
}
lines.push('');
}
if (this.fileTodos.size > 0) {
lines.push('## Files Requiring Manual Attention');
lines.push('');
// Sort files alphabetically
const sortedFiles = [...this.fileTodos.keys()].sort();
for (const filePath of sortedFiles) {
const relativePath = filePath.startsWith('/') ? filePath.substring(1) : filePath;
lines.push(`### [\`${relativePath}\`](./${relativePath})`);
const todos = this.fileTodos.get(filePath);
if (todos) {
// Sort todos by line number
todos.sort((a, b) => a.line - b.line);
for (const todo of todos) {
lines.push(`- [L${todo.line}](./${relativePath}#L${todo.line}): ${todo.category}`);
}
}
lines.push('');
}
}
else {
lines.push('## No Manual Changes Required');
lines.push('');
lines.push('All identified patterns were successfully transformed.');
}
return lines.join('\n');
}
printSummary(verbose = false) {
if (verbose && this.verboseLogs.size > 0) {
this.logger.info('Detailed Transformation Log:');
for (const [filePath, logs] of this.verboseLogs) {
this.logger.info(`Processing: ${filePath}`);
logs.forEach((log) => this.logger.info(` - ${log}`));
}
this.logger.info(''); // Add a blank line for separation
}
this.logger.info('Jasmine to Vitest Refactoring Summary:');
this.logger.info(`- ${this.filesScanned} test file(s) scanned.`);
this.logger.info(`- ${this.filesTransformed} file(s) transformed.`);
const filesSkipped = this.filesScanned - this.filesTransformed;
if (filesSkipped > 0) {
this.logger.info(`- ${filesSkipped} file(s) skipped (no changes needed).`);
}
if (this.todos.size > 0) {
const totalTodos = [...this.todos.values()].reduce((a, b) => a + b, 0);
this.logger.warn(`- ${totalTodos} TODO(s) added for manual review:`);
for (const [category, count] of this.todos) {
this.logger.warn(` - ${count}x ${category}`);
}
}
}
}
exports.RefactorReporter = RefactorReporter;
//# sourceMappingURL=refactor-reporter.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,138 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* @fileoverview This file is the single source of truth for all "TODO" notes
* generated by the Jasmine to Vitest schematic.
*
* It defines the `TODO_NOTES` constant, which contains the message and optional
* documentation URL for each category of manual migration task.
*
* The file also exports advanced mapped types (`TodoCategory`, `TodoContextMap`)
* that are inferred directly from the `TODO_NOTES` object. This creates a
* maintainable, type-safe system that ensures consistency across all
* transformers and prevents runtime errors.
*/
/**
* The central configuration for all "TODO" notes. Each key represents a unique
* `TodoCategory`.
*
* Each entry is an object with:
* - `message`: A string or a function that returns a string. If it's a function,
* it receives a `context` object to generate a dynamic message.
* - `url`: An optional documentation URL that will be appended to the message.
*/
export declare const TODO_NOTES: {
readonly pending: {
readonly message: "The pending() function was converted to a skipped test (`it.skip`).";
readonly url: "https://vitest.dev/api/vi.html#it-skip";
};
readonly toHaveSpyInteractions: {
readonly message: string;
};
readonly toThrowMatching: {
readonly message: (context: {
name: string;
}) => string;
readonly url: "https://vitest.dev/api/expect.html#tothrowerror";
};
readonly toBePending: {
readonly message: string;
};
readonly 'unsupported-expect-async-matcher': {
readonly message: (context: {
name: string;
}) => string;
};
readonly 'arrayWithExactContents-dynamic-variable': {
readonly message: "Cannot transform jasmine.arrayWithExactContents with a dynamic variable. Please migrate this manually.";
};
readonly 'arrayWithExactContents-check': {
readonly message: "Verify this matches strict array content (multiset equality). Vitest's arrayContaining is a subset check.";
};
readonly 'expect-nothing': {
readonly message: "expect().nothing() has been removed because it is redundant in Vitest. Tests without assertions pass by default.";
};
readonly 'unsupported-global-function': {
readonly message: (context: {
name: string;
}) => string;
};
readonly addMatchers: {
readonly message: "jasmine.addMatchers is not supported. Please manually migrate to expect.extend().";
readonly url: "https://vitest.dev/api/expect.html#expect-extend";
};
readonly addCustomEqualityTester: {
readonly message: "jasmine.addCustomEqualityTester is not supported. Please manually migrate to expect.addEqualityTesters().";
readonly url: "https://vitest.dev/api/expect.html#expect-addequalitytesters";
};
readonly mapContaining: {
readonly message: string;
};
readonly setContaining: {
readonly message: string;
};
readonly 'unknown-jasmine-property': {
readonly message: (context: {
name: string;
}) => string;
};
readonly spyOnAllFunctions: {
readonly message: string;
readonly url: "https://vitest.dev/api/vi.html#vi-spyon";
};
readonly 'createSpyObj-single-argument': {
readonly message: "jasmine.createSpyObj called with a single argument is not supported for transformation.";
readonly url: "https://vitest.dev/api/vi.html#vi-fn";
};
readonly 'createSpyObj-dynamic-variable': {
readonly message: "Cannot transform jasmine.createSpyObj with a dynamic variable. Please migrate this manually.";
readonly url: "https://vitest.dev/api/vi.html#vi-fn";
};
readonly 'createSpyObj-dynamic-property-map': {
readonly message: "Cannot transform jasmine.createSpyObj with a dynamic property map. Please migrate this manually.";
readonly url: "https://vitest.dev/api/vi.html#vi-fn";
};
readonly 'unsupported-spy-strategy': {
readonly message: (context: {
name: string;
}) => string;
readonly url: "https://vitest.dev/api/mocked.html#mock";
};
readonly 'mostRecent-without-args': {
readonly message: string;
readonly url: "https://vitest.dev/api/mocked.html#mock-lastcall";
};
readonly 'unhandled-done-usage': {
readonly message: "The 'done' callback was used in an unhandled way. Please migrate manually.";
};
};
/**
* A union type of all possible "TODO" categories.
* It is derived from the keys of the `TODO_NOTES` object to ensure that only
* valid categories can be used throughout the transformers.
*/
export type TodoCategory = keyof typeof TODO_NOTES;
/**
* A mapped type that creates a map from a `TodoCategory` to the type of the
* context object that its message function expects. This provides strong type
* safety for calls to `addTodoComment`.
*
* It works by checking if the `message` property for a given category is a
* function. If it is, it uses `infer` to extract the type of the first
* parameter (`P`). If it's not a function, it resolves to `never`.
*
* @example
* // `Context` will be `{ name: string }`
* type Context = TodoContextMap['unknown-jasmine-property'];
*
* // `Context` will be `never`
* type Context = TodoContextMap['pending'];
*/
export type TodoContextMap = {
[K in TodoCategory]: (typeof TODO_NOTES)[K]['message'] extends (context: infer P) => string ? P : never;
};
@@ -0,0 +1,114 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TODO_NOTES = void 0;
/**
* @fileoverview This file is the single source of truth for all "TODO" notes
* generated by the Jasmine to Vitest schematic.
*
* It defines the `TODO_NOTES` constant, which contains the message and optional
* documentation URL for each category of manual migration task.
*
* The file also exports advanced mapped types (`TodoCategory`, `TodoContextMap`)
* that are inferred directly from the `TODO_NOTES` object. This creates a
* maintainable, type-safe system that ensures consistency across all
* transformers and prevents runtime errors.
*/
/**
* The central configuration for all "TODO" notes. Each key represents a unique
* `TodoCategory`.
*
* Each entry is an object with:
* - `message`: A string or a function that returns a string. If it's a function,
* it receives a `context` object to generate a dynamic message.
* - `url`: An optional documentation URL that will be appended to the message.
*/
exports.TODO_NOTES = {
'pending': {
message: 'The pending() function was converted to a skipped test (`it.skip`).',
url: 'https://vitest.dev/api/vi.html#it-skip',
},
'toHaveSpyInteractions': {
message: 'Unsupported matcher ".toHaveSpyInteractions()" found. ' +
'Please migrate this manually by checking the `mock.calls.length` of the individual spies.',
},
'toThrowMatching': {
message: (context) => `Unsupported matcher ".${context.name}()" found. Please migrate this manually.`,
url: 'https://vitest.dev/api/expect.html#tothrowerror',
},
'toBePending': {
message: 'Unsupported matcher ".toBePending()" found. Vitest does not have a direct equivalent. ' +
'Please migrate this manually, for example by using `Promise.race` to check if the promise settles within a short timeout.',
},
'unsupported-expect-async-matcher': {
message: (context) => `Unsupported expectAsync matcher ".${context.name}()" found. Please migrate this manually.`,
},
'arrayWithExactContents-dynamic-variable': {
message: 'Cannot transform jasmine.arrayWithExactContents with a dynamic variable. Please migrate this manually.',
},
'arrayWithExactContents-check': {
message: "Verify this matches strict array content (multiset equality). Vitest's arrayContaining is a subset check.",
},
'expect-nothing': {
message: 'expect().nothing() has been removed because it is redundant in Vitest. Tests without assertions pass by default.',
},
'unsupported-global-function': {
message: (context) => `Unsupported global function \`${context.name}\` found. This function is used for custom reporters in Jasmine ` +
'and has no direct equivalent in Vitest.',
},
'addMatchers': {
message: 'jasmine.addMatchers is not supported. Please manually migrate to expect.extend().',
url: 'https://vitest.dev/api/expect.html#expect-extend',
},
'addCustomEqualityTester': {
message: 'jasmine.addCustomEqualityTester is not supported. Please manually migrate to expect.addEqualityTesters().',
url: 'https://vitest.dev/api/expect.html#expect-addequalitytesters',
},
'mapContaining': {
message: 'jasmine.mapContaining is not supported. Vitest does not have a built-in matcher for Maps.' +
' Please manually assert the contents of the Map.',
},
'setContaining': {
message: 'jasmine.setContaining is not supported. Vitest does not have a built-in matcher for Sets.' +
' Please manually assert the contents of the Set.',
},
'unknown-jasmine-property': {
message: (context) => `Unsupported jasmine property "${context.name}" found. Please migrate this manually.`,
},
'spyOnAllFunctions': {
message: 'Vitest does not have a direct equivalent for jasmine.spyOnAllFunctions().' +
' Please spy on individual methods manually using vi.spyOn().',
url: 'https://vitest.dev/api/vi.html#vi-spyon',
},
'createSpyObj-single-argument': {
message: 'jasmine.createSpyObj called with a single argument is not supported for transformation.',
url: 'https://vitest.dev/api/vi.html#vi-fn',
},
'createSpyObj-dynamic-variable': {
message: 'Cannot transform jasmine.createSpyObj with a dynamic variable. Please migrate this manually.',
url: 'https://vitest.dev/api/vi.html#vi-fn',
},
'createSpyObj-dynamic-property-map': {
message: 'Cannot transform jasmine.createSpyObj with a dynamic property map. Please migrate this manually.',
url: 'https://vitest.dev/api/vi.html#vi-fn',
},
'unsupported-spy-strategy': {
message: (context) => `Unsupported spy strategy ".and.${context.name}()" found. Please migrate this manually.`,
url: 'https://vitest.dev/api/mocked.html#mock',
},
'mostRecent-without-args': {
message: 'Direct usage of mostRecent() is not supported.' +
' Please refactor to access .args directly or use vi.mocked(spy).mock.lastCall.',
url: 'https://vitest.dev/api/mocked.html#mock-lastcall',
},
'unhandled-done-usage': {
message: "The 'done' callback was used in an unhandled way. Please migrate manually.",
},
};
//# sourceMappingURL=todo-notes.js.map
@@ -0,0 +1 @@
{"version":3,"file":"todo-notes.js","sourceRoot":"","sources":["todo-notes.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;GAQG;AACU,QAAA,UAAU,GAAG;IACxB,SAAS,EAAE;QACT,OAAO,EAAE,qEAAqE;QAC9E,GAAG,EAAE,wCAAwC;KAC9C;IACD,uBAAuB,EAAE;QACvB,OAAO,EACL,wDAAwD;YACxD,2FAA2F;KAC9F;IACD,iBAAiB,EAAE;QACjB,OAAO,EAAE,CAAC,OAAyB,EAAU,EAAE,CAC7C,yBAAyB,OAAO,CAAC,IAAI,0CAA0C;QACjF,GAAG,EAAE,iDAAiD;KACvD;IACD,aAAa,EAAE;QACb,OAAO,EACL,wFAAwF;YACxF,2HAA2H;KAC9H;IACD,kCAAkC,EAAE;QAClC,OAAO,EAAE,CAAC,OAAyB,EAAU,EAAE,CAC7C,qCAAqC,OAAO,CAAC,IAAI,0CAA0C;KAC9F;IACD,yCAAyC,EAAE;QACzC,OAAO,EACL,wGAAwG;KAC3G;IACD,8BAA8B,EAAE;QAC9B,OAAO,EACL,2GAA2G;KAC9G;IACD,gBAAgB,EAAE;QAChB,OAAO,EACL,kHAAkH;KACrH;IACD,6BAA6B,EAAE;QAC7B,OAAO,EAAE,CAAC,OAAyB,EAAU,EAAE,CAC7C,iCAAiC,OAAO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