From 91ff0a7fc6a52cc7798aa3a63f34864492d47904 Mon Sep 17 00:00:00 2001 From: dword Date: Sat, 4 Jul 2020 14:40:07 +0000 Subject: [PATCH] fix: fixes after upgrades --- .github/workflows/build.yml | 32 +++++++++++++++++++++++--------- .gitignore | 4 +++- README.md | 5 ++--- package.json | 7 +++++-- src/index.js | 12 +++++++----- src/index.spec.js | 35 +++++++++++++++++++++++++++-------- 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 90f300f..0369c36 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' @@ -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: @@ -51,5 +66,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - yarn semantic-release \ No newline at end of file + run: yarn semantic-release diff --git a/.gitignore b/.gitignore index 87bc275..c1df170 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 0038020..8631ea8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![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) @@ -20,7 +19,7 @@ Temporarily overrides the command line arguments. This is useful for testing. -# Install +## Install ```bash # NPM @@ -54,7 +53,7 @@ test('works', async () => { ``` -# License +## License Unless stated otherwise all works are: diff --git a/package.json b/package.json index 174beb3..396578a 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/index.js b/src/index.js index c4d2d18..ae0df03 100644 --- a/src/index.js +++ b/src/index.js @@ -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 + } } diff --git a/src/index.spec.js b/src/index.spec.js index e0e0428..8c47c39 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -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() + }) }, } -