From 6c87b540b49c8d56266c8925c4fd32ed760b23bf Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Sat, 17 Sep 2022 20:42:32 -0700 Subject: [PATCH] refactor: move unit tests to separate job --- .github/workflows/build.yaml | 62 ++++++++++++++++++++++++++++-------- ci/dev/test-unit.sh | 31 ------------------ package.json | 2 +- 3 files changed, 50 insertions(+), 45 deletions(-) delete mode 100755 ci/dev/test-unit.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6fb661496..65e47f336 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -182,6 +182,55 @@ jobs: if: failure() uses: andymckay/cancel-action@0.2 + test-unit: + name: Run unit tests + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v23.2 + with: + files: | + src/** + + - name: Install Node.js v16 + if: steps.changed-files.outputs.any_changed == 'true' + uses: actions/setup-node@v3 + with: + node-version: "16" + + - name: Fetch dependencies from cache + if: steps.changed-files.outputs.any_changed == 'true' + id: cache-yarn + uses: actions/cache@v3 + with: + path: "node_modules" + key: yarn-build-${{ hashFiles('yarn.lock') }} + restore-keys: | + yarn-build- + + - name: Install dependencies + if: steps.changed-files.outputs.any_changed == 'true' && steps.cache-yarn.outputs.cache-hit != 'true' + run: SKIP_SUBMODULE_DEPS=1 yarn --frozen-lockfile + + - name: Run unit tests + if: steps.changed-files.outputs.any_changed == 'true' + run: yarn test:unit + + - name: Upload coverage report to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + if: success() + + - name: Fail workflow + if: failure() + uses: andymckay/cancel-action@0.2 + typecheck: name: Check TypeScript types runs-on: ubuntu-latest @@ -292,19 +341,6 @@ jobs: if: steps.cache-vscode.outputs.cache-hit != 'true' run: yarn build:vscode - # Our code imports code from VS Code's `out` directory meaning VS Code - # must be built before running these tests. - # TODO: Move to its own step? - - name: Run code-server unit tests - run: yarn test:unit - if: success() - - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - if: success() - # The release package does not contain any native modules # and is neutral to architecture/os/libc version. - name: Create release package diff --git a/ci/dev/test-unit.sh b/ci/dev/test-unit.sh deleted file mode 100755 index e832c1031..000000000 --- a/ci/dev/test-unit.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -main() { - cd "$(dirname "$0")/../.." - - source ./ci/lib.sh - - # Our code imports from `out` in order to work during development but if you - # have only built for production you will have not have this directory. In - # that case symlink `out` to a production build directory. - if [[ ! -e lib/vscode/out ]]; then - pushd lib - local out=(vscode-reh-web-*) - if [[ -d "${out[0]}" ]]; then - ln -s "../${out[0]}/out" ./vscode/out - else - echo "Could not find lib/vscode/out or lib/vscode-reh-web-*" - echo "Code must be built before running unit tests" - # exit 1 - fi - popd - fi - - # We must keep jest in a sub-directory. See ../../test/package.json for more - # information. We must also run it from the root otherwise coverage will not - # include our source files. - CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --testRegex "./test/unit/.*ts" --testPathIgnorePatterns "./test/unit/node/test-plugin" -} - -main "$@" diff --git a/package.json b/package.json index 2833c02df..9a5d61968 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "release:prep": "./ci/build/release-prep.sh", "test:e2e": "VSCODE_IPC_HOOK_CLI= ./ci/dev/test-e2e.sh", "test:e2e:proxy": "USE_PROXY=1 ./ci/dev/test-e2e.sh", - "test:unit": "./ci/dev/test-unit.sh --forceExit --detectOpenHandles", + "test:unit": "CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest --testRegex './test/unit/.*ts' --forceExit --detectOpenHandles", "test:integration": "./ci/dev/test-integration.sh", "test:scripts": "./ci/dev/test-scripts.sh", "package": "./ci/build/build-packages.sh",