• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mock-fs.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mock-fs.file函数代码示例发布时间:2022-05-25
下一篇:
TypeScript addContext.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap