Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('render breaking', () => {
const change: Change = {
criticality: {
level: CriticalityLevel.Breaking,
},
type: ChangeType.TypeRemoved,
message: 'Boom, breaking',
path: 'Type.field',
};
const [symbol, msg] = renderChange(change);
expect(symbol).toBeDefined();
expect(symbol).toEqual(getSymbol(CriticalityLevel.Breaking));
expect(msg).toBeDefined();
expect(msg).toEqual(change.message);
});
test('render breaking', () => {
const change: Change = {
criticality: {
level: CriticalityLevel.Breaking,
},
type: ChangeType.TypeRemoved,
message: 'Boom, breaking',
path: 'Type.field',
};
const [symbol, msg] = renderChange(change);
expect(symbol).toBeDefined();
expect(symbol).toEqual(getSymbol(CriticalityLevel.Breaking));
expect(msg).toBeDefined();
expect(msg).toEqual(change.message);
});
return changes.some(c => c.criticality.level === CriticalityLevel.Breaking);
}
export function getSymbol(level: CriticalityLevel): string {
const symbols = {
[CriticalityLevel.Dangerous]: logSymbols.warning,
[CriticalityLevel.Breaking]: logSymbols.error,
[CriticalityLevel.NonBreaking]: logSymbols.success,
};
return symbols[level];
}
c => c.criticality.level === CriticalityLevel.Breaking,
).length;
function getSymbol(level: CriticalityLevel): string {
const symbols = {
[CriticalityLevel.Dangerous]: logSymbols.warning,
[CriticalityLevel.Breaking]: logSymbols.error,
[CriticalityLevel.NonBreaking]: logSymbols.success
};
return symbols[level];
}
change => change.criticality.level === CriticalityLevel.Breaking,
)
if (
changes.some(
change => change.criticality.level === CriticalityLevel.Breaking,
)
) {
conclusion = CheckConclusion.Failure;
}
return {
conclusion,
annotations,
};
}
const levelMap = {
[CriticalityLevel.Breaking]: AnnotationLevel.Failure,
[CriticalityLevel.Dangerous]: AnnotationLevel.Warning,
[CriticalityLevel.NonBreaking]: AnnotationLevel.Notice,
};
function annotate({
path,
change,
schemas,
}: {
path: string;
change: Change;
schemas: {
old: GraphQLSchema;
new: GraphQLSchema;
};
}): Annotation {
const breakingCount = changes.filter(c => c.criticality.level === CriticalityLevel.Breaking).length;
throw `Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}\n`;