本文整理汇总了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", () =>{
//.........这里部分代码省略.........
示例2: mockFs
beforeEach(() => {
mockFs();
});
示例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");
//.........这里部分代码省略.........
示例4: b
function b() {
mock({
'path/to/file.txt': 'file content here'
});
}
示例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
});
示例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([]);
});