From cfe068d683aef103a68f3b97a4924ee97ce320c9 Mon Sep 17 00:00:00 2001 From: Tristan Menzel Date: Fri, 6 Dec 2024 08:10:00 -0800 Subject: [PATCH] build: Tweak approval tests for ci --- .github/workflows/ci-all.yml | 1 + package-lock.json | 20 ++++++++++++++++++++ package.json | 3 ++- tests/approvals.spec.ts | 15 ++++++++++----- tests/constants.ts | 3 +++ 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tests/constants.ts diff --git a/.github/workflows/ci-all.yml b/.github/workflows/ci-all.yml index c9458b6f..5ef9987e 100644 --- a/.github/workflows/ci-all.yml +++ b/.github/workflows/ci-all.yml @@ -49,3 +49,4 @@ jobs: pipx install algokit --python 3.12.6 algokit localnet reset --update pipx install git+https://github.com/algorandfoundation/puya --python 3.12.6 + test-script: npm run test:ci diff --git a/package-lock.json b/package-lock.json index 218577eb..1679b107 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "better-npm-audit": "3.11.0", "conventional-changelog-conventionalcommits": "^8.0.0", "copyfiles": "2.4.1", + "cross-env": "^7.0.3", "eslint": "9.15.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", @@ -3834,6 +3835,25 @@ "typescript": ">=4" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", diff --git a/package.json b/package.json index 3ff0a0ce..c926bf2c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "test:approvals": "vitest run tests/approvals.spec.ts", "test:expected-output": "vitest run tests/expected-output.spec.ts", "test:coverage": "vitest run --coverage", - "test:ci": "vitest run --coverage --reporter junit --outputFile test-results.xml", + "test:ci": "cross-env NODE_ENV=ci vitest run --coverage --reporter junit --outputFile test-results.xml", "install-local-packages": "npm run algo-ts", "watch-local-packages": "npm run algo-ts:build:watch", "algo-ts": "run-s algo-ts:*", @@ -60,6 +60,7 @@ "better-npm-audit": "3.11.0", "conventional-changelog-conventionalcommits": "^8.0.0", "copyfiles": "2.4.1", + "cross-env": "^7.0.3", "eslint": "9.15.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", diff --git a/tests/approvals.spec.ts b/tests/approvals.spec.ts index 770f88d4..d41b9b00 100644 --- a/tests/approvals.spec.ts +++ b/tests/approvals.spec.ts @@ -6,9 +6,12 @@ import { buildCompileOptions } from '../src/compile-options' import { isErrorOrCritical, LoggingContext, LogLevel } from '../src/logger' import { defaultPuyaOptions } from '../src/puya/options' import { invariant } from '../src/util' +import { Environment } from './constants' describe('Approvals', async () => { - await rimraf('tests/approvals/out') + if (Environment.IsCi) { + await rimraf('tests/approvals/out') + } using logCtx = LoggingContext.create() const result = compile( @@ -55,10 +58,12 @@ describe('Approvals', async () => { }) it('There should be no differences to committed changes', () => { - // // Run git add to force line ending changes - // sync('git', ['add', '.'], { - // stdio: 'inherit', - // }) + if (Environment.IsCi) { + // Run git add to force line ending changes + sync('git', ['add', '.'], { + stdio: 'inherit', + }) + } const result = sync('git', ['status', '--porcelain'], { stdio: 'pipe', }) diff --git a/tests/constants.ts b/tests/constants.ts new file mode 100644 index 00000000..13ee3391 --- /dev/null +++ b/tests/constants.ts @@ -0,0 +1,3 @@ +export const Environment = { + IsCi: process.env.NODE_ENV === 'ci', +} as const