本文整理匯總了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();
});