Skip to content

Commit

Permalink
chore(monorepo): add make test targets for frontend projects (#13711)
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin authored Oct 24, 2023
1 parent 91b7664 commit 32dd347
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/app-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
make setup-js
- name: 'test frontend packages'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="app/src/**/*.(js|ts|tsx)" app/src components/src shared-data/js
make -C app test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down Expand Up @@ -141,8 +141,7 @@ jobs:
yarn config set cache-folder ${{ github.workspace }}/.yarn-cache
make setup-js
- name: 'test native(er) packages'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="(app-shell|app-shell-odd| discovery-client)/src/**/*.(js|ts|tsx)" app-shell/src app-shell-odd/src discovery-client/src
run: make test-js-internal tests="app-shell/src app-shell-odd/src discovery-client/src" cov_opts="--coverage=true --ci=true --collectCoverageFrom='(app-shell|app-shell-odd| discovery-client)/src/**/*.(js|ts|tsx)'"
- name: 'Upload coverage report'
uses: 'codecov/codecov-action@v3'
with:
Expand Down Expand Up @@ -315,7 +314,8 @@ jobs:
deploy-release-app:
name: 'Deploy built app artifacts to S3'
runs-on: 'ubuntu-22.04'
needs: ['js-unit-test', 'backend-unit-test', 'build-app', 'determine-build-type']
needs:
['js-unit-test', 'backend-unit-test', 'build-app', 'determine-build-type']
if: contains(fromJSON(needs.determine-build-type.outputs.variants), 'release') || contains(fromJSON(needs.determine-build-type.outputs.variants), 'internal-release')
steps:
- name: 'download run app builds'
Expand Down Expand Up @@ -401,15 +401,15 @@ jobs:
uses: slackapi/[email protected]
if: contains(fromJSON(needs.determine-build-type.outputs.variants), 'internal-release')
with:
payload: "{\"branch_or_tag\":\"${{ github.ref_name }}\",\"build_type\":\"${{ needs.determine-build-type.outputs.type }}\", \"gh_linkback\":\"https://github.com/Opentrons/opentrons/tree/${{ github.ref_name }}\", \"windows_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.windows-internal-release}}\", \"mac_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.mac-internal-release}}\", \"linux_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.linux-internal-release}}\"}"
payload: '{"branch_or_tag":"${{ github.ref_name }}","build_type":"${{ needs.determine-build-type.outputs.type }}", "gh_linkback":"https://github.com/Opentrons/opentrons/tree/${{ github.ref_name }}", "windows_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.windows-internal-release}}", "mac_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.mac-internal-release}}", "linux_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.linux-internal-release}}"}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.OT_APP_OT3_SLACK_NOTIFICATION_WEBHOOK_URL }}
_ACCESS_URL: https://${{env._APP_DEPLOY_BUCKET_OT3}}/${{env._APP_DEPLOY_FOLDER_OT3}}
- name: 'slack notify release'
uses: slackapi/[email protected]
if: contains(fromJSON(needs.determine-build-type.outputs.variants), 'release')
with:
payload: "{\"branch_or_tag\":\"${{ github.ref_name }}\",\"build_type\":\"${{ needs.determine-build-type.outputs.type }}\", \"gh_linkback\":\"https://github.com/Opentrons/opentrons/tree/${{ github.ref_name }}\", \"windows_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.windows-release}}\", \"mac_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.mac-release}}\", \"linux_build\":\"${{ env._ACCESS_URL }}/${{steps.names.outputs.linux-release}}\"}"
payload: '{"branch_or_tag":"${{ github.ref_name }}","build_type":"${{ needs.determine-build-type.outputs.type }}", "gh_linkback":"https://github.com/Opentrons/opentrons/tree/${{ github.ref_name }}", "windows_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.windows-release}}", "mac_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.mac-release}}", "linux_build":"${{ env._ACCESS_URL }}/${{steps.names.outputs.linux-release}}"}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.OT_APP_ROBOTSTACK_SLACK_NOTIFICATION_WEBHOOK_URL }}
_ACCESS_URL: https://${{env._APP_DEPLOY_BUCKET_ROBOTSTACK}}/${{env._APP_DEPLOY_FOLDER_ROBOTSTACK}}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/components-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run components unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="components/src/**/*.(js|ts|tsx)" components/src
run: make -C components test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ll-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run labware library unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="labware-library/src/**/*.(js|ts|tsx)" labware-library/src
run: make -C labware-library test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pd-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run PD unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="protocol-designer/src/**/*.(js|ts|tsx)" protocol-designer/src
run: make -C protocol-designer test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/react-api-client-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run react-api-client unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="react-api-client/src/**/*.(js|ts|tsx)" react-api-client/src
run: make -C react-api-client test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/shared-data-test-lint-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run shared-data JS unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="shared-data/js/**/*.(js|ts|tsx)" shared-data/js
run: make -C shared-data test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/step-generation-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ jobs:
yarn config set cache-folder ./.yarn-cache
make setup-js
- name: 'run step generation unit tests'
run: |
yarn jest --coverage=true --ci=true --collectCoverageFrom="step-generation/src/**/*.(js|ts|tsx)" step-generation/src
run: make -C step-generation test-cov
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
with:
Expand Down
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
include ./scripts/python.mk

API_DIR := api
API_CLIENT_DIR := api-client
APP_SHELL_DIR := app-shell
APP_SHELL_ODD_DIR := app-shell-odd
COMPONENTS_DIR := components
Expand All @@ -15,14 +16,17 @@ NOTIFY_SERVER_DIR := notify-server
PROTOCOL_DESIGNER_DIR := protocol-designer
SHARED_DATA_DIR := shared-data
UPDATE_SERVER_DIR := update-server
REACT_API_CLIENT_DIR := react-api-client
ROBOT_SERVER_DIR := robot-server
SERVER_UTILS_DIR := server-utils
STEP_GENERATION_DIR := step-generation
SYSTEM_SERVER_DIR := system-server
HARDWARE_DIR := hardware
USB_BRIDGE_DIR := usb-bridge
NODE_USB_BRIDGE_CLIENT_DIR := usb-bridge/node-client

PYTHON_DIRS := $(API_DIR) $(UPDATE_SERVER_DIR) $(NOTIFY_SERVER_DIR) $(ROBOT_SERVER_DIR) $(SERVER_UTILS_DIR) $(SHARED_DATA_DIR)/python $(G_CODE_TESTING_DIR) $(HARDWARE_DIR) $(USB_BRIDGE_DIR)
JS_PACKAGES := $(API_CLIENT_DIR) $(APP_SHELL_DIR) $(APP_SHELL_ODD_DIR) $(COMPONENTS_DIR) $(DISCOVERY_CLIENT_DIR) $(LABWARE_LIBRARY_DIR) $(PROTOCOL_DESIGNER_DIR) $(SHARED_DATA_DIR) $(REACT_API_CLIENT_DIR) $(STEP_GENERATION_DIR) $(NODE_USB_BRIDGE_CLIENT_DIR)

# This may be set as an environment variable (and is by CI tasks that upload
# to test pypi) to add a .dev extension to the python package versions. If
Expand Down Expand Up @@ -195,12 +199,8 @@ test-py: test-py-windows
$(MAKE) -C $(USB_BRIDGE_DIR) test

.PHONY: test-js
test-js:
yarn jest \
--coverage=$(cover) \
--watch=$(watch) \
--updateSnapshot=$(updateSnapshot) \
--ci=$(if $(CI),true,false)
test-js: tests?=$(JS_PACKAGES)
test-js: test-js-internal

# lints and typechecks
.PHONY: lint
Expand Down Expand Up @@ -261,3 +261,11 @@ circular-dependencies-js:
yarn madge $(and $(CI),--no-spinner --no-color) --circular labware-library/src/index.tsx
yarn madge $(and $(CI),--no-spinner --no-color) --circular app/src/index.tsx
yarn madge $(and $(CI),--no-spinner --no-color) --circular components/src/index.ts

.PHONY: test-js-internal
test-js-internal:
yarn jest $(tests) $(test_opts) $(cov_opts)

.PHONY: test-js-%
test-js-%:
$(MAKE) test-js-internal tests="$(if $(tests),$(foreach test,$(tests),$*/$(test)),$*)" test_opts="$(test_opts)" cov_opts="$(cov_opts)"
4 changes: 4 additions & 0 deletions api-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ clean:
.PHONY: build
build:
rollup --config rollup.config.js

.PHONY: test
test:
$(MAKE) -C .. test-js-api-client
4 changes: 4 additions & 0 deletions app-shell-odd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ dev: export NODE_ENV := development
dev:
webpack
$(electron)

.PHONY: test
test:
$(MAKE) -C .. test-js-app-shell-odd
15 changes: 15 additions & 0 deletions app-shell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PORT ?= 8090
# TODO(mc, 2018-08-07): figure out a better way to do this
ui_dir := ../app

# Path of source package
SRC_PATH = app-shell

# cross-platform noop command
noop := cd .

Expand All @@ -23,6 +26,14 @@ dist_files = $(if $(filter $(1),robot-stack),"dist/**/Opentrons-*","dist/**/Open
update_files := "dist/@(alpha|beta|latest)*.@(yml|json)"
publish_dir := dist/publish

# These variables can be overriden when make is invoked to customize the
# behavior of jest. For instance,
# make test tests=src/__tests__/http.test.ts would run only the
# specified test
tests ?= $(SRC_PATH)/src
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='app-shell/src/**/*.(js|ts|tsx)'
test_opts ?=

# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)

Expand Down Expand Up @@ -173,3 +184,7 @@ dev: export OPENTRONS_PROJECT := $(OPENTRONS_PROJECT)
dev: clean-dev-autoupdate ./dev-app-update.yml
webpack
$(electron)

.PHONY: test
test:
$(MAKE) -C .. test-js-app-shell
19 changes: 19 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ PATH := $(shell cd .. && yarn bin):$(PATH)
# dev server port
PORT ?= 8090

# Path of source package
SRC_PATH = app

OPENTRONS_PROJECT ?= robot-stack

# dependency directories for dev
shell_dir := ../app-shell
shell_odd_dir := ../app-shell-odd
discovery_client_dir := ../discovery-client

# These variables can be overriden when make is invoked to customize the
# behavior of jest. For instance,
# make test tests=src/pages/Labware/__tests__/hooks.test.tsx would run only the
# specified test
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='app/src/**/*.(js|ts|tsx)'
test_opts ?=

# standard targets
#####################################################################

Expand Down Expand Up @@ -77,3 +88,11 @@ dev-shell-odd: export OT_APP_UI__HEIGHT := 600
dev-shell-odd:
wait-on http-get://localhost:$(PORT)
$(MAKE) -C $(shell_odd_dir) dev OPENTRONS_PROJECT=$(OPENTRONS_PROJECT)

.PHONY: test
test:
make -C .. test-js-app tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-app tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"
14 changes: 14 additions & 0 deletions components/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# dev server port
port ?= 6060

# These variables can be overriden when make is invoked to customize the
# behavior of jest
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='components/src/**/*.(js|ts|tsx)'
test_opts ?=

# standard targets
#####################################################################

Expand All @@ -26,3 +32,11 @@ dist:
.PHONY: dev
dev:
yarn --cwd .. start-storybook --port $(port)

.PHONY: test
test:
$(MAKE) -C .. test-js-components tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-components tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"
4 changes: 4 additions & 0 deletions discovery-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ lib: $(main_out) $(cli_out)

$(main_out) $(cli_out):
yarn webpack

.PHONY: test
test:
$(MAKE) -C .. test-js-discovery-client
4 changes: 4 additions & 0 deletions labware-designer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ dist:
dev: export NODE_ENV := development
dev:
webpack-dev-server --hot

.PHONY: test
test:
$(MAKE) -C .. test-js-labware-designer
20 changes: 20 additions & 0 deletions labware-library/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ SHELL := bash
# add node_modules/.bin to PATH
PATH := $(shell cd .. && yarn bin):$(PATH)

# These variables can be overriden when make is invoked to customize the
# behavior of jest
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='labware-library/src/**/*.(js|ts|tsx)'
test_opts ?=

# --coverage=true --ci=true --collectCoverageFrom="labware-library/src/**/*.(js|ts|tsx)" labware-library/src

.PHONY: all
all: clean dist

Expand Down Expand Up @@ -37,3 +45,15 @@ test-e2e:
concurrently --no-color --kill-others --success first --names "labware-library-server,labware-library-tests" \
"$(MAKE) dev CYPRESS=1 GTM_ID=''" \
"wait-on http://localhost:8080/ && cypress run --browser chrome --headless --record false"
# unit tests
.PHONY: test
test:
$(MAKE) -C .. test-js-labware-library

.PHONY: test
test:
$(MAKE) -C .. test-js-labware-library tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-labware-library tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"
14 changes: 14 additions & 0 deletions protocol-designer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ PATH := $(shell cd .. && yarn bin):$(PATH)

benchmark_output := $(shell node -e 'console.log(new Date());')

# These variables can be overriden when make is invoked to customize the
# behavior of jest
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='protocol-designer/src/**/*.(js|ts|tsx)'
test_opts ?=

# standard targets
#####################################################################

Expand Down Expand Up @@ -57,3 +63,11 @@ test-e2e:
concurrently --no-color --kill-others --success first --names "protocol-designer-server,protocol-designer-tests" \
"$(MAKE) dev CYPRESS=1" \
"wait-on http://localhost:8080/ && cypress run --browser chrome --headless --record false"

.PHONY: test
test:
$(MAKE) -C .. test-js-protocol-designer tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-protocol-designer tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"
14 changes: 14 additions & 0 deletions react-api-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# TODO(mc, 2021-02-12): this may be unnecessary by using `yarn run` instead
SHELL := bash

# These variables can be overriden when make is invoked to customize the
# behavior of jest
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='react-api-client/src/**/*.(js|ts|tsx)'
test_opts ?=

# standard targets
#####################################################################

Expand All @@ -17,3 +23,11 @@ clean:
.PHONY: build
build:
rollup --config rollup.config.js

.PHONY: test
test:
$(MAKE) -C .. test-js-react-api-client tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-react-api-client tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"
15 changes: 15 additions & 0 deletions shared-data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ SHELL := bash
# TODO(mc, 2018-10-25): use dist to match other projects
BUILD_DIR := build

# These variables can be overriden when make is invoked to customize the
# behavior of jest
tests ?=
cov_opts ?= --coverage=true --ci=true --collectCoverageFrom='shared-data/js/**/*.(js|ts|tsx)'
test_opts ?=

# Top level targets

.PHONY: all
Expand Down Expand Up @@ -83,3 +89,12 @@ deploy-py:
.PHONY: test-py
test-py:
$(MAKE) -C python test

.PHONY: test
test:
$(MAKE) -C .. test-js-shared-data tests="$(tests)" test_opts="$(test_opts)"

.PHONY: test-cov
test-cov:
make -C .. test-js-shared-data tests=$(tests) test_opts="$(test_opts)" cov_opts="$(cov_opts)"

Loading

0 comments on commit 32dd347

Please sign in to comment.