diff --git a/src/plugins/shadowdog-local-cache.test.ts b/src/plugins/shadowdog-local-cache.test.ts index f083e31..7bc0537 100644 --- a/src/plugins/shadowdog-local-cache.test.ts +++ b/src/plugins/shadowdog-local-cache.test.ts @@ -1,5 +1,5 @@ import fs from 'fs-extra' -import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest' +import { describe, it, beforeEach, afterEach, vi, expect, afterAll } from 'vitest' import shadowdogLocalCache, { compressArtifact } from './shadowdog-local-cache' describe('shadowdog local cache', () => { @@ -117,4 +117,42 @@ describe('shadowdog local cache', () => { }) }) }) + + describe('when local cache path is overriden by env var', () => { + beforeEach(async () => { + vi.stubEnv('SHADOWDOG_LOCAL_CACHE_PATH', 'tmp/tests/cache_overriden') + fs.writeFileSync('tmp/tests/artifacts/foo', 'foo') + }) + + afterAll(() => { + vi.unstubAllEnvs() + }) + + it('stores the cache in the defined path', async () => { + await shadowdogLocalCache.middleware({ + config: { + command: 'echo foo', + artifacts: [ + { + output: 'tmp/tests/artifacts/foo', + }, + ], + tags: [], + workingDirectory: '', + }, + files: [], + invalidators: { + environment: [], + files: [], + }, + next, + abort: () => {}, + options: { + path: 'tmp/tests/cache', + }, + }) + expect(fs.existsSync('tmp/tests/cache/0adeca2ac6.tar.gz')).toBe(false) + expect(fs.existsSync('tmp/tests/cache_overriden/0adeca2ac6.tar.gz')).toBe(true) + }) + }) }) diff --git a/src/plugins/shadowdog-local-cache.ts b/src/plugins/shadowdog-local-cache.ts index 3915b71..0b38c9d 100644 --- a/src/plugins/shadowdog-local-cache.ts +++ b/src/plugins/shadowdog-local-cache.ts @@ -184,6 +184,8 @@ const middleware: Middleware = async ({ const mergedOptions = pluginOptionsSchema.parse(options) + mergedOptions.path = process.env.SHADOWDOG_LOCAL_CACHE_PATH ?? mergedOptions.path + const currentCache = computeCache([...files, ...invalidators.files], invalidators.environment) fs.mkdirpSync(mergedOptions.path)