UNPKG

@laoban/filesops-node

Version:

File operations (interfaces are in utils). This mainly decouples from the actual version of the files software and makes file operations easy to test

46 lines (45 loc) 3.25 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); //Copyright (c)2020-2023 Philip Rice. <br />Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the Software), to dealin the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: <br />The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS const fileOpsNode_1 = require("./fileOpsNode"); describe("fileOpsNode.loadFile", () => { it('should load a file', () => __awaiter(void 0, void 0, void 0, function* () { expect(yield (0, fileOpsNode_1.fileOpsNode)().loadFileOrUrl('test.txt')).toEqual('some text'); })); }); describe("fileOpsNode.log", () => { const filename = 'log.test.txt'; it('should create a file with no speed up', () => __awaiter(void 0, void 0, void 0, function* () { const fileOps = (0, fileOpsNode_1.fileOpsNode)(false); yield fileOps.removeFile(filename); yield fileOps.log(filename, 'some more text'); expect(yield fileOps.loadFileOrUrl(filename)).toEqual('some more text\n'); })); it('should create a file with speed up', () => __awaiter(void 0, void 0, void 0, function* () { const fileOps = (0, fileOpsNode_1.fileOpsNode)(true); yield fileOps.removeFile(filename); yield fileOps.log(filename, 'some more text'); expect(yield fileOps.loadFileOrUrl(filename)).toEqual('some more text\n'); })); it('should append to a file with no speed up', () => __awaiter(void 0, void 0, void 0, function* () { const fileOps = (0, fileOpsNode_1.fileOpsNode)(false); yield fileOps.saveFile(filename, 'initial text\n'); yield fileOps.log(filename, 'some more text'); expect(yield fileOps.loadFileOrUrl(filename)).toEqual('initial text\nsome more text\n'); })); it('should append to a file with speed up', () => __awaiter(void 0, void 0, void 0, function* () { const fileOps = (0, fileOpsNode_1.fileOpsNode)(true); yield fileOps.saveFile(filename, 'initial text\n'); yield fileOps.log(filename, 'some more text'); expect(yield fileOps.loadFileOrUrl(filename)).toEqual('initial text\nsome more text\n'); })); });