Repository: Synthetixio/synthetix-v3
Pull request #284 (2021-11-01 18:09:01)

Add core-js tests to increase coverage

codecov[bot]: # [Codecov](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio) Report
> Merging [#284](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio) (7e08862) into [main](https://codecov.io/gh/Synthetixio/synthetix-v3/commit/7d7bdecc93399242905809be2e253ce3ae396936?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio) (7d7bdec) will **increase** coverage by `10.58%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/graphs/tree.svg?width=650&height=150&src=pr&token=B9BK0U5KAT&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio)](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio)

```diff
@@             Coverage Diff              @@
##             main      #284       +/-   ##
============================================
+ Coverage   89.41%   100.00%   +10.58%     
============================================
  Files          82         6       -76     
  Lines        1266        36     -1230     
  Branches       23         2       -21     
============================================
- Hits         1132        36     -1096     
+ Misses        134         0      -134     
```

| Flag | Coverage Δ | |
|---|---|---|
| core-contracts | `?` | |
| core-js | `?` | |
| core-modules | `?` | |
| deployer | `?` | |
| synthetix-main | `100.00% <ø> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio) | Coverage Δ | |
|---|---|---|
| [packages/core-js/utils/logger.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1qcy91dGlscy9sb2dnZXIuanM=) | | |
| [packages/core-js/utils/prompter.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1qcy91dGlscy9wcm9tcHRlci5qcw==) | | |
| [...ules/contracts/mocks/modules/UpgradeModuleMock.sol](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1tb2R1bGVzL2NvbnRyYWN0cy9tb2Nrcy9tb2R1bGVzL1VwZ3JhZGVNb2R1bGVNb2NrLnNvbA==) | | |
| [...ntracts/contracts/mocks/utils/ContractUtilMock.sol](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1jb250cmFjdHMvY29udHJhY3RzL21vY2tzL3V0aWxzL0NvbnRyYWN0VXRpbE1vY2suc29s) | | |
| [...es/core-modules/contracts/storage/ProxyStorage.sol](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1tb2R1bGVzL2NvbnRyYWN0cy9zdG9yYWdlL1Byb3h5U3RvcmFnZS5zb2w=) | | |
| [packages/deployer/subtasks/deploy-contracts.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvZGVwbG95ZXIvc3VidGFza3MvZGVwbG95LWNvbnRyYWN0cy5qcw==) | | |
| [packages/deployer/subtasks/clear-deployments.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvZGVwbG95ZXIvc3VidGFza3MvY2xlYXItZGVwbG95bWVudHMuanM=) | | |
| [packages/core-js/utils/get-date.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvY29yZS1qcy91dGlscy9nZXQtZGF0ZS5qcw==) | | |
| [packages/deployer/internal/config-defaults.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvZGVwbG95ZXIvaW50ZXJuYWwvY29uZmlnLWRlZmF1bHRzLmpz) | | |
| [packages/deployer/utils/deployments.js](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio#diff-cGFja2FnZXMvZGVwbG95ZXIvdXRpbHMvZGVwbG95bWVudHMuanM=) | | |
| ... and [66 more](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio). Last update [7d7bdec...7e08862](https://codecov.io/gh/Synthetixio/synthetix-v3/pull/284?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Synthetixio).


Patch:
diff --git a/packages/core-js/utils/logger.js b/packages/core-js/utils/logger.js
index 87449cc9..58a8acad 100644
--- a/packages/core-js/utils/logger.js
+++ b/packages/core-js/utils/logger.js
@@ -3,6 +3,7 @@ const chalk = require('chalk');
 const BOX_WIDTH = 90;
 
 module.exports = {
+  _log: console.log.bind(console),
   quiet: false,
   debugging: false,
   prepend: '',
@@ -33,7 +34,7 @@ module.exports = {
     const completeLen = Math.max(BOX_WIDTH + 8 - [...msg].length, 0);
     const completeStr = this.boxing ? chalk.gray('.'.repeat(completeLen)) : '';
 
-    console.log(`${this.prepend}${msg}${completeStr}${this.postpend}`);
+    this._log(`${this.prepend}${msg}${completeStr}${this.postpend}`);
   },
 
   subtitle(msg) {
@@ -41,7 +42,7 @@ module.exports = {
       return;
     }
 
-    console.log('\n');
+    this._log('\n');
 
     this.boxStart();
     this.log(chalk.cyan(`‣ ${msg}`));
diff --git a/packages/core-js/utils/prompter.js b/packages/core-js/utils/prompter.js
index e8155685..f52436e6 100644
--- a/packages/core-js/utils/prompter.js
+++ b/packages/core-js/utils/prompter.js
@@ -1,6 +1,7 @@
 const inquirer = require('inquirer');
 
 module.exports = {
+  _prompt: inquirer.prompt.bind(inquirer),
   noConfirm: false,
 
   /**
@@ -13,7 +14,7 @@ module.exports = {
       return true;
     }
 
-    const { confirmation } = await inquirer.prompt([
+    const { confirmation } = await this._prompt([
       {
         type: 'confirm',
         name: 'confirmation',


Test patch:
diff --git a/packages/core-js/test/utils/hardhat.test.js b/packages/core-js/test/utils/hardhat.test.js
new file mode 100644
index 00000000..f47ecfb5
--- /dev/null
+++ b/packages/core-js/test/utils/hardhat.test.js
@@ -0,0 +1,40 @@
+const { deepEqual } = require('assert/strict');
+const { getAllContractASTs } = require('../../utils/hardhat');
+
+describe('utils/hardhat.js', () => {
+  it('should get artifacts ASTs', async () => {
+    const qualifiedNames = [
+      'contracts/modules/OwnerModule.sol:OwnerModule',
+      'contracts/modules/SomeModule.sol:SomeModule',
+    ];
+
+    const output = {
+      sources: {
+        'contracts/modules/OwnerModule.sol': {
+          OwnerModule: {
+            ast: { some: 'ast' },
+          },
+        },
+        'contracts/modules/SomeModule.sol': {
+          SomeModule: {
+            ast: { another: 'ast' },
+          },
+        },
+      },
+    };
+
+    const hreMock = {
+      artifacts: {
+        getAllFullyQualifiedNames: async () => qualifiedNames,
+        getBuildInfo: async () => ({ output }),
+      },
+    };
+
+    const result = await getAllContractASTs(hreMock);
+
+    deepEqual(result, {
+      OwnerModule: { some: 'ast' },
+      SomeModule: { another: 'ast' },
+    });
+  });
+});
diff --git a/packages/core-js/test/utils/logger.test.js b/packages/core-js/test/utils/logger.test.js
index d908799a..3c41258f 100644
--- a/packages/core-js/test/utils/logger.test.js
+++ b/packages/core-js/test/utils/logger.test.js
@@ -1,37 +1,100 @@
-const assert = require('assert/strict');
+const { equal, deepEqual } = require('assert/strict');
+const chalk = require('chalk');
 const logger = require('../../utils/logger');
 
 describe('utils/logger.js', () => {
-  let logCache;
-  let logged = '';
+  let logged = [];
 
-  function _log(msg) {
-    logged += msg;
-  }
+  before('disable chalk color usage', () => {
+    chalk.level = 0;
+  });
 
-  before('capture output', async () => {
-    logCache = console.log;
-    console.log = _log;
+  before('capture output', () => {
+    logger._log = (...args) => {
+      logged.push(args);
+    };
   });
 
-  after('release output', async () => {
-    console.log = logCache;
+  beforeEach('reset captured output', () => {
+    logged = [];
   });
 
-  it('starts with the correct default props', async () => {
-    assert.equal(logger.quiet, false);
-    assert.equal(logger.debugging, false);
-    assert.equal(logger.prepend, '');
-    assert.equal(logger.postpend, '');
-    assert.equal(logger.boxing, false);
+  it('starts with the correct default props', () => {
+    equal(logger.quiet, false);
+    equal(logger.debugging, false);
+    equal(logger.prepend, '');
+    equal(logger.postpend, '');
+    equal(logger.boxing, false);
+  });
+
+  describe('when quiet is not enabled', () => {
+    before('disable quiet', () => {
+      logger.quiet = false;
+    });
+
+    it('prints logs to the console', () => {
+      logger.log('hello');
+      logger.info('hello');
+      logger.notice('hello');
+      logger.error('hello');
+      logger.warn('hello');
+      logger.checked('hello');
+      logger.success('hello');
+      logger.complete('hello');
+      logger.debug('hello');
+      logger.subtitle('hello');
+      logger.boxStart();
+      logger.log('boxed hello');
+      logger.boxEnd();
+
+      deepEqual(logged, [
+        ['hello'],
+        ['ⓘ  hello'],
+        ['> hello'],
+        ['☠ hello'],
+        ['⚠ hello'],
+        ['✓ hello'],
+        ['✅ hello'],
+        ['💯 hello'],
+        ['\n'],
+        [
+          '┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓',
+        ],
+        [
+          '┃ ‣ hello........................................................................................... ┃',
+        ],
+        [
+          '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛',
+        ],
+        [
+          '┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓',
+        ],
+        [
+          '┃ boxed hello....................................................................................... ┃',
+        ],
+        [
+          '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛',
+        ],
+      ]);
+    });
+
+    it('should log when debugging is enabled', () => {
+      logger.debugging = true;
+      try {
+        logger.debug('debugging!');
+        deepEqual(logged, [['debugging!']]);
+      } finally {
+        logger.debugging = false;
+      }
+    });
   });
 
   describe('when quiet is enabled', () => {
-    before('enable quiet', async () => {
+    before('enable quiet', () => {
       logger.quiet = true;
     });
 
-    before('perform some logs', async () => {
+    it('does not record any logs', () => {
       logger.log('hello');
       logger.info('hello');
       logger.notice('hello');
@@ -41,10 +104,12 @@ describe('utils/logger.js', () => {
       logger.success('hello');
       logger.complete('hello');
       logger.debug('hello');
-    });
+      logger.subtitle('hello');
+      logger.boxStart();
+      logger.log('boxed hello');
+      logger.boxEnd();
 
-    it('does not record any logs', async () => {
-      assert.equal(logged.length, 0);
+      equal(logged.length, 0);
     });
   });
 });
diff --git a/packages/core-js/test/utils/prompter.test.js b/packages/core-js/test/utils/prompter.test.js
new file mode 100644
index 00000000..3f3ea90a
--- /dev/null
+++ b/packages/core-js/test/utils/prompter.test.js
@@ -0,0 +1,61 @@
+const { equal } = require('assert/strict');
+const prompter = require('../../utils/prompter');
+
+describe('utils/prompter.js', function () {
+  describe('when noConfirm is enabled', function () {
+    before('enable noCofirm', function () {
+      prompter.noConfirm = true;
+    });
+
+    describe('#ask', function () {
+      it('returns always true', async function () {
+        const result = await prompter.ask('something?');
+        equal(result, true);
+      });
+    });
+
+    describe('#confirmAction', function () {
+      it('does not halt execution', async function () {
+        await prompter.confirmAction('something?');
+      });
+    });
+  });
+
+  describe('when noConfirm is disabled', function () {
+    before('enable noCofirm', function () {
+      prompter.noConfirm = false;
+    });
+
+    describe('#ask', function () {
+      it('returns always the users response', async function () {
+        prompter._prompt = async () => ({ confirmation: true });
+        equal(await prompter.ask('something?'), true);
+
+        prompter._prompt = async () => ({ confirmation: false });
+        equal(await prompter.ask('another something?'), false);
+      });
+    });
+
+    describe('#confirmAction', function () {
+      it('does not halt execution when responding positively', async function () {
+        prompter._prompt = async () => ({ confirmation: true });
+        await prompter.confirmAction('something?');
+      });
+
+      it('halts execution when responding negatively', async function () {
+        prompter._prompt = async () => ({ confirmation: false });
+
+        let exited = false;
+        const exitCache = process.exit;
+        process.exit = () => (exited = true);
+
+        try {
+          await prompter.confirmAction('something?');
+          equal(exited, true);
+        } finally {
+          process.exit = exitCache;
+        }
+      });
+    });
+  });
+});
diff --git a/packages/core-js/test/utils/rpc.test.js b/packages/core-js/test/utils/rpc.test.js
index 2831a464..07565a1e 100644
--- a/packages/core-js/test/utils/rpc.test.js
+++ b/packages/core-js/test/utils/rpc.test.js
@@ -21,7 +21,6 @@ describe('utils/rpc.js', () => {
     let snapshotId;
 
     before('call createSnapshot', async () => {
-      console.log(provider);
       snapshotId = await takeSnapshot(provider);
     });