From 4e352a733d56f0a8f43b9e675e6efe3ebb2e1f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 10 Nov 2020 10:05:54 +0100 Subject: [PATCH] created assertion fileExist --- assertions/directoryExist.ts | 1 - assertions/fileExist.ts | 9 +++++++++ assertions/index.ts | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 assertions/fileExist.ts diff --git a/assertions/directoryExist.ts b/assertions/directoryExist.ts index 8ef7c335..1acf419a 100644 --- a/assertions/directoryExist.ts +++ b/assertions/directoryExist.ts @@ -1,4 +1,3 @@ -import { RunResult } from "../engine/run_result"; import * as fs from "fs"; export class DirectoryExist { diff --git a/assertions/fileExist.ts b/assertions/fileExist.ts new file mode 100644 index 00000000..5f50ec82 --- /dev/null +++ b/assertions/fileExist.ts @@ -0,0 +1,9 @@ +import * as fs from "fs"; + +export class FileExist { + public static run(filepath: string): void { + if(!fs.existsSync(filepath)) { + throw new Error("file " + filepath + " does not exist"); + } + } +} \ No newline at end of file diff --git a/assertions/index.ts b/assertions/index.ts index 6946937c..e1607dbf 100644 --- a/assertions/index.ts +++ b/assertions/index.ts @@ -4,6 +4,7 @@ import { Command } from "../engine/command"; import { NoErrorCode } from "./noErrorCode"; import { NoException } from "./noException"; import { DirectoryExist } from "./directoryExist"; +import { FileExist } from "./fileExist"; export class Assertions { @@ -22,4 +23,9 @@ export class Assertions { DirectoryExist.run(directory); return this; } + + public fileExits(filepath: string): Assertions { + FileExist.run(filepath); + return this; + } } \ No newline at end of file