constructor(options = {}) { assert(options.name, '[egg:singleton] Singleton#constructor options.name is required'); assert(options.app, '[egg:singleton] Singleton#constructor options.app is required'); assert(options.create, '[egg:singleton] Singleton#constructor options.create is required'); assert(!options.app[options.name], `${options.name} is already exists in app`); this.clients = new Map(); this.app = options.app; this.name = options.name; this.create = options.create; /* istanbul ignore next */ this.options = options.app.config[this.name] || {}; }
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)); });
app.beforeStart(function*() { // dumpConfig() dynamically json = readJSON(path.join(baseDir, 'run/application_config.json')); assert(json.config.dynamic === 1, 'should dump in config'); json = readJSON(path.join(baseDir, 'run/agent_config.json')); assert(json.config.dynamic === 0, 'should dump in config'); yield sleep(2000); app.config.dynamic = 2; });
it('should got right level on local env', async () => { mm.env('local'); mm(process.env, 'EGG_LOG', ''); app = utils.app('apps/mock-dev-app'); await app.ready(); assert(app.logger.get('file').options.level === Logger.INFO); assert(app.logger.get('console').options.level === Logger.INFO); assert(app.coreLogger.get('file').options.level === Logger.INFO); assert(app.coreLogger.get('console').options.level === Logger.WARN); assert(app.config.logger.disableConsoleAfterReady === false); });
request(url, opt) { return new Promise(resolve => { assert(/^http/.test(url), 'url should start with http, but got ' + url); resolve(); }).then(() => { return super.request(url, opt); }); }
describe('#exportChatInviteLink', function exportChatInviteLinkSuite() { before(function before() { utils.handleRatelimit(bot, 'exportChatInviteLink', this); }); it('should export the group invite link', function test() { return bot.exportChatInviteLink(GROUPID).then(resp => { assert(resp.match(/^https:\/\/t\.me\/joinchat\/.+$/i), 'is a telegram invite link'); }); }); });
it('should got right level on prod env when set allowDebugAtProd to true', async () => { mm.env('prod'); mm(process.env, 'EGG_LOG', ''); mm(process.env, 'HOME', utils.getFilepath('apps/mock-production-app-do-not-force/config')); app = utils.app('apps/mock-production-app-do-not-force'); await app.ready(); assert(app.config.logger.allowDebugAtProd === true); assert(app.logger.get('file').options.level === Logger.DEBUG); assert(app.logger.get('console').options.level === Logger.INFO); assert(app.coreLogger.get('file').options.level === Logger.DEBUG); assert(app.coreLogger.get('console').options.level === Logger.INFO); });
it('should create error when passing invalid url', function() { var response = queue.addToQueue({ url: '$#$#@%@#' }) assert(response.error) assert.equal(response.code, error.getErrorCode(error.ERROR_INVALID_URL)) })
it('should not cache ip', async () => { const obj = urlparse(url.replace('localhost', '127.0.0.1') + '/get_headers'); const result = await app.curl(obj, { dataType: 'json' }); assert(result.status === 200); assert(result.data.host === obj.host); assert(!app.httpclient.dnsCache.get('127.0.0.1')); });
it('should parse share attachment correctly', function () { var formatted = formatDeltaMessage(shareAttachmentFixture); assert(formatted.attachments[0].type === "share"); assert(formatted.attachments[0].title === "search engines"); assert(formatted.attachments[0].target.items[0].name === "search engines"); assert(formatted.attachments[0].target.items[0].call_to_actions.length === 3); assert(formatted.attachments[0].target.items[0].call_to_actions[0].title === "Google"); });
it('should read timing data', function* () { let json = readJson(path.join(baseDir, `run/agent_timing_${process.pid}.json`)); assert(json.length === 41); assert(json[1].name === 'Application Start'); assert(json[0].pid === process.pid); json = readJson(path.join(baseDir, `run/application_timing_${process.pid}.json`)); assert(json.length === 63); assert(json[1].name === 'Application Start'); assert(json[0].pid === process.pid); });
it('should request callback with error', done => { client.request(url + '/error', { dataType: 'json' }, err => { assert(err); done(); }); });