Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add type alias scope extend case
  • Loading branch information
wanlwanl committed Oct 30, 2024
commit ee250fbc83d05eb3179021b4893da6ac10df970d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface Routes {
export type typesChange = "basic" | "remove";
export type typesRemove = "basic" | "remove";

export type typesExpand = string | number;
export type typesNarrow = string | number | boolean;

export interface A {a: string;}
export interface B {b: string;}
export interface C {c: string;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export interface Routes {
export type typesChange = "basic" | "rEmove";
export type typesAdd = "basic" | "rEmove";

export type typesExpand = string | number | boolean;
export type typesNarrow = string | number;

export interface A {a: string;}
export interface B {b: string;}
export interface C {c: string;}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-codegen-breaking-change-detector",
"version": "0.5.4",
"version": "0.5.5",
"description": "Detect breaking changes to your TypeScript client generated by open api, typespec and more...",
"main": "dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export function findFunctionBreakingChanges(source: FunctionDeclaration, target:
}

export function findTypeAliasBreakingChanges(source: TypeAliasDeclaration, target: TypeAliasDeclaration): DiffPair[] {
if (source.getType().isAssignableTo(target.getType())) return [];
if (source.getType().isAssignableTo(target.getType()) && target.getType().isAssignableTo(source.getType())) return [];

let sourceNameNode: NameNode = { name: source.getName(), node: source };
let targetNameNode: NameNode = { name: target.getName(), node: target };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function patchRoutes(astContext: AstContext): DiffPair[] {
return [...breakingChangePairs, ...newFeaturePairs];
}

export function patchUnionType(name: string, astContext: AstContext, assignDirection: AssignDirection): DiffPair[] {
export function patchTypeAlias(name: string, astContext: AstContext, assignDirection: AssignDirection): DiffPair[] {
const baseline = astContext.baseline.getTypeAlias(name);
const current = astContext.current.getTypeAlias(name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest';

import { join } from 'node:path';
import { createAstContext } from '../azure/detect-breaking-changes';
import { patchFunction, patchRoutes, patchUnionType } from '../azure/patch/patch-detection';
import { patchFunction, patchRoutes, patchTypeAlias } from '../azure/patch/patch-detection';
import { createTempFolder, getFormattedDate } from './utils';
import { DiffLocation, DiffReasons, AssignDirection } from '../azure/common/types';

Expand Down Expand Up @@ -142,26 +142,40 @@ describe("patch current tool's breaking changes", async () => {
try {
const tempFolder = await createTempFolder(`.tmp/temp-${date}`);
const astContext = await createAstContext(baselineApiViewPath, currentApiViewPath, tempFolder);
let breakingPairs = patchUnionType('typesChange', astContext, AssignDirection.CurrentToBaseline);
let breakingPairs = patchTypeAlias('typesChange', astContext, AssignDirection.CurrentToBaseline);
expect(breakingPairs.length).toBe(1);
expect(breakingPairs[0].assignDirection).toBe(AssignDirection.CurrentToBaseline);
expect(breakingPairs[0].location).toBe(DiffLocation.TypeAlias);
expect(breakingPairs[0].reasons).toBe(DiffReasons.TypeChanged);
expect(breakingPairs[0].target?.name).toBe('typesChange');

breakingPairs = patchUnionType('typesRemove', astContext, AssignDirection.CurrentToBaseline);
breakingPairs = patchTypeAlias('typesRemove', astContext, AssignDirection.CurrentToBaseline);
expect(breakingPairs.length).toBe(1);
expect(breakingPairs[0].assignDirection).toBe(AssignDirection.CurrentToBaseline);
expect(breakingPairs[0].location).toBe(DiffLocation.TypeAlias);
expect(breakingPairs[0].reasons).toBe(DiffReasons.Removed);
expect(breakingPairs[0].target?.name).toBe('typesRemove');

breakingPairs = patchUnionType('typesAdd', astContext, AssignDirection.CurrentToBaseline);
breakingPairs = patchTypeAlias('typesAdd', astContext, AssignDirection.CurrentToBaseline);
expect(breakingPairs.length).toBe(1);
expect(breakingPairs[0].assignDirection).toBe(AssignDirection.CurrentToBaseline);
expect(breakingPairs[0].location).toBe(DiffLocation.TypeAlias);
expect(breakingPairs[0].reasons).toBe(DiffReasons.Added);
expect(breakingPairs[0].source?.name).toBe('typesAdd');

breakingPairs = patchTypeAlias('typesExpand', astContext, AssignDirection.CurrentToBaseline);
expect(breakingPairs.length).toBe(1);
expect(breakingPairs[0].assignDirection).toBe(AssignDirection.CurrentToBaseline);
expect(breakingPairs[0].location).toBe(DiffLocation.TypeAlias);
expect(breakingPairs[0].reasons).toBe(DiffReasons.TypeChanged);
expect(breakingPairs[0].source?.name).toBe('typesExpand');

breakingPairs = patchTypeAlias('typesNarrow', astContext, AssignDirection.CurrentToBaseline);
expect(breakingPairs.length).toBe(1);
expect(breakingPairs[0].assignDirection).toBe(AssignDirection.CurrentToBaseline);
expect(breakingPairs[0].location).toBe(DiffLocation.TypeAlias);
expect(breakingPairs[0].reasons).toBe(DiffReasons.TypeChanged);
expect(breakingPairs[0].source?.name).toBe('typesNarrow');
} finally {
if (tempFolder) remove(tempFolder);
}
Expand Down