Skip to content

Commit

Permalink
Merge e32b6a2 into b18c44c
Browse files Browse the repository at this point in the history
  • Loading branch information
bkendall committed Oct 31, 2018
2 parents b18c44c + e32b6a2 commit c270343
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 29 deletions.
1 change: 1 addition & 0 deletions mocha.opts
@@ -1,4 +1,5 @@
--require ts-node/register
--require source-map-support/register
--recursive
--timeout=1000
src/test/**/*.{ts,js}
13 changes: 13 additions & 0 deletions package.json
Expand Up @@ -49,6 +49,18 @@
"url": "https://github.com/firebase/firebase-tools/issues"
},
"homepage": "https://github.com/firebase/firebase-tools",
"nyc": {
"require": [
"ts-node/register"
],
"extension": [
".js",
".ts"
],
"exclude": [
"src/test/**/*"
]
},
"dependencies": {
"JSONStream": "^1.2.1",
"archiver": "^2.1.1",
Expand Down Expand Up @@ -110,6 +122,7 @@
"prettier": "1.14.3",
"sinon": "^6.3.4",
"sinon-chai": "^3.2.0",
"source-map-support": "^0.5.9",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-plugin-prettier": "^2.0.0",
Expand Down
22 changes: 0 additions & 22 deletions src/fsutils.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/fsutils.ts
@@ -0,0 +1,17 @@
import { statSync } from "fs";

export function fileExistsSync(path: string): boolean {
try {
return statSync(path).isFile();
} catch (e) {
return false;
}
}

export function dirExistsSync(path: string): boolean {
try {
return statSync(path).isDirectory();
} catch (e) {
return false;
}
}
8 changes: 4 additions & 4 deletions src/listFiles.ts
@@ -1,11 +1,11 @@
import * as glob from "glob";
import { sync } from "glob";

export function listFiles(cwd: string, ignore: string[]) {
return glob.sync("**/*", {
export function listFiles(cwd: string, ignore: string[] = []): string[] {
return sync("**/*", {
cwd,
dot: true,
follow: true,
ignore: ["**/firebase-debug.log", ".firebase/*"].concat(ignore || []),
ignore: ["**/firebase-debug.log", ".firebase/*"].concat(ignore),
nodir: true,
nosort: true,
});
Expand Down
33 changes: 33 additions & 0 deletions src/test/fsutils.spec.ts
@@ -0,0 +1,33 @@
import { expect } from "chai";

import * as fsutils from "../fsutils";

describe("fsutils", () => {
describe("fileExistsSync", () => {
it("should return true if the file exists", () => {
expect(fsutils.fileExistsSync(__filename)).to.be.true;
});

it("should return false if the file does not exist", () => {
expect(fsutils.fileExistsSync(`${__filename}/nope.never`)).to.be.false;
});

it("should return false if the path is a directory", () => {
expect(fsutils.fileExistsSync(__dirname)).to.be.false;
});
});

describe("dirExistsSync", () => {
it("should return true if the directory exists", () => {
expect(fsutils.dirExistsSync(__dirname)).to.be.true;
});

it("should return false if the directory does not exist", () => {
expect(fsutils.dirExistsSync(`${__dirname}/nope/never`)).to.be.false;
});

it("should return false if the path is a file", () => {
expect(fsutils.dirExistsSync(__filename)).to.be.false;
});
});
});
19 changes: 16 additions & 3 deletions src/test/listFiles.spec.ts
@@ -1,18 +1,31 @@
import { expect } from "chai";

import * as path from "path";
import { resolve } from "path";

import { listFiles } from "../listFiles";

describe("listFiles", () => {
// for details, see the file structure and firebase.json in test/fixtures/ignores
it("should ignore firebase-debug.log, specified ignores, and nothing else", () => {
const fileNames = listFiles(path.resolve(__dirname, "./fixtures/ignores"), [
const fileNames = listFiles(resolve(__dirname, "./fixtures/ignores"), [
"**/.*",
"firebase.json",
"ignored.txt",
"ignored/**/*.txt",
]);
expect(fileNames).to.deep.equal(["index.html", "ignored/index.html", "present/index.html"]);
});

it("should allow us to not specify additional ignores", () => {
const fileNames = listFiles(resolve(__dirname, "./fixtures/ignores"));
expect(fileNames.sort()).to.have.members([
".hiddenfile",
"firebase.json",
"ignored.txt",
"ignored/deeper/index.txt",
"ignored/ignore.txt",
"ignored/index.html",
"index.html",
"present/index.html",
]);
});
});

0 comments on commit c270343

Please sign in to comment.