├── .appveyor.yml ├── .gitignore ├── .travis.yml ├── README.md ├── index.js ├── license ├── package.json └── test ├── helpers.js └── test.js /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Test against these versions of Node.js 2 | environment: 3 | matrix: 4 | - nodejs_version: 8 5 | - nodejs_version: 10 6 | - nodejs_version: 12 7 | - nodejs_version: '' # latest version 8 | 9 | platform: 10 | - x86 11 | - x64 12 | 13 | # Install scripts (runs after repo cloning) 14 | install: 15 | # Get the latest stable version of Node.js 16 | - ps: Install-Product node $env:nodejs_version $env:platform 17 | # Install modules 18 | - npm install 19 | 20 | # Post-install test scripts 21 | test_script: 22 | # Output useful info for debugging 23 | - node --version 24 | - npm --version 25 | # Run tests 26 | - ps: "npm run ci --loglevel=error # PowerShell" # Hide warnings to avoid exceptions; Pass comment for easier debugging 27 | - cmd: npm run ci 28 | 29 | # Don't actually build 30 | build: off 31 | 32 | # Set build version format here instead of in the admin panel 33 | version: "{build}" 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | node_modules/ 3 | .nyc_output/ 4 | package-lock.json 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 8 4 | - 10 5 | - 12 6 | - node 7 | #script: npm run ci 8 | script: npm test # no coverage, as coveralls cannot merge reports 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hidefile [![NPM Version][npm-image]][npm-url] [![Linux Build][travis-image]][travis-url] [![Windows Build][appveyor-image]][appveyor-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url] 2 | 3 | > Hide files and directories on all platforms. 4 | 5 | Unix: 6 | * Adds or removes a "." prefix on a file or dir 7 | 8 | Windows: 9 | * Adds or removes a "." prefix on a file or dir 10 | * Adds or removes the "hidden" attribute on a file or dir 11 | 12 | A native binding is used, offering great performance. As a contingency in case that fails, functionality will silently revert to a command line, though it is considerably slower. 13 | 14 | 15 | ## Installation 16 | 17 | [Node.js](http://nodejs.org/) `>= 8` is required. To install, type this at the command line: 18 | ``` 19 | npm install hidefile 20 | ``` 21 | 22 | 23 | ## Methods 24 | 25 | ### `hide(path, callback)` 26 | `path` - Path to file or directory 27 | `callback(err,newpath)` - A callback which is called upon completion 28 | ```js 29 | hidefile.hide('path/to/file.ext', (err, newpath) => { 30 | if (err == null) { 31 | console.log(newpath); //-> 'path/to/.file.ext' 32 | } 33 | }); 34 | ``` 35 | 36 | ### `hideSync(path)` 37 | `path` - Path to file or directory 38 | 39 | Throws an error if the file or dir cannot be found/accessed. 40 | ```js 41 | const newpath = hidefile.hideSync('path/to/file.ext'); 42 | 43 | console.log(newpath); //-> 'path/to/.file.ext' 44 | ``` 45 | 46 | ### `isDotPrefixed(path)` 47 | `path` - Path to file or directory 48 | ```js 49 | console.log( hidefile.isDotPrefixed('path/to/.file.ext') ); //-> true 50 | console.log( hidefile.isDotPrefixed('path/to/file.ext') ); //-> false 51 | ``` 52 | 53 | ### `isHidden(path, callback)` 54 | `path` - Path to file or directory 55 | `callback(result)` - A callback which is called upon completion 56 | ```js 57 | hidefile.isHidden('path/to/file.ext', (err, result) => { 58 | if (err == null) { 59 | console.log(result); //-> false 60 | } 61 | }); 62 | ``` 63 | Unix: `result` is `true` if prefixed. 64 | Windows: `result` is `true` if prefixed *and* has "hidden" attribute, `false` if only prefixed. 65 | 66 | ### `isHiddenSync(path)` 67 | `path` - Path to file or directory 68 | 69 | Throws an error if the file or dir cannot be found/accessed. 70 | ```js 71 | const result = hidefile.isHiddenSync('path/to/file.ext'); 72 | 73 | console.log(result); //-> false 74 | ``` 75 | 76 | ### `reveal(path, callback)` 77 | `path` - Path to file or directory 78 | `callback(err,newpath)` - A callback which is called upon completion 79 | ```js 80 | hidefile.reveal('path/to/.file.ext', (err, newpath) => { 81 | if (err == null) { 82 | console.log(newpath); //-> 'path/to/file.ext' 83 | } 84 | }); 85 | ``` 86 | 87 | ### `revealSync(path)` 88 | `path` - Path to file or directory 89 | 90 | Throws an error if the file or dir cannot be found/accessed. 91 | ```js 92 | const newpath = hidefile.revealSync('path/to/.file.ext'); 93 | 94 | console.log(newpath); //-> 'path/to/file.ext' 95 | ``` 96 | 97 | ### `shouldBeHidden(path, callback)` 98 | `path` - Path to file or directory 99 | `callback(result)` - A callback which is called upon completion 100 | ```js 101 | if (isWindows) { 102 | hidefile.shouldBeHidden('path/to/.file.ext', (err, result) => { 103 | if (err == null) { 104 | console.log(result); //-> true 105 | } 106 | }); 107 | } 108 | ``` 109 | Unix: `result` is `true` if prefixed. 110 | Windows: `result` is `true` if prefixed *or* has "hidden" attribute. 111 | 112 | ### `shouldBeHiddenSync(path)` 113 | `path` - Path to file or directory 114 | 115 | Throws an error if the file or dir cannot be found/accessed. 116 | ```js 117 | if (isWindows) { 118 | result = hidefile.shouldBeHiddenSync('path/to/.file.ext'); 119 | 120 | console.log(result); //-> true 121 | } 122 | ``` 123 | 124 | 125 | [npm-image]: https://img.shields.io/npm/v/hidefile.svg 126 | [npm-url]: https://npmjs.com/package/hidefile 127 | [travis-image]: https://img.shields.io/travis/stevenvachon/hidefile.svg?label=linux 128 | [travis-url]: https://travis-ci.org/stevenvachon/hidefile 129 | [appveyor-image]: https://img.shields.io/appveyor/ci/stevenvachon/hidefile.svg?label=windows 130 | [appveyor-url]: https://ci.appveyor.com/project/stevenvachon/hidefile 131 | [coveralls-image]: https://img.shields.io/coveralls/stevenvachon/hidefile.svg 132 | [coveralls-url]: https://coveralls.io/github/stevenvachon/hidefile 133 | [greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/hidefile.svg 134 | [greenkeeper-url]: https://greenkeeper.io/ 135 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const fs = require("fs"); 3 | const pathlib = require("path"); 4 | const winattr = require("winattr"); 5 | 6 | const isWindows = process.platform.startsWith("win"); 7 | const prefix = "."; 8 | 9 | 10 | 11 | const change = (before, after, attrs, callback) => 12 | { 13 | //if (before !== after) 14 | //{ 15 | fs.rename(before, after, error => 16 | { 17 | if (error==null && isWindows) 18 | { 19 | winattr.set(after, attrs, error => 20 | { 21 | change_callback(error, after, callback); 22 | }); 23 | } 24 | else 25 | { 26 | change_callback(error, after, callback); 27 | } 28 | }); 29 | /*} 30 | else if (isWindows) 31 | { 32 | winattr.set(after, attrs, error => 33 | { 34 | change_callback(error, after, callback); 35 | }); 36 | } 37 | else 38 | { 39 | // Will not produce error if file does not exist and did not attempt to rename 40 | callback(null, after); 41 | }*/ 42 | }; 43 | 44 | 45 | 46 | const change_callback = (error, after, callback) => 47 | { 48 | if (error == null) 49 | { 50 | callback(error, after); 51 | } 52 | else 53 | { 54 | // Avoids arguments being [error,undefined].length===2 55 | callback(error); 56 | } 57 | }; 58 | 59 | 60 | 61 | const changeSync = (before, after, attrs) => 62 | { 63 | //if (before !== after) 64 | //{ 65 | fs.renameSync(before, after); 66 | //} 67 | // Else: will not produce error if file does not exist and did not attempt to rename 68 | 69 | if (isWindows) 70 | { 71 | winattr.setSync(after, attrs); 72 | } 73 | 74 | return after; 75 | }; 76 | 77 | 78 | 79 | const parsePath = path => 80 | { 81 | const basename = pathlib.basename(path); 82 | let dirname = pathlib.dirname(path); 83 | 84 | // Omit current dir marker 85 | if (dirname === ".") dirname = ""; 86 | 87 | return { 88 | basename: basename, 89 | dirname: dirname, 90 | prefixed: basename[0] === prefix 91 | }; 92 | }; 93 | 94 | 95 | 96 | const stat = (path, callback) => 97 | { 98 | const result = 99 | { 100 | unix: parsePath(path).prefixed, 101 | windows: false 102 | }; 103 | 104 | if (isWindows) 105 | { 106 | winattr.get(path, (error, data) => 107 | { 108 | result.windows = (error!=null) ? false : data.hidden; 109 | 110 | callback(error, result); 111 | }); 112 | } 113 | else 114 | { 115 | callback(null, result); 116 | } 117 | }; 118 | 119 | 120 | 121 | const statSync = path => 122 | { 123 | const result = 124 | { 125 | unix: parsePath(path).prefixed, 126 | windows: false 127 | }; 128 | 129 | if (isWindows) 130 | { 131 | result.windows = winattr.getSync(path).hidden; 132 | } 133 | 134 | return result; 135 | }; 136 | 137 | 138 | 139 | const stringifyPath = (pathObj, shouldHavePrefix) => 140 | { 141 | let result = ""; 142 | 143 | if (pathObj.basename !== "") 144 | { 145 | if (shouldHavePrefix && !pathObj.prefixed) 146 | { 147 | result = prefix + pathObj.basename; 148 | } 149 | else if (!shouldHavePrefix && pathObj.prefixed) 150 | { 151 | result = pathObj.basename.slice(1); 152 | } 153 | else 154 | { 155 | result = pathObj.basename; 156 | } 157 | } 158 | 159 | if (pathObj.dirname !== "") 160 | { 161 | // If has a basename, and dirname is not "/" nor has a trailing slash (unlikely) 162 | if (result!=="" && pathObj.dirname!=="/" && pathObj.dirname[pathObj.dirname.length-1]!=="/") 163 | { 164 | result = pathObj.dirname +"/"+ result; 165 | } 166 | else 167 | { 168 | result = pathObj.dirname + result; 169 | } 170 | } 171 | 172 | return result; 173 | }; 174 | 175 | 176 | 177 | //::: PUBLIC FUNCTIONS 178 | 179 | 180 | 181 | const hide = (path, callback) => 182 | { 183 | const newpath = stringifyPath( parsePath(path), true ); 184 | 185 | change(path, newpath, {hidden:true}, callback); 186 | }; 187 | 188 | 189 | 190 | const hideSync = path => 191 | { 192 | const newpath = stringifyPath( parsePath(path), true ); 193 | 194 | return changeSync(path, newpath, {hidden:true}); 195 | }; 196 | 197 | 198 | 199 | const isDotPrefixed = path => 200 | { 201 | return pathlib.basename(path)[0] === prefix; 202 | }; 203 | 204 | 205 | 206 | const isHidden = (path, callback) => 207 | { 208 | stat(path, (error, data) => 209 | { 210 | if (error == null) 211 | { 212 | callback( null, data.unix && ((data.windows && isWindows) || !isWindows) ); 213 | } 214 | else 215 | { 216 | callback(error); 217 | } 218 | }); 219 | }; 220 | 221 | 222 | 223 | const isHiddenSync = (path, callback) => 224 | { 225 | const data = statSync(path); 226 | 227 | return data.unix && ((data.windows && isWindows) || !isWindows); 228 | }; 229 | 230 | 231 | 232 | const reveal = (path, callback) => 233 | { 234 | const newpath = stringifyPath( parsePath(path), false ); 235 | 236 | change(path, newpath, {hidden:false}, callback); 237 | }; 238 | 239 | 240 | 241 | const revealSync = (path, callback) => 242 | { 243 | const newpath = stringifyPath( parsePath(path), false ); 244 | 245 | return changeSync(path, newpath, {hidden:false}); 246 | }; 247 | 248 | 249 | 250 | const shouldBeHidden = (path, callback) => 251 | { 252 | stat(path, (error, data) => 253 | { 254 | if (error == null) 255 | { 256 | callback( null, data.unix || data.windows ); 257 | } 258 | else 259 | { 260 | callback(error); 261 | } 262 | }); 263 | }; 264 | 265 | 266 | 267 | const shouldBeHiddenSync = (path, callback) => 268 | { 269 | const data = statSync(path); 270 | 271 | return data.unix || data.windows; 272 | }; 273 | 274 | 275 | 276 | module.exports = 277 | { 278 | hide, 279 | hideSync, 280 | isDotPrefixed, 281 | isHidden, 282 | isHiddenSync, 283 | reveal, 284 | revealSync, 285 | shouldBeHidden, 286 | shouldBeHiddenSync 287 | }; 288 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Steven Vachon (svachon.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hidefile", 3 | "description": "Hide files and directories on all platforms.", 4 | "version": "3.0.0", 5 | "license": "MIT", 6 | "author": "Steven Vachon (https://svachon.com)", 7 | "repository": "github:stevenvachon/hidefile", 8 | "dependencies": { 9 | "winattr": "^3.0.0" 10 | }, 11 | "devDependencies": { 12 | "chai": "^4.2.0", 13 | "coveralls": "^3.0.3", 14 | "mocha": "^6.1.4", 15 | "nyc": "^14.0.0" 16 | }, 17 | "engines": { 18 | "node": ">= 8" 19 | }, 20 | "scripts": { 21 | "ci": "npm run test && nyc report --reporter=text-lcov | coveralls", 22 | "posttest": "nyc report --reporter=text-summary --reporter=html", 23 | "test": "nyc --silent mocha test/ --bail --check-leaks" 24 | }, 25 | "files": [ 26 | "index.js" 27 | ], 28 | "keywords": [ 29 | "directory", 30 | "dotfile", 31 | "file", 32 | "folder", 33 | "fs", 34 | "hidden", 35 | "hide", 36 | "native", 37 | "windows" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/helpers.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const fs = require("fs"); 3 | const winattr = require("winattr"); 4 | 5 | const isWindows = process.platform.startsWith("win"); 6 | 7 | 8 | 9 | const newFile = (path, attrs) => 10 | { 11 | fs.writeFileSync(path, ""); 12 | setAttrs(path, attrs); 13 | }; 14 | 15 | 16 | 17 | const newFolder = (path, attrs) => 18 | { 19 | fs.mkdirSync(path); 20 | setAttrs(path, attrs); 21 | }; 22 | 23 | 24 | 25 | const setAttrs = (path, attrs) => 26 | { 27 | if (isWindows) 28 | { 29 | if (attrs!=null && typeof attrs==="object") 30 | { 31 | winattr.setSync(path, attrs); 32 | } 33 | } 34 | }; 35 | 36 | 37 | 38 | module.exports = 39 | { 40 | isWindows, 41 | newFile, 42 | newFolder, 43 | removeFile: fs.unlinkSync, 44 | removeFolder: fs.rmdirSync, 45 | TEMP_HIDDEN: ".temp", 46 | TEMP_VISIBLE: "temp" 47 | }; 48 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const {expect} = require("chai"); 3 | const hidefile = require("../"); 4 | const {isWindows, newFile, newFolder, removeFile, removeFolder, TEMP_HIDDEN, TEMP_VISIBLE} = require("./helpers"); 5 | const winattr = require("winattr"); 6 | 7 | const describe_unixOnly = !isWindows ? describe : describe.skip; 8 | const describe_windowsOnly = isWindows ? describe : describe.skip; 9 | 10 | 11 | 12 | describe("isDotPrefixed()", () => 13 | { 14 | it("should be true for prefixed dot", () => 15 | { 16 | expect( hidefile.isDotPrefixed("path/to/.file.ext") ).to.be.true; 17 | expect( hidefile.isDotPrefixed("path/to/.file") ).to.be.true; 18 | expect( hidefile.isDotPrefixed(".file.ext") ).to.be.true; 19 | expect( hidefile.isDotPrefixed(".file") ).to.be.true; 20 | 21 | expect( hidefile.isDotPrefixed(".path/to/.file.ext") ).to.be.true; 22 | expect( hidefile.isDotPrefixed("path/.to/.file.ext") ).to.be.true; 23 | expect( hidefile.isDotPrefixed("path/to/.file.file.ext") ).to.be.true; 24 | expect( hidefile.isDotPrefixed("./.file") ).to.be.true; 25 | }); 26 | 27 | it("should be false for missing prefixed dot", () => 28 | { 29 | expect( hidefile.isDotPrefixed("path/to/file.ext") ).to.be.false; 30 | expect( hidefile.isDotPrefixed("path/to/file") ).to.be.false; 31 | expect( hidefile.isDotPrefixed("file.ext") ).to.be.false; 32 | expect( hidefile.isDotPrefixed("file") ).to.be.false; 33 | 34 | expect( hidefile.isDotPrefixed(".path/to/file.ext") ).to.be.false; 35 | expect( hidefile.isDotPrefixed("path/.to/file.ext") ).to.be.false; 36 | expect( hidefile.isDotPrefixed("path/to/file.file.ext") ).to.be.false; 37 | expect( hidefile.isDotPrefixed("./file") ).to.be.false; 38 | }); 39 | }); 40 | 41 | 42 | 43 | describe("isHidden()", () => 44 | { 45 | describe_unixOnly("on Unix", () => 46 | { 47 | it("should be true for prefix-only files", done => 48 | { 49 | // No need to create file on Unix as it's all string-based 50 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 51 | { 52 | expect(error).to.be.null; 53 | expect(result).to.be.true; 54 | done(); 55 | }); 56 | }); 57 | 58 | it("should be true for prefix-only folders", done => 59 | { 60 | // No need to create file on Unix as it's all string-based 61 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 62 | { 63 | expect(error).to.be.null; 64 | expect(result).to.be.true; 65 | done(); 66 | }); 67 | }); 68 | }); 69 | 70 | describe_windowsOnly("on Windows", () => 71 | { 72 | it("should be false for unprefixed-unattributed files", done => 73 | { 74 | newFile(TEMP_VISIBLE); 75 | 76 | hidefile.isHidden(TEMP_VISIBLE, (error, result) => 77 | { 78 | removeFile(TEMP_VISIBLE); 79 | expect(error).to.be.null; 80 | expect(result).to.be.false; 81 | done(); 82 | }); 83 | }); 84 | 85 | it("should be false for unprefixed-unattributed folders", done => 86 | { 87 | newFolder(TEMP_VISIBLE); 88 | 89 | hidefile.isHidden(TEMP_VISIBLE, (error, result) => 90 | { 91 | removeFolder(TEMP_VISIBLE); 92 | expect(error).to.be.null; 93 | expect(result).to.be.false; 94 | done(); 95 | }); 96 | }); 97 | 98 | it("should be false for prefix-only files", done => 99 | { 100 | newFile(TEMP_HIDDEN); 101 | 102 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 103 | { 104 | removeFile(TEMP_HIDDEN); 105 | expect(error).to.be.null; 106 | expect(result).to.be.false; 107 | done(); 108 | }); 109 | }); 110 | 111 | it("should be false for prefix-only folders", done => 112 | { 113 | newFolder(TEMP_HIDDEN); 114 | 115 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 116 | { 117 | removeFolder(TEMP_HIDDEN); 118 | expect(error).to.be.null; 119 | expect(result).to.be.false; 120 | done(); 121 | }); 122 | }); 123 | 124 | it("should be false for attribute-only files", done => 125 | { 126 | newFile(TEMP_VISIBLE, {hidden:true}); 127 | 128 | hidefile.isHidden(TEMP_VISIBLE, (error, result) => 129 | { 130 | removeFile(TEMP_VISIBLE); 131 | expect(error).to.be.null; 132 | expect(result).to.be.false; 133 | done(); 134 | }); 135 | }); 136 | 137 | it("should be false for attribute-only folders", done => 138 | { 139 | newFolder(TEMP_VISIBLE, {hidden:true}); 140 | 141 | hidefile.isHidden(TEMP_VISIBLE, (error, result) => 142 | { 143 | removeFolder(TEMP_VISIBLE); 144 | expect(error).to.be.null; 145 | expect(result).to.be.false; 146 | done(); 147 | }); 148 | }); 149 | 150 | it("should be true for prefixed-attributed files", done => 151 | { 152 | newFile(TEMP_HIDDEN, {hidden:true}); 153 | 154 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 155 | { 156 | removeFile(TEMP_HIDDEN); 157 | expect(error).to.be.null; 158 | expect(result).to.be.true; 159 | done(); 160 | }); 161 | }); 162 | 163 | it("should be true for prefixed-attributed folders", done => 164 | { 165 | newFolder(TEMP_HIDDEN, {hidden:true}); 166 | 167 | hidefile.isHidden(TEMP_HIDDEN, (error, result) => 168 | { 169 | removeFolder(TEMP_HIDDEN); 170 | expect(error).to.be.null; 171 | expect(result).to.be.true; 172 | done(); 173 | }); 174 | }); 175 | 176 | it("should error for non-existent unprefixed paths", done => 177 | { 178 | hidefile.isHidden("fake", (error, result) => 179 | { 180 | expect(error).to.be.instanceOf(Error); 181 | expect(result).to.be.undefined; 182 | done(); 183 | }); 184 | }); 185 | 186 | it("should error for non-existent prefixed paths", done => 187 | { 188 | hidefile.isHidden(".fake", (error, result) => 189 | { 190 | expect(error).to.be.instanceOf(Error); 191 | expect(result).to.be.undefined; 192 | done(); 193 | }); 194 | }); 195 | }); 196 | }); 197 | 198 | 199 | 200 | describe("isHiddenSync()", () => 201 | { 202 | describe_unixOnly("on Unix", () => 203 | { 204 | it("should be true for prefix-only files", () => 205 | { 206 | // No need to create file on Unix as it's all string-based 207 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 208 | 209 | expect(result).to.be.true; 210 | }); 211 | 212 | it("should be true for prefix-only folders", () => 213 | { 214 | // No need to create file on Unix as it's all string-based 215 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 216 | 217 | expect(result).to.be.true; 218 | }); 219 | }); 220 | 221 | describe_windowsOnly("on Windows", () => 222 | { 223 | it("should be false for unprefixed-unattributed files", () => 224 | { 225 | newFile(TEMP_VISIBLE); 226 | 227 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 228 | 229 | removeFile(TEMP_VISIBLE); 230 | expect(result).to.be.false; 231 | }); 232 | 233 | it("should be false for unprefixed-unattributed folders", () => 234 | { 235 | newFolder(TEMP_VISIBLE); 236 | 237 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 238 | 239 | removeFolder(TEMP_VISIBLE); 240 | expect(result).to.be.false; 241 | }); 242 | 243 | it("should be false for prefix-only files", () => 244 | { 245 | newFile(TEMP_HIDDEN); 246 | 247 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 248 | 249 | removeFile(TEMP_HIDDEN); 250 | expect(result).to.be.false; 251 | }); 252 | 253 | it("should be false for prefix-only folders", () => 254 | { 255 | newFolder(TEMP_HIDDEN); 256 | 257 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 258 | 259 | removeFolder(TEMP_HIDDEN); 260 | expect(result).to.be.false; 261 | }); 262 | 263 | it("should be false for attribute-only files", () => 264 | { 265 | newFile(TEMP_VISIBLE, {hidden:true}); 266 | 267 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 268 | 269 | removeFile(TEMP_VISIBLE); 270 | expect(result).to.be.false; 271 | }); 272 | 273 | it("should be false for attribute-only folders", () => 274 | { 275 | newFolder(TEMP_VISIBLE, {hidden:true}); 276 | 277 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 278 | 279 | removeFolder(TEMP_VISIBLE); 280 | expect(result).to.be.false; 281 | }); 282 | 283 | it("should be true for prefixed-attributed files", () => 284 | { 285 | newFile(TEMP_HIDDEN, {hidden:true}); 286 | 287 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 288 | 289 | removeFile(TEMP_HIDDEN); 290 | expect(result).to.be.true; 291 | }); 292 | 293 | it("should be true for prefixed-attributed folders", () => 294 | { 295 | newFolder(TEMP_HIDDEN, {hidden:true}); 296 | 297 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 298 | 299 | removeFolder(TEMP_HIDDEN); 300 | expect(result).to.be.true; 301 | }); 302 | 303 | it("should error for non-existent unprefixed paths", () => 304 | { 305 | let error,result; 306 | 307 | try 308 | { 309 | result = hidefile.isHiddenSync("fake"); 310 | } 311 | catch (e) 312 | { 313 | error = e; 314 | } 315 | 316 | expect(error).to.be.instanceOf(Error); 317 | expect(result).to.be.undefined; 318 | }); 319 | 320 | it("should error for non-existent prefixed paths", () => 321 | { 322 | let error,result; 323 | 324 | try 325 | { 326 | result = hidefile.isHiddenSync(".fake"); 327 | } 328 | catch (e) 329 | { 330 | error = e; 331 | } 332 | 333 | expect(error).to.be.instanceOf(Error); 334 | expect(result).to.be.undefined; 335 | }); 336 | }); 337 | }); 338 | 339 | 340 | 341 | describe("shouldBeHidden()", () => 342 | { 343 | it("should be false for unprefixed-unattributed files", done => 344 | { 345 | newFile(TEMP_VISIBLE); 346 | 347 | hidefile.shouldBeHidden(TEMP_VISIBLE, (error, result) => 348 | { 349 | removeFile(TEMP_VISIBLE); 350 | expect(error).to.be.null; 351 | expect(result).to.be.false; 352 | done(); 353 | }); 354 | }); 355 | 356 | it("should be false for unprefixed-unattributed folders", done => 357 | { 358 | newFolder(TEMP_VISIBLE); 359 | 360 | hidefile.shouldBeHidden(TEMP_VISIBLE, (error, result) => 361 | { 362 | removeFolder(TEMP_VISIBLE); 363 | expect(error).to.be.null; 364 | expect(result).to.be.false; 365 | done(); 366 | }); 367 | }); 368 | 369 | it("should be true for prefix-only files", done => 370 | { 371 | newFile(TEMP_HIDDEN); 372 | 373 | hidefile.shouldBeHidden(TEMP_HIDDEN, (error, result) => 374 | { 375 | removeFile(TEMP_HIDDEN); 376 | expect(error).to.be.null; 377 | expect(result).to.be.true; 378 | done(); 379 | }); 380 | }); 381 | 382 | it("should be true for prefix-only folders", done => 383 | { 384 | newFolder(TEMP_HIDDEN); 385 | 386 | hidefile.shouldBeHidden(TEMP_HIDDEN, (error, result) => 387 | { 388 | removeFolder(TEMP_HIDDEN); 389 | expect(error).to.be.null; 390 | expect(result).to.be.true; 391 | done(); 392 | }); 393 | }); 394 | 395 | describe_windowsOnly("on Windows", () => 396 | { 397 | it("should be true for attribute-only files", done => 398 | { 399 | newFile(TEMP_VISIBLE, {hidden:true}); 400 | 401 | hidefile.shouldBeHidden(TEMP_VISIBLE, (error, result) => 402 | { 403 | removeFile(TEMP_VISIBLE); 404 | expect(error).to.be.null; 405 | expect(result).to.be.true; 406 | done(); 407 | }); 408 | }); 409 | 410 | it("should be true for attribute-only folders", done => 411 | { 412 | newFolder(TEMP_VISIBLE, {hidden:true}); 413 | 414 | hidefile.shouldBeHidden(TEMP_VISIBLE, (error, result) => 415 | { 416 | removeFolder(TEMP_VISIBLE); 417 | expect(error).to.be.null; 418 | expect(result).to.be.true; 419 | done(); 420 | }); 421 | }); 422 | 423 | it("should be true for prefixed-attributed files", done => 424 | { 425 | newFile(TEMP_HIDDEN, {hidden:true}); 426 | 427 | hidefile.shouldBeHidden(TEMP_HIDDEN, (error, result) => 428 | { 429 | removeFile(TEMP_HIDDEN); 430 | expect(error).to.be.null; 431 | expect(result).to.be.true; 432 | done(); 433 | }); 434 | }); 435 | 436 | it("should be true for prefixed-attributed folders", done => 437 | { 438 | newFolder(TEMP_HIDDEN, {hidden:true}); 439 | 440 | hidefile.shouldBeHidden(TEMP_HIDDEN, (error, result) => 441 | { 442 | removeFolder(TEMP_HIDDEN); 443 | expect(error).to.be.null; 444 | expect(result).to.be.true; 445 | done(); 446 | }); 447 | }); 448 | 449 | it("should error for non-existent unprefixed paths", done => 450 | { 451 | hidefile.shouldBeHidden("fake", (error, result) => 452 | { 453 | expect(error).to.be.instanceOf(Error); 454 | expect(result).to.be.undefined; 455 | done(); 456 | }); 457 | }); 458 | 459 | it("should error for non-existent prefixed paths", done => 460 | { 461 | hidefile.shouldBeHidden(".fake", (error, result) => 462 | { 463 | expect(error).to.be.instanceOf(Error); 464 | expect(result).to.be.undefined; 465 | done(); 466 | }); 467 | }); 468 | }); 469 | }); 470 | 471 | 472 | 473 | describe("shouldBeHiddenSync()", () => 474 | { 475 | it("should be false for unprefixed-unattributed files", () => 476 | { 477 | newFile(TEMP_VISIBLE); 478 | 479 | const result = hidefile.shouldBeHiddenSync(TEMP_VISIBLE); 480 | 481 | removeFile(TEMP_VISIBLE); 482 | expect(result).to.be.false; 483 | }); 484 | 485 | it("should be false for unprefixed-unattributed folders", () => 486 | { 487 | newFolder(TEMP_VISIBLE); 488 | 489 | const result = hidefile.shouldBeHiddenSync(TEMP_VISIBLE); 490 | 491 | removeFolder(TEMP_VISIBLE); 492 | expect(result).to.be.false; 493 | }); 494 | 495 | it("should be true for prefix-only files", () => 496 | { 497 | newFile(TEMP_HIDDEN); 498 | 499 | const result = hidefile.shouldBeHiddenSync(TEMP_HIDDEN); 500 | 501 | removeFile(TEMP_HIDDEN); 502 | expect(result).to.be.true; 503 | }); 504 | 505 | it("should be true for prefix-only folders", () => 506 | { 507 | newFolder(TEMP_HIDDEN); 508 | 509 | const result = hidefile.shouldBeHiddenSync(TEMP_HIDDEN); 510 | 511 | removeFolder(TEMP_HIDDEN); 512 | expect(result).to.be.true; 513 | }); 514 | 515 | describe_windowsOnly("on Windows", () => 516 | { 517 | it("should be true for attribute-only files", () => 518 | { 519 | newFile(TEMP_VISIBLE, {hidden:true}); 520 | 521 | const result = hidefile.shouldBeHiddenSync(TEMP_VISIBLE); 522 | 523 | removeFile(TEMP_VISIBLE); 524 | expect(result).to.be.true; 525 | }); 526 | 527 | it("should be true for attribute-only folders", () => 528 | { 529 | newFolder(TEMP_VISIBLE, {hidden:true}); 530 | 531 | const result = hidefile.shouldBeHiddenSync(TEMP_VISIBLE); 532 | 533 | removeFolder(TEMP_VISIBLE); 534 | expect(result).to.be.true; 535 | }); 536 | 537 | it("should be true for prefixed-attributed files", () => 538 | { 539 | newFile(TEMP_HIDDEN, {hidden:true}); 540 | 541 | const result = hidefile.shouldBeHiddenSync(TEMP_HIDDEN); 542 | 543 | removeFile(TEMP_HIDDEN); 544 | expect(result).to.be.true; 545 | }); 546 | 547 | it("should be true for prefixed-attributed folders", () => 548 | { 549 | newFolder(TEMP_HIDDEN, {hidden:true}); 550 | 551 | const result = hidefile.shouldBeHiddenSync(TEMP_HIDDEN); 552 | 553 | removeFolder(TEMP_HIDDEN); 554 | expect(result).to.be.true; 555 | }); 556 | 557 | it("should error for non-existent unprefixed paths", () => 558 | { 559 | let error,result; 560 | 561 | try 562 | { 563 | result = hidefile.shouldBeHiddenSync("fake"); 564 | } 565 | catch (e) 566 | { 567 | error = e; 568 | } 569 | 570 | expect(error).to.be.instanceOf(Error); 571 | expect(result).to.be.undefined; 572 | }); 573 | 574 | it("should error for non-existent prefixed paths", () => 575 | { 576 | let error,result; 577 | 578 | try 579 | { 580 | result = hidefile.shouldBeHiddenSync(".fake"); 581 | } 582 | catch (e) 583 | { 584 | error = e; 585 | } 586 | 587 | expect(error).to.be.instanceOf(Error); 588 | expect(result).to.be.undefined; 589 | }); 590 | }); 591 | }); 592 | 593 | 594 | 595 | describe("hide()", () => 596 | { 597 | it("should work on unprefixed-unattributed files", done => 598 | { 599 | newFile(TEMP_VISIBLE); 600 | 601 | hidefile.hide(TEMP_VISIBLE, (error, newpath) => 602 | { 603 | const result = hidefile.isHiddenSync(newpath); 604 | 605 | removeFile(newpath); 606 | expect(error).to.be.null; 607 | expect(result).to.be.true; 608 | done(); 609 | }); 610 | }); 611 | 612 | it("should work on unprefixed-unattributed folders", done => 613 | { 614 | newFolder(TEMP_VISIBLE); 615 | 616 | hidefile.hide(TEMP_VISIBLE, (error, newpath) => 617 | { 618 | const result = hidefile.isHiddenSync(newpath); 619 | 620 | removeFolder(newpath); 621 | expect(error).to.be.null; 622 | expect(result).to.be.true; 623 | done(); 624 | }); 625 | }); 626 | 627 | it("should work on prefix-only files", done => 628 | { 629 | newFile(TEMP_HIDDEN); 630 | 631 | hidefile.hide(TEMP_HIDDEN, (error, newpath) => 632 | { 633 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 634 | 635 | removeFile(TEMP_HIDDEN); 636 | expect(error).to.be.null; 637 | expect(result).to.be.true; 638 | done(); 639 | }); 640 | }); 641 | 642 | it("should work on prefix-only folders", done => 643 | { 644 | newFolder(TEMP_HIDDEN); 645 | 646 | hidefile.hide(TEMP_HIDDEN, (error, newpath) => 647 | { 648 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 649 | 650 | removeFolder(TEMP_HIDDEN); 651 | expect(error).to.be.null; 652 | expect(result).to.be.true; 653 | done(); 654 | }); 655 | }); 656 | 657 | it("should error for non-existent unprefixed paths", done => 658 | { 659 | hidefile.hide("fake", (error, newpath) => 660 | { 661 | expect(error).to.be.instanceOf(Error); 662 | expect(newpath).to.be.undefined; 663 | done(); 664 | }); 665 | }); 666 | 667 | it("should error for non-existent prefixed paths", done => 668 | { 669 | hidefile.hide(".fake", (error, newpath) => 670 | { 671 | expect(error).to.be.instanceOf(Error); 672 | expect(newpath).to.be.undefined; 673 | done(); 674 | }); 675 | }); 676 | 677 | describe_windowsOnly("on Windows", () => 678 | { 679 | it("should work on attribute-only files", done => 680 | { 681 | newFile(TEMP_VISIBLE, {hidden:true}); 682 | 683 | hidefile.hide(TEMP_VISIBLE, (error, newpath) => 684 | { 685 | const result = hidefile.isHiddenSync(newpath); 686 | 687 | removeFile(newpath); 688 | expect(error).to.be.null; 689 | expect(result).to.be.true; 690 | done(); 691 | }); 692 | }); 693 | 694 | it("should work on attribute-only folders", done => 695 | { 696 | newFolder(TEMP_VISIBLE, {hidden:true}); 697 | 698 | hidefile.hide(TEMP_VISIBLE, (error, newpath) => 699 | { 700 | const result = hidefile.isHiddenSync(newpath); 701 | 702 | removeFolder(newpath); 703 | expect(error).to.be.null; 704 | expect(result).to.be.true; 705 | done(); 706 | }); 707 | }); 708 | 709 | it("should work on prefixed-attributed files", done => 710 | { 711 | newFile(TEMP_HIDDEN, {hidden:true}); 712 | 713 | hidefile.hide(TEMP_HIDDEN, (error, newpath) => 714 | { 715 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 716 | 717 | removeFile(TEMP_HIDDEN); 718 | expect(error).to.be.null; 719 | expect(result).to.be.true; 720 | done(); 721 | }); 722 | }); 723 | 724 | it("should work on prefixed-attributed folders", done => 725 | { 726 | newFolder(TEMP_HIDDEN, {hidden:true}); 727 | 728 | hidefile.hide(TEMP_HIDDEN, (error, newpath) => 729 | { 730 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 731 | 732 | removeFolder(TEMP_HIDDEN); 733 | expect(error).to.be.null; 734 | expect(result).to.be.true; 735 | done(); 736 | }); 737 | }); 738 | }); 739 | }); 740 | 741 | 742 | 743 | describe("hideSync()", () => 744 | { 745 | it("should work on unprefixed-unattributed files", () => 746 | { 747 | newFile(TEMP_VISIBLE); 748 | 749 | const newpath = hidefile.hideSync(TEMP_VISIBLE); 750 | const result = hidefile.isHiddenSync(newpath); 751 | 752 | removeFile(newpath); 753 | expect(result).to.be.true; 754 | }); 755 | 756 | it("should work on unprefixed-unattributed folders", () => 757 | { 758 | newFolder(TEMP_VISIBLE); 759 | 760 | const newpath = hidefile.hideSync(TEMP_VISIBLE); 761 | const result = hidefile.isHiddenSync(newpath); 762 | 763 | removeFolder(newpath); 764 | expect(result).to.be.true; 765 | }); 766 | 767 | it("should work on prefix-only files", () => 768 | { 769 | newFile(TEMP_HIDDEN); 770 | 771 | const newpath = hidefile.hideSync(TEMP_HIDDEN); 772 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 773 | 774 | removeFile(TEMP_HIDDEN); 775 | expect(result).to.be.true; 776 | }); 777 | 778 | it("should work on prefix-only folders", () => 779 | { 780 | newFolder(TEMP_HIDDEN); 781 | 782 | const newpath = hidefile.hideSync(TEMP_HIDDEN); 783 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 784 | 785 | removeFolder(TEMP_HIDDEN); 786 | expect(result).to.be.true; 787 | }); 788 | 789 | it("should error for non-existent unprefixed paths", () => 790 | { 791 | let error,newpath; 792 | 793 | try 794 | { 795 | newpath = hidefile.hideSync("fake"); 796 | } 797 | catch (e) 798 | { 799 | error = e; 800 | } 801 | 802 | expect(error).to.be.instanceOf(Error); 803 | expect(newpath).to.be.undefined; 804 | }); 805 | 806 | it("should error for non-existent prefixed paths", () => 807 | { 808 | let error,newpath; 809 | 810 | try 811 | { 812 | newpath = hidefile.hideSync(".fake"); 813 | } 814 | catch (e) 815 | { 816 | error = e; 817 | } 818 | 819 | expect(error).to.be.instanceOf(Error); 820 | expect(newpath).to.be.undefined; 821 | }); 822 | 823 | describe_windowsOnly("on Windows", () => 824 | { 825 | it("should work on attribute-only files", () => 826 | { 827 | newFile(TEMP_VISIBLE, {hidden:true}); 828 | 829 | const newpath = hidefile.hideSync(TEMP_VISIBLE); 830 | const result = hidefile.isHiddenSync(newpath); 831 | 832 | removeFile(newpath); 833 | expect(result).to.be.true; 834 | }); 835 | 836 | it("should work on attribute-only folders", () => 837 | { 838 | newFolder(TEMP_VISIBLE, {hidden:true}); 839 | 840 | const newpath = hidefile.hideSync(TEMP_VISIBLE); 841 | const result = hidefile.isHiddenSync(newpath); 842 | 843 | removeFolder(newpath); 844 | expect(result).to.be.true; 845 | }); 846 | 847 | it("should work on prefixed-attributed files", () => 848 | { 849 | newFile(TEMP_HIDDEN, {hidden:true}); 850 | 851 | const newpath = hidefile.hideSync(TEMP_HIDDEN); 852 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 853 | 854 | removeFile(TEMP_HIDDEN); 855 | expect(result).to.be.true; 856 | }); 857 | 858 | it("should work on prefixed-attributed folders", () => 859 | { 860 | newFolder(TEMP_HIDDEN, {hidden:true}); 861 | 862 | const newpath = hidefile.hideSync(TEMP_HIDDEN); 863 | const result = hidefile.isHiddenSync(TEMP_HIDDEN); 864 | 865 | removeFolder(TEMP_HIDDEN); 866 | expect(result).to.be.true; 867 | }); 868 | }); 869 | }); 870 | 871 | 872 | 873 | describe("reveal()", () => 874 | { 875 | it("should work on unprefixed-unattributed files", done => 876 | { 877 | newFile(TEMP_VISIBLE); 878 | 879 | hidefile.reveal(TEMP_VISIBLE, (error, newpath) => 880 | { 881 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 882 | 883 | removeFile(TEMP_VISIBLE); 884 | expect(error).to.be.null; 885 | expect(result).to.be.false; 886 | done(); 887 | }); 888 | }); 889 | 890 | it("should work on unprefixed-unattributed folders", done => 891 | { 892 | newFolder(TEMP_VISIBLE); 893 | 894 | hidefile.reveal(TEMP_VISIBLE, (error, newpath) => 895 | { 896 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 897 | 898 | removeFolder(TEMP_VISIBLE); 899 | expect(error).to.be.null; 900 | expect(result).to.be.false; 901 | done(); 902 | }); 903 | }); 904 | 905 | it("should work on prefix-only files", done => 906 | { 907 | newFile(TEMP_HIDDEN); 908 | 909 | hidefile.reveal(TEMP_HIDDEN, (error, newpath) => 910 | { 911 | const result = hidefile.isHiddenSync(newpath); 912 | 913 | removeFile(newpath); 914 | expect(error).to.be.null; 915 | expect(result).to.be.false; 916 | done(); 917 | }); 918 | }); 919 | 920 | it("should work on prefix-only folders", done => 921 | { 922 | newFolder(TEMP_HIDDEN); 923 | 924 | hidefile.reveal(TEMP_HIDDEN, (error, newpath) => 925 | { 926 | const result = hidefile.isHiddenSync(newpath); 927 | 928 | removeFolder(newpath); 929 | expect(error).to.be.null; 930 | expect(result).to.be.false; 931 | done(); 932 | }); 933 | }); 934 | 935 | it("should error for non-existent unprefixed paths", done => 936 | { 937 | hidefile.reveal("fake", (error, newpath) => 938 | { 939 | expect(error).to.be.instanceOf(Error); 940 | expect(newpath).to.be.undefined; 941 | done(); 942 | }); 943 | }); 944 | 945 | it("should error for non-existent prefixed paths", done => 946 | { 947 | hidefile.reveal(".fake", (error, newpath) => 948 | { 949 | expect(error).to.be.instanceOf(Error); 950 | expect(newpath).to.be.undefined; 951 | done(); 952 | }); 953 | }); 954 | 955 | describe_windowsOnly("on Windows", () => 956 | { 957 | it("should work on attribute-only files", done => 958 | { 959 | newFile(TEMP_VISIBLE, {hidden:true}); 960 | 961 | hidefile.reveal(TEMP_VISIBLE, (error, newpath) => 962 | { 963 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 964 | 965 | removeFile(TEMP_VISIBLE); 966 | expect(error).to.be.null; 967 | expect(result).to.be.false; 968 | done(); 969 | }); 970 | }); 971 | 972 | it("should work on attribute-only folders", done => 973 | { 974 | newFolder(TEMP_VISIBLE, {hidden:true}); 975 | 976 | hidefile.reveal(TEMP_VISIBLE, (error, newpath) => 977 | { 978 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 979 | 980 | removeFolder(TEMP_VISIBLE); 981 | expect(error).to.be.null; 982 | expect(result).to.be.false; 983 | done(); 984 | }); 985 | }); 986 | 987 | it("should work on prefixed-attributed files", done => 988 | { 989 | newFile(TEMP_HIDDEN, {hidden:true}); 990 | 991 | hidefile.reveal(TEMP_HIDDEN, (error, newpath) => 992 | { 993 | const result = hidefile.isHiddenSync(newpath); 994 | 995 | removeFile(newpath); 996 | expect(error).to.be.null; 997 | expect(result).to.be.false; 998 | done(); 999 | }); 1000 | }); 1001 | 1002 | it("should work on prefixed-attributed folders", done => 1003 | { 1004 | newFolder(TEMP_HIDDEN, {hidden:true}); 1005 | 1006 | hidefile.reveal(TEMP_HIDDEN, (error, newpath) => 1007 | { 1008 | const result = hidefile.isHiddenSync(newpath); 1009 | 1010 | removeFolder(newpath); 1011 | expect(error).to.be.null; 1012 | expect(result).to.be.false; 1013 | done(); 1014 | }); 1015 | }); 1016 | }); 1017 | }); 1018 | 1019 | 1020 | 1021 | describe("revealSync()", () => 1022 | { 1023 | it("should work on unprefixed-unattributed files", () => 1024 | { 1025 | newFile(TEMP_VISIBLE); 1026 | 1027 | const newpath = hidefile.revealSync(TEMP_VISIBLE); 1028 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 1029 | 1030 | removeFile(TEMP_VISIBLE); 1031 | expect(result).to.be.false; 1032 | }); 1033 | 1034 | it("should work on unprefixed-unattributed folders", () => 1035 | { 1036 | newFolder(TEMP_VISIBLE); 1037 | 1038 | const newpath = hidefile.revealSync(TEMP_VISIBLE); 1039 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 1040 | 1041 | removeFolder(TEMP_VISIBLE); 1042 | expect(result).to.be.false; 1043 | }); 1044 | 1045 | it("should work on prefix-only files", () => 1046 | { 1047 | newFile(TEMP_HIDDEN); 1048 | 1049 | const newpath = hidefile.revealSync(TEMP_HIDDEN); 1050 | const result = hidefile.isHiddenSync(newpath); 1051 | 1052 | removeFile(newpath); 1053 | expect(result).to.be.false; 1054 | }); 1055 | 1056 | it("should work on prefix-only folders", () => 1057 | { 1058 | newFolder(TEMP_HIDDEN); 1059 | 1060 | const newpath = hidefile.revealSync(TEMP_HIDDEN); 1061 | const result = hidefile.isHiddenSync(newpath); 1062 | 1063 | removeFolder(newpath); 1064 | expect(result).to.be.false; 1065 | }); 1066 | 1067 | it("should error for non-existent unprefixed paths", () => 1068 | { 1069 | let error,newpath; 1070 | 1071 | try 1072 | { 1073 | newpath = hidefile.revealSync("fake"); 1074 | } 1075 | catch (e) 1076 | { 1077 | error = e; 1078 | } 1079 | 1080 | expect(error).to.be.instanceOf(Error); 1081 | expect(newpath).to.be.undefined; 1082 | }); 1083 | 1084 | it("should error for non-existent prefixed paths", () => 1085 | { 1086 | let error,newpath; 1087 | 1088 | try 1089 | { 1090 | newpath = hidefile.revealSync(".fake"); 1091 | } 1092 | catch (e) 1093 | { 1094 | error = e; 1095 | } 1096 | 1097 | expect(error).to.be.instanceOf(Error); 1098 | expect(newpath).to.be.undefined; 1099 | }); 1100 | 1101 | describe_windowsOnly("on Windows", () => 1102 | { 1103 | it("should work on attribute-only files", () => 1104 | { 1105 | newFile(TEMP_VISIBLE, {hidden:true}); 1106 | 1107 | const newpath = hidefile.revealSync(TEMP_VISIBLE); 1108 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 1109 | 1110 | removeFile(TEMP_VISIBLE); 1111 | expect(result).to.be.false; 1112 | }); 1113 | 1114 | it("should work on attribute-only folders", () => 1115 | { 1116 | newFolder(TEMP_VISIBLE, {hidden:true}); 1117 | 1118 | const newpath = hidefile.revealSync(TEMP_VISIBLE); 1119 | const result = hidefile.isHiddenSync(TEMP_VISIBLE); 1120 | 1121 | removeFolder(TEMP_VISIBLE); 1122 | expect(result).to.be.false; 1123 | }); 1124 | 1125 | it("should work on prefixed-attributed files", () => 1126 | { 1127 | newFile(TEMP_HIDDEN, {hidden:true}); 1128 | 1129 | const newpath = hidefile.revealSync(TEMP_HIDDEN); 1130 | const result = hidefile.isHiddenSync(newpath); 1131 | 1132 | removeFile(newpath); 1133 | expect(result).to.be.false; 1134 | }); 1135 | 1136 | it("should work on prefixed-attributed folders", () => 1137 | { 1138 | newFolder(TEMP_HIDDEN, {hidden:true}); 1139 | 1140 | const newpath = hidefile.revealSync(TEMP_HIDDEN); 1141 | const result = hidefile.isHiddenSync(newpath); 1142 | 1143 | removeFolder(newpath); 1144 | expect(result).to.be.false; 1145 | }); 1146 | }); 1147 | }); 1148 | --------------------------------------------------------------------------------