Skip to content

Commit

Permalink
πŸ”€ pull request #15 from devnetkc:addPkgEntryTest
Browse files Browse the repository at this point in the history
βœ… Adds testing to pkg main entry file
  • Loading branch information
devnetkc authored Nov 28, 2022
2 parents 3ca2567 + 7617218 commit 66180ed
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 40 deletions.
116 changes: 116 additions & 0 deletions __tests__/customJestStubs-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @format
* @module customModule_CS-test
*/

import customJestStubs from '../customJestStubs';

beforeEach(() => {
jest.clearAllMocks();
});
// eslint-disable-next-line import/no-amd
describe('customJestStubs.js Tests', () => {
describe('customStubs method should ', () => {
describe('ExcludeStubs param', () => {});
// * GIVEN
test('return an array when passed empty array', () => {
// * GIVEN
const ExcludeStubs = [];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.any(Array));
expect(jest.fn(() => CustomStubsList)).not.toThrow(Error);
});
test('throw an error if NOT given an array', () => {
// * GIVEN
const ExcludeStubs = {};
// * THEN
expect(jest.fn(() => customJestStubs.customStubs(ExcludeStubs))).toThrow(
'EXCLUDED_STUBS_TYPEERROR'
);
});
describe('useMinified is false', () => {
test('return array with excluded module path instead of stub path', () => {
// * GIVEN
const ExcludeStubs = [
{
name: '/SuiteScripts/Modules/aModule',
path: `<rootDir>/src/FileCabinet`,
useMinified: {
value: false,
},
},
];
const ExpectedResult = [
{
module: '/SuiteScripts/Modules/aModule',
path: `<rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/aModule.min',
path: `<rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/bModule',
path: `<rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
{
module: '/SuiteScripts/Modules/bModule.min',
path: `<rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.arrayContaining(ExpectedResult));
});
});
describe('useMinified is true', () => {
/* test.todo(
'should return array with minified excluded module path instead of stub path '
); */
test('return array with excluded module path instead of stub path', () => {
// * GIVEN
const ExcludeStubs = [
{
name: '/SuiteScripts/Modules/aModule',
path: `<rootDir>/src/FileCabinet`,
useMinified: {
value: true,
},
},
{
name: '/SuiteScripts/Modules/bModule.min',
path: `<rootDir>/src/FileCabinet`,
useMinified: {
value: false,
},
},
];
const ExpectedResult = [
{
module: '/SuiteScripts/Modules/aModule',
path: `<rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/aModule.min',
path: `<rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.min.js`,
},
{
module: '/SuiteScripts/Modules/bModule',
path: `<rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
{
module: '/SuiteScripts/Modules/bModule.min',
path: `<rootDir>/src/FileCabinet/SuiteScripts/Modules/bModule.js`,
},
];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.arrayContaining(ExpectedResult));
});
});
});
});
27 changes: 15 additions & 12 deletions customJestStubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const PKG_STUBS_PATH =
*/
const customStubs = exclude =>
Object.keys(CustomStubMap).map(filename => {
if (!Array.isArray(exclude)) throw 'EXCLUDED_STUBS_TYPEERROR';
let stubModuleName = `/SuiteScripts/${filename}`;
let ext = '.js';
const Module = {
Expand All @@ -73,22 +74,13 @@ const customStubs = exclude =>
};
// Loop over array of excludes and link min/non-min to project overrides
for (const ExcludedModule of exclude) {
if (RegExp(ExcludedModule.name).test(filename)) continue; //?
if (!RegExp(ExcludedModule.name).test(stubModuleName)) continue; //?
ExcludedModule.useMinified.minName =
ExcludedModule.useMinified.hasOwnProperty('minName')
? ExcludedModule.useMinified.minName
: '.min';
const ModuleNameMinified = `${ExcludedModule.name}${ExcludedModule.useMinified.minName}`;
if (
ExcludedModule.name !== stubModuleName &&
ModuleNameMinified !== stubModuleName
)
continue;
if (ExcludedModule.useMinified.value) {
Module.path = ExcludedModule.path.replace(
ExcludedModule.useMinified.minName,
''
);
Module.path = ExcludedModule.path + stubModuleName + ext;
break;
}
stubModuleName = stubModuleName.replace(
Expand All @@ -100,7 +92,18 @@ const customStubs = exclude =>
}
return Module;
});

/*
const ExcludeStubs = [
{
name: '/SuiteScripts/Modules/aModule',
path: `${__dirname}/src/FileCabinet`,
useMinified: {
value: false,
},
},
];
customStubs(ExcludeStubs); //?
*/
module.exports = {
customStubs,
};
167 changes: 167 additions & 0 deletions docs/-__tests___customJestStubs-test.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: __tests__/customJestStubs-test.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

<h1 class="page-title">Source: __tests__/customJestStubs-test.js</h1>






<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @format
* @module customModule_CS-test
*/

import customJestStubs from '../customJestStubs';

beforeEach(() => {
jest.clearAllMocks();
});
// eslint-disable-next-line import/no-amd
describe('customJestStubs.js Tests', () => {
describe('customStubs method should ', () => {
describe('ExcludeStubs param', () => {});
// * GIVEN
test('return an array when passed empty array', () => {
// * GIVEN
const ExcludeStubs = [];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.any(Array));
expect(jest.fn(() => CustomStubsList)).not.toThrow(Error);
});
test('throw an error if NOT given an array', () => {
// * GIVEN
const ExcludeStubs = {};
// * THEN
expect(jest.fn(() => customJestStubs.customStubs(ExcludeStubs))).toThrow(
'EXCLUDED_STUBS_TYPEERROR'
);
});
describe('useMinified is false', () => {
test('return array with excluded module path instead of stub path', () => {
// * GIVEN
const ExcludeStubs = [
{
name: '/SuiteScripts/Modules/aModule',
path: `&lt;rootDir>/src/FileCabinet`,
useMinified: {
value: false,
},
},
];
const ExpectedResult = [
{
module: '/SuiteScripts/Modules/aModule',
path: `&lt;rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/aModule.min',
path: `&lt;rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/bModule',
path: `&lt;rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
{
module: '/SuiteScripts/Modules/bModule.min',
path: `&lt;rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.arrayContaining(ExpectedResult));
});
});
describe('useMinified is true', () => {
/* test.todo(
'should return array with minified excluded module path instead of stub path '
); */
test('return array with excluded module path instead of stub path', () => {
// * GIVEN
const ExcludeStubs = [
{
name: '/SuiteScripts/Modules/aModule',
path: `&lt;rootDir>/src/FileCabinet`,
useMinified: {
value: true,
},
},
{
name: '/SuiteScripts/Modules/bModule.min',
path: `&lt;rootDir>/src/FileCabinet`,
useMinified: {
value: false,
},
},
];
const ExpectedResult = [
{
module: '/SuiteScripts/Modules/aModule',
path: `&lt;rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.js`,
},
{
module: '/SuiteScripts/Modules/aModule.min',
path: `&lt;rootDir>/src/FileCabinet/SuiteScripts/Modules/aModule.min.js`,
},
{
module: '/SuiteScripts/Modules/bModule',
path: `&lt;rootDir>/node_modules/@vnetwork-solutions/ns-custom-stubs-template/stubs/SuiteScripts/Modules/bModule`,
},
{
module: '/SuiteScripts/Modules/bModule.min',
path: `&lt;rootDir>/src/FileCabinet/SuiteScripts/Modules/bModule.js`,
},
];
// * WHEN
const CustomStubsList = customJestStubs.customStubs(ExcludeStubs);
// * THEN
expect(CustomStubsList).toEqual(expect.arrayContaining(ExpectedResult));
});
});
});
});
</code></pre>
</article>
</section>




</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aModule.html">aModule</a></li><li><a href="module-bModule.html">bModule</a></li><li><a href="module-CustomJestStubs.html">CustomJestStubs</a></li><li><a href="module-customModule_CS-test.html">customModule_CS-test</a></li><li><a href="module-JestConfig.html">JestConfig</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 14:49:55 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:25:43 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 14:49:55 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-aM
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 03:25:43 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Nov 28 2022 14:49:55 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit 66180ed

Please sign in to comment.