Repository: nuxt/nuxt.js
Pull request #5320 (2019-03-21 19:59:34)

fix: apply default lock options before setting lock
<!--- Provide a general summary of your changes in the title above -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (a non-breaking change which fixes an issue)
- [ ] New feature (a non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)


## Description
<!--- Describe your changes in detail -->
<!--- Why is this change required? What problem does it solve? -->
<!--- If it resolves an open issue, please link to the issue here. For example "Resolves: #1337" -->

As second / third time is the charm, now not only relax the lock settings but also really use them. Sorry :blush: 

## Checklist:
<!--- Put an `x` in all the boxes that apply. -->
<!--- If your change requires a documentation PR, please link it appropriately -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly. (PR: #)
- [x] I have added tests to cover my changes (if not applicable, please state why)
- [ ] All new and existing tests are passing.

Fixes: #5319

codecov-io: # [Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=h1) Report
> Merging [#5320](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=desc) into [dev](https://codecov.io/gh/nuxt/nuxt.js/commit/3153e89645cce9f487d745e42f189da53cb4faed?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/nuxt/nuxt.js/pull/5320/graphs/tree.svg?width=650&token=nGD1PtMB3M&height=150&src=pr)](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             dev    #5320      +/-   ##
=========================================
- Coverage   95.7%   95.66%   -0.04%     
=========================================
  Files         74       74              
  Lines       2512     2514       +2     
  Branches     639      639              
=========================================
+ Hits        2404     2405       +1     
- Misses        91       92       +1     
  Partials      17       17
```


| [Impacted Files](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/utils/src/locking.js](https://codecov.io/gh/nuxt/nuxt.js/pull/5320/diff?src=pr&el=tree#diff-cGFja2FnZXMvdXRpbHMvc3JjL2xvY2tpbmcuanM=) | `100% <100%> (ø)` | :arrow_up: |
| [packages/vue-renderer/src/renderer.js](https://codecov.io/gh/nuxt/nuxt.js/pull/5320/diff?src=pr&el=tree#diff-cGFja2FnZXMvdnVlLXJlbmRlcmVyL3NyYy9yZW5kZXJlci5qcw==) | `91.58% <0%> (-0.5%)` | :arrow_down: |
| [packages/core/src/hookable.js](https://codecov.io/gh/nuxt/nuxt.js/pull/5320/diff?src=pr&el=tree#diff-cGFja2FnZXMvY29yZS9zcmMvaG9va2FibGUuanM=) | `100% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=footer). Last update [3153e89...abd7fb8](https://codecov.io/gh/nuxt/nuxt.js/pull/5320?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/utils/src/locking.js b/packages/utils/src/locking.js
index 68cc1a731..d0ee5f0f0 100644
--- a/packages/utils/src/locking.js
+++ b/packages/utils/src/locking.js
@@ -40,6 +40,7 @@ export async function lock({ id, dir, root, options }) {
     consola.fatal(`A lock with id '${id}' already exists on ${dir}`)
   }
 
+  options = getLockOptions(options)
   const release = await properlock.lock(lockPath, options)
 
   if (!release) {


Test patch:
diff --git a/packages/utils/test/locking.test.js b/packages/utils/test/locking.test.js
index 58dfcf5c4..225c64157 100644
--- a/packages/utils/test/locking.test.js
+++ b/packages/utils/test/locking.test.js
@@ -18,16 +18,16 @@ describe('util: locking', () => {
   beforeEach(() => jest.resetAllMocks())
   beforeEach(() => lockPaths.clear())
 
-  test('onCompromised lock is warn error by default', () => {
+  test('onCompromised lock warns on compromise by default', () => {
     defaultLockOptions.onCompromised()
     expect(consola.warn).toHaveBeenCalledTimes(1)
   })
 
   test('can override default options', () => {
-    const options = getLockOptions({ onCompromised: err => consola.warn(err) })
+    const options = getLockOptions({ onCompromised: err => consola.fatal(err) })
     options.onCompromised()
 
-    expect(consola.warn).toHaveBeenCalledTimes(1)
+    expect(consola.fatal).toHaveBeenCalledTimes(1)
   })
 
   test('createLockPath creates the same lockPath for identical locks', () => {
@@ -143,4 +143,17 @@ describe('util: locking', () => {
     expect(fs.removeSync).toHaveBeenCalledWith(path1)
     expect(fs.removeSync).toHaveBeenCalledWith(path2)
   })
+
+  test('lock uses setLockOptions to set defaults', async () => {
+    const spy = properlock.lock.mockImplementationOnce(() => true)
+
+    await lock(lockConfig)
+
+    expect(spy).toHaveBeenCalledWith(expect.any(String), expect.any(Object))
+    const options = spy.mock.calls[0][1]
+    expect(options.stale).toBeDefined()
+    expect(options.onCompromised).toBeDefined()
+    expect(() => options.onCompromised()).not.toThrow()
+    expect(consola.fatal).not.toHaveBeenCalled()
+  })
 })