Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('bold', () => {
const change: Change = {
criticality: {
level: CriticalityLevel.Dangerous,
},
type: ChangeType.TypeDescriptionChanged,
message: `Type 'Foo' changed its name to 'Bar'.`,
path: 'Type.field',
};
const [, msg] = renderChange(change);
expect(msg).toEqual(
`Type ${chalk.bold('Foo')} changed its name to ${chalk.bold('Bar')}.`,
);
});
test('render dangerous', () => {
const change: Change = {
criticality: {
level: CriticalityLevel.Dangerous,
},
type: ChangeType.TypeRemoved,
message: 'Ooo dangerous...',
path: 'Type.field',
};
const [symbol, msg] = renderChange(change);
expect(symbol).toBeDefined();
expect(symbol).toEqual(getSymbol(CriticalityLevel.Dangerous));
expect(msg).toBeDefined();
expect(msg).toEqual(change.message);
});
test('render dangerous', () => {
const change: Change = {
criticality: {
level: CriticalityLevel.Dangerous,
},
type: ChangeType.TypeRemoved,
message: 'Ooo dangerous...',
path: 'Type.field',
};
const [symbol, msg] = renderChange(change);
expect(symbol).toBeDefined();
expect(symbol).toEqual(getSymbol(CriticalityLevel.Dangerous));
expect(msg).toBeDefined();
expect(msg).toEqual(change.message);
});
function getSymbol(level: CriticalityLevel): string {
const symbols = {
[CriticalityLevel.Dangerous]: logSymbols.warning,
[CriticalityLevel.Breaking]: logSymbols.error,
[CriticalityLevel.NonBreaking]: logSymbols.success
};
return symbols[level];
}
export function getSymbol(level: CriticalityLevel): string {
const symbols = {
[CriticalityLevel.Dangerous]: logSymbols.warning,
[CriticalityLevel.Breaking]: logSymbols.error,
[CriticalityLevel.NonBreaking]: logSymbols.success,
};
return symbols[level];
}
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 level = change.criticality.level;