<commit_before>const path = require("path");
const valueAsPromise = value => new Promise(resolve => resolve(value));
const rejection = err => new Promise((resolve, reject) => reject(err));

module.exports = class FakeAwaitableFs {
	constructor(files = {}){
		this.files = files;
	}

	mkdir(/*folder*/){
		return valueAsPromise();
	}

	readdir(/*folder*/){
		return valueAsPromise(Object.keys(this.files));
	}

	async readFile(filename){
		filename = path.basename(filename);
		if(this.files[filename] === undefined){
			let err = new Error("File not found");
			err.code = "ENOENT";
			return rejection(err);
		}
		return valueAsPromise(this.files[filename]);
	}

	appendFile(filename, data){
		filename = path.basename(filename);
		return valueAsPromise(this.files[filename] = data);
	}
}<commit_msg>Fixed FakeAwaitableFs: Implemented test for wether file exists with possible rejection in appendFile method<commit_after>const path = require("path");
const valueAsPromise = value => new Promise(resolve => resolve(value));
const rejection = err => new Promise((resolve, reject) => reject(err));

module.exports = class FakeAwaitableFs {
	constructor(files = {}){
		this.files = files;
	}

	mkdir(/*folder*/){
		return valueAsPromise();
	}

	readdir(/*folder*/){
		return valueAsPromise(Object.keys(this.files));
	}

	async readFile(filename){
		filename = path.basename(filename);
		if(this.files[filename] === undefined){
			let err = new Error("File not found");
			err.code = "ENOENT";
			return rejection(err);
		}
		return valueAsPromise(this.files[filename]);
	}

	appendFile(filename, data, options){
		filename = path.basename(filename);
		if(options.flag == "wx" && this.files[filename]){
			let err = new Error("...");	//TODO: Insert the correct message and code here! -arjan 2017-09-11
			err.code = "...";
			return rejection(err);
		}
		return valueAsPromise(this.files[filename] = data);
	}
}
{'fraction_non_alphanumeric': 0.156790770844258, 'fraction_numerical': 0.004195070791819612, 'mean_word_length': 4.712574850299402, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7522749', 'n_tokens_mistral': 655, 'n_tokens_neox': 590, 'n_words': 140}