當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mock-fs.default函數代碼示例

本文整理匯總了TypeScript中mock-fs.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: suite

suite("FileStructureDivination Tests", () => {
    let divine = new FileStructureDivination();

    //using mock-js to override default fs behaviour, which allows us to create a 
    //temporary in-memory file system for testing 
    mock({
        'path/to/': {
            'some-file.txt': 'file content here',
            'dir-with-file': {
                'single-file.txt':"file content"    
            },
            'multiple':{
                'emptyfolder1':{},
                'emptyfolder2':{},
            },
            'multiplemixed':{
                'emptyfolder1':{},
                'file.txt':'',
            },
            'withasubfolder':{
                'folderwithfile':{
                    'file.txt':'contents'
                }
            },
            'withtwosubfolder':{
                'folderwithfile1':{
                    'file1.txt':'contents'
                },
                'folderwithfile2':{
                    'file2.txt':'contents'
                }
            },
            'complex':{
                'folderwithfile1':{
                    'file1.txt':'contents'
                },
                'folder':{
                    'folder':{
                        'folder':{
                            'file.txt':'contents'
                        },
                        'file.txt':'',
                        'file2.txt':''
                    }
                },
                'folder2':{
                    'file.txt':''
                }
            }
        },
        'single/empty/root':{},
        'single/empty/notroot':{
            'folder':{}
        },
        'single/path/to/single-file.txt':'content'
    });

    test("file does not exist returns error message and empty file string", () =>{
        var output = divine.getFileStructure("non-existent");
        assert.equal(output.outputMessage, "Error: File Not Found");
        assert.equal(output.filePath, "");
    });

    test("root is single empty folder is returned returns only the empty root folder", () =>{
        var output = divine.getFileStructure("single/empty/root");
        assert.equal(output.outputMessage, "File found");
        assert.equal(output.filePath, "root\n");
    });

    test("non-root empty folder returns only the empty folder", () =>{
        var output = divine.getFileStructure("single/empty/notroot/folder");
        assert.equal(output.outputMessage, "File found");
        assert.equal(output.filePath, "folder\n");
    });

    test("input has spaces included trims before returning result", () =>{
        var output = divine.getFileStructure(" single/empty/root ");
        assert.equal(output.outputMessage, "File found");
        assert.equal(output.filePath, "root\n");
    });

    test("numerical input returns error message", () =>{
        var output = divine.getFileStructure("1234435");
        assert.equal(output.outputMessage, "Error: File Not Found");
        assert.equal(output.filePath, "");
    });

    test("file location given in utf encoded string is returned with success message", () =>{
         var output = divine.getFileStructure("\x73\x69\x6E\x67\x6C\x65\x2F\x70\x61\x74\x68\x2F\x74\x6F\x2F\x73\x69\x6E\x67\x6C\x65\x2D\x66\x69\x6C\x65\x2E\x74\x78\x74");
        assert.equal(output.outputMessage, "File found");
         assert.equal(output.filePath, "single-file.txt\n");
    });

    test("single file is returned with success message", () =>{
         var output = divine.getFileStructure("single/path/to/single-file.txt");
        assert.equal(output.outputMessage, "File found");
         assert.equal(output.filePath, "single-file.txt\n");
    });

    test("location with single file is returned with success message", () =>{
//.........這裏部分代碼省略.........
開發者ID:joemeadway,項目名稱:file-structure-text-output,代碼行數:101,代碼來源:extension.test.ts

示例2: mockFs

beforeEach(() => {
  mockFs();
});
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:3,代碼來源:io.test.ts

示例3: IsValid

    it("renders a simple model to a single file", (done): void => {
        const renderer: CSharpModelRenderer = new CSharpModelRenderer();
        const input: ModelViewModel = {
            classes: [
                {
                    name: "CanValidate",
                    isInterface: true,
                    methods: [
                        {
                            name: "IsValid",
                            parameters:[
                                {
                                    name: "deep",
                                    isCollection: false,
                                    typeInfo: {
                                        name: "bool",
                                        isReference: false
                                    }
                                }
                            ],
                            typeInfo: {
                                name: "bool",
                                isReference: false
                            }
                        },
                        {
                            name: "Invalidate"
                        }
                    ]
                },
                {
                    name: "TestClass",
                    ctor: { parameters: [], parentParameterNames: [], relations: [] },
                    interfaceExtends: ["CanValidate"],
                    classExtends: ["TestClass"],
                    props: [{
                        name: "Prop",
                        hasConstraints: false,
                        isCollection: false,
                        typeInfo: {
                            name: "int",
                            isInterface: false,
                            isReference: false,
                            shouldMakeNullable: true
                        }
                    }]
                }
            ],
            namespace: "MyNamespace"
        };
        const expected: string =
            `using Ccmi.OntoUml.Utilities.AssociationClasses;
using Ccmi.OntoUml.Utilities.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyNamespace
{
    public interface ICanValidate
    {
        bool IsValid(bool deep);
        void Invalidate();
    }

    public interface ITestClass : ICanValidate
    {
        int? Prop { get; set; }
    }
    public class TestClass : ITestClass
    {
        public TestClass()
        {
        }
        private int? prop;
        public virtual int? Prop
        {
            get { return prop; }
            set 
            {
                prop = value;
            }
        }
        private bool isInvalidated = false;
        public virtual void Invalidate()
        {
            isInvalidated = true;
        }
        public virtual bool IsValid(bool deep)
        {
            if (isInvalidated) return false;
            return true;
        }
    }
}`.replace(/\r\n/g, "\n");
        mock({
            "testDir": {}
        });
        renderer.generateCode(input, { input: null, inputForm: null, output: "testDir/Model.cs", outputForm: null, singleFile: true })
            .then((): void => {
                const result: string = fs.readFileSync(path.join("testDir", "Model.cs"), "utf8").replace(/\r\n/g, "\n");
//.........這裏部分代碼省略.........
開發者ID:CCMi-FIT,項目名稱:ontouml-code-generator,代碼行數:101,代碼來源:CSharpModelRenderer-test.ts

示例4: b

function b() {
	mock({
		'path/to/file.txt': 'file content here'
	});
}
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:5,代碼來源:mock-fs-tests.ts

示例5: f

			}
		})
	});
}

function f() {
	mock({
		'some/dir': {
			'regular-file': 'file contents',
			'a-symlink': mock.symlink({
				path: 'regular-file'
			})
		}
	});
}

var mockedFS = mock.fs({
	'/file': 'blah'
});

if (mockedFS.readFileSync('/file', { encoding: 'utf8' }) === 'blah') {
	console.log('woo');
}

mock({
	'path/to/file.txt': 'file content here'
}, {
  createTmp: true,
  createCwd: false
});
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:mock-fs-tests.ts

示例6: it

    it('should handle changes via symbolic links', () => {
      let testDir = {
        'orig_path': {
          'file-1.txt': mockfs.file({content: 'file-1.txt content', mtime: new Date(1000)}),
          'file-2.txt': mockfs.file({content: 'file-2.txt content', mtime: new Date(1000)}),
          'subdir-1': {
            'file-1.1.txt':
                mockfs.file({content: 'file-1.1.txt content', mtime: new Date(1000)})
          }
        },
        'symlinks': {
          'file-1.txt': mockfs.symlink({path: '../orig_path/file-1.txt'}),
          'file-2.txt': mockfs.symlink({path: '../orig_path/file-2.txt'}),
          'subdir-1':
              {'file-1.1.txt': mockfs.symlink({path: '../../orig_path/subdir-1/file-1.1.txt'})}
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('symlinks');

      let diffResult = differ.diffTree();

      expect(diffResult.changedPaths)
          .toEqual(['file-1.txt', 'file-2.txt', 'subdir-1/file-1.1.txt']);

      // change two files
      testDir['orig_path']['file-1.txt'] =
          mockfs.file({content: 'new content', mtime: new Date(1000)});
      testDir['orig_path']['subdir-1']['file-1.1.txt'] =
          mockfs.file({content: 'file-1.1.txt content', mtime: new Date(9999)});
      mockfs(testDir);

      diffResult = differ.diffTree();

      expect(diffResult.changedPaths).toEqual(['file-1.txt', 'subdir-1/file-1.1.txt']);

      expect(diffResult.removedPaths).toEqual([]);

      // change one file
      testDir['orig_path']['file-1.txt'] =
          mockfs.file({content: 'super new', mtime: new Date(1000)});
      mockfs(testDir);

      diffResult = differ.diffTree();
      expect(diffResult.changedPaths).toEqual(['file-1.txt']);

      // remove a link
      delete testDir['orig_path']['file-1.txt'];
      mockfs(testDir);

      diffResult = differ.diffTree();
      expect(diffResult.changedPaths).toEqual([]);
      expect(diffResult.removedPaths).toEqual(['file-1.txt']);

      // don't report it as a removal twice
      mockfs(testDir);

      diffResult = differ.diffTree();
      expect(diffResult.changedPaths).toEqual([]);
      expect(diffResult.removedPaths).toEqual([]);

      // re-add it.
      testDir['orig_path']['file-1.txt'] =
          mockfs.file({content: 'super new', mtime: new Date(1000)});
      mockfs(testDir);

      diffResult = differ.diffTree();
      expect(diffResult.changedPaths).toEqual(['file-1.txt']);
      expect(diffResult.removedPaths).toEqual([]);
    });
開發者ID:188799958,項目名稱:angular,代碼行數:71,代碼來源:tree-differ.spec.ts


注:本文中的mock-fs.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。