UNPKG

fluentnode

Version:

Fluent apis for node (based on the concepts used in C#'s FluentSharp

423 lines (300 loc) 20.6 kB
<!DOCTYPE html> <html> <head> <title>fs.test.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="Array.html"> Array.litcoffee </a> <a class="source" href="Boolean.html"> Boolean.litcoffee </a> <a class="source" href="Function.html"> Function.litcoffee </a> <a class="source" href="Number.html"> Number.litcoffee </a> <a class="source" href="Object.html"> Object.litcoffee </a> <a class="source" href="String.html"> String.litcoffee </a> <a class="source" href="_register.html"> _register.js </a> <a class="source" href="_to_map_and_write_Tests.html"> _to_map_and_write_Tests.litcoffee </a> <a class="source" href="assert_Array.html"> assert_Array.litcoffee </a> <a class="source" href="assert_Boolean.html"> assert_Boolean.litcoffee </a> <a class="source" href="assert_Function.html"> assert_Function.litcoffee </a> <a class="source" href="assert_Number.html"> assert_Number.litcoffee </a> <a class="source" href="assert_Object.html"> assert_Object.litcoffee </a> <a class="source" href="assert_String.html"> assert_String.litcoffee </a> <a class="source" href="console.html"> console.litcoffee </a> <a class="source" href="fs.html"> fs.litcoffee </a> <a class="source" href="globals.html"> globals.litcoffee </a> <a class="source" href="http.html"> http.litcoffee </a> <a class="source" href="index.html"> index.md </a> <a class="source" href="path.html"> path.litcoffee </a> <a class="source" href="process.html"> process.litcoffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="console.test.html"> console.test.coffee </a> <a class="source" href="fs.test.html"> fs.test.coffee </a> <a class="source" href="globals.test.html"> globals.test.coffee </a> <a class="source" href="http.test.html"> http.test.coffee </a> <a class="source" href="path.test.html"> path.test.coffee </a> <a class="source" href="process.test.html"> process.test.coffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>fs.test.coffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>back to <a href="fluent.html">main</a></p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/assert/assert_Array'</span>) <span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/String'</span>) <span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/path'</span>) <span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/fs'</span>) expect = <span class="hljs-built_in">require</span>(<span class="hljs-string">'chai'</span>).expect describe <span class="hljs-string">'fs'</span>,<span class="hljs-function">-&gt;</span> it <span class="hljs-string">'folder_Create and folder_Delete'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-comment"># tests the String's folder_Create and folder_Delete methods</span> <span class="hljs-string">""</span>.folder_Create.assert_Is_Function() <span class="hljs-comment"># checks if String::folder_Create exists</span> <span class="hljs-string">""</span>.folder_Delete.assert_Is_Function() <span class="hljs-comment"># checks if String::folder_Delete exists</span> tmpDir = <span class="hljs-string">"./"</span>.temp_Name_In_Folder() <span class="hljs-comment"># get a temp folder name in the folder provided as string</span> tmpDir.assert_Folder_Not_Exists() <span class="hljs-comment"># asserts that folder doesn't exist</span> .folder_Create().assert_Is tmpDir.realPath() <span class="hljs-comment"># creates folder and confirms that the return value is the full path to the folder</span> tmpDir.assert_Folder_Exists() <span class="hljs-comment"># assert that folders exists</span> .folder_Delete().assert_Is_True() <span class="hljs-comment"># deletes folder (confirming OK result from delete action)</span> tmpDir.assert_Folder_Not_Exists() <span class="hljs-comment"># asserts that folder doesn't exist</span> it <span class="hljs-string">'folder_Create (and its parent)'</span>, <span class="hljs-function">-&gt;</span> tmpDir = <span class="hljs-string">"./"</span>.temp_Name_In_Folder() tmpDir2 = tmpDir.path_Combine(<span class="hljs-string">'aaa'</span>) tmpDir2.create_Dir().assert_That_Folder_Exists() tmpDir.folder_Delete_Recursive().assert_Is_True() it <span class="hljs-string">'folder_Delete_Recursive'</span> , <span class="hljs-function">-&gt;</span> tmpDir = <span class="hljs-string">"./"</span> .temp_Name_In_Folder().folder_Create() tmpFile = tmpDir.temp_Name_In_Folder().file_Create() tmpDir.folder_Delete_Recursive().assert_Is_True() it <span class="hljs-string">'file_Create and file_Delete'</span>,<span class="hljs-function">-&gt;</span> tmpName = <span class="hljs-string">'.'</span>.temp_Name_In_Folder() tmpName.file_Create().assert_Is(tmpName) tmpName.exists() .assert_True() tmpName.file_Delete().assert_True() tmpName.exists() .assert_False() it <span class="hljs-string">'file_Copy'</span> , <span class="hljs-function">-&gt;</span> file1 = <span class="hljs-string">'.'</span>.temp_Name_In_Folder() file2 = <span class="hljs-string">'.'</span>.temp_Name_In_Folder() file1.file_Create().assert_Is(file1) file1.assert_File_Exists() file1.file_Copy(file2) file2.assert_File_Exists() folder = <span class="hljs-string">'_tmp_file_Copy'</span>.folder_Create() file_In_Folder = file1.file_Copy(folder) file_In_Folder.assert_File_Exists() assert_Is_Null(<span class="hljs-string">'aaa'</span>.file_Copy(<span class="hljs-string">'bbb'</span>)) assert_Is_Null(file1.file_Copy(<span class="hljs-literal">null</span>)) folder.folder_Delete_Recursive().assert_True() file1.file_Delete().assert_True() file2.file_Delete().assert_True() it <span class="hljs-string">'file_Contents'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.file_Contents.assert_Is_Function() file_Name = <span class="hljs-string">'_temp_name_'</span>.add_Random_String(<span class="hljs-number">5</span>) file_Contents = <span class="hljs-string">'value_'</span>.add_Random_String(<span class="hljs-number">5</span>) (file_Name.file_Exists().assert_Is_False()) file_Contents.saveAs(file_Name) file_Name.file_Exists().assert_Is_True() file_Name.file_Contents().assert_Is(file_Contents) file_Name.file_Delete().assert_Is_True() it <span class="hljs-string">'file_Exists'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.file_Exists.assert_Is_Function() <span class="hljs-string">'.git'</span> .file_Exists().assert_Is_True() <span class="hljs-string">'./src/_register.js'</span>.file_Exists().assert_Is_True() <span class="hljs-string">'./aaa.js'</span> .file_Exists().assert_Is_False() <span class="hljs-string">'./aaa.js'</span> .file_Exists().assert_Is_False() it <span class="hljs-string">'file_Not_Exists'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.file_Not_Exists.assert_Is_Function() <span class="hljs-string">'.git'</span> .file_Not_Exists().assert_Is_False() <span class="hljs-string">'./index.js'</span>.file_Not_Exists().assert_Is_True() <span class="hljs-string">'./aaa.js'</span> .file_Not_Exists().assert_Is_True() it <span class="hljs-string">'file_Write'</span>,<span class="hljs-function">-&gt;</span> content = (<span class="hljs-number">20</span>).random_Letters() tmpFile = <span class="hljs-string">'./src'</span>.fullPath().path_Combine(<span class="hljs-string">'_temp_file.abcd'</span>).assert_File_Not_Exists() .file_Write(content) tmpFile.assert_File_Exists() .file_Contents().assert_Is(content) tmpFile.file_Delete().assert_Is_True() it <span class="hljs-string">'files_And_Folders'</span>,<span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.files_And_Folders.assert_Is_Function() files = <span class="hljs-string">'./'</span>.files_And_Folders(); files.assert_Contains <span class="hljs-string">'.git'</span> .realPath() .assert_Contains <span class="hljs-string">'.gitignore'</span>.realPath() .assert_Not_Contains <span class="hljs-string">'.aaaaa'</span>.realPath() <span class="hljs-string">'aaaa'</span>.files_And_Folders().assert_Is([]) it <span class="hljs-string">'files'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.files.assert_Is_Function() files = <span class="hljs-string">'./'</span>.files().filter (file) -&gt; file <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.DS_Store'</span>.realPath() expectedFiles = (file.realPath() <span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> <span class="hljs-string">'.gitignore,.travis.yml,LICENSE,README.md,package.json'</span>.split(<span class="hljs-string">','</span>)) files.assert_Contains(expectedFiles) <span class="hljs-string">'./'</span>.files(<span class="hljs-string">'.yml'</span> ).assert_Is([<span class="hljs-string">'.travis.yml'</span>.realPath()]) <span class="hljs-string">'./'</span>.files(<span class="hljs-string">'.json'</span>).assert_Is([<span class="hljs-string">'package.json'</span>.realPath()]) it <span class="hljs-string">'files_Recursive'</span> , <span class="hljs-function">-&gt;</span> <span class="hljs-string">''</span>.files_Recursive.assert_Is_Function() <span class="hljs-string">'./src'</span>.files_Recursive().assert_Size_Is_Bigger_Than(<span class="hljs-number">9</span>) .assert_Contains(<span class="hljs-string">'./src/fs.litcoffee'</span>.fullPath()) tmpFile = <span class="hljs-string">'./src'</span>.fullPath().path_Combine(<span class="hljs-string">'_temp_file.abcd'</span>).file_Write((<span class="hljs-number">20</span>).random_Letters()) <span class="hljs-string">'./src'</span>.files_Recursive(<span class="hljs-string">'.abcd'</span>).assert_Size_Is(<span class="hljs-number">1</span>) .first().assert_Is(tmpFile) tmpFile.file_Delete().assert_Is_True() it <span class="hljs-string">'folders'</span> , <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">''</span>.folders).to.be.an(<span class="hljs-string">'function'</span>) folders = (folder <span class="hljs-keyword">for</span> folder <span class="hljs-keyword">in</span> <span class="hljs-string">'./'</span>.folders() <span class="hljs-keyword">when</span> folder.not_Contains(<span class="hljs-string">'.c9'</span>)) <span class="hljs-comment">#handle scenario when we coded inside Cloud9 IDE </span> expectedFolders = (folder.realPath() <span class="hljs-keyword">for</span> folder <span class="hljs-keyword">in</span> <span class="hljs-string">'.git,src,test'</span>.split(<span class="hljs-string">','</span>)) folders.assert_Contains(expectedFolders) it <span class="hljs-string">'is_Folder'</span>, <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">''</span>.is_Folder).to.be.an(<span class="hljs-string">'function'</span>) expect(<span class="hljs-string">'.git'</span> .is_Folder()).to.be.<span class="hljs-literal">true</span> expect(<span class="hljs-string">'.gitignore'</span>.is_Folder()).to.be.<span class="hljs-literal">false</span> expect(<span class="hljs-string">'.gitAAA'</span> .is_Folder()).to.be.<span class="hljs-literal">false</span> it <span class="hljs-string">'is_Not_Folder'</span>,<span class="hljs-function">-&gt;</span> <span class="hljs-string">""</span>.add_5_Random_Letters().is_Not_Folder().assert_Is_True() it <span class="hljs-string">'is_File'</span>, <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">''</span>.is_Folder).to.be.an(<span class="hljs-string">'function'</span>) expect(<span class="hljs-string">'.git'</span> .is_File()).to.be.<span class="hljs-literal">false</span> expect(<span class="hljs-string">'.gitignore'</span>.is_File()).to.be.<span class="hljs-literal">true</span> expect(<span class="hljs-string">'.gitAAA'</span> .is_File()).to.be.<span class="hljs-literal">false</span> it <span class="hljs-string">'realPath'</span>, <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">''</span>.realPath).to.be.an(<span class="hljs-string">'function'</span>) expect(<span class="hljs-string">'.git'</span> .realPath()).to.equal(process.cwd().path_Combine(<span class="hljs-string">'.git'</span> )) expect(<span class="hljs-string">'.gitignore'</span> .realPath()).to.equal(process.cwd().path_Combine(<span class="hljs-string">'.gitignore'</span>)) expect(<span class="hljs-string">'.gitignore2'</span> .realPath()).to.equal(<span class="hljs-literal">null</span>) it <span class="hljs-string">'saveAs'</span>, <span class="hljs-function">-&gt;</span> file_Name = <span class="hljs-string">'_tmp_file_'</span> .add_Random_String(<span class="hljs-number">5</span>) file_Value1 = <span class="hljs-string">'value'</span>.add_Random_String(<span class="hljs-number">5</span>) file_Value2 = <span class="hljs-string">'value'</span>.add_Random_String(<span class="hljs-number">5</span>) file_Name.exists().assert_Is_False() file_Value1.saveAs(file_Name).assert_Is_True() file_Name.exists() .assert_Is_True() file_Name.file_Contents() .assert_Is (file_Value1) file_Name.file_Contents() .assert_Is_Not(file_Value2) file_Value2.saveAs(file_Name).assert_Is_True() file_Name.exists() .assert_Is_True() file_Name.file_Contents() .assert_Is_Not(file_Value1) file_Name.file_Contents() .assert_Is (file_Value2) file_Name.file_Delete() .assert_Is_True() it <span class="hljs-string">'temp_Name_In_Folder'</span>, <span class="hljs-function">-&gt;</span> tmpName = <span class="hljs-string">'./'</span>.temp_Name_In_Folder() expect(tmpName ).to.contain(<span class="hljs-string">'./'</span>.realPath()) expect(tmpName ).to.contain(<span class="hljs-string">'_tmp_'</span>) expect(tmpName.size()).to.equal(<span class="hljs-string">'./'</span>.realPath().size()+<span class="hljs-number">16</span>) it <span class="hljs-string">'touch'</span>,<span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">''</span>.touch).to.be.an(<span class="hljs-string">'function'</span>) tempFile = <span class="hljs-string">'.'</span>.temp_Name_In_Folder().touch() expect(tempFile.file_Exists()).to.be.<span class="hljs-literal">true</span> expect(tempFile.file_Delete()).to.be.<span class="hljs-literal">true</span> it <span class="hljs-string">'exists'</span> , <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">'.git'</span>.exists ).to.equal(<span class="hljs-string">".git"</span>.file_Exists) it <span class="hljs-string">'create_Dir'</span> , <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">'.git'</span>.create_Dir ).to.equal(<span class="hljs-string">".git"</span>.folder_Create) it <span class="hljs-string">'folder_Exists'</span>, <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">'.git'</span>.folder_Exists).to.equal(<span class="hljs-string">".git"</span>.is_Folder) it <span class="hljs-string">'is_Directory'</span> , <span class="hljs-function">-&gt;</span> expect(<span class="hljs-string">'.git'</span>.is_Directory ).to.equal(<span class="hljs-string">".git"</span>.is_Folder)</pre></div></div> </li> </ul> </div> </body> </html>