UNPKG

danger-plugin-no-console

Version:

Danger plugin to prevent merging code that still has `console.log`s inside it.

102 lines (83 loc) 3.14 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../"> <title data-ice="title">src/index.test.js | API Document</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <a data-ice="repoURL" href="https://github.com/withspectrum/danger-plugin-no-console.git" class="repo-url-github">Repository</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> </header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-noConsole">noConsole</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/index.test.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import noConsole from &apos;./&apos;; const files = { &apos;src/log.js&apos;: &apos;function add(a, b) {\n console.log(a, b);\n return a + b;\n}&apos;, &apos;src/clean.js&apos;: &apos;function add(a, b) {\n return a + b;\n}&apos;, &apos;src/error.js&apos;: &apos;function add(a, b) {\n console.error(a, b);\n return a + b;\n}&apos;, } const fileNames = Object.keys(files); // Mock the Danger API global.danger = { git: { modified_files: [fileNames[0], fileNames[1]], created_files: [fileNames[2]] }, github: { utils: { fileContents: (path) =&gt; new Promise(res =&gt; { res(files[path]) }) } } } beforeEach(() =&gt; { global.fail = jest.fn() }) afterEach(() =&gt; { global.fail = undefined }) describe(&apos;noConsole()&apos;, () =&gt; { it(&apos;should fail any files with a console.log in it&apos;, async () =&gt; { await noConsole(); expect(global.fail).toHaveBeenCalledTimes(2); }); it(&apos;should respect the whitelist of console properties&apos;, async () =&gt; { await noConsole({ whitelist: [&apos;error&apos;] }); expect(global.fail).toHaveBeenCalledTimes(1); }) }) </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.5.2)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>