<commit_before>/*
 * webdisk
 * https://github.com/parroit/webdisk
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

"use strict";

var expect = require("expect.js"),
    fs = require("fs"),
    concat = require("concat-stream"),
    webdisk = require("../lib/webdisk");


describe("webdisk", function() {

    before(function(done) {
        fs.unlink("test/files/fold2/remove.this", function(err) {
            if (err) {
                return console.log(err);
            }
            fs.unlink("test/only-folders/fold1/remove.this", function(err) {
                if (err) {
                    return console.log(err);
                }
                done();
            });
        });
    });

     after(function(done) {
        fs.writeFile("test/files/fold2/remove.this", "remove.this", function (err) {
          
       
            if (err) {
                return console.log(err);
            }
            
            fs.writeFile("test/only-folders/fold1/remove.this", "remove.this", function(err) {
                if (err) {
                    return console.log(err);
                }
                done();
            });
        });
    });

    function sortByName(array) {
        array.sort(function(a, b) {
            if (a.name === b.name) {
                return 0;
            }
            return a.name < b.name ? -1 : +1;
        });
    }

    it("is defined", function() {
        expect(webdisk).to.be.an("object");
    });

    describe("listFiles", function() {
        it("is defined", function() {
            expect(webdisk.listFiles).to.be.an("function");
        });

        it("return readable stream", function() {
            expect(webdisk.listFiles(".").readable).to.be.equal(true);
        });

        it("return all file names in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].name).to.be.equal("1.txt");
                expect(results[1].name).to.be.equal("2.txt");
                done();
            }));

        });



        it("return folder with only files as empty array", function(done) {
            webdisk.listFiles("test/only-folders").pipe(concat(function(results) {


                expect(results).to.be.equal("[]");

                done();
            }));

        });


        it("return all file paths in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].path).to.be.equal("test/files/1.txt");
                expect(results[1].path).to.be.equal("test/files/2.txt");
                done();
            }));

        });

        it("return empty folder as empty array", function(done) {
            webdisk.listFiles("test/files/fold2").pipe(concat(function(results) {


                expect(results).to.be.equal("[]");

                done();
            }));

        });

        it("return all file size in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].size).to.be.equal(5);
                expect(results[1].size).to.be.equal(5);
                done();
            }));

        });

        it("return all files uplodad date in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].uploaded).to.be.equal(1390843390000);
                expect(results[1].uploaded).to.be.equal(1390843390000);
                done();
            }));

        });
    });

    describe("listFolders", function() {

        it("is defined", function() {
            expect(webdisk.listFolders).to.be.an("function");
        });

        it("return readable stream", function() {
            expect(webdisk.listFolders(".").readable).to.be.equal(true);
        });

        it("return all subfolders names", function(done) {
            webdisk.listFolders("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].name).to.be.equal("fold1");
                expect(results[1].name).to.be.equal("fold2");
                done();
            }));<commit_msg>files creation is always now on travis<commit_after>/*
 * webdisk
 * https://github.com/parroit/webdisk
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

"use strict";

var expect = require("expect.js"),
    fs = require("fs"),
    concat = require("concat-stream"),
    webdisk = require("../lib/webdisk");


describe("webdisk", function() {

    before(function(done) {
        fs.unlink("test/files/fold2/remove.this", function(err) {
            if (err) {
                return console.log(err);
            }
            fs.unlink("test/only-folders/fold1/remove.this", function(err) {
                if (err) {
                    return console.log(err);
                }
                done();
            });
        });
    });

    after(function(done) {
        fs.writeFile("test/files/fold2/remove.this", "remove.this", function(err) {


            if (err) {
                return console.log(err);
            }

            fs.writeFile("test/only-folders/fold1/remove.this", "remove.this", function(err) {
                if (err) {
                    return console.log(err);
                }
                done();
            });
        });
    });

    function sortByName(array) {
        array.sort(function(a, b) {
            if (a.name === b.name) {
                return 0;
            }
            return a.name < b.name ? -1 : +1;
        });
    }

    it("is defined", function() {
        expect(webdisk).to.be.an("object");
    });

    describe("listFiles", function() {
        it("is defined", function() {
            expect(webdisk.listFiles).to.be.an("function");
        });

        it("return readable stream", function() {
            expect(webdisk.listFiles(".").readable).to.be.equal(true);
        });

        it("return all file names in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].name).to.be.equal("1.txt");
                expect(results[1].name).to.be.equal("2.txt");
                done();
            }));

        });



        it("return folder with only files as empty array", function(done) {
            webdisk.listFiles("test/only-folders").pipe(concat(function(results) {


                expect(results).to.be.equal("[]");

                done();
            }));

        });


        it("return all file paths in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].path).to.be.equal("test/files/1.txt");
                expect(results[1].path).to.be.equal("test/files/2.txt");
                done();
            }));

        });

        it("return empty folder as empty array", function(done) {
            webdisk.listFiles("test/files/fold2").pipe(concat(function(results) {


                expect(results).to.be.equal("[]");

                done();
            }));

        });

        it("return all file size in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].size).to.be.equal(5);
                expect(results[1].size).to.be.equal(5);
                done();
            }));

        });

        it("return all files uplodad date in folder", function(done) {
            webdisk.listFiles("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].uploaded).to.be.greaterThan(1390843380000);
                expect(results[1].uploaded).to.be.greaterThan(1390843380000);
                done();
            }));

        });
    });

    describe("listFolders", function() {

        it("is defined", function() {
            expect(webdisk.listFolders).to.be.an("function");
        });

        it("return readable stream", function() {
            expect(webdisk.listFolders(".").readable).to.be.equal(true);
        });

        it("return all subfolders names", function(done) {
            webdisk.listFolders("test/files").pipe(concat(function(results) {

                results = JSON.parse(results);
                sortByName(results);
                expect(results[0].name).to.be.equal("fold1");
                expect(results[1].name).to.be.equal("fold2");
                done();
            }));
{'fraction_non_alphanumeric': 0.1591153102855916, 'fraction_numerical': 0.012024908739531888, 'mean_word_length': 1.6343325791855203, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2808728', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2539, 'n_words': 379}