Skip to content

Commit

Permalink
fix: fixes after upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dword-design committed Jul 4, 2020
1 parent 50a243b commit 91ff0a7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
32 changes: 23 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
name: build

on:
push:
branches:
- '**'

- "**"
jobs:
cancel-existing:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@v0.2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
runs-on: ${{ matrix.os }}
needs: cancel-existing
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node: [10, 12]
os:
- macos-latest
- windows-latest
- ubuntu-latest
node:
- 10
- 12
exclude:
- os: macos-latest
node: 10
- os: windows-latest
node: 10
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: git config --global user.email "actions@github.com"
- run: git config --global user.name "GitHub Actions"
- run: yarn --frozen-lockfile
- run: yarn test
- name: Coveralls
if: matrix.os == 'ubuntu-latest' && matrix.node == 12
run: yarn dw-ci coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
COVERALLS_GIT_COMMIT: ${{ github.sha }}
COVERALLS_GIT_BRANCH: ${{ github.ref }}

release:
needs: test
if: github.ref == 'refs/heads/master'
Expand All @@ -41,7 +53,10 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: 12
- run: git config --global user.email "actions@github.com"
- run: git config --global user.name "GitHub Actions"
- run: yarn --frozen-lockfile
- run: yarn lint
- name: Push changed files
run: yarn dw-ci push-changed-files
env:
Expand All @@ -51,5 +66,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn semantic-release
run: yarn semantic-release
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.DS_Store
/.babelrc.json
/.cz.json
/.editorconfig
/.env
/.env.json
/.eslintrc.json
/.nyc_output
/.releaserc.json
/.test.env.json
/.vscode
/coverage
/dist
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<!-- BADGES/ -->
[![NPM version](https://img.shields.io/npm/v/mock-argv.svg)](https://npmjs.org/package/mock-argv)
![Linux macOS Windows compatible](https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue)

[![Build status](https://img.shields.io/github/workflow/status/dword-design/mock-argv/build)](https://github.com/dword-design/mock-argv/actions)
[![Coverage status](https://img.shields.io/coveralls/dword-design/mock-argv)](https://coveralls.io/github/dword-design/mock-argv)
[![Dependency status](https://img.shields.io/david/dword-design/mock-argv)](https://david-dm.org/dword-design/mock-argv)
Expand All @@ -20,7 +19,7 @@ Temporarily overrides the command line arguments. This is useful for testing.
<!-- /DESCRIPTION -->

<!-- INSTALL/ -->
# Install
## Install

```bash
# NPM
Expand Down Expand Up @@ -54,7 +53,7 @@ test('works', async () => {
```

<!-- LICENSE/ -->
# License
## License

Unless stated otherwise all works are:

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
],
"scripts": {
"commit": "base commit",
"depgraph": "base depgraph",
"dev": "base dev",
"lint": "base lint",
"prepare": "base prepare",
"prepublishOnly": "base prepublishOnly",
"release": "base release",
"test": "base test"
},
"devDependencies": {
"@dword-design/base": "^6.0.0"
},
"publishConfig": {
"access": "public"
}
}
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export default (args, callback) => {
export default async (args, func) => {
if (typeof args === 'function') {
callback = args
func = args
args = []
}

const oldArgv = process.argv
process.argv = [...oldArgv.slice(0, 2), ...args]

return Promise.resolve().then(callback).finally(() => process.argv = oldArgv)
try {
await func()
} finally {
process.argv = oldArgv
}
}
35 changes: 27 additions & 8 deletions src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import mockArgv from '.'

export default {
async: () => mockArgv(
['foo', 'bar'],
() => new Promise(resolve => setTimeout(() => { expect(process.argv).toEqual([...process.argv.slice(0, 2), 'foo', 'bar']); return resolve() }, 100)),
),
async: () =>
mockArgv(
['foo', 'bar'],
() =>
new Promise(resolve =>
setTimeout(() => {
expect(process.argv).toEqual([
...process.argv.slice(0, 2),
'foo',
'bar',
])
return resolve()
}, 100)
)
),
'empty args': done => {
mockArgv([], () => { expect(process.argv).toEqual(process.argv.slice(0, 2)); done() })
mockArgv([], () => {
expect(process.argv).toEqual(process.argv.slice(0, 2))
done()
})
},
'has args': done => {
mockArgv(['foo', 'bar'], () => { expect(process.argv).toEqual([...process.argv.slice(0, 2), 'foo', 'bar']); done() })
mockArgv(['foo', 'bar'], () => {
expect(process.argv).toEqual([...process.argv.slice(0, 2), 'foo', 'bar'])
done()
})
},
'missing args': done => {
mockArgv(() => { expect(process.argv).toEqual(process.argv.slice(0, 2)); done() })
mockArgv(() => {
expect(process.argv).toEqual(process.argv.slice(0, 2))
done()
})
},
}

0 comments on commit 91ff0a7

Please sign in to comment.