当前位置: 首页>>代码示例>>TypeScript>>正文


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

本文整理汇总了TypeScript中mock-fs.file函数的典型用法代码示例。如果您正苦于以下问题:TypeScript file函数的具体用法?TypeScript file怎么用?TypeScript file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了file函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('should flatten files and be incremental', () => {
    let testDir = {
      'input': {
        'dir1': {
          '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)})
          },
          'empty-dir': {}
        },
      },
      'output': {}
    };
    mockfs(testDir);

    let differ = new TreeDiffer('testLabel', 'input');
    let flattenedTree = flatten('input');
    flattenedTree.rebuild(differ.diffTree());

    expect(fs.readdirSync('output')).toEqual(['file-1.1.txt', 'file-1.txt', 'file-2.txt']);
    // fails  due to a mock-fs bug related to reading symlinks?
    // expect(read('output/file-1.1.txt')).toBe('file-1.1.txt content');


    // delete a file
    rm('input/dir1/file-1.txt');
    // add a new one
    write('input/dir1/file-3.txt', 'file-3.txt content');

    flattenedTree.rebuild(differ.diffTree());

    expect(fs.readdirSync('output')).toEqual(['file-1.1.txt', 'file-2.txt', 'file-3.txt']);
  });
开发者ID:KarthiTrichy20,项目名称:angular,代码行数:34,代码来源:broccoli-flatten.spec.ts

示例2: it

    it('should return empty diff if nothing has changed', () => {
      let testDir = {
        'dir1': {
          '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)})
          },
        }
      };
      mockfs(testDir);

      let differ = new TreeDiffer('testLabel', 'dir1');

      let diffResult = differ.diffTree();

      expect(diffResult.addedPaths).not.toEqual([]);
      expect(diffResult.changedPaths).toEqual([]);
      expect(diffResult.removedPaths).toEqual([]);

      diffResult = differ.diffTree();

      expect(diffResult.addedPaths).toEqual([]);
      expect(diffResult.changedPaths).toEqual([]);
      expect(diffResult.removedPaths).toEqual([]);
    });
开发者ID:AsherBarak,项目名称:angular,代码行数:26,代码来源:tree-differ.spec.ts

示例3: it

  it('should throw if duplicates are found during rebuild', () => {
    let testDir = {
      'tree1': {'foo.js': mockfs.file({content: 'tree1/foo.js content', mtime: new Date(1000)})},
      'tree2': {},
      'tree3': {}
    };
    mockfs(testDir);

    let treeDiffer = MakeTreeDiffers(['tree1', 'tree2', 'tree3']);
    let treeMerger = mergeTrees(['tree1', 'tree2', 'tree3'], 'dest', {});
    expect(() => treeMerger.rebuild(treeDiffer.diffTrees())).not.toThrow();


    testDir.tree2['foo.js'] = mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)});
    mockfs(testDir);
    expect(() => treeMerger.rebuild(treeDiffer.diffTrees()))
        .toThrowError("`overwrite` option is required for handling duplicates.");
  });
开发者ID:B-Thapa,项目名称:angular,代码行数:18,代码来源:broccoli-merge-trees.spec.ts

示例4: c

function c() {
	mock({
		foo: mock.file({
			content: 'file content here',
			ctime: new Date(1),
			mtime: new Date(1)
		 })
	});
}
开发者ID:ClearboxSystems,项目名称:DefinitelyTyped,代码行数:9,代码来源:mock-fs-tests.ts

示例5: it

  it('should throw an exception if duplicates are found', () => {
    let testDir = {
      'input': {
        'dir1': {
          'file-1.txt': mockfs.file({content: 'file-1.txt content', mtime: new Date(1000)}),
          'subdir-1':
              {'file-1.txt': mockfs.file({content: 'file-1.1.txt content', mtime: new Date(1000)})},
          'empty-dir': {}
        },
      },
      'output': {}
    };
    mockfs(testDir);

    let differ = new TreeDiffer('testLabel', 'input');
    let flattenedTree = flatten('input');
    expect(() => flattenedTree.rebuild(differ.diffTree()))
        .toThrowError("Duplicate file 'file-1.txt' found in path 'dir1/subdir-1/file-1.txt'");
  });
开发者ID:AsherBarak,项目名称:angular,代码行数:19,代码来源:broccoli-flatten.spec.ts

示例6: test

  test('should not throw if the custom expiry has not been reached yet', async () => {
    mockFs({
      [CACHE_PATH]: mockFs.file({
        content: JSON.stringify('Some test data'),
        mtime: subHours(new Date(), 36), // 36 hours ago
      }),
    });

    const cache = getCache<string>(CACHE_KEY, 48 * 60);
    await expect(cache.read()).resolves.toEqual('Some test data');
  });
开发者ID:nusmodifications,项目名称:nusmods,代码行数:11,代码来源:io.test.ts

示例7: it

  it('should throw if duplicates are used by default', () => {
    let testDir: any = {
      'tree1': {'foo.js': mockfs.file({content: 'tree1/foo.js content', mtime: new Date(1000)})},
      'tree2': {'foo.js': mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)})},
      'tree3': {'foo.js': mockfs.file({content: 'tree3/foo.js content', mtime: new Date(1000)})}
    };
    mockfs(testDir);
    let treeDiffer = MakeTreeDiffers(['tree1', 'tree2', 'tree3']);
    let treeMerger = mergeTrees(['tree1', 'tree2', 'tree3'], 'dest', {});
    expect(() => treeMerger.rebuild(treeDiffer.diffTrees())).toThrow();

    delete testDir.tree2['foo.js'];
    delete testDir.tree3['foo.js'];
    mockfs(testDir);
    expect(() => treeMerger.rebuild(treeDiffer.diffTrees())).not.toThrow();

    testDir.tree2['foo.js'] = mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)});
    mockfs(testDir);
    expect(() => treeMerger.rebuild(treeDiffer.diffTrees())).toThrow();
  });
开发者ID:Mariem-07,项目名称:angular,代码行数:20,代码来源:broccoli-merge-trees.spec.ts

示例8: it

  it('should throw if duplicates are found during rebuild', () => {
    let testDir: any = {
      'tree1': {'foo.js': mockfs.file({content: 'tree1/foo.js content', mtime: new Date(1000)})},
      'tree2': {},
      'tree3': {}
    };
    mockfs(testDir);

    let treeDiffer = MakeTreeDiffers(['tree1', 'tree2', 'tree3']);
    let treeMerger = mergeTrees(['tree1', 'tree2', 'tree3'], 'dest', {});
    expect(() => treeMerger.rebuild(diffTrees(treeDiffer))).not.toThrow();


    testDir.tree2['foo.js'] = mockfs.file({content: 'tree2/foo.js content', mtime: new Date(1000)});
    mockfs(testDir);
    expect(() => treeMerger.rebuild(diffTrees(treeDiffer)))
        .toThrowError(
            'Duplicate path found while merging trees. Path: "foo.js".\n' +
            'Either remove the duplicate or enable the "overwrite" option for this merge.');
  });
开发者ID:KarthiTrichy20,项目名称:angular,代码行数:20,代码来源:broccoli-merge-trees.spec.ts

示例9: beforeEach

        beforeEach(()=>{
            mock({
                '/data': {
                    'foo.json': mock.file({
                        content: `{
    "this":"is mock file",
    "that":"is my cat"
}`,
                        mtime,
                    }),
                    'bar.yaml': mock.file({
                        content: `cat:
  name: 三毛猫
  hp: 300
  attack: 50
`,
                        mtime: new Date(mtime.getTime()-7200000),
                    }),
                },
            });
        });
开发者ID:uhyo,项目名称:my-load-data,代码行数:21,代码来源:loader.spec.ts


注:本文中的mock-fs.file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。