Best JavaScript code snippet using istanbul
test-config.js
Source:test-config.js
...5 config;6module.exports = {7 "when no explicit config is present": {8 setUp: function (cb) {9 config = configuration.loadObject(null);10 cb();11 },12 "verbose option should be set": function (test) {13 test.equal(false, config.verbose);14 test.done();15 },16 "default instrumentation options should be correct": function (test) {17 var iOpts = config.instrumentation;18 test.equal(process.cwd(), iOpts.root());19 test.equal(true, iOpts.defaultExcludes());20 test.equal(false, iOpts.embedSource());21 test.equal('__coverage__', iOpts.variable());22 test.equal(true, iOpts.compact());23 test.equal(false, iOpts.preserveComments());24 test.equal(false, iOpts.completeCopy());25 test.equal(false, iOpts.saveBaseline());26 test.equal(false, iOpts.includeAllSources());27 test.equal('./coverage/coverage-baseline.json', iOpts.baselineFile());28 test.deepEqual(['**/node_modules/**'], iOpts.excludes());29 test.deepEqual(['**/node_modules/**', '**/test/**', '**/tests/**'], iOpts.excludes(true));30 test.done();31 },32 "default reporting options should be correct": function (test) {33 var rOpts = config.reporting;34 test.equal('summary', rOpts.print());35 test.deepEqual( ['lcov'], rOpts.reports());36 test.equal('./coverage', rOpts.dir());37 test.equal('lcov.info', rOpts.reportConfig().lcovonly.file);38 test.done();39 },40 "default hook options should be correct": function (test) {41 var hOpts = config.hooks;42 test.equal(false, hOpts.hookRunInContext());43 test.equal(null, hOpts.postRequireHook());44 test.done();45 }46 },47 "when overrides passed in": {48 "as initial object": {49 "should use overrides": function (test) {50 config = configuration.loadObject({ instrumentation: { compact: false, 'save-baseline': true }});51 test.equal(false, config.instrumentation.compact());52 test.equal(true, config.instrumentation.saveBaseline());53 test.done();54 }55 },56 "as override object": {57 "should use overrides": function (test) {58 config = configuration.loadObject({},59 { verbose: true, instrumentation: { compact: false, 'save-baseline': true }}60 );61 test.equal(true, config.verbose);62 test.equal(false, config.instrumentation.compact());63 test.equal(true, config.instrumentation.saveBaseline());64 test.done();65 }66 },67 "at both levels": {68 "should use override object values": function (test) {69 config = configuration.loadObject(70 { verbose: true, instrumentation: { compact: false, 'save-baseline': true } },71 { verbose: false, instrumentation: { compact: true, 'save-baseline': false } }72 );73 test.equal(false, config.verbose);74 test.equal(true, config.instrumentation.compact());75 test.equal(false, config.instrumentation.saveBaseline());76 test.done();77 }78 },79 "deeper in the tree": {80 "should use overrides": function (test) {81 config = configuration.loadObject({82 reporting: {83 'report-config': {84 'lcovonly': {85 file: 'foo.info'86 }87 }88 }89 });90 test.equal('foo.info', config.reporting.reportConfig().lcovonly.file);91 test.equal('clover.xml', config.reporting.reportConfig().clover.file);92 test.equal(null, config.reporting.reportConfig().text.file);93 test.done();94 }95 }96 },97 "excludes array changes based on default excludes": {98 "should honor default excludes setting - when set" : function (test) {99 config = configuration.loadObject({100 instrumentation: {101 "excludes": [ '**/vendor/**' ]102 }103 });104 var iOpts = config.instrumentation;105 test.deepEqual(['**/node_modules/**', '**/vendor/**'], iOpts.excludes());106 test.deepEqual(['**/node_modules/**', '**/test/**', '**/tests/**', '**/vendor/**'], iOpts.excludes(true));107 test.done();108 },109 "should honor default excludes setting - when not set" : function (test) {110 config = configuration.loadObject({111 instrumentation: {112 "default-excludes": null,113 "excludes": [ '**/vendor/**' ]114 }115 });116 var iOpts = config.instrumentation;117 test.deepEqual(['**/vendor/**'], iOpts.excludes());118 test.deepEqual(['**/vendor/**'], iOpts.excludes(true));119 test.done();120 },121 "should return nothing when defaults off and no excludes" : function (test) {122 config = configuration.loadObject({123 instrumentation: {124 "default-excludes": null125 }126 });127 var iOpts = config.instrumentation;128 test.deepEqual([], iOpts.excludes());129 test.deepEqual([], iOpts.excludes(true));130 test.done();131 }132 },133 "when loading files": {134 "should fail on bad config file": function (test) {135 try {136 config = configuration.loadFile('/a/non/existent/path.js');137 test.fail();138 } catch (ex) {139 test.ok(1);140 }141 test.done();142 },143 "should use default config when no default file found": function (test) {144 config = configuration.loadFile();145 var defaultConfig = configuration.loadObject();146 test.deepEqual(config, defaultConfig);147 test.done();148 },149 "when files present": {150 setUp: function (cb) {151 process.chdir(newCwd);152 cb();153 },154 tearDown: function (cb) {155 process.chdir(oldCwd);156 cb();157 },158 "should use default YAML config when not explicit": function (test) {159 config = configuration.loadFile(undefined, { verbose: true });160 test.equal(false, config.instrumentation.compact());161 test.deepEqual(['lcov', 'cobertura'], config.reporting.reports());162 test.done();163 },164 "should use explicit file when provided": function (test) {165 config = configuration.loadFile('cfg.json', { verbose: true });166 test.equal(true, config.instrumentation.compact());167 test.deepEqual(['lcov'], config.reporting.reports());168 test.equal(true, config.instrumentation.saveBaseline());169 test.equal('yui-istanbul', config.hooks.postRequireHook());170 test.done();171 }172 }173 },174 "with custom watermarks": {175 "should load from sparse config": function (test) {176 config = configuration.loadObject({ reporting: { watermarks: { statements: [ 10, 90] } } });177 var w = config.reporting.watermarks();178 test.deepEqual([ 10, 90 ], w.statements);179 test.deepEqual([ 50, 80 ], w.branches);180 test.deepEqual([ 50, 80 ], w.functions);181 test.deepEqual([ 50, 80 ], w.lines);182 test.done();183 },184 "should not load any junk config": function (test) {185 config = configuration.loadObject({186 reporting: {187 watermarks: {188 statements: [ 10, 90, 95],189 branches: [ -10, 70 ],190 lines: [ 70, 110 ],191 functions: [ 'a', 10 ]192 }193 }194 });195 var w = config.reporting.watermarks();196 test.deepEqual([ 50, 80 ], w.statements);197 test.deepEqual([ 50, 80 ], w.branches);198 test.deepEqual([ 50, 80 ], w.functions);199 test.deepEqual([ 50, 80 ], w.lines);200 test.done();201 },202 "should not load any junk config (2)": function (test) {203 config = configuration.loadObject({204 reporting: {205 watermarks: {206 statements: [ 90, 80 ]207 }208 }209 });210 var w = config.reporting.watermarks();211 test.deepEqual([ 50, 80 ], w.statements);212 test.deepEqual([ 50, 80 ], w.branches);213 test.deepEqual([ 50, 80 ], w.functions);214 test.deepEqual([ 50, 80 ], w.lines);215 test.done();216 }217 }...
config.test.js
Source:config.test.js
...11 beforeEach(hijack.silent);12 afterEach(reset);13 describe('no explicit config', function () {14 beforeEach(function () {15 config = configuration.loadObject(null);16 });17 it('sets verbose option', function () {18 assert.equal(config.verbose, false);19 reset();20 });21 it('sets sane instrument options', function () {22 var iOpts = config.instrumentation;23 assert.equal(iOpts.root(), process.cwd());24 assert.equal(iOpts.defaultExcludes(), true);25 assert.equal(iOpts.variable(), '__coverage__');26 assert.equal(iOpts.compact(), true);27 assert.equal(iOpts.preserveComments(), false);28 assert.equal(iOpts.completeCopy(), false);29 assert.equal(iOpts.saveBaseline(), false);30 assert.equal(iOpts.includeAllSources(), false);31 assert.equal(iOpts.baselineFile(), './coverage/coverage-baseline.raw.json');32 assert.deepEqual(iOpts.excludes(), ['**/node_modules/**']);33 assert.deepEqual(iOpts.excludes(true), ['**/node_modules/**', '**/test/**', '**/tests/**']);34 reset();35 });36 it('sets correct reporting options', function () {37 var rOpts = config.reporting;38 assert.equal(rOpts.print(), 'summary');39 assert.deepEqual(rOpts.reports(), ['lcov']);40 assert.equal(rOpts.dir(), './coverage');41 reset();42 });43 it('sets correct hook options', function () {44 var hOpts = config.hooks;45 assert.equal(hOpts.hookRunInContext(), false);46 assert.equal(hOpts.postRequireHook(), null);47 reset();48 });49 });50 describe('when overrides passed in', function () {51 describe('as initial object', function () {52 it('uses overrides', function () {53 config = configuration.loadObject({54 instrumentation: {55 compact: false,56 'save-baseline': true57 }58 });59 assert.equal(config.instrumentation.compact(), false);60 assert.equal(config.instrumentation.saveBaseline(), true);61 reset();62 });63 });64 describe('as override object', function () {65 it('uses overrides', function () {66 config = configuration.loadObject({},67 {68 verbose: true,69 instrumentation: {compact: false, 'save-baseline': true}70 }71 );72 assert.equal(config.verbose, true);73 assert.equal(config.instrumentation.compact(), false);74 assert.equal(config.instrumentation.saveBaseline(), true);75 reset();76 });77 });78 describe('at both levels', function () {79 it('uses overrides', function () {80 config = configuration.loadObject(81 {82 verbose: true,83 instrumentation: {compact: false, 'save-baseline': true}84 },85 {86 verbose: false,87 instrumentation: {compact: true, 'save-baseline': false}88 }89 );90 assert.equal(config.verbose, false);91 assert.equal(config.instrumentation.compact(), true);92 assert.equal(config.instrumentation.saveBaseline(), false);93 reset();94 });95 });96 describe('deeper in the tree', function () {97 config = configuration.loadObject({98 check: {99 'global': {100 'statements': 80101 }102 }103 });104 assert.equal(config.check.global.statements, 80);105 reset();106 });107 });108 describe('excludes array', function () {109 it('honors default excludes when set', function () {110 config = configuration.loadObject({111 instrumentation: {112 "excludes": ['**/vendor/**']113 }114 });115 var iOpts = config.instrumentation;116 assert.deepEqual(iOpts.excludes(), ['**/node_modules/**', '**/vendor/**']);117 assert.deepEqual(iOpts.excludes(true), ['**/node_modules/**', '**/test/**', '**/tests/**', '**/vendor/**']);118 reset();119 });120 it('honors default excludes when not set', function () {121 config = configuration.loadObject({122 instrumentation: {123 "default-excludes": null,124 "excludes": ['**/vendor/**']125 }126 });127 var iOpts = config.instrumentation;128 assert.deepEqual(iOpts.excludes(), ['**/vendor/**']);129 assert.deepEqual(iOpts.excludes(true), ['**/vendor/**']);130 reset();131 });132 it('returns nothing when defaults off and no excludes', function () {133 config = configuration.loadObject({134 instrumentation: {135 "default-excludes": null136 }137 });138 var iOpts = config.instrumentation;139 assert.deepEqual(iOpts.excludes(), []);140 assert.deepEqual(iOpts.excludes(true), []);141 reset();142 });143 });144 describe("file loading", function () {145 it('fails on bad config file', function () {146 assert.throws(function () {147 return configuration.loadFile('/a/non/existent/path.js');148 });149 reset();150 });151 it('uses default config when no default file found', function () {152 config = configuration.loadFile();153 var defaultConfig = configuration.loadObject();154 assert.deepEqual(defaultConfig, config);155 reset();156 });157 describe('when files present', function () {158 beforeEach(function () {159 process.chdir(newCwd);160 });161 afterEach(function () {162 process.chdir(oldCwd);163 });164 it('uses default YAML config when not explicit', function () {165 config = configuration.loadFile(undefined, {verbose: true});166 assert.equal(config.instrumentation.compact(), false);167 assert.deepEqual(config.reporting.reports(), ['lcov', 'cobertura']);168 reset();169 });170 it('uses explicit file when provided', function () {171 config = configuration.loadFile('cfg.json', {verbose: true});172 assert.equal(config.instrumentation.compact(), true);173 assert.deepEqual(config.reporting.reports(), ['lcov']);174 assert.equal(config.instrumentation.saveBaseline(), true);175 assert.equal(config.hooks.postRequireHook(), 'yui-istanbul');176 reset();177 });178 });179 });180 describe('custom watermarks', function () {181 it('loads from sparse config', function () {182 config = configuration.loadObject({reporting: {watermarks: {statements: [10, 90]}}});183 var w = config.reporting.watermarks();184 assert.deepEqual(w.statements, [10, 90]);185 assert.deepEqual(w.branches, [50, 80]);186 assert.deepEqual(w.functions, [50, 80]);187 assert.deepEqual(w.lines, [50, 80]);188 reset();189 });190 it('does not load any junk config', function () {191 config = configuration.loadObject({192 reporting: {193 watermarks: {194 statements: [10, 90, 95],195 branches: [-10, 70],196 lines: [70, 110],197 functions: ['a', 10]198 }199 }200 });201 var w = config.reporting.watermarks();202 assert.deepEqual(w.statements, [50, 80]);203 assert.deepEqual(w.branches, [50, 80]);204 assert.deepEqual(w.functions, [50, 80]);205 assert.deepEqual(w.lines, [50, 80]);...
Using AI Code Generation
1var istanbul = require('istanbul');2var config = istanbul.config.loadObject({3 instrumentation: {4 }5});6var istanbul = require('istanbul');7var config = istanbul.config.loadObject({8 instrumentation: {9 }10});11var istanbul = require('istanbul');12var config = istanbul.config.loadObject({13 instrumentation: {14 }15});16var istanbul = require('istanbul');17var config = istanbul.config.loadObject({18 instrumentation: {19 }20});21var istanbul = require('istanbul');22var config = istanbul.config.loadObject({23 instrumentation: {24 }25});26var istanbul = require('istanbul');27var config = istanbul.config.loadObject({28 instrumentation: {
Using AI Code Generation
1var istanbul = require('istanbul');2var config = istanbul.config.loadObject({3 instrumentation: {4 }5});6var istanbul = require('istanbul');7var config = istanbul.config.loadFile('test.json');8var istanbul = require('istanbul');9var config = istanbul.config.loadDefault();10var istanbul = require('istanbul');11var config = istanbul.config.loadFile('test.json');12var istanbul = require('istanbul');13var config = istanbul.config.loadFile('test.json');14var istanbul = require('istanbul');15var config = istanbul.config.loadFile('test.json');16var istanbul = require('istanbul');17var config = istanbul.config.loadFile('test.json');18var istanbul = require('istanbul');19var config = istanbul.config.loadFile('test.json');20var istanbul = require('istanbul');21var config = istanbul.config.loadFile('test.json');22var istanbul = require('istanbul');23var config = istanbul.config.loadFile('test.json');24var istanbul = require('istanbul');25var config = istanbul.config.loadFile('test.json');26var istanbul = require('istanbul');27var config = istanbul.config.loadFile('test.json');28var istanbul = require('istanbul');29var config = istanbul.config.loadFile('test.json');30var istanbul = require('
Using AI Code Generation
1var istanbul = require('istanbul');2var configuration = istanbul.config.loadObject({instrumentation: {root: './'}});3var instrumenter = new istanbul.Instrumenter(configuration);4instrumenter.instrumentSync('var foo = 1;', 'test.js');5var istanbul = require('istanbul-lib-instrument');6var configuration = istanbul.config.loadObject({root: './'});7var instrumenter = istanbul.createInstrumenter(configuration);8instrumenter.instrumentSync('var foo = 1;', 'test.js');
Using AI Code Generation
1var istanbul = require('istanbul');2var config = istanbul.config.loadObject({3 instrumentation: {4 }5});6var collector = new istanbul.Collector();7collector.add(config.instrumentation().defaultExcludes());8collector.add(__dirname + '/coverage/coverage.json');9var reporter = new istanbul.Reporter();10reporter.addAll(['text', 'lcov']);11reporter.write(collector, true, function () {12 console.log('All reports generated');13});14{15 "instrumentation": {16 }17}
Using AI Code Generation
1const istanbul = require('istanbul-api');2const config = istanbul.config.loadObject({3 instrumentation: {4 }5});6const map = istanbul.libCoverage.createCoverageMap();7const coverage = istanbul.libCoverage.createCoverageMap();8const collector = new istanbul.Collector();9const reporter = new istanbul.Reporter();10const sync = false;11const verbose = false;12const check = {13};14const watermarks = {15};16const reportingDir = 'coverage';17const reportTypes = ['lcovonly', 'html'];18const reports = istanbul.utils.defaultReportDir(config.reporting.dir());19const instrumenter = istanbul.createInstrumenter();20instrumenter.instrumentSync('src/index.js', 'instrumented/index.js');21const coverageMap = istanbul.libCoverage.createCoverageMap();22coverageMap.addFileCoverage({23 statementMap: {24 '0': {25 start: {26 },27 end: {28 }29 },30 '1': {31 start: {32 },33 end: {34 }35 },36 '2': {37 start: {38 },39 end: {40 }41 },42 '3': {43 start: {44 },45 end: {46 }47 }48 },
Using AI Code Generation
1var istanbul = require('istanbul');2 reporting: {3 },4 instrumentation: {5 }6};7var collector = new istanbul.Collector();8var collector = new istanbul.Collector();9var istanbul = require('istanbul');10 reporting: {11 },12 instrumentation: {13 }14};15var collector = new istanbul.Collector();16var configObj = config.getConfig();17var collector = new istanbul.Collector();18var configObj = config.getConfig();
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!!