@villedemontreal/scripting
Version:
Scripting core utilities
49 lines (42 loc) • 1.29 kB
text/typescript
import * as nock from 'nock';
import { stripVTControlCharacters } from 'node:util';
export function simulateSonarServerIsNotFound() {
nock('https://example.com').head(RegExp('/sonar/{0,1}')).reply(404);
}
function simulateSonarServerIsOk() {
nock('https://example.com').head(RegExp('/sonar/{0,1}')).reply(200);
}
export function simulateSonarProjectDoesNotYetExist() {
simulateSonarServerIsOk();
nock('https://example.com')
.get('/sonar/api/project_branches/list')
.query({ project: 'my-test-project-key' })
.reply(404);
}
export function simulateSonarProjectAlreadyExists() {
simulateSonarServerIsOk();
nock('https://example.com')
.get('/sonar/api/project_branches/list')
.query({ project: 'my-test-project-key' })
.reply(200);
}
export class LoggerRecorder {
logger: any;
recordedLogs: string;
constructor() {
this.recordedLogs = '';
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this;
this.logger = new Proxy(
{},
{
get: (target, prop) => {
return function () {
// eslint-disable-next-line prefer-rest-params
that.recordedLogs += stripVTControlCharacters(`${prop.toString()}: ${arguments[0]}\n`);
};
},
},
);
}
}