本文整理汇总了TypeScript中fs.readFileSync类的典型用法代码示例。如果您正苦于以下问题:TypeScript readFileSync类的具体用法?TypeScript readFileSync怎么用?TypeScript readFileSync使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了readFileSync类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
require('fs').readFileSync = function (path, ops) {
if (path === '/dev/stdin' && ops === 'utf8') {
require('fs').readFileSync = read;
return require('fs').readFileSync(input, 'utf8');
}
return read.apply(require('fs'), arguments);
};
示例2: function
export default function(
globalObject: NodeJS.Global,
globals: Config.ConfigGlobals,
): NodeJS.Global & Config.ConfigGlobals {
globalObject.process = createProcessObject();
const symbol = (globalObject.Symbol as unknown) as SymbolConstructor;
// Keep a reference to some globals that Jest needs
Object.defineProperties(globalObject, {
[symbol.for('jest-native-promise')]: {
enumerable: false,
value: Promise,
writable: false,
},
[symbol.for('jest-native-now')]: {
enumerable: false,
value: globalObject.Date.now.bind(globalObject.Date),
writable: false,
},
[symbol.for('jest-native-read-file')]: {
enumerable: false,
value: fs.readFileSync.bind(fs),
writable: false,
},
[symbol.for('jest-native-write-file')]: {
enumerable: false,
value: fs.writeFileSync.bind(fs),
writable: false,
},
[symbol.for('jest-native-exists-file')]: {
enumerable: false,
value: fs.existsSync.bind(fs),
writable: false,
},
'jest-symbol-do-not-touch': {
enumerable: false,
value: symbol,
writable: false,
},
});
// Forward some APIs.
DTRACE.forEach(dtrace => {
// @ts-ignore: no index
globalObject[dtrace] = function(...args: Array<any>) {
// @ts-ignore: no index
return global[dtrace].apply(this, args);
};
});
// Forward some others (this breaks the sandbox but for now it's OK).
globalObject.Buffer = global.Buffer;
globalObject.setImmediate = global.setImmediate;
globalObject.clearImmediate = global.clearImmediate;
return Object.assign(globalObject, deepCyclicCopy(globals));
}
示例3: it
it('returns an empty object representation', () => {
sinon.stub(fs, 'readFileSync').throws();
expect(loadPackageJson()).to.eql('{}');
fs.readFileSync.restore();
});