_(fs.readdirSync(baseDir, {withFileTypes: true})) .filter(dirent => dirent.isDirectory()) .map(dirent => dirent.name) .concat('.') .map(directory => path.resolve(baseDir, directory, '.platform.app.yaml')) .filter(file => fs.existsSync(file)) .map(file => ({data: yamlPlatform.load(fs.readFileSync(file)), file})) .map(data => ({name: data.data.name, file: data.file, dir: path.dirname(data.file)})) .value()
function renderPost (results) { const templateStr = fs.readFileSync(path.resolve(__dirname, 'release.hbs')).toString('utf8') const template = Handlebars.compile(templateStr, { noEscape: true }) const view = Object.assign({ date: new Date().toISOString(), versionSlug: slugify(results.version) }, results) return Object.assign({ content: template(view) }, results) }
const sslConnectionOpts = () => Object.assign(connectionOpts(), { port: 9093, ssl: { servername: 'localhost', rejectUnauthorized: false, ca: [fs.readFileSync('./testHelpers/certs/cert-signed', 'utf-8')], }, })
/** * @param {string} fileURL * @param {string} encoding */ readFile(fileURL, encoding) { return fs.readFileSync(new URL(fileURL), encoding); }
_(files) // Filter if file exists .filter(fs.existsSync) // Start collecting .reduce((a, file) => exports.merge(a, yaml.safeLoad(fs.readFileSync(file))), {})
it('should log CookieLimitExceed error when cookie value too long', done => { const ctx = app.mockContext(); const value = Buffer.alloc(4094).fill(49).toString(); ctx.cookies.set('foo', value); setTimeout(() => { const logPath = path.join(utils.getFilepath('apps/secure-app'), 'logs/secure-app/common-error.log'); const content = fs.readFileSync(logPath, 'utf8'); assert(content.match(/CookieLimitExceedError: cookie foo's length\(4094\) exceed the limit\(4093\)/)); done(); }, 100); });
http.createServer(function (req, res) { var url = URL.parse(req.url); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(fs.readFileSync(__dirname + url.pathname)); })
it('should truncate really long lines when asked to', () => { const logController = new LoggerController(new WinstonLoggerAdapter()); const longString = fs.readFileSync(loremFile, 'utf8'); const truncatedString = logController.truncateLogMessage(longString); expect(truncatedString.length).toBe(1015); // truncate length + the string '... (truncated)' });
/* * Helper to load landofile */ const loadLandoFile = file => { try { return yaml.safeLoad(fs.readFileSync(file)); } catch (e) { throw new Error(`There was a problem with parsing ${file}. Ensure it is valid YAML! ${e}`); } }
mods.forEach(mod => { fs.writeFileSync( require.resolve(mod[0]), fs.readFileSync(path.join(__dirname, "mods", mod[1]), "utf8"), "utf8" ); });
(function main() { const version = require('./package.json').version; let preload = fs.readFileSync('./lib/preload/ndb/preload.js', 'utf8'); preload = preload.replace(/process\.versions\['ndb'\] = '[\d+\.]+';/, `process.versions['ndb'] = '${version}';`); fs.writeFileSync('./lib/preload/ndb/preload.js', preload, 'utf8'); })();
// Let's also make a copy of caCert with the standarized .crt ending for better linux compat // See: https://github.com/lando/lando/issues/1550 lando.events.on('pre-engine-start', 3, data => { const caNormalizedCert = path.join(caDir, `${caDomain}.crt`); if (fs.existsSync(caCert) && !fs.existsSync(caNormalizedCert)) { // @NOTE: we need to use pre node 8.x-isms because pld roles with node 7.9 currently fs.writeFileSync(caNormalizedCert, fs.readFileSync(caCert)); } });
it('should has log', () => { const eggLogPath = utils.getFilepath('apps/demo/logs/demo/egg-web.log'); let content = fs.readFileSync(eggLogPath, 'utf8'); assert(/\[egg:core] dump config after load, \d+ms/.test(content)); assert(/\[egg:core] dump config after ready, \d+ms/.test(content)); const agentLogPath = utils.getFilepath('apps/demo/logs/demo/egg-agent.log'); content = fs.readFileSync(agentLogPath, 'utf8'); assert(/\[egg:core] dump config after load, \d+ms/.test(content)); assert(/\[egg:core] dump config after ready, \d+ms/.test(content)); });
/* * Helper to load cached file without cache module */ const loadCacheFile = file => { try { return JSON.parse(JSON.parse(fs.readFileSync(file, {encoding: 'utf-8'}))); } catch (e) { throw new Error(`There was a problem with parsing ${file}. Ensure it is valid JSON! ${e}`); } }
mods.forEach(mod => { fs.writeFileSync( require.resolve(mod[0]), fs.readFileSync(path.join(__dirname, "mods", mod[1]), "utf8"), "utf8" ); });