From 2bfd5507bffce49416c25e8f300933e17839894a Mon Sep 17 00:00:00 2001 From: James Singleton Date: Thu, 10 Dec 2020 15:55:58 -0700 Subject: [PATCH 1/9] chore(workflow): add release and test workflows --- .github/workflows/release.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 36 ++++++++++++++++++++++++++++++ .travis.yml | 25 --------------------- 3 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..5eaac196 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + checkCommit: + name: Check Commit + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - id: commit + run: echo "::set-output name=message::${{ github.even.head_commit.message }}" + outputs: + commitMessage: ${{ steps.commit.outputs.message }} + release: + name: Release + needs: [checkCommit] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: '12' + - name: Install Dependencies + run: npm ci + env: + NODE_ENV: development + - name: Test Packages + run: npm run test + - name: Release Packages + env: + NODE_ENV: production + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: |- + echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> $HOME/.npmrc 2> /dev/null + npm run lerna:deploy -- "${{ need.checkCommit.outputs.commitMsg }}" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..20ec88e7 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Tests + +on: + push: + branches: + - main + pull_requests: + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '10.x', '12.x', '14.x' ] + name: Node ${{ matrix.node }} + steps: + - uses: actions/checkout@v2 + - run: | + git remote set-branches --add origin main + git fetch + - name: Setup Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: Install Dependencies + run: npm ci + env: + NODE_ENV: development + - name: Unit Tests + run: npm test + - name: Git History Test + run: npm run test:git-history + - name: Lockfile Lint Test + run: npm run test:lockfile + - name: Lint + run: npm run test:lint diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7be97f9c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: node_js -node_js: - - 10 - - 12 - - 14 -cache: - directories: - - node_modules -before_install: - # Create a main branch for commitlint - # https://github.com/conventional-changelog/commitlint/issues/6 - - git remote set-branches origin main && git fetch -before_deploy: - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> $HOME/.npmrc 2> /dev/null -jobs: - include: - # Define the release stage that publishes lerna to npm - - stage: release - deploy: - on: - branch: main - provider: script - skip_cleanup: true - script: - - npm run lerna:deploy -- "${TRAVIS_COMMIT_MESSAGE}" From a2a4ddf504451f86164ca7a17e00b2731743bc0f Mon Sep 17 00:00:00 2001 From: James Singleton Date: Thu, 10 Dec 2020 15:58:56 -0700 Subject: [PATCH 2/9] chore(workflow): fix pull_request --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 20ec88e7..83973ebe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_requests: + pull_request: jobs: tests: From 81090796c2148255328772fb574431445ea75fde Mon Sep 17 00:00:00 2001 From: James Singleton Date: Mon, 14 Dec 2020 13:32:50 -0700 Subject: [PATCH 3/9] chore(workflow): install yargs globally --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 83973ebe..f50cdf39 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install Dependencies - run: npm ci + run: npm ci && npm i -g yargs@latest env: NODE_ENV: development - name: Unit Tests From a254456cfa54cbe994c3ce50e5447e1adf061641 Mon Sep 17 00:00:00 2001 From: James Singleton Date: Mon, 14 Dec 2020 14:02:18 -0700 Subject: [PATCH 4/9] chore(workflows): update testing workflow --- .github/workflows/tests.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f50cdf39..0ba0e3ed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,15 +15,14 @@ jobs: name: Node ${{ matrix.node }} steps: - uses: actions/checkout@v2 - - run: | - git remote set-branches --add origin main - git fetch + with: + fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - name: Install Dependencies - run: npm ci && npm i -g yargs@latest + run: npm ci && npm i --no-save yargs@latest env: NODE_ENV: development - name: Unit Tests From 59bbf064f71b4a115883c088dfbfbe09161037bf Mon Sep 17 00:00:00 2001 From: James Singleton Date: Mon, 14 Dec 2020 18:54:32 -0700 Subject: [PATCH 5/9] chore(workflows): update install command --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ba0e3ed..8b07aa9e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,7 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install Dependencies - run: npm ci && npm i --no-save yargs@latest + run: npm ci && npm ls yargs && npm list -g --depth 0 env: NODE_ENV: development - name: Unit Tests From 684de69c17feda88872f30b5ea2f37b4f4a67c0a Mon Sep 17 00:00:00 2001 From: James Singleton Date: Fri, 18 Dec 2020 15:13:14 -0700 Subject: [PATCH 6/9] test(unit): move away from snapshots for one-app-runner --- .../__snapshots__/one-app-runner.spec.js.snap | 263 ------------------ .../__tests__/bin/one-app-runner.spec.js | 22 +- 2 files changed, 12 insertions(+), 273 deletions(-) diff --git a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap index c96b8909..3c72c62e 100644 --- a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap +++ b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap @@ -1,44 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`--modules option is required if --dev-endpoints option is given 1`] = ` -Array [ - Array [ - "Options: - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to - your application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to - use for Parrot mocking [string] - --modules path to local module to serve to One App [array] - --dev-endpoints path to dev endpoints file for One App to use for - its One App Dev Proxy set up [string] - --envVars Environment variables to be applied to the One App - instance - --output-file File to redirect all stdout and stderr from One App - Container to [string] - --create-docker-network Creates a new docker network - [boolean] [default: false] - --docker-network-to-join Connect One App container to a docker network - [string] - --use-host Use req.headers.host instead of localhost for - one-app-dev-cdn [boolean] [default: false] - --offline skip docker pull when the docker registry is not - available / offline [boolean] [default: false] - ----container-name Assign a container name with the --name option - [string] - --help Show help [boolean]", - ], - Array [], - Array [ - "Missing dependent arguments: - dev-endpoints -> modules", - ], -] -`; - exports[`--modules option is required if --module-map-url option is not given 1`] = ` Array [ Array [ @@ -147,227 +108,3 @@ Object { "MY_VARIABLE": "my-variable", } `; - -exports[`command errors out if --dev-endpoints is not given a value 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "Missing required arguments: root-module-name, docker-image", - ], -] -`; - -exports[`command errors out if --docker-image option is not given 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "Missing required argument: docker-image", - ], -] -`; - -exports[`command errors out if --docker-image option is not given a value 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "⚠️ --docker-image option must be given a value but was not given one. Did you mean to pass a value? ⚠️", - ], -] -`; - -exports[`command errors out if --module-map-url option is not given 1`] = ` -Array [ - Array [ - "Options: - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to - your application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to - use for Parrot mocking [string] - --modules path to local module to serve to One App - [array] [required] - --dev-endpoints path to dev endpoints file for One App to use for - its One App Dev Proxy set up [string] - --envVars Environment variables to be applied to the One App - instance - --output-file File to redirect all stdout and stderr from One App - Container to [string] - --create-docker-network Creates a new docker network - [boolean] [default: false] - --docker-network-to-join Connect One App container to a docker network - [string] - --use-host Use req.headers.host instead of localhost for - one-app-dev-cdn [boolean] [default: false] - --offline skip docker pull when the docker registry is not - available / offline [boolean] [default: false] - ----container-name Assign a container name with the --name option - [string] - --help Show help [boolean]", - ], - Array [], - Array [ - "Missing required argument: modules", - ], -] -`; - -exports[`command errors out if --module-map-url option is not given a value 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "⚠️ --module-map-url option must be given a value but was not given one. Did you mean to pass a value? ⚠️", - ], -] -`; - -exports[`command errors out if --modules option is not given any values 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "Missing required arguments: root-module-name, docker-image", - ], -] -`; - -exports[`command errors out if --root-module-name option is not given 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "Missing required argument: root-module-name", - ], -] -`; - -exports[`command errors out if --root-module-name option is not given a value 1`] = ` -Array [ - Array [ - "Options: - --help Show help [boolean] - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to your - application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to use for - Parrot mocking [string]", - ], - Array [], - Array [ - "⚠️ --root-module-name option must be given a value but was not given one. Did you mean to pass a value? ⚠️", - ], -] -`; - -exports[`command errors out if an unknown option is given 1`] = ` -Array [ - Array [ - "Options: - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to - your application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to - use for Parrot mocking [string] - --modules path to local module to serve to One App [array] - --dev-endpoints path to dev endpoints file for One App to use for - its One App Dev Proxy set up [string] - --envVars Environment variables to be applied to the One App - instance - --output-file File to redirect all stdout and stderr from One App - Container to [string] - --create-docker-network Creates a new docker network - [boolean] [default: false] - --docker-network-to-join Connect One App container to a docker network - [string] - --use-host Use req.headers.host instead of localhost for - one-app-dev-cdn [boolean] [default: false] - --offline skip docker pull when the docker registry is not - available / offline [boolean] [default: false] - ----container-name Assign a container name with the --name option - [string] - --help Show help [boolean]", - ], - Array [], - Array [ - "Unknown arguments: not-a-valid-option, notAValidOption", - ], -] -`; diff --git a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js index 80f02e6d..a62a3795 100644 --- a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js +++ b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js @@ -45,7 +45,7 @@ test('command errors out if --module-map-url option is not given a value', () => process.argv = ['', '', '--module-map-url']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --module-map-url option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); }); test('command errors out if --module-map-url option is not given', () => { @@ -54,7 +54,7 @@ test('command errors out if --module-map-url option is not given', () => { process.argv = ['', '', '--root-module-name', 'frank-lloyd-root', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: modules'); }); test('command errors out if --root-module-name option is not given a value', () => { @@ -63,7 +63,7 @@ test('command errors out if --root-module-name option is not given a value', () process.argv = ['', '', '--root-module-name']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --root-module-name option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); }); test('command errors out if --root-module-name option is not given', () => { @@ -72,7 +72,7 @@ test('command errors out if --root-module-name option is not given', () => { process.argv = ['', '', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: root-module-name'); }); test('command errors out if --docker-image option is not given a value', () => { @@ -81,7 +81,7 @@ test('command errors out if --docker-image option is not given a value', () => { process.argv = ['', '', '--docker-image']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --docker-image option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); }); test('command errors out if --docker-image option is not given', () => { @@ -90,7 +90,7 @@ test('command errors out if --docker-image option is not given', () => { process.argv = ['', '', '--module-map-url', 'https://example.com/module-map.json', '--root-module-name', 'frank-lloyd-root']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: docker-image'); }); @@ -134,7 +134,7 @@ test('command errors out if --dev-endpoints is not given a value', () => { process.argv = ['', '', '--dev-endpoints']; jest.mock('../../src/startApp', () => jest.fn(() => Promise.resolve())); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required arguments: root-module-name, docker-image'); }); test('reads modules from package.json', async () => { @@ -161,7 +161,7 @@ test('command errors out if --modules option is not given any values', () => { process.argv = ['', '', '--modules']; jest.mock('../../src/startApp', () => jest.fn(() => Promise.resolve())); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required arguments: root-module-name, docker-image'); }); test('--parrot-middleware, --module values, --output-file, and --dev-endpoints are left alone if already absolute paths', () => { @@ -246,7 +246,7 @@ test('command errors out if an unknown option is given', () => { process.argv = ['', '', '--not-a-valid-option', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Unknown arguments: not-a-valid-option, notAValidOption'); }); test('--modules option is required if --module-map-url option is not given', () => { @@ -273,7 +273,9 @@ test('--modules option is required if --dev-endpoints option is given', () => { process.argv = ['', '', '--dev-endpoints', '../path/to/dev.endpoints.js', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual( + 'Missing dependent arguments:\n dev-endpoints -> modules' + ); }); test('an `envVars` key is supported within the config entry', () => { From 0a40174ad8020dc76fceef2b040c2be3e7be6feb Mon Sep 17 00:00:00 2001 From: James Singleton Date: Fri, 18 Dec 2020 15:41:27 -0700 Subject: [PATCH 7/9] test(unit): remove one more snapshot --- .../__snapshots__/one-app-runner.spec.js.snap | 39 ------------------- .../__tests__/bin/one-app-runner.spec.js | 4 +- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap index 3c72c62e..caa1c191 100644 --- a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap +++ b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap @@ -39,45 +39,6 @@ Array [ ] `; -exports[`--modules option is required if --parrot-middleware option is given 1`] = ` -Array [ - Array [ - "Options: - --version Show version number [boolean] - --module-map-url module map for One App to use and fetch modules from - [string] - --root-module-name name of the module to serve as an entry point to - your application [string] [required] - --docker-image docker image to use for One App [string] [required] - --parrot-middleware path to parrot dev middleware file for One App to - use for Parrot mocking [string] - --modules path to local module to serve to One App [array] - --dev-endpoints path to dev endpoints file for One App to use for - its One App Dev Proxy set up [string] - --envVars Environment variables to be applied to the One App - instance - --output-file File to redirect all stdout and stderr from One App - Container to [string] - --create-docker-network Creates a new docker network - [boolean] [default: false] - --docker-network-to-join Connect One App container to a docker network - [string] - --use-host Use req.headers.host instead of localhost for - one-app-dev-cdn [boolean] [default: false] - --offline skip docker pull when the docker registry is not - available / offline [boolean] [default: false] - ----container-name Assign a container name with the --name option - [string] - --help Show help [boolean]", - ], - Array [], - Array [ - "Missing dependent arguments: - parrot-middleware -> modules", - ], -] -`; - exports[`all options are used if specified 1`] = ` Array [ Array [ diff --git a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js index a62a3795..c82f9543 100644 --- a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js +++ b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js @@ -264,7 +264,9 @@ test('--modules option is required if --parrot-middleware option is given', () = process.argv = ['', '', '--parrot-middleware', '../path/to/dev.middleware.js', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); + expect(consoleErrorSpy.mock.calls[2][0]).toEqual( + 'Missing dependent arguments:\n parrot-middleware -> modules' + ); }); test('--modules option is required if --dev-endpoints option is given', () => { From b93ca69a21c8eb698b661a485eb3de995d3a2138 Mon Sep 17 00:00:00 2001 From: James Singleton Date: Fri, 18 Dec 2020 16:24:16 -0700 Subject: [PATCH 8/9] chore(runner): demand dev-endpoints & parrot-middleware if modules --- .../__snapshots__/one-app-runner.spec.js.snap | 233 +++++++++++++++++- .../__tests__/bin/one-app-runner.spec.js | 26 +- packages/one-app-runner/bin/one-app-runner.js | 8 +- 3 files changed, 243 insertions(+), 24 deletions(-) diff --git a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap index caa1c191..79e060f1 100644 --- a/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap +++ b/packages/one-app-runner/__tests__/bin/__snapshots__/one-app-runner.spec.js.snap @@ -1,6 +1,51 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`--modules option is required if --dev-endpoints option is given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required] + --parrot-middleware path to parrot dev middleware file for One App to use for + Parrot mocking [string] [required]", + ], + Array [], + Array [ + "Missing required argument: parrot-middleware +https://example.com/module-map.json", + ], +] +`; + exports[`--modules option is required if --module-map-url option is not given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required] + --parrot-middleware path to parrot dev middleware file for One App to use for + Parrot mocking [string] + --modules path to local module to serve to One App + [array] [required]", + ], + Array [], + Array [ + "Missing required argument: modules", + ], +] +`; + +exports[`--modules option is required if --parrot-middleware option is given 1`] = ` Array [ Array [ "Options: @@ -11,11 +56,10 @@ Array [ your application [string] [required] --docker-image docker image to use for One App [string] [required] --parrot-middleware path to parrot dev middleware file for One App to - use for Parrot mocking [string] - --modules path to local module to serve to One App - [array] [required] + use for Parrot mocking [string] [required] + --modules path to local module to serve to One App [array] --dev-endpoints path to dev endpoints file for One App to use for - its One App Dev Proxy set up [string] + its One App Dev Proxy set up [string] [required] --envVars Environment variables to be applied to the One App instance --output-file File to redirect all stdout and stderr from One App @@ -34,7 +78,8 @@ Array [ ], Array [], Array [ - "Missing required argument: modules", + "Missing required argument: dev-endpoints +https://example.com/module-map.json", ], ] `; @@ -69,3 +114,181 @@ Object { "MY_VARIABLE": "my-variable", } `; + +exports[`command errors out if --dev-endpoints is not given a value 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "Missing required arguments: root-module-name, docker-image", + ], +] +`; + +exports[`command errors out if --docker-image option is not given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "Missing required argument: docker-image", + ], +] +`; + +exports[`command errors out if --docker-image option is not given a value 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "⚠️ --docker-image option must be given a value but was not given one. Did you mean to pass a value? ⚠️", + ], +] +`; + +exports[`command errors out if --module-map-url option is not given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required] + --parrot-middleware path to parrot dev middleware file for One App to use for + Parrot mocking [string] + --modules path to local module to serve to One App + [array] [required]", + ], + Array [], + Array [ + "Missing required argument: modules", + ], +] +`; + +exports[`command errors out if --module-map-url option is not given a value 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "⚠️ --module-map-url option must be given a value but was not given one. Did you mean to pass a value? ⚠️", + ], +] +`; + +exports[`command errors out if --modules option is not given any values 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "Missing required arguments: root-module-name, docker-image", + ], +] +`; + +exports[`command errors out if --root-module-name option is not given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "Missing required argument: root-module-name", + ], +] +`; + +exports[`command errors out if --root-module-name option is not given a value 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required]", + ], + Array [], + Array [ + "⚠️ --root-module-name option must be given a value but was not given one. Did you mean to pass a value? ⚠️", + ], +] +`; + +exports[`command errors out if an unknown option is given 1`] = ` +Array [ + Array [ + "Options: + --help Show help [boolean] + --version Show version number [boolean] + --module-map-url module map for One App to use and fetch modules from + [string] + --root-module-name name of the module to serve as an entry point to your + application [string] [required] + --docker-image docker image to use for One App [string] [required] + --parrot-middleware path to parrot dev middleware file for One App to use for + Parrot mocking [string] [required]", + ], + Array [], + Array [ + "Missing required argument: parrot-middleware +https://example.com/module-map.json", + ], +] +`; diff --git a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js index c82f9543..80f02e6d 100644 --- a/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js +++ b/packages/one-app-runner/__tests__/bin/one-app-runner.spec.js @@ -45,7 +45,7 @@ test('command errors out if --module-map-url option is not given a value', () => process.argv = ['', '', '--module-map-url']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --module-map-url option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('command errors out if --module-map-url option is not given', () => { @@ -54,7 +54,7 @@ test('command errors out if --module-map-url option is not given', () => { process.argv = ['', '', '--root-module-name', 'frank-lloyd-root', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: modules'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('command errors out if --root-module-name option is not given a value', () => { @@ -63,7 +63,7 @@ test('command errors out if --root-module-name option is not given a value', () process.argv = ['', '', '--root-module-name']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --root-module-name option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('command errors out if --root-module-name option is not given', () => { @@ -72,7 +72,7 @@ test('command errors out if --root-module-name option is not given', () => { process.argv = ['', '', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: root-module-name'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('command errors out if --docker-image option is not given a value', () => { @@ -81,7 +81,7 @@ test('command errors out if --docker-image option is not given a value', () => { process.argv = ['', '', '--docker-image']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('⚠️ --docker-image option must be given a value but was not given one. Did you mean to pass a value? ⚠️'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('command errors out if --docker-image option is not given', () => { @@ -90,7 +90,7 @@ test('command errors out if --docker-image option is not given', () => { process.argv = ['', '', '--module-map-url', 'https://example.com/module-map.json', '--root-module-name', 'frank-lloyd-root']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required argument: docker-image'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); @@ -134,7 +134,7 @@ test('command errors out if --dev-endpoints is not given a value', () => { process.argv = ['', '', '--dev-endpoints']; jest.mock('../../src/startApp', () => jest.fn(() => Promise.resolve())); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required arguments: root-module-name, docker-image'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('reads modules from package.json', async () => { @@ -161,7 +161,7 @@ test('command errors out if --modules option is not given any values', () => { process.argv = ['', '', '--modules']; jest.mock('../../src/startApp', () => jest.fn(() => Promise.resolve())); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Missing required arguments: root-module-name, docker-image'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('--parrot-middleware, --module values, --output-file, and --dev-endpoints are left alone if already absolute paths', () => { @@ -246,7 +246,7 @@ test('command errors out if an unknown option is given', () => { process.argv = ['', '', '--not-a-valid-option', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual('Unknown arguments: not-a-valid-option, notAValidOption'); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('--modules option is required if --module-map-url option is not given', () => { @@ -264,9 +264,7 @@ test('--modules option is required if --parrot-middleware option is given', () = process.argv = ['', '', '--parrot-middleware', '../path/to/dev.middleware.js', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual( - 'Missing dependent arguments:\n parrot-middleware -> modules' - ); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('--modules option is required if --dev-endpoints option is given', () => { @@ -275,9 +273,7 @@ test('--modules option is required if --dev-endpoints option is given', () => { process.argv = ['', '', '--dev-endpoints', '../path/to/dev.endpoints.js', '--root-module-name', 'frank-lloyd-root', '--module-map-url', 'https://example.com/module-map.json', '--docker-image', 'one-app:5.0.0']; jest.mock('../../src/startApp', () => jest.fn()); require('../../bin/one-app-runner'); - expect(consoleErrorSpy.mock.calls[2][0]).toEqual( - 'Missing dependent arguments:\n dev-endpoints -> modules' - ); + expect(consoleErrorSpy.mock.calls).toMatchSnapshot(); }); test('an `envVars` key is supported within the config entry', () => { diff --git a/packages/one-app-runner/bin/one-app-runner.js b/packages/one-app-runner/bin/one-app-runner.js index 23f78778..77c6f08e 100644 --- a/packages/one-app-runner/bin/one-app-runner.js +++ b/packages/one-app-runner/bin/one-app-runner.js @@ -65,6 +65,8 @@ const createYargsConfig = () => { }, }) .option('parrot-middleware', { + // eslint-disable-next-line global-require + demandOption: !require('yargs').argv.modules && require('yargs').argv.moduleMapUrl, describe: 'path to parrot dev middleware file for One App to use for Parrot mocking', type: 'string', coerce: (value) => { @@ -88,6 +90,8 @@ const createYargsConfig = () => { }, }) .option('dev-endpoints', { + // eslint-disable-next-line global-require + demandOption: !require('yargs').argv.modules && require('yargs').argv.moduleMapUrl, describe: 'path to dev endpoints file for One App to use for its One App Dev Proxy set up', type: 'string', coerce: (value) => { @@ -138,10 +142,6 @@ const createYargsConfig = () => { describe: 'Assign a container name with the --name option', type: 'string', }) - .implies({ - 'parrot-middleware': 'modules', - 'dev-endpoints': 'modules', - }) .strict() .help(); From cfc3784d93005ea79ad03b78399dd197c6854e47 Mon Sep 17 00:00:00 2001 From: James Singleton Date: Mon, 4 Jan 2021 13:39:05 -0700 Subject: [PATCH 9/9] chore(workflow): remove ls and depth --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b07aa9e..afcb6d27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,7 @@ jobs: with: node-version: ${{ matrix.node }} - name: Install Dependencies - run: npm ci && npm ls yargs && npm list -g --depth 0 + run: npm ci env: NODE_ENV: development - name: Unit Tests