How to use writeLogs method in ava

Best JavaScript code snippet using ava

localization.spec.js

Source:localization.spec.js Github

copy

Full Screen

1const { expect } = require('chai');2const assert = require('assert');3const sinon = require('sinon');4const rimraf = require('rimraf');5const fs = require('fs');6const path = require('path');7const localization = require('@src/command-line/localization');8const { Intent, FilteredIntent } = require('@src/parser/intent.coffee').lib9const testSkillDirectory = 'localization-test-skill';10class RecordingLogger {11 constructor() {12 this.errors = [];13 this.importantLogs = []14 this.logs = [];15 this.verboseLogs = [];16 this.warningLogs = [];17 this.writeLogs = [];18 }19 20 error(err) {21 this.errors.push(err.message);22 }23 important(line) {24 this.importantLogs.push(line);25 }26 log(line) {27 this.logs.push(line);28 }29 verbose(line) {30 this.verboseLogs.push(line);31 }32 warning(line) {33 this.warningLogs.push(line);34 }35 write({line}) {36 this.writeLogs.push(line);37 }38}39function createOptionsObject() {40 return {41 root: path.join(__dirname, testSkillDirectory),42 logger: new RecordingLogger(),43 doNotParseExtensions: true44 }45}46describe('localization command', async () => {47 let options = undefined;48 doMemoryCleanup = () => {49 Intent.unregisterUtterances();50 delete require.cache[path.join(options.root, 'localization.json')];51 }52 beforeEach(async () => {53 options = createOptionsObject();54 if (!fs.existsSync(path.join(options.root, 'litexa'))) {55 fs.mkdirSync(path.join(options.root, 'litexa'));56 }57 });58 afterEach(async () => {59 doMemoryCleanup();60 rimraf.sync(path.join(options.root, 'litexa'));61 rimraf.sync(path.join(options.root, 'localization.json'));62 });63 describe('localizing speech output', async () => {64 const litexaContent = [65 'launch',66 ' say "say line 1."',67 ' say "say line 2."',68 ' reprompt "reprompt line 1."',69 ' reprompt "reprompt line 2."',70 '',71 'stateA',72 ' say "say line 3."',73 ' reprompt "reprompt line 3."'74 ]75 beforeEach(async () => {76 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), litexaContent.join('\n'));77 await localization.localizeSkill(options);78 doMemoryCleanup();79 });80 it('added a say line', async () => {81 const skillCode = [...litexaContent];82 skillCode.push(' say "say line 4."');83 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));84 options = createOptionsObject();85 await localization.localizeSkill(options);86 expect(options.logger.verboseLogs[9]).to.equal('number of new speech lines added since last localization: 1');87 expect('+ say line 4.').to.equal(options.logger.writeLogs[0]);88 });89 it('changed a say line, disabled removeOrphanedSpeech', async () => {90 const skillCode = [...litexaContent];91 skillCode[1] = ' say "modified say line 1."';92 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));93 options = createOptionsObject();94 await localization.localizeSkill(options);95 expect(options.logger.verboseLogs[9]).to.equal('number of new speech lines added since last localization: 1');96 expect(options.logger.verboseLogs[11]).to.equal('number of localization.json speech lines that are missing in skill: 1');97 expect('+ modified say line 1.').to.equal(options.logger.writeLogs[0]);98 expect('- say line 1.').to.equal(options.logger.writeLogs[1]);99 });100 it('changed a say line, enabled removeOrphanedSpeech', async () => {101 const skillCode = [...litexaContent];102 skillCode[1] = ' say "modified say line 1."';103 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));104 options = createOptionsObject();105 options.removeOrphanedSpeech = true106 await localization.localizeSkill(options);107 expect(options.logger.verboseLogs[9]).to.equal('number of new speech lines added since last localization: 1');108 expect(options.logger.verboseLogs[11]).to.equal('number of orphaned speech lines removed from localization.json: 1');109 expect('+ modified say line 1.').to.equal(options.logger.writeLogs[0]);110 expect('- say line 1.').to.equal(options.logger.writeLogs[1]);111 });112 it('deleted a say line, disabled removeOrphanedSpeech', async () => {113 const skillCode = [...litexaContent];114 skillCode.splice(2,1);115 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));116 options = createOptionsObject();117 await localization.localizeSkill(options);118 expect(options.logger.verboseLogs[9]).to.equal('number of new speech lines added since last localization: 0');119 expect(options.logger.verboseLogs[11]).to.equal('number of localization.json speech lines that are missing in skill: 1');120 expect('- say line 2.').to.equal(options.logger.writeLogs[0]);121 });122 it('deleted a say line, enabled removeOrphanedSpeech', async () => {123 const skillCode = [...litexaContent];124 skillCode.splice(3,1);125 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));126 options = createOptionsObject();127 options.removeOrphanedSpeech = true128 await localization.localizeSkill(options);129 expect(options.logger.verboseLogs[9]).to.equal('number of new speech lines added since last localization: 0');130 expect(options.logger.verboseLogs[11]).to.equal('number of orphaned speech lines removed from localization.json: 1');131 expect('- reprompt line 1.').to.equal(options.logger.writeLogs[0]);132 });133 });134 describe('localizing utterances', async () => {135 const litexaContent = [136 'launch',137 ' say "say line 1."',138 ' reprompt "reprompt line 1."',139 ' when "yes intent"',140 ' or "yes"',141 ' say "say yes intent."',142 ' when AMAZON.NoIntent',143 ' or "no intent"',144 ' or "no"',145 ' say "say no intent."',146 ]147 beforeEach(async () => {148 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), litexaContent.join('\n'));149 await localization.localizeSkill(options);150 doMemoryCleanup();151 });152 it('added an utterance', async () => {153 const skillCode = [...litexaContent];154 skillCode.splice(4, 0, ' or "added yes utterance"');155 skillCode.splice(8, 0, ' or "added no utterance"');156 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));157 options = createOptionsObject();158 await localization.localizeSkill(options);159 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 2',);160 expect('+ added yes utterance').to.equal(options.logger.writeLogs[0]);161 expect('+ added no utterance').to.equal(options.logger.writeLogs[1]);162 });163 it('changed an utterance, disabled removeOrphanedUtterances', async () => {164 const skillCode = [...litexaContent];165 skillCode[4] = ' or "modified yes utterance"';166 skillCode[7] = ' or "modified no utterance"';167 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));168 options = createOptionsObject();169 await localization.localizeSkill(options);170 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 2');171 expect(options.logger.verboseLogs[7]).to.equal('number of localization.json utterances that are missing in skill: 2');172 expect('+ modified yes utterance').to.equal(options.logger.writeLogs[0]);173 expect('+ modified no utterance').to.equal(options.logger.writeLogs[1]);174 expect('- yes').to.equal(options.logger.writeLogs[2]);175 expect('- no intent').to.equal(options.logger.writeLogs[3]);176 });177 it('changed an utterance, enabled removeOrphanedUtterances', async () => {178 const skillCode = [...litexaContent];179 skillCode[4] = ' or "modified yes utterance"';180 skillCode[7] = ' or "modified no utterance"';181 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));182 options = createOptionsObject();183 options.removeOrphanedUtterances = true;184 await localization.localizeSkill(options);185 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 2');186 expect(options.logger.verboseLogs[7]).to.equal('number of orphaned utterances removed from localization.json: 2');187 expect('+ modified yes utterance').to.equal(options.logger.writeLogs[0]);188 expect('+ modified no utterance').to.equal(options.logger.writeLogs[1]);189 expect('- yes').to.equal(options.logger.writeLogs[2]);190 expect('- no intent').to.equal(options.logger.writeLogs[3]);191 });192 it('deleted an utterance, disabled removeOrphanedUtterances', async () => {193 const skillCode = [...litexaContent];194 skillCode.splice(4,1);195 skillCode.splice(6,1);196 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));197 options = createOptionsObject();198 await localization.localizeSkill(options);199 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 0');200 expect(options.logger.verboseLogs[7]).to.equal('number of localization.json utterances that are missing in skill: 2');201 expect('- yes').to.equal(options.logger.writeLogs[0]);202 expect('- no intent').to.equal(options.logger.writeLogs[1]);203 });204 it('deleted an utterance, enabled removeOrphanedUtterances', async () => {205 const skillCode = [...litexaContent];206 skillCode.splice(4,1);207 skillCode.splice(6,1);208 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));209 options = createOptionsObject();210 options.removeOrphanedUtterances = true;211 await localization.localizeSkill(options);212 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 0');213 expect(options.logger.verboseLogs[7]).to.equal('number of orphaned utterances removed from localization.json: 2');214 expect('- yes').to.equal(options.logger.writeLogs[0]);215 expect('- no intent').to.equal(options.logger.writeLogs[1]);216 });217 });218 describe('localizing intents', async () => {219 const litexaContent = [220 'launch',221 ' say "say line 1."',222 ' reprompt "reprompt line 1."',223 ' when "yes intent"',224 ' or "yes"',225 ' say "say yes intent."',226 ' when AMAZON.NoIntent',227 ' or "no intent"',228 ' or "no"',229 ' say "say no intent."',230 ]231 beforeEach(async () => {232 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), litexaContent.join('\n'));233 await localization.localizeSkill(options);234 doMemoryCleanup();235 });236 it('added an intent', async () => {237 const skillCode = [...litexaContent];238 skillCode.push(' when AMAZON.HelpIntent');239 skillCode.push(' when "new intent"');240 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));241 options = createOptionsObject();242 await localization.localizeSkill(options);243 expect(options.logger.verboseLogs[1]).to.equal('number of new intents added since last localization: 2');244 expect(options.logger.verboseLogs[5]).to.equal('number of new utterances added since last localization: 1');245 expect('+ AMAZON.HelpIntent').to.equal(options.logger.writeLogs[0]);246 expect('+ NEW_INTENT').to.equal(options.logger.writeLogs[1]);247 expect('+ new intent').to.equal(options.logger.writeLogs[2]);248 });249 it('changed an intent', async () => {250 const skillCode = [...litexaContent];251 skillCode[3] = ' when "modified yes intent"';252 253 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));254 options = createOptionsObject();255 256 await localization.localizeSkill(options);257 expect(options.logger.verboseLogs[1]).to.equal('number of new intents added since last localization: 1');258 expect(options.logger.verboseLogs[3]).to.equal('the following intents in localization.json are missing in skill:');259 expect(options.logger.verboseLogs[4]).to.equal('- YES_INTENT');260 expect(options.logger.verboseLogs[7]).to.equal('number of new utterances added since last localization: 2');261 expect('+ MODIFIED_YES_INTENT').to.equal(options.logger.writeLogs[0]);262 expect('+ modified yes intent').to.equal(options.logger.writeLogs[1]);263 expect('+ yes').to.equal(options.logger.writeLogs[2]);264 });265 it('deleted an intent', async () => {266 const skillCode = [...litexaContent];267 skillCode.splice(6,3);268 269 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), skillCode.join('\n'));270 options = createOptionsObject();271 272 await localization.localizeSkill(options);273 expect(options.logger.verboseLogs[1]).to.equal('number of new intents added since last localization: 0');274 expect(options.logger.verboseLogs[3]).to.equal('the following intents in localization.json are missing in skill:');275 expect(options.logger.verboseLogs[4]).to.equal('- AMAZON.NoIntent');276 expect(options.logger.verboseLogs[5]).to.equal('number of localization intents that are missing in skill: 1');277 expect(options.logger.verboseLogs[7]).to.equal('number of new utterances added since last localization: 0');278 expect(0).to.equal(options.logger.writeLogs.length);279 });280 });281 describe('cloning languages', async () => {282 const litexaContent = [283 'launch',284 ' say "say line 1."',285 ' reprompt "reprompt line 1."',286 ' when "yes intent"',287 ' or "yes"',288 ' say "say yes intent."',289 ' when AMAZON.NoIntent',290 ' or "no intent"',291 ' or "no"',292 ' say "say no intent."',293 ' when NumberIntent',294 ' or "number $number"',295 ' or "$number"',296 ' or "$number cats"',297 ' or "$number cat"',298 ' with $number = AMAZON.NUMBER',299 ' say "Got number intent with value $number."'300 ]301 before(async () => {302 sinon.stub(process, 'exit');303 })304 after(async () => {305 process.exit.restore();306 });307 beforeEach(async () => {308 fs.writeFileSync(path.join(options.root, 'litexa', 'main.litexa'), litexaContent.join('\n'));309 await localization.localizeSkill(options);310 doMemoryCleanup();311 });312 it('should clone a language and sort strings given valid parameters', async () => {313 options = createOptionsObject();314 options.cloneFrom = 'default';315 options.cloneTo = 'en-US';316 await localization.localizeSkill(options);317 doMemoryCleanup();318 options = createOptionsObject();319 options.cloneFrom = 'en-US';320 options.cloneTo = 'en';321 await localization.localizeSkill(options);322 const localizationJson = JSON.parse(fs.readFileSync(path.join(options.root, 'localization.json'), 'utf8'));323 const intents = Object.keys(localizationJson.intents);324 intents.forEach((intent) => {325 expect(Object.keys(localizationJson.intents[intent])).to.deep.equal(['default','en','en-US']);326 expect(localizationJson.intents[intent]['en-US']).to.deep.equal(localizationJson.intents[intent]['en']);327 // no test to compare to default because default does not get sorted328 });329 const sayStrings = Object.keys(localizationJson.speech);330 sayStrings.forEach((sayString) => {331 expect(Object.keys(localizationJson.speech[sayString])).to.deep.equal(['en','en-US']);332 expect(sayString).to.deep.equal(localizationJson.speech[sayString]['en']);333 expect(sayString).to.deep.equal(localizationJson.speech[sayString]['en-US']);334 });335 });336 it('should warn when there was nothing to clone', async () => {337 options = createOptionsObject();338 await localization.localizeSkill(options);339 const originalLocalizationJson = JSON.parse(fs.readFileSync(path.join(options.root, 'localization.json'), 'utf8'));340 doMemoryCleanup();341 options = createOptionsObject();342 options.cloneFrom = 'non-existent';343 options.cloneTo = 'en';344 await localization.localizeSkill(options);345 expect(options.logger.verboseLogs[12]).to.equal('No sample utterances were found for `non-existent`, so no utterances were cloned.');346 expect(options.logger.warningLogs[0]).to.equal('No speech was found for non-existent, so no speech cloning occurred.');347 const cloneResultLocalizationJson = JSON.parse(fs.readFileSync(path.join(options.root, 'localization.json'), 'utf8'));348 expect(originalLocalizationJson).to.deep.equal(cloneResultLocalizationJson);349 });350 it('should not clone a language if it is missing the source', async () => {351 options = createOptionsObject();352 options.cloneTo = 'en';353 await localization.localizeSkill(options);354 expect(options.logger.errors[0]).to.equal('Missing `cloneFrom` option. Please specify a Litexa language to clone from.');355 assert(process.exit.called);356 assert(process.exit.calledWith(1));357 });358 it('should not clone a language if it is missing the target', async () => {359 options = createOptionsObject();360 options.cloneFrom = 'en';361 await localization.localizeSkill(options);362 expect(options.logger.errors[0]).to.equal('Missing `cloneTo` option. Please specify a Litexa language to clone to.');363 assert(process.exit.called);364 assert(process.exit.calledWith(1));365 });366 it('should not allow "default" as a clone target', async () => {367 options = createOptionsObject();368 options.cloneFrom = 'en';369 options.cloneTo = 'default';370 await localization.localizeSkill(options);371 expect(options.logger.errors[0]).to.equal('Not allowed to clone localizations to `default` language.');372 assert(process.exit.called);373 assert(process.exit.calledWith(1));374 });375 });...

Full Screen

Full Screen

lockscreen-lock2unlock-test.esp.js

Source:lockscreen-lock2unlock-test.esp.js Github

copy

Full Screen

1'use strict';2/* globals require, module, Performance */3module.exports = function(filepath, outpath, requiredir) {4 // Developer can write their super fancy filter here.5 if (!filepath.match(/lockscreen.js$/)) {6 return;7 }8 var Logger = function() {9 this._writelogs = {};10 };11 Logger.prototype.log = function(outpath, advice) {12 this._writelogs[filepath] = {13 'outpath': outpath,14 'file': advice.file,15 'query': advice.query16 };17 };18 var logger = new Logger();19 var opts = {};20 if (outpath) {21 var fs = require('fs');22 opts.writer = {23 write: function(advice) {24 if (advice.instance.applied) {25 logger.log(filepath, advice);26 }27 var code = advice.code;28 fs.writeFile(outpath, code);29 }30 };31 }32 var Espect = require(requiredir + 'espect.js');33 var espect = new Espect(opts);34 espect35 .select(filepath + ' LockScreen.prototype.lock')36 .before(function() {37 performance.mark('lockScreenLock');38 })39 .done()40 .select(filepath + ' lockScreen.prototype.unlock')41 .before(function() {42 performance.mark('lockScreenUnlock');43 })44 .done()45 .done();46 // If it matched nothing as it was supposed to do, we have a bug.47 if (!logger._writelogs[filepath]) {48 throw new Error('TransformingFailed::Matched nothing to transform code.');49 } else {50 Object.keys(logger._writelogs).forEach(function(filepath) {51 var info = logger._writelogs[filepath];52 console.log('|lock2unlock.esp| Successfully wove ', filepath);53 });54 }...

Full Screen

Full Screen

logger.js

Source:logger.js Github

copy

Full Screen

...21 && typeof console[method] !== 'undefined'22 && typeof console[method].apply !== 'undefined'23 /* eslint-enable no-console */24 },25 writeLogs(method, args) {26 /* eslint-disable no-console */27 if (Logger.shouldLog(method) && Logger.consoleMethodDefined(method)) {28 console[method].apply(console, args)29 }30 /* eslint-enable no-console */31 },32 log() {33 Logger.writeLogs('log', arguments)34 },35 debug() {36 Logger.writeLogs('debug', arguments)37 },38 error() {39 Logger.writeLogs('error', arguments)40 },41 warn() {42 Logger.writeLogs('warn', arguments)43 },44 info() {45 Logger.writeLogs('info', arguments)46 },47 time() {48 Logger.writeLogs('time', arguments)49 },50 timeEnd() {51 Logger.writeLogs('timeEnd', arguments)52 }53}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { writeLogs } = require('available-logger');2writeLogs('Test', 'Test');3const { writeErrorLogs } = require('available-logger');4writeErrorLogs('Test', 'Test');5const { writeInfoLogs } = require('available-logger');6writeInfoLogs('Test', 'Test');7const { writeWarningLogs } = require('available-logger');8writeWarningLogs('Test', 'Test');9const { writeDebugLogs } = require('available-logger');10writeDebugLogs('Test', 'Test');11const { writeTraceLogs } = require('available-logger');12writeTraceLogs('Test', 'Test');13const { writeLogs } = require('available-logger');14writeLogs('Test', 'Test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const availableLoggers = require('./logger');2availableLoggers.writeLogs('test.js', 'Test log message');3const winston = require('winston');4const { createLogger, format, transports } = winston;5const { combine, timestamp, label, printf } = format;6const myFormat = printf(({ level, message, label, timestamp }) => {7 return `${timestamp} [${label}] ${level}: ${message}`;8});9const logger = createLogger({10 format: combine(11 label({ label: 'right meow!' }),12 timestamp(),13 new transports.File({ filename: 'error.log', level: 'error' }),14 new transports.File({ filename: 'combined.log' })15});16module.exports = logger;17const winston = require('winston');18const { createLogger, format, transports } = winston;19const { combine, timestamp, label, printf } = format;20const myFormat = printf(({ level, message, label, timestamp }) => {21 return `${timestamp} [${label}] ${level}: ${message}`;22});23const logger = createLogger({24 format: combine(25 label({ label: 'right meow!' }),26 timestamp(),27 new transports.Console()28});29module.exports = logger;30const winston = require('winston');31const { createLogger, format, transports } = winston;32const { combine, timestamp, label, printf } = format;33const myFormat = printf(({ level, message, label, timestamp }) => {34 return `${timestamp} [${label}] ${level}: ${message}`;35});36const logger = createLogger({37 format: combine(38 label({ label: 'right meow!' }),39 timestamp(),40 new transports.Console(),41 new transports.File({ filename: 'error.log', level: 'error' }),42 new transports.File({ filename: 'combined.log' })43});44module.exports = logger;

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful