From 996e5d0b880f9fd86f860ea34a1ccd58f89c6d15 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Tue, 9 Jun 2026 12:11:40 +0200 Subject: [PATCH] fix: tidy up Vitest migration follow-ups (#210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small, non-behavioral cleanups after the Jest→Vitest migration: - interfaces.ts: revert beforeAdd param `any` → `unknown` (project No-any rule) - add missing vitest type imports (Mock / MockInstance) to 5 specs that used the types without importing them — they aren't provided by vitest/globals, so this fixes editor/tsc errors (runtime was unaffected; specs aren't typechecked in CI) - tsconfig.json: types ["vitest/globals", "node"] so specs keep Node ambient types (process, Buffer, …) - prune 2 obsolete jest-format snapshots left behind in ng-add.spec.ts.snap - builder-integration.spec.ts: drop an unnecessary `as any` - test.fork-fixes.spec.ts: restore the "implicitly tested by test.options.bool.no.spec.ts" note (lost with its empty describe, which vitest rejects) - docs: add "Supporting a new Angular version" to the contributor README TOC Build clean, all 430 tests green, no obsolete snapshots. --- docs/README_contributors.md | 1 + src/__snapshots__/ng-add.spec.ts.snap | 69 ------------------- .../test/test.fork-fixes.spec.ts | 2 + .../engine.gh-pages-integration.spec.ts | 1 + src/engine/engine.spec.ts | 2 + src/interfaces.ts | 2 +- src/ng-add.spec.ts | 1 + .../builder-integration.spec.ts | 3 +- src/test-fixtures/angular-versions.spec.ts | 1 + src/tsconfig.json | 2 +- 10 files changed, 12 insertions(+), 72 deletions(-) diff --git a/docs/README_contributors.md b/docs/README_contributors.md index e68bb11..5b6d1bc 100644 --- a/docs/README_contributors.md +++ b/docs/README_contributors.md @@ -15,6 +15,7 @@ - [Advanced: Angular Builder Integration](#advanced-angular-builder-integration) - [Dependency on gh-pages Internal API](#dependency-on-gh-pages-internal-api) - [Remote URL Discovery](#remote-url-discovery) + - [Supporting a new Angular version](#supporting-a-new-angular-version) - [Keeping track of all the forks](#keeping-track-of-all-the-forks) ## How to start diff --git a/src/__snapshots__/ng-add.spec.ts.snap b/src/__snapshots__/ng-add.spec.ts.snap index b73dbc1..3d38754 100644 --- a/src/__snapshots__/ng-add.spec.ts.snap +++ b/src/__snapshots__/ng-add.spec.ts.snap @@ -68,72 +68,3 @@ exports[`ng-add > generating files > overrides existing files 1`] = ` } }" `; - -exports[`ng-add generating files generates new files if starting from scratch 1`] = ` -"{ - "version": 1, - "projects": { - "THEPROJECT": { - "projectType": "application", - "root": "PROJECTROOT", - "architect": { - "build": { - "options": { - "outputPath": "dist/THEPROJECT" - } - }, - "deploy": { - "builder": "angular-cli-ghpages:deploy" - } - } - }, - "OTHERPROJECT": { - "projectType": "application", - "root": "PROJECTROOT", - "architect": { - "build": { - "options": { - "outputPath": "dist/OTHERPROJECT" - } - } - } - } - } -}" -`; - -exports[`ng-add generating files overrides existing files 1`] = ` -"{ - "version": 1, - "projects": { - "THEPROJECT": { - "projectType": "application", - "root": "PROJECTROOT", - "architect": { - "build": { - "options": { - "outputPath": "dist/THEPROJECT" - } - }, - "deploy": { - "builder": "angular-cli-ghpages:deploy" - } - } - }, - "OTHERPROJECT": { - "projectType": "application", - "root": "PROJECTROOT", - "architect": { - "build": { - "options": { - "outputPath": "dist/OTHERPROJECT" - } - }, - "deploy": { - "builder": "angular-cli-ghpages:deploy" - } - } - } - } -}" -`; diff --git a/src/commander-fork/test/test.fork-fixes.spec.ts b/src/commander-fork/test/test.fork-fixes.spec.ts index 8354359..1b6f530 100644 --- a/src/commander-fork/test/test.fork-fixes.spec.ts +++ b/src/commander-fork/test/test.fork-fixes.spec.ts @@ -14,6 +14,8 @@ import { MockInstance } from 'vitest'; const commander = require('../'); +// Fork Fix 1 (tightened negate-detection regex) is implicitly covered by +// test.options.bool.no.spec.ts — no dedicated tests needed here. describe('Fork Fix 2: Version short-only and custom flags', () => { describe('version() with short-only flag', () => { diff --git a/src/engine/engine.gh-pages-integration.spec.ts b/src/engine/engine.gh-pages-integration.spec.ts index 695faeb..05d18ae 100644 --- a/src/engine/engine.gh-pages-integration.spec.ts +++ b/src/engine/engine.gh-pages-integration.spec.ts @@ -10,6 +10,7 @@ */ import { logging } from '@angular-devkit/core'; +import { Mock, MockInstance } from 'vitest'; import * as engine from './engine'; import { cleanupMonkeypatch } from './engine.prepare-options-helpers'; diff --git a/src/engine/engine.spec.ts b/src/engine/engine.spec.ts index bf93b1a..62d14a5 100644 --- a/src/engine/engine.spec.ts +++ b/src/engine/engine.spec.ts @@ -1,5 +1,7 @@ import { logging } from '@angular-devkit/core'; +import { Mock, MockInstance } from 'vitest'; + import * as engine from './engine'; import { cleanupMonkeypatch } from './engine.prepare-options-helpers'; diff --git a/src/interfaces.ts b/src/interfaces.ts index a6aa48b..e7200ce 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -65,7 +65,7 @@ export interface PublishOptions { cname?: string; add?: boolean; git?: string; - beforeAdd?: (git: any) => void | Promise; + beforeAdd?: (git: unknown) => void | Promise; [key: string]: unknown; // Allow additional gh-pages options } diff --git a/src/ng-add.spec.ts b/src/ng-add.spec.ts index 6853919..bc85daa 100644 --- a/src/ng-add.spec.ts +++ b/src/ng-add.spec.ts @@ -1,4 +1,5 @@ import { SchematicContext, Tree } from '@angular-devkit/schematics'; +import { Mock } from 'vitest'; import { ngAdd } from './ng-add'; diff --git a/src/parameter-tests/builder-integration.spec.ts b/src/parameter-tests/builder-integration.spec.ts index 38ca5e7..16f0f6e 100644 --- a/src/parameter-tests/builder-integration.spec.ts +++ b/src/parameter-tests/builder-integration.spec.ts @@ -3,6 +3,7 @@ import { JsonObject, logging } from '@angular-devkit/core'; import { BuildTarget, PublishOptions } from '../interfaces'; import { Schema } from '../deploy/schema'; import { cleanupMonkeypatch } from '../engine/engine.prepare-options-helpers'; +import { Mock } from 'vitest'; /** * ANGULAR BUILDER INTEGRATION TESTS @@ -77,7 +78,7 @@ describe('Angular Builder Integration Tests', () => { if (callback) { callback(null); } - return Promise.resolve() as any; + return Promise.resolve(); } ); }); diff --git a/src/test-fixtures/angular-versions.spec.ts b/src/test-fixtures/angular-versions.spec.ts index 6b84ecc..faeb1f6 100644 --- a/src/test-fixtures/angular-versions.spec.ts +++ b/src/test-fixtures/angular-versions.spec.ts @@ -13,6 +13,7 @@ import { SchematicContext, Tree } from '@angular-devkit/schematics'; import fs from 'fs'; import path from 'path'; +import { Mock } from 'vitest'; import { ngAdd } from '../ng-add'; // Mock context with logger - only the methods we actually use diff --git a/src/tsconfig.json b/src/tsconfig.json index b35dcd4..346231f 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -14,7 +14,7 @@ "lib": ["es2022"], "skipLibCheck": true, "esModuleInterop": true, - "types": ["vitest/globals"] + "types": ["vitest/globals", "node"] }, "angularCompilerOptions": { "skipTemplateCodegen": true,