Fix cred issue shouldn't return undefined (#24)

This commit is contained in:
Timothee Guerin 2019-05-24 11:38:13 -07:00 коммит произвёл GitHub
Родитель 5386209eb0
Коммит 706f4114f7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 32 добавлений и 40 удалений

Просмотреть файл

@ -5,7 +5,7 @@ import { RepoAuth } from "./repo-auth";
describe("RepoAuth", () => {
describe("Model", () => {
it("doesn't generated any creds when no options are passed", () => {
expect(new RepoAuth().toCreds()).toBeUndefined();
expect(new RepoAuth().toCreds()).toEqual(Cred.defaultNew());
});
it("returns undefined if invalid basic header", () => {

Просмотреть файл

@ -48,11 +48,11 @@ export class RepoAuth {
return new RepoAuth();
}
public toCreds(): Cred | undefined {
public toCreds(): Cred {
if (this.username && this.password) {
return Cred.userpassPlaintextNew(this.username, this.password);
}
return undefined;
return Cred.defaultNew();
}
public toAuthorizationHeader(): string | undefined {

Просмотреть файл

@ -1,16 +1,16 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { Clone, Fetch, FetchOptions, Repository } from "nodegit";
import { Clone, Cred, Fetch, FetchOptions, Repository } from "nodegit";
import path from "path";
import { FSService } from "../fs";
import { GitBaseOptions } from "../repo";
export function credentialsCallback(options: GitBaseOptions) {
export function credentialsCallback(options: GitBaseOptions): () => Cred {
return () => {
if (options.auth) {
return options.auth.toCreds();
}
return undefined;
return Cred.defaultNew();
};
}

Просмотреть файл

@ -38,6 +38,13 @@ function toMatchSpecificSnapshot(
received: object | object[],
filename: string,
): jest.CustomMatcherResult {
if (this.isNot) {
return {
pass: true, // Will get inverted because of the .not
message: () => `.${this.utils.BOLD_WEIGHT("not")} cannot be used with snapshot matchers`,
};
}
const filepath = getAbsolutePathToSnapshot(this.testPath!, filename);
const content = serializeContent(received);
const updateSnapshot: "none" | "all" | "new" = (this.snapshotState as any)._updateSnapshot;
@ -51,7 +58,7 @@ function toMatchSpecificSnapshot(
this.snapshotState.unmatched++;
return {
pass: this.isNot,
pass: false,
message: () =>
`New output file ${coloredFilename} was ${errorColor("not written")}.\n\n` +
"The update flag must be explicitly passed to write a new snapshot.\n\n",
@ -61,47 +68,32 @@ function toMatchSpecificSnapshot(
if (fs.existsSync(filepath)) {
const output = fs.readFileSync(filepath, "utf8");
// The matcher is being used with `.not`
if (this.isNot) {
if (output !== content) {
this.snapshotState.matched++;
// The value of `pass` is reversed when used with `.not`
return { pass: false, message: () => "" };
if (output === content) {
this.snapshotState.matched++;
return { pass: true, message: () => "" };
} else {
if (updateSnapshot === "all") {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content);
this.snapshotState.updated++;
return { pass: true, message: () => "" };
} else {
this.snapshotState.unmatched++;
return {
pass: true,
message: () => `Expected received content ${errorColor("to not match")} the snapshot ${coloredFilename}.`,
pass: false,
message: () =>
`Received content ${errorColor("doesn't match")} the file ${coloredFilename}.\n\n${this.utils.diff(
content,
output,
)}`,
};
}
} else {
if (output === content) {
this.snapshotState.matched++;
return { pass: true, message: () => "" };
} else {
if (updateSnapshot === "all") {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content);
this.snapshotState.updated++;
return { pass: true, message: () => "" };
} else {
this.snapshotState.unmatched++;
return {
pass: false,
message: () =>
`Received content ${errorColor("doesn't match")} the file ${coloredFilename}.\n\n${this.utils.diff(
content,
output,
)}`,
};
}
}
}
} else {
if (!this.isNot && (updateSnapshot === "new" || updateSnapshot === "all")) {
if (updateSnapshot === "new" || updateSnapshot === "all") {
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content);