Best JavaScript code snippet using storybook-root
server.js
Source:server.js
1/**2 * Copyright (c) 2018, 2019 National Digital ID COMPANY LIMITED3 *4 * This file is part of NDID software.5 *6 * NDID is the free software: you can redistribute it and/or modify it under7 * the terms of the Affero GNU General Public License as published by the8 * Free Software Foundation, either version 3 of the License, or any later9 * version.10 *11 * NDID is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.14 * See the Affero GNU General Public License for more details.15 *16 * You should have received a copy of the Affero GNU General Public License17 * along with the NDID source code. If not, see https://www.gnu.org/licenses/agpl.txt.18 *19 * Please contact info@ndid.co.th for any further questions20 *21 */22import 'source-map-support/register';23import 'dotenv/config';24import mkdirp from 'mkdirp';25import './env_var_validate';26import * as httpServer from './http_server';27import * as node from './node';28import * as coreCommon from './core/common';29import * as rp from './core/rp';30import * as idp from './core/idp';31import * as as from './core/as';32import * as proxy from './core/proxy';33import * as requestProcessManager from './core/request_process_manager';34import * as nodeCallback from './core/node_callback';35import * as nodeKey from './utils/node_key';36import { getFunction } from './functions';37import * as cacheDb from './db/cache';38import * as longTermDb from './db/long_term';39import * as dataDb from './db/data';40import * as tendermint from './tendermint';41import * as tendermintWsPool from './tendermint/ws_pool';42import * as mq from './mq';43import * as callbackUtil from './callback';44import * as externalCryptoService from './external_crypto_service';45import * as jobMaster from './master-worker-interface/server';46import * as jobWorker from './master-worker-interface/client';47import * as prometheus from './prometheus';48import logger from './logger';49import { version } from './version';50import MODE from './mode';51import ROLE from './role';52import * as config from './config';53process.on('unhandledRejection', function(reason, p) {54 if (reason && reason.name === 'CustomError') {55 logger.error({56 message: 'Unhandled Rejection',57 p,58 });59 logger.error({ err: reason });60 } else {61 logger.error({62 message: 'Unhandled Rejection',63 p,64 reason: reason.stack || reason,65 });66 }67});68async function initialize() {69 logger.info({ message: 'Initializing server' });70 try {71 tendermint.loadSavedData();72 await Promise.all([73 cacheDb.initialize(),74 longTermDb.initialize(),75 dataDb.initialize(),76 ]);77 if (config.prometheusEnabled) {78 prometheus.initialize();79 }80 if (config.ndidNode) {81 tendermint.setWaitForInitEndedBeforeReady(false);82 }83 tendermint.setTxResultCallbackFnGetter(getFunction);84 const tendermintReady = new Promise((resolve) =>85 tendermint.eventEmitter.once('ready', (status) => resolve(status))86 );87 await tendermint.connectWS();88 const tendermintStatusOnSync = await tendermintReady;89 let role;90 if (!config.ndidNode) {91 logger.info({ message: 'Getting node role' });92 role = await node.getNodeRoleFromBlockchain();93 logger.info({ message: 'Node role', role });94 }95 if (role === ROLE.RP) {96 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {97 mq.setMessageHandlerFunction(rp.handleMessageFromQueue);98 tendermint.setTendermintNewBlockEventHandler(99 rp.handleTendermintNewBlock100 );101 }102 await rp.checkCallbackUrls();103 } else if (role === ROLE.IDP) {104 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {105 mq.setMessageHandlerFunction(idp.handleMessageFromQueue);106 tendermint.setTendermintNewBlockEventHandler(107 idp.handleTendermintNewBlock108 );109 }110 await idp.checkCallbackUrls();111 } else if (role === ROLE.AS) {112 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {113 mq.setMessageHandlerFunction(as.handleMessageFromQueue);114 tendermint.setTendermintNewBlockEventHandler(115 as.handleTendermintNewBlock116 );117 }118 await as.checkCallbackUrls();119 } else if (role === ROLE.PROXY) {120 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {121 mq.setMessageHandlerFunction(proxy.handleMessageFromQueue);122 tendermint.setTendermintNewBlockEventHandler(123 proxy.handleTendermintNewBlock124 );125 }126 await rp.checkCallbackUrls();127 await idp.checkCallbackUrls();128 await as.checkCallbackUrls();129 }130 if (131 role === ROLE.RP ||132 role === ROLE.IDP ||133 role === ROLE.AS ||134 role === ROLE.PROXY135 ) {136 await nodeCallback.checkCallbackUrls();137 }138 callbackUtil.setShouldRetryFnGetter(getFunction);139 callbackUtil.setResponseCallbackFnGetter(getFunction);140 let externalCryptoServiceReady;141 if (config.useExternalCryptoService) {142 await externalCryptoService.checkCallbackUrls();143 if (!(await externalCryptoService.isCallbackUrlsSet())) {144 externalCryptoServiceReady = new Promise((resolve) =>145 externalCryptoService.eventEmitter.once('allCallbacksSet', () =>146 resolve()147 )148 );149 }150 } else {151 await nodeKey.initialize();152 }153 if (config.mode === MODE.MASTER) {154 await jobMaster.initialize();155 logger.info({ message: 'Waiting for available worker' });156 await new Promise((resolve) =>157 jobMaster.eventEmitter.once('worker_connected', () => resolve())158 );159 } else if (config.mode === MODE.WORKER) {160 await jobWorker.initialize();161 }162 if (config.mode === MODE.STANDALONE || config.mode === MODE.WORKER) {163 httpServer.initialize();164 }165 if (externalCryptoServiceReady != null) {166 logger.info({ message: 'Waiting for DPKI callback URLs to be set' });167 await externalCryptoServiceReady;168 }169 if (170 role === ROLE.RP ||171 role === ROLE.IDP ||172 role === ROLE.AS ||173 role === ROLE.PROXY174 ) {175 mq.setErrorHandlerFunction(176 coreCommon.getHandleMessageQueueErrorFn(() => {177 if (role === ROLE.RP) {178 return 'rp.getErrorCallbackUrl';179 } else if (role === ROLE.IDP) {180 return 'idp.getErrorCallbackUrl';181 } else if (role === ROLE.AS) {182 return 'as.getErrorCallbackUrl';183 } else if (role === ROLE.PROXY) {184 return 'proxy.getErrorCallbackUrl';185 }186 })187 );188 if (config.mode === MODE.STANDALONE) {189 await mq.initialize();190 } else if (config.mode === MODE.MASTER) {191 await mq.initializeInbound();192 } else if (config.mode === MODE.WORKER) {193 await mq.initializeOutbound(false);194 }195 }196 await tendermint.initialize();197 if (role === ROLE.RP || role === ROLE.IDP || role === ROLE.PROXY) {198 let nodeIds;199 if (role === ROLE.RP) {200 nodeIds = [config.nodeId];201 } else if (role === ROLE.IDP) {202 nodeIds = [config.nodeId];203 } else if (role === ROLE.PROXY) {204 const nodesBehindProxy = await node.getNodesBehindProxyWithKeyOnProxy();205 nodeIds = nodesBehindProxy.map((node) => node.node_id);206 }207 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {208 await coreCommon.resumeTimeoutScheduler(nodeIds);209 }210 }211 if (212 role === ROLE.RP ||213 role === ROLE.IDP ||214 role === ROLE.AS ||215 role === ROLE.PROXY216 ) {217 if (config.mode === MODE.STANDALONE || config.mode === MODE.WORKER) {218 await coreCommon.setMessageQueueAddress();219 }220 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {221 await mq.loadAndProcessBacklogMessages();222 }223 }224 if (config.mode === MODE.STANDALONE || config.mode === MODE.MASTER) {225 tendermint.processMissingBlocks(tendermintStatusOnSync);226 await tendermint.loadExpectedTxFromDB();227 tendermint.loadAndRetryBacklogTransactRequests();228 tendermint.loadAndRetryTransact();229 callbackUtil.resumeCallbackToClient();230 }231 logger.info({ message: 'Server initialized' });232 } catch (error) {233 logger.error({234 message: 'Cannot initialize server',235 err: error,236 });237 // shutDown();238 }239}240const {241 privateKeyPassphrase, // eslint-disable-line no-unused-vars242 masterPrivateKeyPassphrase, // eslint-disable-line no-unused-vars243 dbPassword, // eslint-disable-line no-unused-vars244 ...configToLog245} = config;246logger.info({247 message: 'Starting server',248 version,249 NODE_ENV: process.env.NODE_ENV,250 config: configToLog,251});252// Make sure data and log directories exist253mkdirp.sync(config.dataDirectoryPath);254// mkdirp.sync(config.logDirectoryPath);255// Graceful Shutdown256let shutDownCalledOnce = false;257async function shutDown() {258 if (shutDownCalledOnce) {259 logger.error({260 message: 'Forcefully shutting down',261 });262 process.exit(1);263 }264 shutDownCalledOnce = true;265 logger.info({266 message: 'Received kill signal, shutting down gracefully',267 });268 console.log('(Ctrl+C again to force shutdown)');269 await httpServer.close();270 callbackUtil.stopAllCallbackRetries();271 externalCryptoService.stopAllCallbackRetries();272 coreCommon.stopAllTimeoutScheduler();273 if (config.mode === MODE.MASTER) {274 jobMaster.shutdown();275 } else if (config.mode === MODE.WORKER) {276 await jobWorker.shutdown();277 }278 // Wait for async operations which going to use TM/MQ/DB to finish before279 // closing connections280 await requestProcessManager.stop();281 await mq.close();282 tendermint.tendermintWsClient.close();283 tendermintWsPool.closeAllConnections();284 await prometheus.stop();285 await Promise.all([cacheDb.close(), longTermDb.close(), dataDb.close()]);286}287process.on('SIGTERM', shutDown);288process.on('SIGINT', shutDown);...
getStorybookMain.test.ts
Source:getStorybookMain.test.ts
1import { getStorybookMain } from './getStorybookMain';2import * as coreCommon from '@storybook/core-common';3jest.mock('@storybook/core-common');4describe('getStorybookMain', () => {5 it('should throw an error if no configuration is found', () => {6 expect(() => getStorybookMain('.storybook')).toThrow();7 });8 it('should return mainjs', () => {9 const mockedMain = {10 stories: [11 {12 directory: '../stories/basic',13 titlePrefix: 'Example',14 },15 ],16 };17 jest.spyOn(coreCommon, 'serverRequire').mockImplementation(() => mockedMain);18 const res = getStorybookMain('.storybook');19 expect(res).toMatchObject(mockedMain);20 });...
index.android.ts
Source:index.android.ts
1import { CoreCommon } from './common';2export class AwarnsCore extends CoreCommon {}...
Using AI Code Generation
1import { coreCommon } from 'storybook-root';2export default function() {3 coreCommon();4}5import { coreCommon } from 'storybook-root';6export default function() {7 coreCommon();8}
Using AI Code Generation
1import { coreCommon } from 'storybook-root';2coreCommon();3import { storiesOf } from '@storybook/react';4import { withInfo } from '@storybook/addon-info';5import { withKnobs } from '@storybook/addon-knobs';6import { addDecorator } from '@storybook/react';7import { setDefaults } from '@storybook/addon-info';8import { setOptions } from '@storybook/addon-options';9import { configure } from '@storybook/react';10import { withOptions } from '@storybook/addon-options';11import { withViewport } from '@storybook/addon-viewport';12addDecorator(withInfo);13addDecorator(withKnobs);14addDecorator(withOptions);15addDecorator(withViewport);16setOptions({
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!