test(`coverage is ignored if it's ${JSON.stringify(arg)}`, function (t) { t.plan(2) const cwd = tempy.directory() const nyc = path.join(cwd, '.nyc_output') cc.write(cwd, arg, function (err) { t.ifError(err) fs.readdir(nyc, function (err) { t.is(err.code, 'ENOENT') }) }) })
const getDockerConfig = async () => { try { const content = await fs.readFile( getDockerSettings(), 'utf8' ); return JSON.parse( content ); } catch ( err ) { throw new Error( `Can't load Docker config, ${ err.stack }` ); } }
function findPkgJson( target ) { let root = path.dirname( target ); while ( root !== '/' ) { const filepath = path.join( root, 'package.json' ); if ( fs.existsSync( filepath ) ) { return JSON.parse( fs.readFileSync( filepath, 'utf8' ) ); } root = path.join( root, '../' ); } throw new Error( 'could not find a pkg json' ); }
getVersion((err, tag) => { if (err) { throw err; } getBranch((err, branch) => { if (err) { throw err; } pjs.version = getPackageVersion(tag, branch); fs.writeFileSync(pjsPath, JSON.stringify(pjs, null, 2)); }) });
function dispatch(type, id, arg) { let selectedID = lastID+1; if (selectedID > numCPUs-1) selectedID = 0; cluster.workers[workers[selectedID]].send(JSON.stringify({ id, type, arg })); lastID = selectedID; }
function decodeClientPayload(payload) { /* Special function which Client using to "encode" clients JSON payload */ return JSON.parse(String.fromCharCode.apply(null, payload)); }
it('should handle a compressed response', async function() { const res = await this.relativeFetch('/compress', { method: 'POST', body: JSON.stringify({ foo: 'bar' }), headers: { 'Content-Type': 'application/json' } }); expect(res.status).to.equal(200); expect(await res.json()).to.deep.equal({ foo: 'bar' }); });
function setItem( key, value ) { try { localStorage.setItem( key, JSON.stringify( value ) ); } catch ( e ) { debug( 'couldnt set localStorage item for: %s', key ); } }
getUser() { if (this.user) { return this.user; } const data = keyValueStore.get(GATEWAY_USER_KEY); if (data) { this.user = JSON.parse(data); } return this.user; }
handleClientConnectivityStatusChange(event) { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_CONNECTIVITY_STATUS_CHANGE, data: JSON.parse(event.data), }); }
toFunctionString() { return ` var characterTable = ${JSON.stringify(this.characterTable)}; var indexTable = ${JSON.stringify(this.indexTable)}; var characters = ${JSON.stringify(this.characters)}; var dataFormatter = { toIndexes: ${this.toIndexes.toString()}, toIndexesInputOutput: ${this.toIndexesInputOutput.toString()}, toCharacters: ${this.toCharacters.toString()}, };`; }
/** * @description Save gateway user keys. * @param {Array} keys - Array of keys. * @example * saveUsersKeys([]); */ async function saveUsersKeys(keys) { await this.variable.setValue('GLADYS_GATEWAY_USERS_KEYS', JSON.stringify(keys)); }
/** * Logs any error notice which is shown to the user so we can determine how often * folks see different errors and what types of sites they occur on. * * @param {string} content The error message. Like "Update failed." * @param {object} options Optional. Extra data logged with the error in Gutenberg. */ const trackErrorNotices = ( content, options ) => tracksRecordEvent( 'wpcom_gutenberg_error_notice', { notice_text: content, notice_options: JSON.stringify( options ), // Returns undefined if options is undefined. } )
handleTaxonomyFullUpdate(event) { AppDispatcher.dispatchServerAction({ type: ActionTypes.TAXONOMY_FULL_UPDATE, data: JSON.parse(event.data), }); }
function sendWsMessage(type, data){ if(wsConnection){ var message = { type: type, data: data }; wsConnection.send(JSON.stringify(message)); } }