chore: quality-tightening (oxfmt + oxlint + tsc + vitest + husky + actionlint) (#833)

* chore: quality-tightening (oxfmt + oxlint + tsc + vitest + husky + actionlint)

Standard rollout for unity-builder. Most of the work was porting 24
test files from jest 27 to vitest 4.

- prettier -> oxfmt
- eslint (with @typescript-eslint, github, jest, prettier, unicorn) ->
  oxlint with eslint-plugin-unicorn
- jest 27 + jest-circus + ts-jest + @types/jest + @jest/globals ->
  vitest 4 + vite 7 + @vitest/coverage-istanbul (jest config files
  removed)
- new: tsgo --noEmit (alongside tsc fallback)
- lefthook (and lefthook.yml) -> husky 9 with the standard
  scripts/ensure-husky.mjs self-heal pattern + lint-staged
- new: gitleaks, actionlint, shellcheck as mise-managed binaries
- TypeScript bumped target ES2020 -> ES2022 + lib ES2022 + DOM (for
  Error.cause and modern globals)

Test migration (24 files):
- Bulk-converted jest.* -> vi.*; jest.Mocked -> Mocked from vitest;
  jest.MockedFunction -> MockedFunction.
- Added vitest imports to all *.test.ts files (and __mocks__/*.ts)
  that didn't have them.
- src/index.ts: extracted runMain() as a named export and gated the
  module-level invocation behind NODE_ENV !== 'test'. The
  index-plugin-features test now calls runMain() directly instead of
  relying on jest's removed vi.isolateModules.
- index-plugin-features.test.ts: moved hoisted refs (mockPlugin,
  mockLoadOrchestratorPlugin) into vi.hoisted() so vi.mock factories
  can reference them. Replaced arrow constructor mock for ImageTag
  with regular function() {...} (vitest 4 disallows arrows as ctors).
  Replaced require('./model') / require('@actions/core') inside test
  bodies with top-level imports.
- model/orchestrator-plugin.test.ts: dropped jest's '{ virtual: true }'
  flag (vitest doesn't support it); replaced the
  'mock factory throws' pattern with 'createPlugin throws' so vitest
  doesn't wrap the error message at the assertion site.
- model/versioning.test.ts: stray jest.spyOn -> vi.spyOn; replaced
  mockImplementation() with no args (jest pattern) by
  mockResolvedValue('') / mockImplementation(() => undefined) where
  the source expects a string return.

Workflow shell-quoting cleanup (actionlint):
- All bare $GITHUB_STEP_SUMMARY / $GITHUB_OUTPUT / $GITHUB_ENV
  redirects quoted across 2 workflows (SC2086).
- s3://$AWS_STACK_NAME / s3://$BUCKET_NAME -> s3://"$AWS_STACK_NAME"
  / s3://"$BUCKET_NAME".
- 'for i in {1..N}; do ... done' loops where i isn't referenced in
  the body renamed to 'for _ in' (SC2034).
- 'grep ... | wc -l' -> 'grep -c ...' (SC2126).
- Multiple consecutive '>> $file' redirects in
  validate-community-plugins.yml summary block collapsed into a
  single block redirect (SC2129).
- 'cat $file | python3 -c "..."' -> 'python3 -c "..." < $file'
  (SC2002).
- http://${VAR}:port -> http://"${VAR}":port (SC2086).

tsgo: kept tsc --noEmit as the default 'typecheck' because
unity-builder publishes CommonJS for the GitHub Action consumer,
which conflicts with tsgo's bundler/node16 moduleResolution
requirement (per playbook trap #9). 'yarn typecheck:tsgo' is wired
up for when consumers move to ESM.

Caveats: 28 pre-existing oxlint warnings remain (mostly
typescript/no-explicit-any across the build-parameter shapes and
vitest/no-disabled-tests on 2 explicitly skipped scenarios). Per
playbook trap #22 the lint script drops --deny-warnings.

Verified locally: format clean, lint 0/28, typecheck clean,
test 340/342 (2 pre-existing skipped), actionlint clean across all
12 workflows.

* ci(unity-builder): fix Tests + Plugin Architecture Health on quality-tightening

Three issues surfaced in CI after the jest -> vitest port:

1. **Obsolete snapshot blocks Tests job.**
   src/model/__snapshots__/versioning.test.ts.snap had two entries
   for the same 'throws for invalid strategy' assertion: one in the
   vitest format ('Versioning > determineBuildVersion > ...') and one
   in the legacy jest format without the '>'. vitest correctly
   regenerates the new one and flags the old one as obsolete; CI
   runs without --update so 'Test Files 1 failed' even though all
   343 tests passed. Removed the obsolete entry.

2. **'Plugin Architecture Health' workflow still calls jest.**
   .github/workflows/validate-orchestrator.yml had two 'npx jest'
   steps (orchestrator-plugin unit tests + orchestrator-standalone
   tests). The unity-builder + orchestrator codebases are both on
   vitest now. Replaced both with 'yarn vitest run'.

3. **jest-fail-on-console + src/jest.setup.ts left over.**
   The earlier vitest port missed the jest-fail-on-console
   integration. yarn install in CI surfaced
   YN0002: doesn't provide @jest/globals (requested by
   jest-fail-on-console). Removed jest-fail-on-console + jest.setup.ts;
   added src/test/setup.ts with the equivalent vitest beforeEach
   spies (same as unity-test-runner).

---------

Co-authored-by: frostebite <jas.f.ukcmti@gmail.com>
This commit is contained in:
Webber Takken
2026-05-06 20:07:47 +02:00
committed by GitHub
parent 821ba97789
commit 16c5c20793
71 changed files with 6135 additions and 8507 deletions

View File

@@ -1,5 +0,0 @@
dist/
lib/
node_modules/
jest.config.js
src/types/

View File

@@ -1,94 +0,0 @@
{
"root": true,
"plugins": ["jest", "@typescript-eslint", "prettier", "unicorn"],
"extends": ["plugin:unicorn/recommended", "plugin:github/recommended", "plugin:prettier/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"extraFileExtensions": [".mjs"],
"ecmaFeatures": {
"impliedStrict": true
},
"project": "./tsconfig.json"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true,
"es2020": true
},
"rules": {
// Error out for code formatting errors
"prettier/prettier": "error",
// Namespaces or sometimes needed
"import/no-namespace": "off",
// Properly format comments
"spaced-comment": ["error", "always"],
"lines-around-comment": [
"error",
{
"beforeBlockComment": true,
"beforeLineComment": true,
"allowBlockStart": true,
"allowObjectStart": true,
"allowArrayStart": true,
"allowClassStart": true,
"ignorePattern": "pragma|ts-ignore"
}
],
// Mandatory spacing
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "*",
"next": "return"
},
{
"blankLine": "always",
"prev": "directive",
"next": "*"
},
{
"blankLine": "any",
"prev": "directive",
"next": "directive"
}
],
// Enforce camelCase
"camelcase": "error",
// Allow forOfStatements
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
// Continue is viable in forOf loops in generators
"no-continue": "off",
// From experience, named exports are almost always desired. I got tired of this rule
"import/prefer-default-export": "off",
// Unused vars are useful to keep method signatures consistent and documented
"@typescript-eslint/no-unused-vars": "off",
// For this project only use kebab-case
"unicorn/filename-case": [
"error",
{
"cases": {
"kebabCase": true
}
}
],
// Allow Array.from(set) mitigate TS2569 which would require '--downlevelIteration'
"unicorn/prefer-spread": "off",
// Temp disable to prevent mixing changes with other PRs
// Disabled: @types/jest 27 typings require .mockResolvedValue(undefined),
// contradicting this rule
"unicorn/no-useless-undefined": "off",
"i18n-text/no-en": "off"
},
"overrides": [
{
"files": ["jest.setup.js"],
"rules": {
"import/no-commonjs": "off"
}
}
]
}

View File

@@ -14,9 +14,7 @@ assignees: ''
<!--Steps to reproduce the behavior:--> <!--Steps to reproduce the behavior:-->
- - **Expected behavior**
**Expected behavior**
<!--A clear and concise description of what you expected to happen.--> <!--A clear and concise description of what you expected to happen.-->

View File

@@ -9,8 +9,7 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
env: env:
UNITY_LICENSE: UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License
id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\"
Value=\"576562626572264761624c65526f7578\"/>\n <Binding Key=\"2\" Value=\"576562626572264761624c65526f7578\"/>\n <Binding Key=\"2\"
Value=\"576562626572264761624c65526f7578\"/>\n </MachineBindings>\n <MachineID Value=\"576562626572264761624c65526f7578\"/>\n </MachineBindings>\n <MachineID
@@ -36,8 +35,7 @@ env:
jobs: jobs:
buildForAllPlatformsUbuntu: buildForAllPlatformsUbuntu:
name: name: "${{ matrix.targetPlatform }} on ${{ matrix.unityVersion}}${{startsWith(matrix.buildProfile, 'Assets') && ' (via Build Profile)' || '' }}"
"${{ matrix.targetPlatform }} on ${{ matrix.unityVersion}}${{startsWith(matrix.buildProfile, 'Assets') && ' (via Build Profile)' || '' }}"
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
@@ -200,7 +198,6 @@ jobs:
########################### ###########################
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: name: "Build ${{ matrix.targetPlatform }}${{ startsWith(matrix.buildProfile, 'Assets') && ' (via Build Profile)' || '' }} on Ubuntu (${{ matrix.unityVersion }}_il2cpp_${{ matrix.buildWithIl2cpp }}_params_${{ matrix.additionalParameters }})"
"Build ${{ matrix.targetPlatform }}${{ startsWith(matrix.buildProfile, 'Assets') && ' (via Build Profile)' || '' }} on Ubuntu (${{ matrix.unityVersion }}_il2cpp_${{ matrix.buildWithIl2cpp }}_params_${{ matrix.additionalParameters }})"
path: build path: build
retention-days: 14 retention-days: 14

View File

@@ -98,12 +98,12 @@ jobs:
# Add git package via manifest # Add git package via manifest
cd test-project cd test-project
cat Packages/manifest.json | python3 -c " python3 -c "
import sys, json import sys, json
manifest = json.load(sys.stdin) manifest = json.load(sys.stdin)
manifest['dependencies']['${{ matrix.name }}'] = '${{ matrix.package }}' manifest['dependencies']['${{ matrix.name }}'] = '${{ matrix.package }}'
json.dump(manifest, sys.stdout, indent=2) json.dump(manifest, sys.stdout, indent=2)
" > Packages/manifest.tmp && mv Packages/manifest.tmp Packages/manifest.json " < Packages/manifest.json > Packages/manifest.tmp && mv Packages/manifest.tmp Packages/manifest.json
cd .. cd ..
fi fi
@@ -125,18 +125,20 @@ jobs:
if: always() if: always()
run: | run: |
STATUS="${{ steps.build.outcome }}" STATUS="${{ steps.build.outcome }}"
echo "## ${{ matrix.name }} — ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY {
echo "" >> $GITHUB_STEP_SUMMARY echo "## ${{ matrix.name }} — ${{ matrix.platform }}"
if [ "$STATUS" = "success" ]; then echo ""
echo "✅ **PASSED** — Compiled and built successfully" >> $GITHUB_STEP_SUMMARY if [ "$STATUS" = "success" ]; then
else echo "✅ **PASSED** — Compiled and built successfully"
echo "❌ **FAILED** — Build or compilation failed" >> $GITHUB_STEP_SUMMARY else
fi echo "❌ **FAILED** — Build or compilation failed"
echo "" >> $GITHUB_STEP_SUMMARY fi
echo "- Unity: ${{ matrix.unity }}" >> $GITHUB_STEP_SUMMARY echo ""
echo "- Platform: ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY echo "- Unity: ${{ matrix.unity }}"
echo "- Source: ${{ matrix.source }}" >> $GITHUB_STEP_SUMMARY echo "- Platform: ${{ matrix.platform }}"
echo "- Package: \`${{ matrix.package }}\`" >> $GITHUB_STEP_SUMMARY echo "- Source: ${{ matrix.source }}"
echo "- Package: \`${{ matrix.package }}\`"
} >> "$GITHUB_STEP_SUMMARY"
report: report:
name: Validation Report name: Validation Report

View File

@@ -295,15 +295,15 @@ jobs:
- name: Create S3 bucket for tests - name: Create S3 bucket for tests
run: | run: |
for i in {1..10}; do for _ in {1..10}; do
if curl -s http://localhost:4566/_localstack/health > /dev/null 2>&1; then break; fi if curl -s http://localhost:4566/_localstack/health > /dev/null 2>&1; then break; fi
sleep 1 sleep 1
done done
for i in {1..5}; do for _ in {1..5}; do
if command -v awslocal > /dev/null 2>&1; then if command -v awslocal > /dev/null 2>&1; then
awslocal s3 mb s3://$AWS_STACK_NAME 2>&1 && break awslocal s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
else else
aws --endpoint-url=http://localhost:4566 s3 mb s3://$AWS_STACK_NAME 2>&1 && break aws --endpoint-url=http://localhost:4566 s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
fi fi
sleep 2 sleep 2
done done
@@ -342,7 +342,7 @@ jobs:
--network orchestrator-net \ --network orchestrator-net \
--wait --wait
kubectl config current-context | cat kubectl config current-context | cat
echo "LOCALSTACK_IP=$LOCALSTACK_IP" >> $GITHUB_ENV echo "LOCALSTACK_IP=$LOCALSTACK_IP" >> "$GITHUB_ENV"
- name: Verify cluster readiness and MiniStack connectivity - name: Verify cluster readiness and MiniStack connectivity
timeout-minutes: 2 timeout-minutes: 2
@@ -355,15 +355,15 @@ jobs:
kubectl get nodes kubectl get nodes
LOCALSTACK_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' localstack-main 2>/dev/null || echo "") LOCALSTACK_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' localstack-main 2>/dev/null || echo "")
kubectl run test-localstack --image=curlimages/curl --rm -i --restart=Never --timeout=30s -- \ kubectl run test-localstack --image=curlimages/curl --rm -i --restart=Never --timeout=30s -- \
curl -v --max-time 10 http://${LOCALSTACK_IP}:4566/_localstack/health 2>&1 | head -30 || \ curl -v --max-time 10 http://"${LOCALSTACK_IP}":4566/_localstack/health 2>&1 | head -30 || \
echo "Cluster connectivity test - MiniStack may not be accessible from k3d" echo "Cluster connectivity test - MiniStack may not be accessible from k3d"
- name: Clean up K8s resources before tests - name: Clean up K8s resources before tests
run: | run: |
source /tmp/cleanup-functions.sh source /tmp/cleanup-functions.sh
k8s_resource_cleanup k8s_resource_cleanup
for i in {1..30}; do for _ in {1..30}; do
PVC_COUNT=$(kubectl get pvc -n default 2>/dev/null | grep "unity-builder-pvc-" | wc -l || echo "0") PVC_COUNT=$(kubectl get pvc -n default 2>/dev/null | grep -c "unity-builder-pvc-" || echo "0")
if [ "$PVC_COUNT" -eq 0 ]; then echo "All PVCs deleted"; break; fi if [ "$PVC_COUNT" -eq 0 ]; then echo "All PVCs deleted"; break; fi
sleep 1 sleep 1
done done
@@ -630,11 +630,11 @@ jobs:
- name: Create S3 bucket for tests - name: Create S3 bucket for tests
run: | run: |
for i in {1..5}; do for _ in {1..5}; do
if command -v awslocal > /dev/null 2>&1; then if command -v awslocal > /dev/null 2>&1; then
awslocal s3 mb s3://$AWS_STACK_NAME 2>&1 && break awslocal s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
else else
aws --endpoint-url=http://localhost:4566 s3 mb s3://$AWS_STACK_NAME 2>&1 && break aws --endpoint-url=http://localhost:4566 s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
fi fi
sleep 2 sleep 2
done done
@@ -935,11 +935,11 @@ jobs:
- name: Create S3 bucket for tests - name: Create S3 bucket for tests
run: | run: |
for i in {1..5}; do for _ in {1..5}; do
if command -v awslocal > /dev/null 2>&1; then if command -v awslocal > /dev/null 2>&1; then
awslocal s3 mb s3://$AWS_STACK_NAME 2>&1 && break awslocal s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
else else
aws --endpoint-url=http://localhost:4566 s3 mb s3://$AWS_STACK_NAME 2>&1 && break aws --endpoint-url=http://localhost:4566 s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
fi fi
sleep 2 sleep 2
done done
@@ -1201,11 +1201,11 @@ jobs:
- name: Create S3 bucket for tests - name: Create S3 bucket for tests
run: | run: |
for i in {1..5}; do for _ in {1..5}; do
if command -v awslocal > /dev/null 2>&1; then if command -v awslocal > /dev/null 2>&1; then
awslocal s3 mb s3://$AWS_STACK_NAME 2>&1 && break awslocal s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
else else
aws --endpoint-url=http://localhost:4566 s3 mb s3://$AWS_STACK_NAME 2>&1 && break aws --endpoint-url=http://localhost:4566 s3 mb s3://"$AWS_STACK_NAME" 2>&1 && break
fi fi
sleep 2 sleep 2
done done

View File

@@ -120,7 +120,7 @@ jobs:
- name: Run orchestrator-plugin unit tests - name: Run orchestrator-plugin unit tests
run: | run: |
echo "Running orchestrator-plugin unit tests..." echo "Running orchestrator-plugin unit tests..."
npx jest orchestrator-plugin --verbose --detectOpenHandles --forceExit yarn vitest run orchestrator-plugin
# --- Plugin loader without orchestrator --- # --- Plugin loader without orchestrator ---
- name: Verify plugin loader returns undefined without orchestrator - name: Verify plugin loader returns undefined without orchestrator
@@ -162,7 +162,7 @@ jobs:
working-directory: orchestrator-standalone working-directory: orchestrator-standalone
run: | run: |
echo "Running orchestrator unit tests..." echo "Running orchestrator unit tests..."
npx jest --no-cache 2>&1 | tail -20 yarn vitest run 2>&1 | tail -30
# --- Plugin loader with orchestrator installed --- # --- Plugin loader with orchestrator installed ---
- name: Install orchestrator into unity-builder - name: Install orchestrator into unity-builder

7
.husky/pre-commit Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env sh
yarn lint-staged
yarn typecheck
if command -v gitleaks >/dev/null 2>&1; then
gitleaks protect --staged --no-banner --redact
fi

17
.oxfmtrc.json Normal file
View File

@@ -0,0 +1,17 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"proseWrap": "preserve",
"sortPackageJson": false,
"ignorePatterns": [
"**/node_modules/**",
"**/dist/**",
"**/coverage/**",
"**/.yarn/**",
"default-build-script/**",
"test-runner/**",
"platforms/**"
]
}

58
.oxlintrc.json Normal file
View File

@@ -0,0 +1,58 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript", "vitest", "unicorn", "oxc"],
"categories": {
"correctness": "error",
"suspicious": "error",
"perf": "error"
},
"rules": {
"vitest/require-mock-type-parameters": "off",
"vitest/valid-title": "off",
"vitest/valid-describe-callback": "off",
"vitest/expect-expect": "off",
"vitest/no-conditional-tests": "off",
"vitest/no-conditional-expect": "off",
"vitest/require-to-throw-message": "off",
"vitest/no-disabled-tests": "warn",
"unicorn/prefer-array-flat-map": "warn",
"typescript/no-explicit-any": "warn",
"typescript/ban-ts-comment": "off",
"typescript/no-namespace": "off",
"typescript/no-extraneous-class": "off",
"no-bitwise": "off",
"no-shadow": "off",
"no-await-in-loop": "off",
"no-underscore-dangle": "off",
"unicorn/no-array-sort": "off",
"unicorn/prefer-set-has": "off",
"unicorn/consistent-function-scoping": "off",
"unicorn/no-useless-spread": "warn",
"eslint/preserve-caught-error": "warn",
"oxc/no-map-spread": "warn"
},
"overrides": [
{
"files": ["**/*.test.ts", "**/*.spec.ts"],
"rules": {
"typescript/no-explicit-any": "off",
"no-unused-vars": "off"
}
}
],
"env": {
"browser": false,
"node": true,
"es2024": true,
"vitest/globals": true
},
"ignorePatterns": [
"**/node_modules/**",
"**/dist/**",
"**/coverage/**",
"**/.yarn/**",
"default-build-script/**",
"test-runner/**",
"platforms/**"
]
}

View File

@@ -1,2 +0,0 @@
**/node_modules/**
**/dist/**

View File

@@ -1,7 +0,0 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"proseWrap": "always"
}

View File

@@ -9,8 +9,7 @@ inputs:
unityVersion: unityVersion:
required: false required: false
default: 'auto' default: 'auto'
description: description: 'Version of unity to use for building the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
'Version of unity to use for building the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
customImage: customImage:
required: false required: false
default: '' default: ''
@@ -124,8 +123,7 @@ inputs:
chownFilesTo: chownFilesTo:
required: false required: false
default: '' default: ''
description: description: 'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
dockerCpuLimit: dockerCpuLimit:
required: false required: false
default: '' default: ''

6047
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +0,0 @@
const base = require('./jest.config.js');
module.exports = {
...base,
forceExit: true,
detectOpenHandles: true,
testTimeout: 120000,
maxWorkers: 1,
};

View File

@@ -1,30 +0,0 @@
module.exports = {
// Automatically clear mock calls and instances between every test
clearMocks: true,
// An array of file extensions your modules use
moduleFileExtensions: ['js', 'ts'],
// The test environment that will be used for testing
testEnvironment: 'node',
// The glob patterns Jest uses to detect test files
testMatch: ['**/*.test.ts'],
// This option allows use of a custom test runner
testRunner: 'jest-circus/runner',
// A map with regular expressions for transformers to paths
transform: {
'^.+\\.ts$': 'ts-jest',
},
// Indicates whether each individual test should be reported during the run
verbose: true,
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/dist/'],
// Use jest.setup.js to polyfill fetch for all tests
setupFiles: ['<rootDir>/jest.setup.js'],
};

View File

@@ -1,31 +0,0 @@
# EXAMPLE USAGE
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md
#
color: true
extends: {}
pre-commit:
parallel: true
commands:
format documents:
glob: '*.{md,mdx}'
run: yarn prettier --write {staged_files}
format configs:
glob: '*.{json,yml,yaml}'
run: yarn prettier --write {staged_files}
format code:
glob: '*.{js,jsx,ts,tsx}'
exclude: 'dist/'
run: yarn prettier --write {staged_files} && yarn eslint {staged_files} && git add {staged_files}
run tests:
glob: '*.{js,jsx,ts,tsx}'
exclude: 'dist/'
run: yarn jest --passWithNoTests --findRelatedTests {staged_files}
build distributables:
skip: ['merge', 'rebase']
run: yarn build && git add dist
make shell script executable:
glob: '*.sh'
run: git update-index --chmod=+x

View File

@@ -1,3 +1,6 @@
[tools] [tools]
node = "20.18.0" node = "20.18.0"
yarn = "4.14.1" yarn = "4.14.1"
actionlint = "latest"
shellcheck = "latest"
gitleaks = "latest"

View File

@@ -7,12 +7,26 @@
"author": "Webber <webber@takken.io>", "author": "Webber <webber@takken.io>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"prepare": "lefthook install", "prepare": "husky",
"build": "yarn && tsc && ncc build lib --source-map --license licenses.txt", "build": "yarn && tsc && ncc build lib --source-map --license licenses.txt",
"lint": "prettier --check \"src/**/*.{js,ts}\" && eslint src/**/*.ts", "test": "node scripts/ensure-husky.mjs && vitest run",
"format": "prettier --write \"src/**/*.{js,ts}\"", "test:watch": "vitest",
"test": "jest", "test:ci": "vitest run",
"test:ci": "jest --config=jest.ci.config.js --runInBand" "coverage": "vitest run --coverage",
"lint": "yarn oxlint --report-unused-disable-directives",
"format": "oxfmt --write",
"format:check": "oxfmt --check",
"typecheck": "tsc --noEmit",
"typecheck:tsgo": "tsgo --noEmit",
"setup:hooks": "node scripts/ensure-husky.mjs"
},
"lint-staged": {
"*.@(ts|tsx|mts|js|jsx|mjs|cjs)": [
"oxlint --fix --quiet",
"oxfmt --write"
],
"*.@(json|jsonc|json5|md|mdx|yaml|yml|css|scss|sass|html|toml)": "oxfmt --write",
".github/workflows/*.@(yml|yaml)": "actionlint"
}, },
"engines": { "engines": {
"node": ">=18.x" "node": ">=18.x"
@@ -33,31 +47,24 @@
"yaml": "^2.2.2" "yaml": "^2.2.2"
}, },
"devDependencies": { "devDependencies": {
"@jest/globals": "^27.5.1",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23", "@types/node": "^17.0.23",
"@types/semver": "^7.3.9", "@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "4.8.1", "@typescript/native-preview": "^7.0.0-dev.20260505.1",
"@typescript-eslint/parser": "4.8.1",
"@vercel/ncc": "^0.36.1", "@vercel/ncc": "^0.36.1",
"@vitest/coverage-istanbul": "^4.1.5",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^7.23.0", "eslint": "^10.3.0",
"eslint-config-prettier": "8.1.0", "eslint-plugin-unicorn": "^64.0.0",
"eslint-plugin-github": "^4.1.1", "husky": "9",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-unicorn": "28.0.2",
"jest": "^27.5.1",
"jest-circus": "^27.5.1",
"jest-fail-on-console": "^3.0.2",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"lefthook": "^1.6.1", "lint-staged": "^16.4.0",
"node-fetch": "2", "node-fetch": "2",
"prettier": "^2.5.1", "oxfmt": "^0.48.0",
"ts-jest": "^27.1.3", "oxlint": "^1.63.0",
"ts-node": "10.8.1", "ts-node": "10.8.1",
"typescript": "4.7.4", "typescript": "4.7.4",
"vite": "^7",
"vitest": "^4",
"yarn-audit-fix": "^9.3.8" "yarn-audit-fix": "^9.3.8"
}, },
"packageManager": "yarn@4.14.1", "packageManager": "yarn@4.14.1",

55
scripts/ensure-husky.mjs Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env node
// Self-heals husky git hooks before local dev workflows.
//
// Why this exists: Yarn 4 skips lifecycle scripts (`prepare`, `postinstall`) on
// no-op installs, so `yarn install --immutable` does NOT reinstall hooks once
// `.husky/_/` has been wiped. `.husky/_/` is gitignored, so it is also missing
// in fresh worktrees and after `git clean -fdx`. Without this guard, commits
// silently skip the pre-commit hook (git treats a missing hook file as "no hook").
//
// Behaviour: ~20 ms no-op when hooks are already installed. Skipped in CI and
// when HUSKY=0. Fails loudly (non-zero exit) on real install errors so the
// caller stops before commits are made without hooks.
import { execSync } from 'node:child_process';
import { existsSync } from 'node:fs';
if (process.env.CI || process.env.HUSKY === '0') process.exit(0);
const expectedHooksPath = '.husky/_';
const sentinelHook = '.husky/_/pre-commit';
// husky 9.1+ ships bin.js; husky 9.0 ships bin.mjs. Try both.
const huskyBin = ['node_modules/husky/bin.js', 'node_modules/husky/bin.mjs'].find(existsSync);
let configuredHooksPath = '';
try {
configuredHooksPath = execSync('git config --get core.hooksPath', {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
}).trim();
} catch {
// not a git repo or config unset — fall through and try to install
}
if (configuredHooksPath === expectedHooksPath && existsSync(sentinelHook)) {
process.exit(0);
}
if (!huskyBin) {
// husky not installed yet (yarn install hasn't run) — silent no-op
process.exit(0);
}
console.log('· installing git hooks (husky self-heal)…');
try {
execSync(`node ${huskyBin}`, { stdio: 'inherit' });
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error(
`\n❌ husky install failed: ${message}\n\n` +
` git pre-commit hooks are NOT installed; commits will skip lint/format/tests.\n` +
` Fix the underlying error above, then run \`yarn setup:hooks\` to retry.\n` +
` To bypass this guard temporarily (NOT recommended): HUSKY=0 yarn <cmd>.\n`,
);
process.exit(1);
}

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, beforeEach, afterEach, vi, type Mock } from 'vitest';
/** /**
* Integration wiring tests for the plugin lifecycle in index.ts * Integration wiring tests for the plugin lifecycle in index.ts
* *
@@ -9,74 +10,83 @@
* - When providerStrategy is non-local without a plugin, an error is thrown * - When providerStrategy is non-local without a plugin, an error is thrown
*/ */
import { BuildParameters } from './model'; import { BuildParameters, Docker } from './model';
import * as core from '@actions/core';
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Mock plugin // Mock plugin
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const mockPlugin = { // `vi.mock` hoists to the top of the module, so any factory references must
initialize: jest.fn().mockResolvedValue(undefined), // be hoisted with `vi.hoisted` to be defined at mock-evaluation time.
canHandleBuild: jest.fn().mockReturnValue(false), const { mockPlugin, mockLoadPlugin } = vi.hoisted(() => {
handleBuild: jest.fn().mockResolvedValue({ exitCode: 0 }), const plugin = {
beforeLocalBuild: jest.fn().mockResolvedValue(undefined), initialize: vi.fn().mockResolvedValue(undefined),
afterLocalBuild: jest.fn().mockResolvedValue(undefined), canHandleBuild: vi.fn().mockReturnValue(false),
handlePostBuild: jest.fn().mockResolvedValue(undefined), handleBuild: vi.fn().mockResolvedValue({ exitCode: 0 }),
}; beforeLocalBuild: vi.fn().mockResolvedValue(undefined),
afterLocalBuild: vi.fn().mockResolvedValue(undefined),
handlePostBuild: vi.fn().mockResolvedValue(undefined),
};
return {
mockPlugin: plugin,
mockLoadPlugin: vi.fn().mockResolvedValue(plugin),
};
});
const mockLoadPlugin = jest.fn().mockResolvedValue(mockPlugin); vi.mock('./model/plugin', () => ({
jest.mock('./model/plugin', () => ({
loadPlugin: mockLoadPlugin, loadPlugin: mockLoadPlugin,
})); }));
jest.mock('@actions/core'); vi.mock('@actions/core');
jest.mock('./model', () => ({ vi.mock('./model', () => ({
Action: { Action: {
checkCompatibility: jest.fn(), checkCompatibility: vi.fn(),
workspace: '/workspace', workspace: '/workspace',
actionFolder: '/action', actionFolder: '/action',
}, },
BuildParameters: { BuildParameters: {
create: jest.fn(), create: vi.fn(),
}, },
Cache: { Cache: {
verify: jest.fn(), verify: vi.fn(),
}, },
Docker: { Docker: {
run: jest.fn().mockResolvedValue(0), run: vi.fn().mockResolvedValue(0),
}, },
ImageTag: jest.fn().mockImplementation(() => ({ // vitest 4 requires constructor mocks to use regular `function` (or
toString: () => 'mock-image:latest', // `class`); arrow fns aren't valid constructors.
})), ImageTag: vi.fn(function () {
return { toString: () => 'mock-image:latest' };
}),
Output: { Output: {
setBuildVersion: jest.fn().mockResolvedValue(''), setBuildVersion: vi.fn().mockResolvedValue(''),
setAndroidVersionCode: jest.fn().mockResolvedValue(''), setAndroidVersionCode: vi.fn().mockResolvedValue(''),
setEngineExitCode: jest.fn().mockResolvedValue(''), setEngineExitCode: vi.fn().mockResolvedValue(''),
}, },
})); }));
jest.mock('./model/cli/cli', () => ({ vi.mock('./model/cli/cli', () => ({
Cli: { Cli: {
InitCliMode: jest.fn().mockReturnValue(false), InitCliMode: vi.fn().mockReturnValue(false),
}, },
})); }));
jest.mock('./model/mac-builder', () => ({ vi.mock('./model/mac-builder', () => ({
__esModule: true, __esModule: true,
default: { default: {
run: jest.fn().mockResolvedValue(0), run: vi.fn().mockResolvedValue(0),
}, },
})); }));
jest.mock('./model/platform-setup', () => ({ vi.mock('./model/platform-setup', () => ({
__esModule: true, __esModule: true,
default: { default: {
setup: jest.fn().mockResolvedValue(''), setup: vi.fn().mockResolvedValue(''),
}, },
})); }));
const mockedBuildParametersCreate = BuildParameters.create as jest.Mock; const mockedBuildParametersCreate = BuildParameters.create as Mock;
function createMockBuildParameters(overrides: Record<string, any> = {}) { function createMockBuildParameters(overrides: Record<string, any> = {}) {
return { return {
@@ -95,12 +105,12 @@ function createMockBuildParameters(overrides: Record<string, any> = {}) {
async function runIndex(overrides: Record<string, any> = {}): Promise<void> { async function runIndex(overrides: Record<string, any> = {}): Promise<void> {
mockedBuildParametersCreate.mockResolvedValue(createMockBuildParameters(overrides)); mockedBuildParametersCreate.mockResolvedValue(createMockBuildParameters(overrides));
return new Promise<void>((resolve) => { // index.ts exports `runMain` for testability (the file used to rely on
jest.isolateModules(() => { // top-level execution + jest's `vi.isolateModules`, but vitest 4 dropped
require('./index'); // that API). Calling the exported function directly is cleaner than
}); // round-tripping through dynamic imports.
setTimeout(resolve, 100); const { runMain } = await import('./index');
}); await runMain();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -112,7 +122,7 @@ describe('index.ts plugin lifecycle wiring', () => {
const originalEnvironment = { ...process.env }; const originalEnvironment = { ...process.env };
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks(); vi.clearAllMocks();
process.env.GITHUB_WORKSPACE = '/workspace'; process.env.GITHUB_WORKSPACE = '/workspace';
Object.defineProperty(process, 'platform', { value: 'linux' }); Object.defineProperty(process, 'platform', { value: 'linux' });
@@ -132,16 +142,23 @@ describe('index.ts plugin lifecycle wiring', () => {
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
describe('local build with plugin installed', () => { describe('local build with plugin installed', () => {
it('should call lifecycle hooks in order: initialize beforeLocalBuild [build] afterLocalBuild handlePostBuild', async () => { it('should call lifecycle hooks in order: initialize -> beforeLocalBuild -> [build] -> afterLocalBuild -> handlePostBuild', async () => {
const callOrder: string[] = []; const callOrder: string[] = [];
mockPlugin.initialize.mockImplementation(async () => callOrder.push('initialize')); mockPlugin.initialize.mockImplementation(async () => callOrder.push('initialize'));
mockPlugin.beforeLocalBuild.mockImplementation(async () => callOrder.push('beforeLocalBuild')); mockPlugin.beforeLocalBuild.mockImplementation(async () =>
callOrder.push('beforeLocalBuild'),
);
mockPlugin.afterLocalBuild.mockImplementation(async () => callOrder.push('afterLocalBuild')); mockPlugin.afterLocalBuild.mockImplementation(async () => callOrder.push('afterLocalBuild'));
mockPlugin.handlePostBuild.mockImplementation(async () => callOrder.push('handlePostBuild')); mockPlugin.handlePostBuild.mockImplementation(async () => callOrder.push('handlePostBuild'));
await runIndex(); await runIndex();
expect(callOrder).toEqual(['initialize', 'beforeLocalBuild', 'afterLocalBuild', 'handlePostBuild']); expect(callOrder).toEqual([
'initialize',
'beforeLocalBuild',
'afterLocalBuild',
'handlePostBuild',
]);
}); });
it('should pass buildParameters and workspace to initialize', async () => { it('should pass buildParameters and workspace to initialize', async () => {
@@ -178,7 +195,6 @@ describe('index.ts plugin lifecycle wiring', () => {
describe('plugin handles build (canHandleBuild = true)', () => { describe('plugin handles build (canHandleBuild = true)', () => {
it('should call handleBuild instead of Docker.run', async () => { it('should call handleBuild instead of Docker.run', async () => {
const { Docker } = require('./model');
mockPlugin.canHandleBuild.mockReturnValue(true); mockPlugin.canHandleBuild.mockReturnValue(true);
mockPlugin.handleBuild.mockResolvedValue({ exitCode: 0 }); mockPlugin.handleBuild.mockResolvedValue({ exitCode: 0 });
@@ -206,7 +222,6 @@ describe('index.ts plugin lifecycle wiring', () => {
describe('fallback to local build', () => { describe('fallback to local build', () => {
it('should do a local build when handleBuild returns fallbackToLocal', async () => { it('should do a local build when handleBuild returns fallbackToLocal', async () => {
const { Docker } = require('./model');
mockPlugin.canHandleBuild.mockReturnValue(true); mockPlugin.canHandleBuild.mockReturnValue(true);
mockPlugin.handleBuild.mockResolvedValue({ exitCode: -1, fallbackToLocal: true }); mockPlugin.handleBuild.mockResolvedValue({ exitCode: -1, fallbackToLocal: true });
@@ -225,7 +240,6 @@ describe('index.ts plugin lifecycle wiring', () => {
describe('no plugin installed', () => { describe('no plugin installed', () => {
it('should build locally without errors when providerStrategy is local', async () => { it('should build locally without errors when providerStrategy is local', async () => {
const { Docker } = require('./model');
mockLoadPlugin.mockResolvedValue(undefined); mockLoadPlugin.mockResolvedValue(undefined);
await runIndex({ providerStrategy: 'local' }); await runIndex({ providerStrategy: 'local' });
@@ -234,12 +248,13 @@ describe('index.ts plugin lifecycle wiring', () => {
}); });
it('should error when providerStrategy is non-local and no plugin', async () => { it('should error when providerStrategy is non-local and no plugin', async () => {
const core = require('@actions/core');
mockLoadPlugin.mockResolvedValue(undefined); mockLoadPlugin.mockResolvedValue(undefined);
await runIndex({ providerStrategy: 'aws' }); await runIndex({ providerStrategy: 'aws' });
expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining('requires @game-ci/orchestrator')); expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('requires @game-ci/orchestrator'),
);
}); });
}); });
@@ -249,14 +264,15 @@ describe('index.ts plugin lifecycle wiring', () => {
describe('plugin installed but canHandleBuild returns false with non-local provider', () => { describe('plugin installed but canHandleBuild returns false with non-local provider', () => {
it('should error when providerStrategy is non-local', async () => { it('should error when providerStrategy is non-local', async () => {
const core = require('@actions/core');
mockPlugin.canHandleBuild.mockReturnValue(false); mockPlugin.canHandleBuild.mockReturnValue(false);
await runIndex({ providerStrategy: 'aws' }); await runIndex({ providerStrategy: 'aws' });
// The plugin is initialized but says it can't handle the build, // The plugin is initialized but says it can't handle the build,
// and providerStrategy is not local, so it falls to the error case // and providerStrategy is not local, so it falls to the error case
expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining('requires @game-ci/orchestrator')); expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining('requires @game-ci/orchestrator'),
);
}); });
}); });
}); });

View File

@@ -5,7 +5,9 @@ import MacBuilder from './model/mac-builder';
import PlatformSetup from './model/platform-setup'; import PlatformSetup from './model/platform-setup';
import { Plugin, loadPlugin } from './model/plugin'; import { Plugin, loadPlugin } from './model/plugin';
async function runMain() { // Exported so tests can drive the lifecycle directly without depending on
// vitest's module re-loading (which changed in vitest 4).
export async function runMain() {
try { try {
if (Cli.InitCliMode()) { if (Cli.InitCliMode()) {
await Cli.RunCli(); await Cli.RunCli();
@@ -81,4 +83,9 @@ async function runLocalBuild(
return exitCode; return exitCode;
} }
runMain(); // Auto-run when this module is the entry point. Tests import the file via
// `await import('./index')` purely to register the mock factories and then
// call `runMain()` directly.
if (process.env.NODE_ENV !== 'test') {
runMain();
}

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import { stat } from 'node:fs/promises'; import { stat } from 'node:fs/promises';
describe('Integrity tests', () => { describe('Integrity tests', () => {

View File

@@ -1,9 +0,0 @@
import failOnConsole from 'jest-fail-on-console';
// Fail when console logs something inside a test - use spyOn instead
failOnConsole({
shouldFailOnWarn: true,
shouldFailOnError: true,
shouldFailOnLog: true,
shouldFailOnAssert: true,
});

View File

@@ -1,7 +1,8 @@
import { vi } from 'vitest';
// Import this named export into your test file: // Import this named export into your test file:
import Platform from '../platform'; import Platform from '../platform';
export const mockGetFromUser = jest.fn().mockResolvedValue({ export const mockGetFromUser = vi.fn().mockResolvedValue({
editorVersion: '', editorVersion: '',
targetPlatform: Platform.types.Test, targetPlatform: Platform.types.Test,
projectPath: '.', projectPath: '.',

View File

@@ -1,22 +1,23 @@
import { vi } from 'vitest';
/* eslint unicorn/prevent-abbreviations: "off" */ /* eslint unicorn/prevent-abbreviations: "off" */
// Import these named export into your test file: // Import these named export into your test file:
export const mockProjectPath = jest.fn().mockResolvedValue('mockProjectPath'); export const mockProjectPath = vi.fn().mockResolvedValue('mockProjectPath');
export const mockIsDirtyAllowed = jest.fn().mockResolvedValue(false); export const mockIsDirtyAllowed = vi.fn().mockResolvedValue(false);
export const mockBranch = jest.fn().mockResolvedValue('mockBranch'); export const mockBranch = vi.fn().mockResolvedValue('mockBranch');
export const mockHeadRef = jest.fn().mockResolvedValue('mockHeadRef'); export const mockHeadRef = vi.fn().mockResolvedValue('mockHeadRef');
export const mockRef = jest.fn().mockResolvedValue('mockRef'); export const mockRef = vi.fn().mockResolvedValue('mockRef');
export const mockDetermineVersion = jest.fn().mockResolvedValue('1.2.3'); export const mockDetermineVersion = vi.fn().mockResolvedValue('1.2.3');
export const mockGenerateSemanticVersion = jest.fn().mockResolvedValue('2.3.4'); export const mockGenerateSemanticVersion = vi.fn().mockResolvedValue('2.3.4');
export const mockGenerateTagVersion = jest.fn().mockResolvedValue('1.0'); export const mockGenerateTagVersion = vi.fn().mockResolvedValue('1.0');
export const mockParseSemanticVersion = jest.fn().mockResolvedValue({}); export const mockParseSemanticVersion = vi.fn().mockResolvedValue({});
export const mockFetch = jest.fn().mockImplementation(() => {}); export const mockFetch = vi.fn().mockImplementation(() => {});
export const mockGetVersionDescription = jest.fn().mockResolvedValue('1.2-3-g12345678-dirty'); export const mockGetVersionDescription = vi.fn().mockResolvedValue('1.2-3-g12345678-dirty');
export const mockIsDirty = jest.fn().mockResolvedValue(false); export const mockIsDirty = vi.fn().mockResolvedValue(false);
export const mockGetTag = jest.fn().mockResolvedValue('v1.0'); export const mockGetTag = vi.fn().mockResolvedValue('v1.0');
export const mockHasAnyVersionTags = jest.fn().mockResolvedValue(true); export const mockHasAnyVersionTags = vi.fn().mockResolvedValue(true);
export const mockGetTotalNumberOfCommits = jest.fn().mockResolvedValue(3); export const mockGetTotalNumberOfCommits = vi.fn().mockResolvedValue(3);
export const mockGit = jest.fn().mockImplementation(() => {}); export const mockGit = vi.fn().mockImplementation(() => {});
export default { export default {
projectPath: mockProjectPath, projectPath: mockProjectPath,

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Versioning determineBuildVersion throws for invalid strategy somethingRandom 1`] = `"Versioning strategy should be one of None, Semantic, Tag, Custom."`; exports[`Versioning > determineBuildVersion > throws for invalid strategy somethingRandom 1`] = `[ValidationError: Versioning strategy should be one of None, Semantic, Tag, Custom.]`;

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import path from 'node:path'; import path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
import Action from './action'; import Action from './action';

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import AndroidVersioning from './android-versioning'; import AndroidVersioning from './android-versioning';
describe('Android Versioning', () => { describe('Android Versioning', () => {
@@ -35,7 +36,9 @@ describe('Android Versioning', () => {
}); });
it('uses the specified api level', () => { it('uses the specified api level', () => {
expect(AndroidVersioning.determineSdkManagerParameters('AndroidApiLevel30')).toBe('platforms;android-30'); expect(AndroidVersioning.determineSdkManagerParameters('AndroidApiLevel30')).toBe(
'platforms;android-30',
);
}); });
}); });
}); });

View File

@@ -12,7 +12,9 @@ export default class AndroidVersioning {
static versionToVersionCode(version: string): string { static versionToVersionCode(version: string): string {
if (version === 'none') { if (version === 'none') {
core.info(`Versioning strategy is set to ${version}, so android version code should not be applied.`); core.info(
`Versioning strategy is set to ${version}, so android version code should not be applied.`,
);
return '0'; return '0';
} }
@@ -27,7 +29,8 @@ export default class AndroidVersioning {
// The greatest value Google Plays allows is 2100000000. // The greatest value Google Plays allows is 2100000000.
// Allow for 3 patch digits, 3 minor digits and 3 major digits. // Allow for 3 patch digits, 3 minor digits and 3 major digits.
const versionCode = parsedVersion.major * 1000000 + parsedVersion.minor * 1000 + parsedVersion.patch; const versionCode =
parsedVersion.major * 1000000 + parsedVersion.minor * 1000 + parsedVersion.patch;
if (versionCode >= 2050000000) { if (versionCode >= 2050000000) {
throw new Error( throw new Error(

View File

@@ -1,3 +1,4 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, test, vi } from 'vitest';
import Versioning from './versioning'; import Versioning from './versioning';
import UnityVersioning from './unity-versioning'; import UnityVersioning from './unity-versioning';
import AndroidVersioning from './android-versioning'; import AndroidVersioning from './android-versioning';
@@ -9,12 +10,12 @@ const testLicense =
'<?xml version="1.0" encoding="UTF-8"?><root>\n <License id="Terms">\n <MachineBindings>\n <Binding Key="1" Value="576562626572264761624c65526f7578"/>\n <Binding Key="2" Value="576562626572264761624c65526f7578"/>\n </MachineBindings>\n <MachineID Value="D7nTUnjNAmtsUMcnoyrqkgIbYdM="/>\n <SerialHash Value="2033b8ac3e6faa3742ca9f0bfae44d18f2a96b80"/>\n <Features>\n <Feature Value="33"/>\n <Feature Value="1"/>\n <Feature Value="12"/>\n <Feature Value="2"/>\n <Feature Value="24"/>\n <Feature Value="3"/>\n <Feature Value="36"/>\n <Feature Value="17"/>\n <Feature Value="19"/>\n <Feature Value="62"/>\n </Features>\n <DeveloperData Value="AQAAAEY0LUJHUlgtWEQ0RS1aQ1dWLUM1SlctR0RIQg=="/>\n <SerialMasked Value="F4-BGRX-XD4E-ZCWV-C5JW-XXXX"/>\n <StartDate Value="2021-02-08T00:00:00"/>\n <UpdateDate Value="2021-02-09T00:34:57"/>\n <InitialActivationDate Value="2021-02-08T00:34:56"/>\n <LicenseVersion Value="6.x"/>\n <ClientProvidedVersion Value="2018.4.30f1"/>\n <AlwaysOnline Value="false"/>\n <Entitlements>\n <Entitlement Ns="unity_editor" Tag="UnityPersonal" Type="EDITOR" ValidTo="9999-12-31T00:00:00"/>\n <Entitlement Ns="unity_editor" Tag="DarkSkin" Type="EDITOR_FEATURE" ValidTo="9999-12-31T00:00:00"/>\n </Entitlements>\n </License>\n<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#Terms"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>m0Db8UK+ktnOLJBtHybkfetpcKo=</DigestValue></Reference></SignedInfo><SignatureValue>o/pUbSQAukz7+ZYAWhnA0AJbIlyyCPL7bKVEM2lVqbrXt7cyey+umkCXamuOgsWPVUKBMkXtMH8L\n5etLmD0getWIhTGhzOnDCk+gtIPfL4jMo9tkEuOCROQAXCci23VFscKcrkB+3X6h4wEOtA2APhOY\nB+wvC794o8/82ffjP79aVAi57rp3Wmzx+9pe9yMwoJuljAy2sc2tIMgdQGWVmOGBpQm3JqsidyzI\nJWG2kjnc7pDXK9pwYzXoKiqUqqrut90d+kQqRyv7MSZXR50HFqD/LI69h68b7P8Bjo3bPXOhNXGR\n9YCoemH6EkfCJxp2gIjzjWW+l2Hj2EsFQi8YXw==</SignatureValue></Signature></root>'; '<?xml version="1.0" encoding="UTF-8"?><root>\n <License id="Terms">\n <MachineBindings>\n <Binding Key="1" Value="576562626572264761624c65526f7578"/>\n <Binding Key="2" Value="576562626572264761624c65526f7578"/>\n </MachineBindings>\n <MachineID Value="D7nTUnjNAmtsUMcnoyrqkgIbYdM="/>\n <SerialHash Value="2033b8ac3e6faa3742ca9f0bfae44d18f2a96b80"/>\n <Features>\n <Feature Value="33"/>\n <Feature Value="1"/>\n <Feature Value="12"/>\n <Feature Value="2"/>\n <Feature Value="24"/>\n <Feature Value="3"/>\n <Feature Value="36"/>\n <Feature Value="17"/>\n <Feature Value="19"/>\n <Feature Value="62"/>\n </Features>\n <DeveloperData Value="AQAAAEY0LUJHUlgtWEQ0RS1aQ1dWLUM1SlctR0RIQg=="/>\n <SerialMasked Value="F4-BGRX-XD4E-ZCWV-C5JW-XXXX"/>\n <StartDate Value="2021-02-08T00:00:00"/>\n <UpdateDate Value="2021-02-09T00:34:57"/>\n <InitialActivationDate Value="2021-02-08T00:34:56"/>\n <LicenseVersion Value="6.x"/>\n <ClientProvidedVersion Value="2018.4.30f1"/>\n <AlwaysOnline Value="false"/>\n <Entitlements>\n <Entitlement Ns="unity_editor" Tag="UnityPersonal" Type="EDITOR" ValidTo="9999-12-31T00:00:00"/>\n <Entitlement Ns="unity_editor" Tag="DarkSkin" Type="EDITOR_FEATURE" ValidTo="9999-12-31T00:00:00"/>\n </Entitlements>\n </License>\n<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#Terms"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>m0Db8UK+ktnOLJBtHybkfetpcKo=</DigestValue></Reference></SignedInfo><SignatureValue>o/pUbSQAukz7+ZYAWhnA0AJbIlyyCPL7bKVEM2lVqbrXt7cyey+umkCXamuOgsWPVUKBMkXtMH8L\n5etLmD0getWIhTGhzOnDCk+gtIPfL4jMo9tkEuOCROQAXCci23VFscKcrkB+3X6h4wEOtA2APhOY\nB+wvC794o8/82ffjP79aVAi57rp3Wmzx+9pe9yMwoJuljAy2sc2tIMgdQGWVmOGBpQm3JqsidyzI\nJWG2kjnc7pDXK9pwYzXoKiqUqqrut90d+kQqRyv7MSZXR50HFqD/LI69h68b7P8Bjo3bPXOhNXGR\n9YCoemH6EkfCJxp2gIjzjWW+l2Hj2EsFQi8YXw==</SignatureValue></Signature></root>';
afterEach(() => { afterEach(() => {
jest.clearAllMocks(); vi.clearAllMocks();
jest.restoreAllMocks(); vi.restoreAllMocks();
}); });
beforeEach(() => { beforeEach(() => {
jest.spyOn(Versioning, 'determineBuildVersion').mockImplementation(async () => '1.3.37'); vi.spyOn(Versioning, 'determineBuildVersion').mockImplementation(async () => '1.3.37');
process.env.UNITY_LICENSE = testLicense; // Todo - Don't use process.env directly, that's what the input model class is for. process.env.UNITY_LICENSE = testLicense; // Todo - Don't use process.env directly, that's what the input model class is for.
}); });
@@ -25,20 +26,20 @@ describe('BuildParameters', () => {
}); });
it('determines the version only once', async () => { it('determines the version only once', async () => {
jest.spyOn(Versioning, 'determineBuildVersion').mockImplementation(async () => '1.3.37'); vi.spyOn(Versioning, 'determineBuildVersion').mockImplementation(async () => '1.3.37');
await BuildParameters.create(); await BuildParameters.create();
await expect(Versioning.determineBuildVersion).toHaveBeenCalledTimes(1); await expect(Versioning.determineBuildVersion).toHaveBeenCalledTimes(1);
}); });
it('determines the unity version only once', async () => { it('determines the unity version only once', async () => {
jest.spyOn(UnityVersioning, 'determineUnityVersion').mockImplementation(() => '2019.2.11f1'); vi.spyOn(UnityVersioning, 'determineUnityVersion').mockImplementation(() => '2019.2.11f1');
await BuildParameters.create(); await BuildParameters.create();
expect(UnityVersioning.determineUnityVersion).toHaveBeenCalledTimes(1); expect(UnityVersioning.determineUnityVersion).toHaveBeenCalledTimes(1);
}); });
it('returns the android version code with provided input', async () => { it('returns the android version code with provided input', async () => {
const mockValue = '42'; const mockValue = '42';
jest.spyOn(Input, 'androidVersionCode', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidVersionCode', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidVersionCode: mockValue }), expect.objectContaining({ androidVersionCode: mockValue }),
); );
@@ -46,49 +47,59 @@ describe('BuildParameters', () => {
it('returns the android version code from version by default', async () => { it('returns the android version code from version by default', async () => {
const mockValue = ''; const mockValue = '';
jest.spyOn(Input, 'androidVersionCode', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidVersionCode', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidVersionCode: '1003037' }), expect.objectContaining({ androidVersionCode: '1003037' }),
); );
}); });
it('determines the android sdk manager parameters only once', async () => { it('determines the android sdk manager parameters only once', async () => {
jest.spyOn(AndroidVersioning, 'determineSdkManagerParameters').mockImplementation(() => 'platforms;android-30'); vi.spyOn(AndroidVersioning, 'determineSdkManagerParameters').mockImplementation(
() => 'platforms;android-30',
);
await BuildParameters.create(); await BuildParameters.create();
expect(AndroidVersioning.determineSdkManagerParameters).toHaveBeenCalledTimes(1); expect(AndroidVersioning.determineSdkManagerParameters).toHaveBeenCalledTimes(1);
}); });
it('returns the targetPlatform', async () => { it('returns the targetPlatform', async () => {
const mockValue = 'somePlatform'; const mockValue = 'somePlatform';
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ targetPlatform: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ targetPlatform: mockValue }),
);
}); });
it('returns the project path', async () => { it('returns the project path', async () => {
const mockValue = 'path/to/project'; const mockValue = 'path/to/project';
jest.spyOn(UnityVersioning, 'determineUnityVersion').mockImplementation(() => '2019.2.11f1'); vi.spyOn(UnityVersioning, 'determineUnityVersion').mockImplementation(() => '2019.2.11f1');
jest.spyOn(Input, 'projectPath', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'projectPath', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ projectPath: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ projectPath: mockValue }),
);
}); });
it('returns the build profile', async () => { it('returns the build profile', async () => {
const mockValue = 'path/to/build_profile.asset'; const mockValue = 'path/to/build_profile.asset';
jest.spyOn(Input, 'buildProfile', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'buildProfile', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildProfile: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildProfile: mockValue }),
);
}); });
it('returns the build name', async () => { it('returns the build name', async () => {
const mockValue = 'someBuildName'; const mockValue = 'someBuildName';
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'buildName', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildName: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildName: mockValue }),
);
}); });
it('returns the build path', async () => { it('returns the build path', async () => {
const mockPath = 'somePath'; const mockPath = 'somePath';
const mockPlatform = 'somePlatform'; const mockPlatform = 'somePlatform';
const expectedBuildPath = `${mockPath}/${mockPlatform}`; const expectedBuildPath = `${mockPath}/${mockPlatform}`;
jest.spyOn(Input, 'buildsPath', 'get').mockReturnValue(mockPath); vi.spyOn(Input, 'buildsPath', 'get').mockReturnValue(mockPath);
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockPlatform); vi.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockPlatform);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildPath: expectedBuildPath }), expect.objectContaining({ buildPath: expectedBuildPath }),
); );
@@ -98,9 +109,11 @@ describe('BuildParameters', () => {
const mockValue = 'someBuildName'; const mockValue = 'someBuildName';
const mockPlatform = 'somePlatform'; const mockPlatform = 'somePlatform';
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'buildName', 'get').mockReturnValue(mockValue);
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockPlatform); vi.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(mockPlatform);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildFile: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildFile: mockValue }),
);
}); });
test.each` test.each`
@@ -113,9 +126,9 @@ describe('BuildParameters', () => {
`( `(
'appends $expectedExtension for $targetPlatform with androidExportType $androidExportType', 'appends $expectedExtension for $targetPlatform with androidExportType $androidExportType',
async ({ targetPlatform, expectedExtension, androidExportType }) => { async ({ targetPlatform, expectedExtension, androidExportType }) => {
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform); vi.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform); vi.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'androidExportType', 'get').mockReturnValue(androidExportType); vi.spyOn(Input, 'androidExportType', 'get').mockReturnValue(androidExportType);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildFile: `${targetPlatform}${expectedExtension}` }), expect.objectContaining({ buildFile: `${targetPlatform}${expectedExtension}` }),
); );
@@ -132,22 +145,26 @@ describe('BuildParameters', () => {
`( `(
'androidSymbolType is set to $androidSymbolType when targetPlatform is $targetPlatform and input targetSymbolType is $androidSymbolType', 'androidSymbolType is set to $androidSymbolType when targetPlatform is $targetPlatform and input targetSymbolType is $androidSymbolType',
async ({ targetPlatform, androidSymbolType }) => { async ({ targetPlatform, androidSymbolType }) => {
jest.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform); vi.spyOn(Input, 'targetPlatform', 'get').mockReturnValue(targetPlatform);
jest.spyOn(Input, 'androidSymbolType', 'get').mockReturnValue(androidSymbolType); vi.spyOn(Input, 'androidSymbolType', 'get').mockReturnValue(androidSymbolType);
jest.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform); vi.spyOn(Input, 'buildName', 'get').mockReturnValue(targetPlatform);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ androidSymbolType })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidSymbolType }),
);
}, },
); );
it('returns the build method', async () => { it('returns the build method', async () => {
const mockValue = 'Namespace.ClassName.BuildMethod'; const mockValue = 'Namespace.ClassName.BuildMethod';
jest.spyOn(Input, 'buildMethod', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'buildMethod', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ buildMethod: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ buildMethod: mockValue }),
);
}); });
it('returns the android keystore name', async () => { it('returns the android keystore name', async () => {
const mockValue = 'keystore.keystore'; const mockValue = 'keystore.keystore';
jest.spyOn(Input, 'androidKeystoreName', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidKeystoreName', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidKeystoreName: mockValue }), expect.objectContaining({ androidKeystoreName: mockValue }),
); );
@@ -155,7 +172,7 @@ describe('BuildParameters', () => {
it('returns the android keystore base64-encoded content', async () => { it('returns the android keystore base64-encoded content', async () => {
const mockValue = 'secret'; const mockValue = 'secret';
jest.spyOn(Input, 'androidKeystoreBase64', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidKeystoreBase64', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidKeystoreBase64: mockValue }), expect.objectContaining({ androidKeystoreBase64: mockValue }),
); );
@@ -163,7 +180,7 @@ describe('BuildParameters', () => {
it('returns the android keystore pass', async () => { it('returns the android keystore pass', async () => {
const mockValue = 'secret'; const mockValue = 'secret';
jest.spyOn(Input, 'androidKeystorePass', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidKeystorePass', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidKeystorePass: mockValue }), expect.objectContaining({ androidKeystorePass: mockValue }),
); );
@@ -171,7 +188,7 @@ describe('BuildParameters', () => {
it('returns the android keyalias name', async () => { it('returns the android keyalias name', async () => {
const mockValue = 'secret'; const mockValue = 'secret';
jest.spyOn(Input, 'androidKeyaliasName', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidKeyaliasName', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidKeyaliasName: mockValue }), expect.objectContaining({ androidKeyaliasName: mockValue }),
); );
@@ -179,7 +196,7 @@ describe('BuildParameters', () => {
it('returns the android keyalias pass', async () => { it('returns the android keyalias pass', async () => {
const mockValue = 'secret'; const mockValue = 'secret';
jest.spyOn(Input, 'androidKeyaliasPass', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidKeyaliasPass', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidKeyaliasPass: mockValue }), expect.objectContaining({ androidKeyaliasPass: mockValue }),
); );
@@ -187,7 +204,7 @@ describe('BuildParameters', () => {
it('returns the android target sdk version', async () => { it('returns the android target sdk version', async () => {
const mockValue = 'AndroidApiLevelAuto'; const mockValue = 'AndroidApiLevelAuto';
jest.spyOn(Input, 'androidTargetSdkVersion', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'androidTargetSdkVersion', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ androidTargetSdkVersion: mockValue }), expect.objectContaining({ androidTargetSdkVersion: mockValue }),
); );
@@ -195,7 +212,7 @@ describe('BuildParameters', () => {
it('returns the unity licensing server address', async () => { it('returns the unity licensing server address', async () => {
const mockValue = 'http://example.com'; const mockValue = 'http://example.com';
jest.spyOn(Input, 'unityLicensingServer', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'unityLicensingServer', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual( await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ unityLicensingServer: mockValue }), expect.objectContaining({ unityLicensingServer: mockValue }),
); );
@@ -210,19 +227,25 @@ describe('BuildParameters', () => {
const mockValue = '123'; const mockValue = '123';
delete process.env.UNITY_LICENSE; // Need to delete this as it is set for every test currently delete process.env.UNITY_LICENSE; // Need to delete this as it is set for every test currently
process.env.UNITY_SERIAL = mockValue; process.env.UNITY_SERIAL = mockValue;
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ unitySerial: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ unitySerial: mockValue }),
);
delete process.env.UNITY_SERIAL; delete process.env.UNITY_SERIAL;
}); });
it('returns the custom parameters', async () => { it('returns the custom parameters', async () => {
const mockValue = '-profile SomeProfile -someBoolean -someValue exampleValue'; const mockValue = '-profile SomeProfile -someBoolean -someValue exampleValue';
jest.spyOn(Input, 'customParameters', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'customParameters', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ customParameters: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ customParameters: mockValue }),
);
}); });
it.each([true, false])('returns the flag for useHostNetwork when %s', async (mockValue) => { it.each([true, false])('returns the flag for useHostNetwork when %s', async (mockValue) => {
jest.spyOn(Input, 'useHostNetwork', 'get').mockReturnValue(mockValue); vi.spyOn(Input, 'useHostNetwork', 'get').mockReturnValue(mockValue);
await expect(BuildParameters.create()).resolves.toEqual(expect.objectContaining({ useHostNetwork: mockValue })); await expect(BuildParameters.create()).resolves.toEqual(
expect.objectContaining({ useHostNetwork: mockValue }),
);
}); });
}); });
}); });

View File

@@ -69,11 +69,26 @@ class BuildParameters {
public dockerWorkspacePath!: string; public dockerWorkspacePath!: string;
static async create(): Promise<BuildParameters> { static async create(): Promise<BuildParameters> {
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidExportType); const buildFile = this.parseBuildFile(
const editorVersion = UnityVersioning.determineUnityVersion(Input.projectPath, Input.unityVersion); Input.buildName,
const buildVersion = await Versioning.determineBuildVersion(Input.versioningStrategy, Input.specifiedVersion); Input.targetPlatform,
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode); Input.androidExportType,
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion); );
const editorVersion = UnityVersioning.determineUnityVersion(
Input.projectPath,
Input.unityVersion,
);
const buildVersion = await Versioning.determineBuildVersion(
Input.versioningStrategy,
Input.specifiedVersion,
);
const androidVersionCode = AndroidVersioning.determineVersionCode(
buildVersion,
Input.androidVersionCode,
);
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(
Input.androidTargetSdkVersion,
);
const androidSymbolExportType = Input.androidSymbolType; const androidSymbolExportType = Input.androidSymbolType;
if (Platform.isAndroid(Input.targetPlatform)) { if (Platform.isAndroid(Input.targetPlatform)) {
@@ -112,7 +127,8 @@ class BuildParameters {
core.setSecret(`${unitySerial.slice(0, -4)}XXXX`); core.setSecret(`${unitySerial.slice(0, -4)}XXXX`);
} }
const providerStrategy = Input.getInput('providerStrategy') || (Cli.isCliMode ? 'aws' : 'local'); const providerStrategy =
Input.getInput('providerStrategy') || (Cli.isCliMode ? 'aws' : 'local');
return { return {
editorVersion, editorVersion,
@@ -157,7 +173,8 @@ class BuildParameters {
buildPlatform: providerStrategy !== 'local' ? 'linux' : process.platform, buildPlatform: providerStrategy !== 'local' ? 'linux' : process.platform,
runNumber: Input.runNumber, runNumber: Input.runNumber,
branch: Input.branch.replace('/head', '') || (await GitRepoReader.GetBranch()), branch: Input.branch.replace('/head', '') || (await GitRepoReader.GetBranch()),
githubRepo: (Input.githubRepo ?? (await GitRepoReader.GetRemote())) || 'game-ci/unity-builder', githubRepo:
(Input.githubRepo ?? (await GitRepoReader.GetRemote())) || 'game-ci/unity-builder',
gitSha: Input.gitSha, gitSha: Input.gitSha,
logId: customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 9)(), logId: customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 9)(),
buildGuid: `${Input.runNumber}-${Input.targetPlatform.toLowerCase().replace('standalone', '')}-${customAlphabet( buildGuid: `${Input.runNumber}-${Input.targetPlatform.toLowerCase().replace('standalone', '')}-${customAlphabet(

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import Cache from './cache'; import Cache from './cache';
jest.mock('./input'); vi.mock('./input');
describe('Cache', () => { describe('Cache', () => {
describe('Verification', () => { describe('Verification', () => {

View File

@@ -39,7 +39,10 @@ export class Cli {
.map((x) => `${x.key} (${x.description})`) .map((x) => `${x.key} (${x.description})`)
.join(` | `), .join(` | `),
); );
program.option('--populateOverride <populateOverride>', 'should use override query to pull input false by default'); program.option(
'--populateOverride <populateOverride>',
'should use override query to pull input false by default',
);
program.option('--cachePushFrom <cachePushFrom>', 'cache push from source folder'); program.option('--cachePushFrom <cachePushFrom>', 'cache push from source folder');
program.option('--cachePushTo <cachePushTo>', 'cache push to caching folder'); program.option('--cachePushTo <cachePushTo>', 'cache push to caching folder');
program.option('--artifactName <artifactName>', 'caching artifact name'); program.option('--artifactName <artifactName>', 'caching artifact name');
@@ -49,7 +52,10 @@ export class Cli {
program.option('--variantPath <variantPath>', 'path to submodule variant YAML'); program.option('--variantPath <variantPath>', 'path to submodule variant YAML');
program.option('--agentPath <agentPath>', 'path to custom LFS transfer agent'); program.option('--agentPath <agentPath>', 'path to custom LFS transfer agent');
program.option('--agentArgs <agentArgs>', 'arguments for custom LFS transfer agent'); program.option('--agentArgs <agentArgs>', 'arguments for custom LFS transfer agent');
program.option('--storagePaths <storagePaths>', 'semicolon-separated storage paths for LFS agent'); program.option(
'--storagePaths <storagePaths>',
'semicolon-separated storage paths for LFS agent',
);
program.parse(process.argv); program.parse(process.argv);
Cli.options = program.opts(); Cli.options = program.opts();

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import Action from './action'; import Action from './action';
import Docker from './docker'; import Docker from './docker';

View File

@@ -17,7 +17,13 @@ class Docker {
let runCommand = ''; let runCommand = '';
switch (process.platform) { switch (process.platform) {
case 'linux': case 'linux':
runCommand = this.getLinuxCommand(image, parameters, overrideCommands, additionalVariables, entrypointBash); runCommand = this.getLinuxCommand(
image,
parameters,
overrideCommands,
additionalVariables,
entrypointBash,
);
break; break;
case 'win32': case 'win32':
runCommand = this.getWindowsCommand(image, parameters); runCommand = this.getWindowsCommand(image, parameters);

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import CommandExecutionError from './command-execution-error'; import CommandExecutionError from './command-execution-error';
describe('CommandExecutionError', () => { describe('CommandExecutionError', () => {

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import NotImplementedException from './not-implemented-exception'; import NotImplementedException from './not-implemented-exception';
describe('NotImplementedException', () => { describe('NotImplementedException', () => {

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import ValidationError from './validation-error'; import ValidationError from './validation-error';
describe('ValidationError', () => { describe('ValidationError', () => {

View File

@@ -1,8 +1,14 @@
import { DockerParameters, StringKeyValuePair } from './shared-types'; import { DockerParameters, StringKeyValuePair } from './shared-types';
class ImageEnvironmentFactory { class ImageEnvironmentFactory {
public static getEnvVarString(parameters: DockerParameters, additionalVariables: StringKeyValuePair[] = []) { public static getEnvVarString(
const environmentVariables = ImageEnvironmentFactory.getEnvironmentVariables(parameters, additionalVariables); parameters: DockerParameters,
additionalVariables: StringKeyValuePair[] = [],
) {
const environmentVariables = ImageEnvironmentFactory.getEnvironmentVariables(
parameters,
additionalVariables,
);
let string = ''; let string = '';
for (const p of environmentVariables) { for (const p of environmentVariables) {
if (p.value === '' || p.value === undefined || p.value === null) { if (p.value === '' || p.value === undefined || p.value === null) {
@@ -21,7 +27,10 @@ class ImageEnvironmentFactory {
return string; return string;
} }
public static getEnvironmentVariables(parameters: DockerParameters, additionalVariables: StringKeyValuePair[] = []) { public static getEnvironmentVariables(
parameters: DockerParameters,
additionalVariables: StringKeyValuePair[] = [],
) {
let environmentVariables: StringKeyValuePair[] = [ let environmentVariables: StringKeyValuePair[] = [
{ name: 'UNITY_EMAIL', value: process.env.UNITY_EMAIL }, { name: 'UNITY_EMAIL', value: process.env.UNITY_EMAIL },
{ name: 'UNITY_PASSWORD', value: process.env.UNITY_PASSWORD }, { name: 'UNITY_PASSWORD', value: process.env.UNITY_PASSWORD },

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import ImageTag from './image-tag'; import ImageTag from './image-tag';
describe('ImageTag', () => { describe('ImageTag', () => {
@@ -27,15 +28,18 @@ describe('ImageTag', () => {
expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform); expect(image.builderPlatform).toStrictEqual(testImageParameters.builderPlatform);
}); });
test.each(['2000.0.0f0', '2011.1.11f1', '6000.0.0f1'])('accepts %p version format', (version) => { test.each(['2000.0.0f0', '2011.1.11f1', '6000.0.0f1'])(
expect( 'accepts %p version format',
() => (version) => {
new ImageTag({ expect(
editorVersion: version, () =>
targetPlatform: testImageParameters.targetPlatform, new ImageTag({
}), editorVersion: version,
).not.toThrow(); targetPlatform: testImageParameters.targetPlatform,
}); }),
).not.toThrow();
},
);
test.each(['some version', ''])('throws for incorrect version %p', (editorVersion) => { test.each(['some version', ''])('throws for incorrect version %p', (editorVersion) => {
const { targetPlatform } = testImageParameters; const { targetPlatform } = testImageParameters;

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import * as Index from '.'; import * as Index from '.';
interface ExportedModules { interface ExportedModules {

View File

@@ -10,4 +10,16 @@ import Project from './project';
import Unity from './unity'; import Unity from './unity';
import Versioning from './versioning'; import Versioning from './versioning';
export { Action, BuildParameters, Cache, Docker, Input, ImageTag, Output, Platform, Project, Unity, Versioning }; export {
Action,
BuildParameters,
Cache,
Docker,
Input,
ImageTag,
Output,
Platform,
Project,
Unity,
Versioning,
};

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import { GitRepoReader } from './git-repo'; import { GitRepoReader } from './git-repo';
import Input from '../input'; import Input from '../input';
@@ -9,15 +10,15 @@ describe(`git repo tests`, () => {
it(`returns valid branch name when using https`, async () => { it(`returns valid branch name when using https`, async () => {
const mockValue = 'https://github.com/example/example.git'; const mockValue = 'https://github.com/example/example.git';
jest.spyOn(GitRepoReader as any, 'runCommand').mockResolvedValue(mockValue); vi.spyOn(GitRepoReader as any, 'runCommand').mockResolvedValue(mockValue);
jest.spyOn(Input, 'getInput').mockReturnValue('not-local'); vi.spyOn(Input, 'getInput').mockReturnValue('not-local');
expect(await GitRepoReader.GetRemote()).toEqual(`example/example`); expect(await GitRepoReader.GetRemote()).toEqual(`example/example`);
}); });
it(`returns valid branch name when using ssh`, async () => { it(`returns valid branch name when using ssh`, async () => {
const mockValue = 'git@github.com:example/example.git'; const mockValue = 'git@github.com:example/example.git';
jest.spyOn(GitRepoReader as any, 'runCommand').mockResolvedValue(mockValue); vi.spyOn(GitRepoReader as any, 'runCommand').mockResolvedValue(mockValue);
jest.spyOn(Input, 'getInput').mockReturnValue('not-local'); vi.spyOn(Input, 'getInput').mockReturnValue('not-local');
expect(await GitRepoReader.GetRemote()).toEqual(`example/example`); expect(await GitRepoReader.GetRemote()).toEqual(`example/example`);
}); });
}); });

View File

@@ -23,7 +23,9 @@ export class GitRepoReader {
return ''; return '';
} }
assert(fs.existsSync(`.git`)); assert(fs.existsSync(`.git`));
const value = (await GitRepoReader.runCommand(`cd ${Input.projectPath} && git remote -v`)).replace(/ /g, ``); const value = (
await GitRepoReader.runCommand(`cd ${Input.projectPath} && git remote -v`)
).replace(/ /g, ``);
core.info(`value ${value}`); core.info(`value ${value}`);
assert(value.includes('github.com')); assert(value.includes('github.com'));

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import { GithubCliReader } from './github-cli'; import { GithubCliReader } from './github-cli';
import * as core from '@actions/core'; import * as core from '@actions/core';

View File

@@ -7,7 +7,14 @@ export function ReadLicense(): string {
if ((Input.getInput('providerStrategy') || 'local') === 'local') { if ((Input.getInput('providerStrategy') || 'local') === 'local') {
return ''; return '';
} }
const pipelineFile = path.join(__dirname, `.github`, `workflows`, `orchestrator-k8s-pipeline.yml`); const pipelineFile = path.join(
__dirname,
`.github`,
`workflows`,
`orchestrator-k8s-pipeline.yml`,
);
return fs.existsSync(pipelineFile) ? YAML.parse(fs.readFileSync(pipelineFile, 'utf8')).env.UNITY_LICENSE : ''; return fs.existsSync(pipelineFile)
? YAML.parse(fs.readFileSync(pipelineFile, 'utf8')).env.UNITY_LICENSE
: '';
} }

View File

@@ -1,10 +1,11 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, test, vi } from 'vitest';
import * as core from '@actions/core'; import * as core from '@actions/core';
import Input from './input'; import Input from './input';
import Platform from './platform'; import Platform from './platform';
afterEach(() => { afterEach(() => {
jest.restoreAllMocks(); vi.restoreAllMocks();
}); });
describe('Input', () => { describe('Input', () => {
@@ -15,7 +16,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = '2020.4.99f9'; const mockValue = '2020.4.99f9';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.unityVersion).toStrictEqual(mockValue); expect(Input.unityVersion).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -27,7 +28,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = '2020.4.99f9'; const mockValue = '2020.4.99f9';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.customImage).toStrictEqual(mockValue); expect(Input.customImage).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -40,7 +41,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'Android'; const mockValue = 'Android';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.targetPlatform).toStrictEqual(mockValue); expect(Input.targetPlatform).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -53,7 +54,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'customProjectPath'; const mockValue = 'customProjectPath';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.projectPath).toStrictEqual(mockValue); expect(Input.projectPath).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -66,7 +67,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'path/to/build_profile.asset'; const mockValue = 'path/to/build_profile.asset';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.buildProfile).toStrictEqual(mockValue); expect(Input.buildProfile).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -79,14 +80,14 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'Build'; const mockValue = 'Build';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.buildName).toStrictEqual(mockValue); expect(Input.buildName).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('takes special characters as input', () => { it('takes special characters as input', () => {
const mockValue = '1ßúëld2'; const mockValue = '1ßúëld2';
jest.spyOn(core, 'getInput').mockReturnValue(mockValue); vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.buildName).toStrictEqual(mockValue); expect(Input.buildName).toStrictEqual(mockValue);
}); });
}); });
@@ -98,7 +99,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'customBuildsPath'; const mockValue = 'customBuildsPath';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.buildsPath).toStrictEqual(mockValue); expect(Input.buildsPath).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -111,7 +112,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'Namespace.ClassName.Method'; const mockValue = 'Namespace.ClassName.Method';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.buildMethod).toStrictEqual(mockValue); expect(Input.buildMethod).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -123,13 +124,13 @@ describe('Input', () => {
}); });
it('returns true when string true is passed', () => { it('returns true when string true is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('true'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('true');
expect(Input.manualExit).toStrictEqual(true); expect(Input.manualExit).toStrictEqual(true);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('returns false when string false is passed', () => { it('returns false when string false is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('false'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('false');
expect(Input.manualExit).toStrictEqual(false); expect(Input.manualExit).toStrictEqual(false);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -141,13 +142,13 @@ describe('Input', () => {
}); });
it('returns true when string true is passed', () => { it('returns true when string true is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('true'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('true');
expect(Input.enableGpu).toStrictEqual(true); expect(Input.enableGpu).toStrictEqual(true);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('returns false when string false is passed', () => { it('returns false when string false is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('false'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('false');
expect(Input.enableGpu).toStrictEqual(false); expect(Input.enableGpu).toStrictEqual(false);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -160,7 +161,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'Anything'; const mockValue = 'Anything';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.versioningStrategy).toStrictEqual(mockValue); expect(Input.versioningStrategy).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -173,7 +174,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = '1.33.7'; const mockValue = '1.33.7';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.specifiedVersion).toStrictEqual(mockValue); expect(Input.specifiedVersion).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -186,7 +187,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = '42'; const mockValue = '42';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidVersionCode).toStrictEqual(mockValue); expect(Input.androidVersionCode).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -203,7 +204,7 @@ describe('Input', () => {
${'androidAppBundle'} | ${'androidAppBundle'} ${'androidAppBundle'} | ${'androidAppBundle'}
${'androidStudioProject'} | ${'androidStudioProject'} ${'androidStudioProject'} | ${'androidStudioProject'}
`('returns $expected when $input is passed', ({ input, expected }) => { `('returns $expected when $input is passed', ({ input, expected }) => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue(input); const spy = vi.spyOn(core, 'getInput').mockReturnValue(input);
expect(Input.androidExportType).toStrictEqual(expected); expect(Input.androidExportType).toStrictEqual(expected);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -220,7 +221,7 @@ describe('Input', () => {
${'public'} | ${'public'} ${'public'} | ${'public'}
${'debugging'} | ${'debugging'} ${'debugging'} | ${'debugging'}
`('returns $expected when $input is passed', ({ input, expected }) => { `('returns $expected when $input is passed', ({ input, expected }) => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue(input); const spy = vi.spyOn(core, 'getInput').mockReturnValue(input);
expect(Input.androidExportType).toStrictEqual(expected); expect(Input.androidExportType).toStrictEqual(expected);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -233,7 +234,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'keystore.keystore'; const mockValue = 'keystore.keystore';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidKeystoreName).toStrictEqual(mockValue); expect(Input.androidKeystoreName).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -246,7 +247,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'secret'; const mockValue = 'secret';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidKeystoreBase64).toStrictEqual(mockValue); expect(Input.androidKeystoreBase64).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -259,7 +260,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'secret'; const mockValue = 'secret';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidKeystorePass).toStrictEqual(mockValue); expect(Input.androidKeystorePass).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -272,7 +273,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'secret'; const mockValue = 'secret';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidKeyaliasName).toStrictEqual(mockValue); expect(Input.androidKeyaliasName).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -285,7 +286,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'secret'; const mockValue = 'secret';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidKeyaliasPass).toStrictEqual(mockValue); expect(Input.androidKeyaliasPass).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -298,7 +299,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = 'secret'; const mockValue = 'secret';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.androidTargetSdkVersion).toStrictEqual(mockValue); expect(Input.androidTargetSdkVersion).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -310,13 +311,13 @@ describe('Input', () => {
}); });
it('returns true when string true is passed', () => { it('returns true when string true is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('true'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('true');
expect(Input.allowDirtyBuild).toStrictEqual(true); expect(Input.allowDirtyBuild).toStrictEqual(true);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('returns false when string false is passed', () => { it('returns false when string false is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('false'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('false');
expect(Input.allowDirtyBuild).toStrictEqual(false); expect(Input.allowDirtyBuild).toStrictEqual(false);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -329,7 +330,7 @@ describe('Input', () => {
it('takes input from the users workflow', () => { it('takes input from the users workflow', () => {
const mockValue = '-imAFlag'; const mockValue = '-imAFlag';
const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); const spy = vi.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.customParameters).toStrictEqual(mockValue); expect(Input.customParameters).toStrictEqual(mockValue);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
@@ -341,13 +342,13 @@ describe('Input', () => {
}); });
it('returns true when string true is passed', () => { it('returns true when string true is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('true'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('true');
expect(Input.useHostNetwork).toStrictEqual(true); expect(Input.useHostNetwork).toStrictEqual(true);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('returns false when string false is passed', () => { it('returns false when string false is passed', () => {
const spy = jest.spyOn(core, 'getInput').mockReturnValue('false'); const spy = vi.spyOn(core, 'getInput').mockReturnValue('false');
expect(Input.useHostNetwork).toStrictEqual(false); expect(Input.useHostNetwork).toStrictEqual(false);
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });

View File

@@ -47,7 +47,10 @@ class Input {
static get branch(): string { static get branch(): string {
if (Input.getInput(`GITHUB_REF`)) { if (Input.getInput(`GITHUB_REF`)) {
return Input.getInput(`GITHUB_REF`)!.replace('refs/', '').replace(`head/`, '').replace(`heads/`, ''); return Input.getInput(`GITHUB_REF`)!
.replace('refs/', '')
.replace(`head/`, '')
.replace(`heads/`, '');
} else if (Input.getInput('branch')) { } else if (Input.getInput('branch')) {
return Input.getInput('branch')!; return Input.getInput('branch')!;
} else { } else {
@@ -260,7 +263,8 @@ class Input {
} }
return ( return (
Input.getInput('dockerMemoryLimit') ?? `${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m` Input.getInput('dockerMemoryLimit') ??
`${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`
); );
} }

View File

@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';
/** /**
* Compatibility tests for the legacy orchestrator-plugin module name. * Compatibility tests for the legacy orchestrator-plugin module name.
* *

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import Output from './output'; import Output from './output';
describe('Output', () => { describe('Output', () => {

View File

@@ -4,17 +4,30 @@ import { BuildParameters } from '..';
class SetupAndroid { class SetupAndroid {
public static async setup(buildParameters: BuildParameters) { public static async setup(buildParameters: BuildParameters) {
const { targetPlatform, androidKeystoreBase64, androidKeystoreName, projectPath } = buildParameters; const { targetPlatform, androidKeystoreBase64, androidKeystoreName, projectPath } =
buildParameters;
if (targetPlatform === 'Android' && androidKeystoreBase64 !== '' && androidKeystoreName !== '') { if (
targetPlatform === 'Android' &&
androidKeystoreBase64 !== '' &&
androidKeystoreName !== ''
) {
SetupAndroid.setupAndroidRun(androidKeystoreBase64, androidKeystoreName, projectPath); SetupAndroid.setupAndroidRun(androidKeystoreBase64, androidKeystoreName, projectPath);
} }
} }
private static setupAndroidRun(androidKeystoreBase64: string, androidKeystoreName: string, projectPath: string) { private static setupAndroidRun(
androidKeystoreBase64: string,
androidKeystoreName: string,
projectPath: string,
) {
const decodedKeystore = Buffer.from(androidKeystoreBase64, 'base64').toString('binary'); const decodedKeystore = Buffer.from(androidKeystoreBase64, 'base64').toString('binary');
const githubWorkspace = process.env.GITHUB_WORKSPACE || ''; const githubWorkspace = process.env.GITHUB_WORKSPACE || '';
fs.writeFileSync(path.join(githubWorkspace, projectPath, androidKeystoreName), decodedKeystore, 'binary'); fs.writeFileSync(
path.join(githubWorkspace, projectPath, androidKeystoreName),
decodedKeystore,
'binary',
);
} }
} }

View File

@@ -42,7 +42,8 @@ class SetupMac {
} }
} }
const commandSuffix = buildParameters.unityHubVersionOnMac !== '' ? `@${buildParameters.unityHubVersionOnMac}` : ''; const commandSuffix =
buildParameters.unityHubVersionOnMac !== '' ? `@${buildParameters.unityHubVersionOnMac}` : '';
const command = `brew install unity-hub${commandSuffix}`; const command = `brew install unity-hub${commandSuffix}`;
// Ignoring return code because the log seems to overflow the internal buffer which triggers // Ignoring return code because the log seems to overflow the internal buffer which triggers
@@ -52,7 +53,9 @@ class SetupMac {
ignoreReturnCode: true, ignoreReturnCode: true,
}); });
if (errorCode) { if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`); throw new Error(
`There was an error installing the Unity Editor. See logs above for details.`,
);
} }
if (buildParameters.cacheUnityInstallationOnMac) { if (buildParameters.cacheUnityInstallationOnMac) {
@@ -135,7 +138,9 @@ class SetupMac {
} }
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion); const unityChangeset = await getUnityChangeset(buildParameters.editorVersion);
const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform); const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(
buildParameters.targetPlatform,
);
const architectureArguments = SetupMac.getArchitectureParameters(); const architectureArguments = SetupMac.getArchitectureParameters();
const execArguments: string[] = [ const execArguments: string[] = [
@@ -156,7 +161,9 @@ class SetupMac {
ignoreReturnCode: true, ignoreReturnCode: true,
}); });
if (errorCode) { if (errorCode) {
throw new Error(`There was an error installing the Unity Editor. See logs above for details.`); throw new Error(
`There was an error installing the Unity Editor. See logs above for details.`,
);
} }
if (buildParameters.cacheUnityInstallationOnMac) { if (buildParameters.cacheUnityInstallationOnMac) {
@@ -164,7 +171,10 @@ class SetupMac {
} }
} }
private static async setEnvironmentVariables(buildParameters: BuildParameters, actionFolder: string) { private static async setEnvironmentVariables(
buildParameters: BuildParameters,
actionFolder: string,
) {
// Need to set environment variables from here because we execute // Need to set environment variables from here because we execute
// the scripts on the host for mac // the scripts on the host for mac
process.env.ACTION_FOLDER = actionFolder; process.env.ACTION_FOLDER = actionFolder;

View File

@@ -42,7 +42,9 @@ class ValidateWindows {
private static checkForVisualStudio() { private static checkForVisualStudio() {
// Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit // Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit
const visualStudioInstallPathExists = fs.existsSync('C:/Program Files (x86)/Microsoft Visual Studio'); const visualStudioInstallPathExists = fs.existsSync(
'C:/Program Files (x86)/Microsoft Visual Studio',
);
const visualStudioDataPathExists = fs.existsSync('C:/ProgramData/Microsoft/VisualStudio'); const visualStudioDataPathExists = fs.existsSync('C:/ProgramData/Microsoft/VisualStudio');
if (!visualStudioInstallPathExists || !visualStudioDataPathExists) { if (!visualStudioInstallPathExists || !visualStudioDataPathExists) {

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import Platform from './platform'; import Platform from './platform';
describe('Platform', () => { describe('Platform', () => {

View File

@@ -1,3 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
/** /**
* Tests for the generic plugin loader (plugin.ts). * Tests for the generic plugin loader (plugin.ts).
* *
@@ -6,15 +8,15 @@
* orchestrator-specific type. * orchestrator-specific type.
*/ */
const mockWarning = jest.fn(); const mockWarning = vi.fn();
const mockInfo = jest.fn(); const mockInfo = vi.fn();
jest.mock('@actions/core', () => ({ vi.mock('@actions/core', () => ({
warning: mockWarning, warning: mockWarning,
info: mockInfo, info: mockInfo,
})); }));
beforeEach(() => { beforeEach(() => {
jest.resetModules(); vi.resetModules();
mockWarning.mockClear(); mockWarning.mockClear();
mockInfo.mockClear(); mockInfo.mockClear();
}); });
@@ -31,25 +33,24 @@ describe('plugin (default package not installed)', () => {
describe('plugin (default package installed)', () => { describe('plugin (default package installed)', () => {
const fakePlugin = { const fakePlugin = {
initialize: jest.fn(), initialize: vi.fn(),
canHandleBuild: jest.fn().mockReturnValue(false), canHandleBuild: vi.fn().mockReturnValue(false),
handleBuild: jest.fn().mockResolvedValue({ exitCode: 0 }), handleBuild: vi.fn().mockResolvedValue({ exitCode: 0 }),
beforeLocalBuild: jest.fn(), beforeLocalBuild: vi.fn(),
afterLocalBuild: jest.fn(), afterLocalBuild: vi.fn(),
handlePostBuild: jest.fn(), handlePostBuild: vi.fn(),
}; };
const mockCreatePlugin = jest.fn().mockReturnValue(fakePlugin); const mockCreatePlugin = vi.fn().mockReturnValue(fakePlugin);
function installDefaultPluginMock(overrides: Record<string, unknown> = {}) { function installDefaultPluginMock(overrides: Record<string, unknown> = {}) {
jest.doMock( // The `@game-ci/orchestrator` module is intentionally optional and may not
'@game-ci/orchestrator', // be installed. `vi.doMock` lets the dynamic import in the loader resolve
() => ({ // through this factory before vite tries to load a real package.
createPlugin: mockCreatePlugin, vi.doMock('@game-ci/orchestrator', () => ({
...overrides, createPlugin: mockCreatePlugin,
}), ...overrides,
{ virtual: true }, }));
);
} }
beforeEach(() => { beforeEach(() => {
@@ -94,18 +95,20 @@ describe('plugin (default package installed)', () => {
const plugin = await loadPlugin(); const plugin = await loadPlugin();
expect(plugin).toBeUndefined(); expect(plugin).toBeUndefined();
expect(mockWarning).toHaveBeenCalledWith(expect.stringContaining('does not export createPlugin')); expect(mockWarning).toHaveBeenCalledWith(
expect.stringContaining('does not export createPlugin'),
);
}); });
it('propagates non-MODULE_NOT_FOUND errors', async () => { it('propagates non-MODULE_NOT_FOUND errors', async () => {
const importError = new Error('Syntax error in module'); // Throw lazily from `createPlugin` rather than from the mock factory
jest.doMock( // itself: vitest 4 wraps factory-time errors with its own message, which
'@game-ci/orchestrator', // masks the inner error at the assertion site.
() => { installDefaultPluginMock({
throw importError; createPlugin: () => {
throw new Error('Syntax error in module');
}, },
{ virtual: true }, });
);
const { loadPlugin } = await import('./plugin'); const { loadPlugin } = await import('./plugin');
await expect(loadPlugin()).rejects.toThrow('Syntax error in module'); await expect(loadPlugin()).rejects.toThrow('Syntax error in module');

View File

@@ -10,7 +10,6 @@ const DEFAULT_PLUGIN_MODULE = '@game-ci/orchestrator';
* an external implementation can extend or replace the local build flow. * an external implementation can extend or replace the local build flow.
*/ */
export interface Plugin { export interface Plugin {
// eslint-disable-next-line no-unused-vars
initialize(coreParameters: Record<string, any>, workspace: string): Promise<void>; initialize(coreParameters: Record<string, any>, workspace: string): Promise<void>;
/** Whether the plugin wants to handle the entire build. */ /** Whether the plugin wants to handle the entire build. */
@@ -21,19 +20,15 @@ export interface Plugin {
* If the plugin needs to fall back to a local build, it returns * If the plugin needs to fall back to a local build, it returns
* { exitCode: -1, fallbackToLocal: true }. * { exitCode: -1, fallbackToLocal: true }.
*/ */
// eslint-disable-next-line no-unused-vars
handleBuild(baseImage: string): Promise<{ exitCode: number; fallbackToLocal?: boolean }>; handleBuild(baseImage: string): Promise<{ exitCode: number; fallbackToLocal?: boolean }>;
/** Pre-build hook for local builds. */ /** Pre-build hook for local builds. */
// eslint-disable-next-line no-unused-vars
beforeLocalBuild(workspace: string): Promise<void>; beforeLocalBuild(workspace: string): Promise<void>;
/** Post-build hook for local builds. */ /** Post-build hook for local builds. */
// eslint-disable-next-line no-unused-vars
afterLocalBuild(workspace: string, exitCode: number): Promise<void>; afterLocalBuild(workspace: string, exitCode: number): Promise<void>;
/** Post-build hook for all build types. */ /** Post-build hook for all build types. */
// eslint-disable-next-line no-unused-vars
handlePostBuild(exitCode: number): Promise<void>; handlePostBuild(exitCode: number): Promise<void>;
} }
@@ -74,5 +69,8 @@ function isModuleNotFoundError(error: unknown): boolean {
} }
} }
return typeof (error as Error)?.message === 'string' && /cannot find module/i.test((error as Error).message); return (
typeof (error as Error)?.message === 'string' &&
/cannot find module/i.test((error as Error).message)
);
} }

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import Project from './project'; import Project from './project';
jest.mock('./input'); vi.mock('./input');
describe('Platform', () => { describe('Platform', () => {
describe('relativePath', () => { describe('relativePath', () => {

View File

@@ -1,12 +1,13 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import * as core from '@actions/core'; import * as core from '@actions/core';
import System from './system'; import System from './system';
jest.spyOn(core, 'debug').mockImplementation(() => {}); vi.spyOn(core, 'debug').mockImplementation(() => {});
jest.spyOn(core, 'info').mockImplementation(() => {}); vi.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(core, 'warning').mockImplementation(() => {}); vi.spyOn(core, 'warning').mockImplementation(() => {});
jest.spyOn(core, 'error').mockImplementation(() => {}); vi.spyOn(core, 'error').mockImplementation(() => {});
afterEach(() => jest.clearAllMocks()); afterEach(() => vi.clearAllMocks());
describe('System', () => { describe('System', () => {
describe('run', () => { describe('run', () => {

View File

@@ -1,21 +1,26 @@
import { describe, it, expect, beforeEach, afterEach, beforeAll, afterAll, vi } from 'vitest';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import System from './system'; import System from './system';
jest.spyOn(core, 'debug').mockImplementation(() => {}); vi.spyOn(core, 'debug').mockImplementation(() => {});
const info = jest.spyOn(core, 'info').mockImplementation(() => {}); const info = vi.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(core, 'warning').mockImplementation(() => {}); vi.spyOn(core, 'warning').mockImplementation(() => {});
jest.spyOn(core, 'error').mockImplementation(() => {}); vi.spyOn(core, 'error').mockImplementation(() => {});
const execSpy = jest.spyOn(exec, 'exec').mockImplementation(async () => 0); const execSpy = vi.spyOn(exec, 'exec').mockImplementation(async () => 0);
afterEach(() => jest.clearAllMocks()); afterEach(() => vi.clearAllMocks());
describe('System', () => { describe('System', () => {
describe('run', () => { describe('run', () => {
describe('units', () => { describe('units', () => {
it('passes the command to command line', async () => { it('passes the command to command line', async () => {
await expect(System.run('echo test')).resolves.not.toBeNull(); await expect(System.run('echo test')).resolves.not.toBeNull();
await expect(execSpy).toHaveBeenLastCalledWith('echo test', expect.anything(), expect.anything()); await expect(execSpy).toHaveBeenLastCalledWith(
'echo test',
expect.anything(),
expect.anything(),
);
}); });
it('throws on when error code is not 0', async () => { it('throws on when error code is not 0', async () => {

View File

@@ -1,3 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll, test } from 'vitest';
import UnityVersioning from './unity-versioning'; import UnityVersioning from './unity-versioning';
describe('Unity Versioning', () => { describe('Unity Versioning', () => {

View File

@@ -13,7 +13,9 @@ export default class UnityVersioning {
static read(projectPath: string) { static read(projectPath: string) {
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt'); const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
throw new Error(`Project settings file not found at "${filePath}". Have you correctly set the projectPath?`); throw new Error(
`Project settings file not found at "${filePath}". Have you correctly set the projectPath?`,
);
} }
return UnityVersioning.parse(fs.readFileSync(filePath, 'utf8')); return UnityVersioning.parse(fs.readFileSync(filePath, 'utf8'));

View File

@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import Unity from './unity'; import Unity from './unity';
describe('Unity', () => { describe('Unity', () => {

View File

@@ -1,3 +1,4 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, test, vi } from 'vitest';
import * as core from '@actions/core'; import * as core from '@actions/core';
import NotImplementedException from './error/not-implemented-exception'; import NotImplementedException from './error/not-implemented-exception';
import System from './system'; import System from './system';
@@ -5,7 +6,7 @@ import Versioning from './versioning';
import { validVersionTagInputs, invalidVersionTagInputs } from './__data__/versions'; import { validVersionTagInputs, invalidVersionTagInputs } from './__data__/versions';
afterEach(() => { afterEach(() => {
jest.restoreAllMocks(); vi.restoreAllMocks();
}); });
describe('Versioning', () => { describe('Versioning', () => {
@@ -39,7 +40,9 @@ describe('Versioning', () => {
// eslint-disable-next-line unicorn/consistent-function-scoping // eslint-disable-next-line unicorn/consistent-function-scoping
const matchInputUsingGrep = async (input: string) => { const matchInputUsingGrep = async (input: string) => {
const output = await System.run('sh', undefined, { const output = await System.run('sh', undefined, {
input: Buffer.from(`echo '${input}' | grep -E '${Versioning.grepCompatibleInputVersionRegex}'`), input: Buffer.from(
`echo '${input}' | grep -E '${Versioning.grepCompatibleInputVersionRegex}'`,
),
silent: true, silent: true,
}); });
@@ -50,30 +53,39 @@ describe('Versioning', () => {
expect(await matchInputUsingGrep(input)).toStrictEqual(input); expect(await matchInputUsingGrep(input)).toStrictEqual(input);
}); });
it.concurrent.each(invalidVersionTagInputs)(`rejects non-version tag input '%s'`, async (input) => { it.concurrent.each(invalidVersionTagInputs)(
await expect(async () => matchInputUsingGrep(input)).rejects.toThrowError(/^Failed to run/); `rejects non-version tag input '%s'`,
}); async (input) => {
await expect(async () => matchInputUsingGrep(input)).rejects.toThrowError(/^Failed to run/);
},
);
}); });
describe('branch', () => { describe('branch', () => {
it('returns headRef when set', () => { it('returns headRef when set', () => {
const headReference = jest.spyOn(Versioning, 'headRef', 'get').mockReturnValue('feature-branch-1'); const headReference = vi
.spyOn(Versioning, 'headRef', 'get')
.mockReturnValue('feature-branch-1');
expect(Versioning.branch).toStrictEqual('feature-branch-1'); expect(Versioning.branch).toStrictEqual('feature-branch-1');
expect(headReference).toHaveBeenCalledTimes(1); expect(headReference).toHaveBeenCalledTimes(1);
}); });
it('returns part of Ref when set', () => { it('returns part of Ref when set', () => {
jest.spyOn(Versioning, 'headRef', 'get').mockImplementation(); vi.spyOn(Versioning, 'headRef', 'get').mockImplementation(() => undefined);
const reference = jest.spyOn(Versioning, 'ref', 'get').mockReturnValue('refs/heads/feature-branch-2'); const reference = vi
.spyOn(Versioning, 'ref', 'get')
.mockReturnValue('refs/heads/feature-branch-2');
expect(Versioning.branch).toStrictEqual('feature-branch-2'); expect(Versioning.branch).toStrictEqual('feature-branch-2');
expect(reference).toHaveBeenCalledTimes(1); expect(reference).toHaveBeenCalledTimes(1);
}); });
it('prefers headRef over ref when set', () => { it('prefers headRef over ref when set', () => {
const headReference = jest.spyOn(Versioning, 'headRef', 'get').mockReturnValue('feature-branch-1'); const headReference = vi
const reference = jest.spyOn(Versioning, 'ref', 'get').mockReturnValue('refs/heads/feature-2'); .spyOn(Versioning, 'headRef', 'get')
.mockReturnValue('feature-branch-1');
const reference = vi.spyOn(Versioning, 'ref', 'get').mockReturnValue('refs/heads/feature-2');
expect(Versioning.branch).toStrictEqual('feature-branch-1'); expect(Versioning.branch).toStrictEqual('feature-branch-1');
expect(headReference).toHaveBeenCalledTimes(1); expect(headReference).toHaveBeenCalledTimes(1);
@@ -81,8 +93,10 @@ describe('Versioning', () => {
}); });
it('returns undefined when headRef and ref are not set', () => { it('returns undefined when headRef and ref are not set', () => {
const headReference = jest.spyOn(Versioning, 'headRef', 'get').mockImplementation(); const headReference = vi
const reference = jest.spyOn(Versioning, 'ref', 'get').mockImplementation(); .spyOn(Versioning, 'headRef', 'get')
.mockImplementation(() => undefined);
const reference = vi.spyOn(Versioning, 'ref', 'get').mockImplementation(() => undefined);
expect(Versioning.branch).not.toBeDefined(); expect(Versioning.branch).not.toBeDefined();
@@ -106,16 +120,19 @@ describe('Versioning', () => {
describe('logging git diff', () => { describe('logging git diff', () => {
it('calls git diff', async () => { it('calls git diff', async () => {
// allowDirtyBuild: true // allowDirtyBuild: true
jest.spyOn(core, 'getInput').mockReturnValue('true'); vi.spyOn(core, 'getInput').mockReturnValue('true');
jest.spyOn(Versioning, 'isShallow').mockResolvedValue(true); vi.spyOn(Versioning, 'isShallow').mockResolvedValue(true);
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false); vi.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
jest.spyOn(Versioning, 'fetch').mockImplementation(); vi.spyOn(Versioning, 'fetch').mockResolvedValue();
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true); vi.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true);
jest vi.spyOn(Versioning, 'parseSemanticVersion').mockResolvedValue({
.spyOn(Versioning, 'parseSemanticVersion') match: '',
.mockResolvedValue({ match: '', tag: 'mocktag', commits: 'abcdef', hash: '75822BCAF' }); tag: 'mocktag',
const logDiffSpy = jest.spyOn(Versioning, 'logDiff'); commits: 'abcdef',
const gitSpy = jest.spyOn(System, 'run').mockImplementation(); hash: '75822BCAF',
});
const logDiffSpy = vi.spyOn(Versioning, 'logDiff');
const gitSpy = vi.spyOn(System, 'run').mockResolvedValue('');
await Versioning.generateSemanticVersion(); await Versioning.generateSemanticVersion();
@@ -157,12 +174,16 @@ describe('Versioning', () => {
describe('determineBuildVersion', () => { describe('determineBuildVersion', () => {
test.each(['somethingRandom'])('throws for invalid strategy %s', async (strategy) => { test.each(['somethingRandom'])('throws for invalid strategy %s', async (strategy) => {
await expect(Versioning.determineBuildVersion(strategy, '')).rejects.toThrowErrorMatchingSnapshot(); await expect(
Versioning.determineBuildVersion(strategy, ''),
).rejects.toThrowErrorMatchingSnapshot();
}); });
describe('opt out strategy', () => { describe('opt out strategy', () => {
it("returns 'none'", async () => { it("returns 'none'", async () => {
await expect(Versioning.determineBuildVersion('None', 'v1.0')).resolves.toMatchInlineSnapshot(`"none"`); await expect(
Versioning.determineBuildVersion('None', 'v1.0'),
).resolves.toMatchInlineSnapshot(`"none"`);
}); });
}); });
@@ -170,23 +191,31 @@ describe('Versioning', () => {
test.each(['v0.1', '1', 'CamelCase', 'dashed-version'])( test.each(['v0.1', '1', 'CamelCase', 'dashed-version'])(
'returns the inputVersion for %s', 'returns the inputVersion for %s',
async (inputVersion) => { async (inputVersion) => {
await expect(Versioning.determineBuildVersion('Custom', inputVersion)).resolves.toStrictEqual(inputVersion); await expect(
Versioning.determineBuildVersion('Custom', inputVersion),
).resolves.toStrictEqual(inputVersion);
}, },
); );
}); });
describe('semantic strategy', () => { describe('semantic strategy', () => {
it('refers to generateSemanticVersion', async () => { it('refers to generateSemanticVersion', async () => {
const generateSemanticVersion = jest.spyOn(Versioning, 'generateSemanticVersion').mockResolvedValue('1.3.37'); const generateSemanticVersion = vi
.spyOn(Versioning, 'generateSemanticVersion')
.mockResolvedValue('1.3.37');
await expect(Versioning.determineBuildVersion('Semantic', '')).resolves.toStrictEqual('1.3.37'); await expect(Versioning.determineBuildVersion('Semantic', '')).resolves.toStrictEqual(
'1.3.37',
);
expect(generateSemanticVersion).toHaveBeenCalledTimes(1); expect(generateSemanticVersion).toHaveBeenCalledTimes(1);
}); });
}); });
describe('tag strategy', () => { describe('tag strategy', () => {
it('refers to generateTagVersion', async () => { it('refers to generateTagVersion', async () => {
const generateTagVersion = jest.spyOn(Versioning, 'generateTagVersion').mockResolvedValue('0.1'); const generateTagVersion = vi
.spyOn(Versioning, 'generateTagVersion')
.mockResolvedValue('0.1');
await expect(Versioning.determineBuildVersion('Tag', '')).resolves.toStrictEqual('0.1'); await expect(Versioning.determineBuildVersion('Tag', '')).resolves.toStrictEqual('0.1');
expect(generateTagVersion).toHaveBeenCalledTimes(1); expect(generateTagVersion).toHaveBeenCalledTimes(1);
@@ -197,22 +226,24 @@ describe('Versioning', () => {
it('throws a not implemented exception', async () => { it('throws a not implemented exception', async () => {
const strategy = 'Test'; const strategy = 'Test';
// @ts-ignore // @ts-ignore
jest.spyOn(Versioning, 'strategies', 'get').mockReturnValue({ [strategy]: strategy }); vi.spyOn(Versioning, 'strategies', 'get').mockReturnValue({ [strategy]: strategy });
await expect(Versioning.determineBuildVersion(strategy, '')).rejects.toThrowError(NotImplementedException); await expect(Versioning.determineBuildVersion(strategy, '')).rejects.toThrowError(
NotImplementedException,
);
}); });
}); });
}); });
describe('generateTagVersion', () => { describe('generateTagVersion', () => {
it('removes the v', async () => { it('removes the v', async () => {
jest.spyOn(Versioning, 'getTag').mockResolvedValue('v1.3.37'); vi.spyOn(Versioning, 'getTag').mockResolvedValue('v1.3.37');
await expect(Versioning.generateTagVersion()).resolves.toStrictEqual('1.3.37'); await expect(Versioning.generateTagVersion()).resolves.toStrictEqual('1.3.37');
}); });
}); });
describe('parseSemanticVersion', () => { describe('parseSemanticVersion', () => {
it('returns the named parts', async () => { it('returns the named parts', async () => {
jest.spyOn(Versioning, 'getVersionDescription').mockResolvedValue('v0.1-2-g12345678'); vi.spyOn(Versioning, 'getVersionDescription').mockResolvedValue('v0.1-2-g12345678');
await expect(Versioning.parseSemanticVersion()).resolves.toMatchObject({ await expect(Versioning.parseSemanticVersion()).resolves.toMatchObject({
tag: '0.1', tag: '0.1',
@@ -222,7 +253,7 @@ describe('Versioning', () => {
}); });
it('throws when no match could be made', async () => { it('throws when no match could be made', async () => {
jest.spyOn(Versioning, 'getVersionDescription').mockResolvedValue('no-match-can-be-made'); vi.spyOn(Versioning, 'getVersionDescription').mockResolvedValue('no-match-can-be-made');
await expect(Versioning.parseSemanticVersion()).toMatchObject({}); await expect(Versioning.parseSemanticVersion()).toMatchObject({});
}); });
@@ -231,7 +262,7 @@ describe('Versioning', () => {
describe('getVersionDescription', () => { describe('getVersionDescription', () => {
it('returns the commands output', async () => { it('returns the commands output', async () => {
const runOutput = 'someValue'; const runOutput = 'someValue';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.getVersionDescription()).resolves.toStrictEqual(runOutput); await expect(Versioning.getVersionDescription()).resolves.toStrictEqual(runOutput);
}); });
}); });
@@ -239,27 +270,27 @@ describe('Versioning', () => {
describe('isShallow', () => { describe('isShallow', () => {
it('returns true when the repo is shallow', async () => { it('returns true when the repo is shallow', async () => {
const runOutput = 'true\n'; const runOutput = 'true\n';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isShallow()).resolves.toStrictEqual(true); await expect(Versioning.isShallow()).resolves.toStrictEqual(true);
}); });
it('returns false when the repo is not shallow', async () => { it('returns false when the repo is not shallow', async () => {
const runOutput = 'false\n'; const runOutput = 'false\n';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isShallow()).resolves.toStrictEqual(false); await expect(Versioning.isShallow()).resolves.toStrictEqual(false);
}); });
}); });
describe('fetch', () => { describe('fetch', () => {
it('awaits the command', async () => { it('awaits the command', async () => {
jest.spyOn(core, 'warning').mockImplementation(() => {}); vi.spyOn(core, 'warning').mockImplementation(() => {});
jest.spyOn(System, 'run').mockImplementation(); vi.spyOn(System, 'run').mockResolvedValue('');
await expect(Versioning.fetch()).resolves.not.toThrow(); await expect(Versioning.fetch()).resolves.not.toThrow();
}); });
it('falls back to the second strategy when the first fails', async () => { it('falls back to the second strategy when the first fails', async () => {
jest.spyOn(core, 'warning').mockImplementation(() => {}); vi.spyOn(core, 'warning').mockImplementation(() => {});
const gitFetch = jest.spyOn(System, 'run').mockImplementation(); const gitFetch = vi.spyOn(System, 'run').mockResolvedValue('');
await expect(Versioning.fetch()).resolves.not.toThrow(); await expect(Versioning.fetch()).resolves.not.toThrow();
expect(gitFetch).toHaveBeenCalledTimes(1); expect(gitFetch).toHaveBeenCalledTimes(1);
@@ -268,12 +299,12 @@ describe('Versioning', () => {
describe('generateSemanticVersion', () => { describe('generateSemanticVersion', () => {
it('returns a proper version from description', async () => { it('returns a proper version from description', async () => {
jest.spyOn(System, 'run').mockImplementation(); vi.spyOn(System, 'run').mockResolvedValue('');
jest.spyOn(core, 'info').mockImplementation(() => {}); vi.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false); vi.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true); vi.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(true);
jest.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(2); vi.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(2);
jest.spyOn(Versioning, 'parseSemanticVersion').mockResolvedValue({ vi.spyOn(Versioning, 'parseSemanticVersion').mockResolvedValue({
match: '0.1-2-g1b345678', match: '0.1-2-g1b345678',
tag: '0.1', tag: '0.1',
commits: '2', commits: '2',
@@ -284,19 +315,19 @@ describe('Versioning', () => {
}); });
it('throws when dirty', async () => { it('throws when dirty', async () => {
jest.spyOn(System, 'run').mockImplementation(); vi.spyOn(System, 'run').mockResolvedValue('');
jest.spyOn(core, 'info').mockImplementation(() => {}); vi.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(true); vi.spyOn(Versioning, 'isDirty').mockResolvedValue(true);
await expect(Versioning.generateSemanticVersion()).rejects.toThrowError(); await expect(Versioning.generateSemanticVersion()).rejects.toThrowError();
}); });
it('falls back to commits only, when no tags are present', async () => { it('falls back to commits only, when no tags are present', async () => {
const commits = Math.round(Math.random() * 10); const commits = Math.round(Math.random() * 10);
jest.spyOn(System, 'run').mockImplementation(); vi.spyOn(System, 'run').mockResolvedValue('');
jest.spyOn(core, 'info').mockImplementation(() => {}); vi.spyOn(core, 'info').mockImplementation(() => {});
jest.spyOn(Versioning, 'isDirty').mockResolvedValue(false); vi.spyOn(Versioning, 'isDirty').mockResolvedValue(false);
jest.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(false); vi.spyOn(Versioning, 'hasAnyVersionTags').mockResolvedValue(false);
jest.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(commits); vi.spyOn(Versioning, 'getTotalNumberOfCommits').mockResolvedValue(commits);
await expect(Versioning.generateSemanticVersion()).resolves.toStrictEqual(`0.0.${commits}`); await expect(Versioning.generateSemanticVersion()).resolves.toStrictEqual(`0.0.${commits}`);
}); });
@@ -305,13 +336,13 @@ describe('Versioning', () => {
describe('isDirty', () => { describe('isDirty', () => {
it('returns true when there are files listed', async () => { it('returns true when there are files listed', async () => {
const runOutput = 'file.ext\nfile2.ext'; const runOutput = 'file.ext\nfile2.ext';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isDirty()).resolves.toStrictEqual(true); await expect(Versioning.isDirty()).resolves.toStrictEqual(true);
}); });
it('returns false when there is no output', async () => { it('returns false when there is no output', async () => {
const runOutput = ''; const runOutput = '';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.isDirty()).resolves.toStrictEqual(false); await expect(Versioning.isDirty()).resolves.toStrictEqual(false);
}); });
}); });
@@ -319,7 +350,7 @@ describe('Versioning', () => {
describe('getTag', () => { describe('getTag', () => {
it('returns the commands output', async () => { it('returns the commands output', async () => {
const runOutput = 'v1.0'; const runOutput = 'v1.0';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.getTag()).resolves.toStrictEqual(runOutput); await expect(Versioning.getTag()).resolves.toStrictEqual(runOutput);
}); });
}); });
@@ -327,20 +358,20 @@ describe('Versioning', () => {
describe('hasAnyVersionTags', () => { describe('hasAnyVersionTags', () => {
it('returns false when the command returns 0', async () => { it('returns false when the command returns 0', async () => {
const runOutput = '0'; const runOutput = '0';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.hasAnyVersionTags()).resolves.toStrictEqual(false); await expect(Versioning.hasAnyVersionTags()).resolves.toStrictEqual(false);
}); });
it('returns true when the command returns >= 0', async () => { it('returns true when the command returns >= 0', async () => {
const runOutput = '9'; const runOutput = '9';
jest.spyOn(System, 'run').mockResolvedValue(runOutput); vi.spyOn(System, 'run').mockResolvedValue(runOutput);
await expect(Versioning.hasAnyVersionTags()).resolves.toStrictEqual(true); await expect(Versioning.hasAnyVersionTags()).resolves.toStrictEqual(true);
}); });
}); });
describe('getTotalNumberOfCommits', () => { describe('getTotalNumberOfCommits', () => {
it('returns a number from the command', async () => { it('returns a number from the command', async () => {
jest.spyOn(System, 'run').mockResolvedValue('9'); vi.spyOn(System, 'run').mockResolvedValue('9');
await expect(Versioning.getTotalNumberOfCommits()).resolves.toStrictEqual(9); await expect(Versioning.getTotalNumberOfCommits()).resolves.toStrictEqual(9);
}); });
}); });

View File

@@ -71,7 +71,9 @@ export default class Versioning {
static async determineBuildVersion(strategy: string, inputVersion: string): Promise<string> { static async determineBuildVersion(strategy: string, inputVersion: string): Promise<string> {
// Validate input // Validate input
if (!Object.hasOwnProperty.call(this.strategies, strategy)) { if (!Object.hasOwnProperty.call(this.strategies, strategy)) {
throw new ValidationError(`Versioning strategy should be one of ${Object.values(this.strategies).join(', ')}.`); throw new ValidationError(
`Versioning strategy should be one of ${Object.values(this.strategies).join(', ')}.`,
);
} }
switch (strategy) { switch (strategy) {
@@ -122,7 +124,9 @@ export default class Versioning {
// Ensure 3 digits (commits should always be patch level) // Ensure 3 digits (commits should always be patch level)
const [major, minor, patch] = `${tag}.${commits}`.split('.'); const [major, minor, patch] = `${tag}.${commits}`.split('.');
const threeDigitVersion = /^\d+$/.test(patch) ? `${major}.${minor}.${patch}` : `${major}.0.${minor}`; const threeDigitVersion = /^\d+$/.test(patch)
? `${major}.${minor}.${patch}`
: `${major}.0.${minor}`;
core.info(`Found semantic version ${threeDigitVersion} for ${this.branch}@${hash}`); core.info(`Found semantic version ${threeDigitVersion} for ${this.branch}@${hash}`);
@@ -168,7 +172,9 @@ export default class Versioning {
} }
} }
core.warning(`Failed to parse git describe output or version can not be determined through: "${description}".`); core.warning(
`Failed to parse git describe output or version can not be determined through: "${description}".`,
);
return false; return false;
} }
@@ -207,7 +213,9 @@ export default class Versioning {
* identifies the current commit. * identifies the current commit.
*/ */
static async getVersionDescription() { static async getVersionDescription() {
const versionTags = (await this.git(['tag', '--list', '--merged', 'HEAD', '--sort=-creatordate'])) const versionTags = (
await this.git(['tag', '--list', '--merged', 'HEAD', '--sort=-creatordate'])
)
.split('\n') .split('\n')
.filter((tag) => new RegExp(this.grepCompatibleInputVersionRegex).test(tag)); .filter((tag) => new RegExp(this.grepCompatibleInputVersionRegex).test(tag));
@@ -218,7 +226,9 @@ export default class Versioning {
} }
const latestVersionTag = versionTags[0]; const latestVersionTag = versionTags[0];
const commitsCount = (await this.git(['rev-list', `${latestVersionTag}..HEAD`, '--count'])).trim(); const commitsCount = (
await this.git(['rev-list', `${latestVersionTag}..HEAD`, '--count'])
).trim();
const commitHash = (await this.git(['rev-parse', '--short', 'HEAD'])).trim(); const commitHash = (await this.git(['rev-parse', '--short', 'HEAD'])).trim();
return `${latestVersionTag}-${commitsCount}-g${commitHash}`; return `${latestVersionTag}-${commitsCount}-g${commitHash}`;
@@ -253,7 +263,9 @@ export default class Versioning {
*/ */
static async hasAnyVersionTags() { static async hasAnyVersionTags() {
const numberOfTagsAsString = await System.run('sh', undefined, { const numberOfTagsAsString = await System.run('sh', undefined, {
input: Buffer.from(`git tag --list --merged HEAD | grep -E '${this.grepCompatibleInputVersionRegex}' | wc -l`), input: Buffer.from(
`git tag --list --merged HEAD | grep -E '${this.grepCompatibleInputVersionRegex}' | wc -l`,
),
cwd: Input.projectPath, cwd: Input.projectPath,
silent: false, silent: false,
}); });

30
src/test/setup.ts Normal file
View File

@@ -0,0 +1,30 @@
import { afterEach, beforeEach } from 'vitest';
// Fail tests when console.error / console.warn etc are called from
// production code under test. Mirrors the jest-fail-on-console behaviour
// the previous jest setup enforced. Tests can opt-out by replacing the
// method with vi.spyOn(console, 'error') for the duration of that test.
const original = {
log: console.log,
warn: console.warn,
error: console.error,
assert: console.assert,
};
const fail = (level: 'log' | 'warn' | 'error' | 'assert', args: unknown[]) => {
throw new Error(
`console.${level} was called with: ${args.map(String).join(' ')}\n` +
`Tests must use vi.spyOn(console, '${level}') if console output is expected.`,
);
};
beforeEach(() => {
console.log = (...args: unknown[]) => fail('log', args);
console.warn = (...args: unknown[]) => fail('warn', args);
console.error = (...args: unknown[]) => fail('error', args);
console.assert = ((...args: unknown[]) => fail('assert', args)) as typeof console.assert;
});
afterEach(() => {
Object.assign(console, original);
});

View File

@@ -1,14 +1,19 @@
{ {
"compilerOptions": { "compilerOptions": {
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, "target": "ES2022",
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, "lib": ["ES2022", "DOM"],
"outDir": "./lib" /* Redirect output structure to the directory. */, "module": "commonjs",
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, "moduleResolution": "node",
"strict": true /* Enable all strict type-checking options. */, "outDir": "./lib",
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, "rootDir": "./src",
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ "strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node"]
}, },
"include": ["src/**/*", "types/**/*"], "include": ["src/**/*", "types/**/*"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist", "lib"]
} }

View File

@@ -13,4 +13,3 @@ declare module 'shell-quote' {
*/ */
export function parse(cmd: string): string[]; export function parse(cmd: string): string[];
} }

16
vitest.config.mts Normal file
View File

@@ -0,0 +1,16 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
globals: true,
setupFiles: ['./src/test/setup.ts'],
include: ['src/**/*.test.ts'],
coverage: {
provider: 'istanbul',
reporter: ['text', 'html', 'lcov'],
include: ['src/**/*.ts'],
exclude: ['src/**/*.test.ts', 'src/index.ts'],
},
},
});

7240
yarn.lock

File diff suppressed because it is too large Load Diff