diff --git a/mocha.opts b/mocha.opts index c70db2fd..4cd00237 100644 --- a/mocha.opts +++ b/mocha.opts @@ -1,4 +1,5 @@ --require ts-node/register +--require source-map-support/register --recursive --timeout=1000 src/test/**/*.{ts,js} diff --git a/package.json b/package.json index 696be29c..1f67ddc2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/fsutils.js b/src/fsutils.js deleted file mode 100644 index 0a25628c..00000000 --- a/src/fsutils.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; - -var fs = require("fs"); - -module.exports = { - fileExistsSync: function(path) { - try { - var stats = fs.statSync(path); - return stats.isFile(); - } catch (e) { - return false; - } - }, - dirExistsSync: function(path) { - try { - var stats = fs.statSync(path); - return stats.isDirectory(); - } catch (e) { - return false; - } - }, -}; diff --git a/src/fsutils.ts b/src/fsutils.ts new file mode 100644 index 00000000..98300331 --- /dev/null +++ b/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; + } +} diff --git a/src/listFiles.ts b/src/listFiles.ts index 2c6fd57b..3cf1f05e 100644 --- a/src/listFiles.ts +++ b/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, }); diff --git a/src/test/fsutils.spec.ts b/src/test/fsutils.spec.ts new file mode 100644 index 00000000..3a7eddba --- /dev/null +++ b/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; + }); + }); +}); diff --git a/src/test/listFiles.spec.ts b/src/test/listFiles.spec.ts index 950b3bb3..af1fbd0c 100644 --- a/src/test/listFiles.spec.ts +++ b/src/test/listFiles.spec.ts @@ -1,13 +1,12 @@ 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", @@ -15,4 +14,18 @@ describe("listFiles", () => { ]); 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", + ]); + }); });