Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 0bbfe5b

Browse files
committed
test: add additional tests to stop the code coverage badgering
1 parent 44754ef commit 0bbfe5b

File tree

3 files changed

+198
-1
lines changed

3 files changed

+198
-1
lines changed

lib/reader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const Boom = require('boom');
1414
const assert = require('assert');
1515
const envify = require('envify');
1616

17+
const DEFAULT_ENV = 'development';
18+
1719
/**
1820
* Unpacks given feeds into directory structure before
1921
* bundling everything together with browserify.
@@ -46,7 +48,7 @@ module.exports = async (feeds, options) => {
4648
const opts = {
4749
sourceMaps: false,
4850
minify: false,
49-
env: process.env.NODE_ENV || 'development',
51+
env: process.env.NODE_ENV || DEFAULT_ENV,
5052
...options,
5153
};
5254

test/__snapshots__/reader.test.js.snap

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61720,6 +61720,144 @@ exports[`should handle node_modules dependencies 1`] = `
6172061720
"
6172161721
`;
6172261722

61723+
exports[`should replace NODE_ENV with default of "development" 1`] = `
61724+
"(function e(t, n, r) {
61725+
function s(o, u) {
61726+
if (!n[o]) {
61727+
if (!t[o]) {
61728+
var a = typeof require == \\"function\\" && require;
61729+
if (!u && a) return a(o, !0);
61730+
if (i) return i(o, !0);
61731+
var f = new Error(\\"Cannot find module '\\" + o + \\"'\\");
61732+
throw ((f.code = \\"MODULE_NOT_FOUND\\"), f);
61733+
}
61734+
var l = (n[o] = { exports: {} });
61735+
t[o][0].call(
61736+
l.exports,
61737+
function(e) {
61738+
var n = t[o][1][e];
61739+
return s(n ? n : e);
61740+
},
61741+
l,
61742+
l.exports,
61743+
e,
61744+
t,
61745+
n,
61746+
r
61747+
);
61748+
}
61749+
return n[o].exports;
61750+
}
61751+
var i = typeof require == \\"function\\" && require;
61752+
for (var o = 0; o < r.length; o++) s(r[o]);
61753+
return s;
61754+
})(
61755+
{
61756+
1: [
61757+
function(require, module, exports) {
61758+
console.log(\\"test\\");
61759+
},
61760+
{}
61761+
]
61762+
},
61763+
{},
61764+
[1]
61765+
);
61766+
"
61767+
`;
61768+
61769+
exports[`should replace NODE_ENV with given value 1`] = `
61770+
"(function e(t, n, r) {
61771+
function s(o, u) {
61772+
if (!n[o]) {
61773+
if (!t[o]) {
61774+
var a = typeof require == \\"function\\" && require;
61775+
if (!u && a) return a(o, !0);
61776+
if (i) return i(o, !0);
61777+
var f = new Error(\\"Cannot find module '\\" + o + \\"'\\");
61778+
throw ((f.code = \\"MODULE_NOT_FOUND\\"), f);
61779+
}
61780+
var l = (n[o] = { exports: {} });
61781+
t[o][0].call(
61782+
l.exports,
61783+
function(e) {
61784+
var n = t[o][1][e];
61785+
return s(n ? n : e);
61786+
},
61787+
l,
61788+
l.exports,
61789+
e,
61790+
t,
61791+
n,
61792+
r
61793+
);
61794+
}
61795+
return n[o].exports;
61796+
}
61797+
var i = typeof require == \\"function\\" && require;
61798+
for (var o = 0; o < r.length; o++) s(r[o]);
61799+
return s;
61800+
})(
61801+
{
61802+
1: [
61803+
function(require, module, exports) {
61804+
console.log(\\"production\\");
61805+
},
61806+
{}
61807+
]
61808+
},
61809+
{},
61810+
[1]
61811+
);
61812+
"
61813+
`;
61814+
61815+
exports[`should replace NODE_ENV with process.env.NODE_ENV 1`] = `
61816+
"(function e(t, n, r) {
61817+
function s(o, u) {
61818+
if (!n[o]) {
61819+
if (!t[o]) {
61820+
var a = typeof require == \\"function\\" && require;
61821+
if (!u && a) return a(o, !0);
61822+
if (i) return i(o, !0);
61823+
var f = new Error(\\"Cannot find module '\\" + o + \\"'\\");
61824+
throw ((f.code = \\"MODULE_NOT_FOUND\\"), f);
61825+
}
61826+
var l = (n[o] = { exports: {} });
61827+
t[o][0].call(
61828+
l.exports,
61829+
function(e) {
61830+
var n = t[o][1][e];
61831+
return s(n ? n : e);
61832+
},
61833+
l,
61834+
l.exports,
61835+
e,
61836+
t,
61837+
n,
61838+
r
61839+
);
61840+
}
61841+
return n[o].exports;
61842+
}
61843+
var i = typeof require == \\"function\\" && require;
61844+
for (var o = 0; o < r.length; o++) s(r[o]);
61845+
return s;
61846+
})(
61847+
{
61848+
1: [
61849+
function(require, module, exports) {
61850+
console.log(\\"production\\");
61851+
},
61852+
{}
61853+
]
61854+
},
61855+
{},
61856+
[1]
61857+
);
61858+
"
61859+
`;
61860+
6172361861
exports[`should successfully bundle 2 feeds 1`] = `
6172461862
"(function e(t, n, r) {
6172561863
function s(o, u) {

test/reader.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,60 @@ test('multiple entrypoints in same feed supported', async () => {
424424
expect(spy).toMatchSnapshot();
425425
expect(spy).toHaveBeenCalledTimes(4);
426426
});
427+
428+
test('should replace NODE_ENV with default of "development"', async () => {
429+
expect.hasAssertions();
430+
const result = await bundleJS([
431+
[
432+
{
433+
id: 'a',
434+
entry: true,
435+
file: './asdas.js',
436+
source: 'console.log(process.env.NODE_ENV)',
437+
deps: {},
438+
},
439+
],
440+
]);
441+
expect(result).toMatch('test');
442+
expect(prettier.format(result)).toMatchSnapshot();
443+
});
444+
445+
test('should replace NODE_ENV with process.env.NODE_ENV', async () => {
446+
expect.hasAssertions();
447+
const env = process.env.NODE_ENV;
448+
process.env.NODE_ENV = 'production';
449+
const result = await bundleJS([
450+
[
451+
{
452+
id: 'a',
453+
entry: true,
454+
file: './asdas.js',
455+
source: 'console.log(process.env.NODE_ENV)',
456+
deps: {},
457+
},
458+
],
459+
]);
460+
expect(result).toMatch('production');
461+
expect(prettier.format(result)).toMatchSnapshot();
462+
process.env.NODE_ENV = env;
463+
});
464+
465+
test('should replace NODE_ENV with given value', async () => {
466+
expect.hasAssertions();
467+
const result = await bundleJS(
468+
[
469+
[
470+
{
471+
id: 'a',
472+
entry: true,
473+
file: './asdas.js',
474+
source: 'console.log(process.env.NODE_ENV)',
475+
deps: {},
476+
},
477+
],
478+
],
479+
{ env: 'production' }
480+
);
481+
expect(result).toMatch('production');
482+
expect(prettier.format(result)).toMatchSnapshot();
483+
});

0 commit comments

Comments
 (0)