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
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 './';
const files = {
'src/log.js': 'function add(a, b) {\n console.log(a, b);\n return a + b;\n}',
'src/clean.js': 'function add(a, b) {\n return a + b;\n}',
'src/error.js': 'function add(a, b) {\n console.error(a, b);\n return a + b;\n}',
}
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) => new Promise(res => {
res(files[path])
})
}
}
}
beforeEach(() => {
global.fail = jest.fn()
})
afterEach(() => {
global.fail = undefined
})
describe('noConsole()', () => {
it('should fail any files with a console.log in it', async () => {
await noConsole();
expect(global.fail).toHaveBeenCalledTimes(2);
});
it('should respect the whitelist of console properties', async () => {
await noConsole({ whitelist: ['error'] });
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>