From 66eda436d614086fd9a820adb3c3557a53b33243 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 9 Jun 2026 00:36:38 +0100 Subject: [PATCH] Clean up utility test setup --- test/unit/src/configuration/resolve-path.test.js | 3 +-- test/unit/src/state/LocalStateStorage.test.js | 3 +-- test/unit/src/utils/cache-hash.test.js | 5 ++--- test/unit/src/utils/fs.test.js | 3 +-- test/unit/src/utils/glob.test.js | 3 +-- .../log-reporters/node/progress-reporter.test.js | 4 ---- test/unit/src/utils/spawn.test.js | 3 +-- 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/test/unit/src/configuration/resolve-path.test.js b/test/unit/src/configuration/resolve-path.test.js index 3ddc2c3..c0f158c 100644 --- a/test/unit/src/configuration/resolve-path.test.js +++ b/test/unit/src/configuration/resolve-path.test.js @@ -1,7 +1,6 @@ 'use strict'; const fs = require('node:fs').promises; -const os = require('node:os'); const path = require('node:path'); const { expect } = require('chai'); @@ -12,7 +11,7 @@ describe('test/unit/src/configuration/resolve-path.test.js', () => { let tmpDir; beforeEach(async () => { - tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'compose-resolve-path-')); + tmpDir = await fs.mkdtemp(path.join(process.cwd(), 'compose-resolve-path-')); }); afterEach(async () => { diff --git a/test/unit/src/state/LocalStateStorage.test.js b/test/unit/src/state/LocalStateStorage.test.js index 32963e9..9f6acd9 100644 --- a/test/unit/src/state/LocalStateStorage.test.js +++ b/test/unit/src/state/LocalStateStorage.test.js @@ -1,6 +1,5 @@ 'use strict'; -const os = require('os'); const path = require('path'); const fsp = require('fs').promises; const expect = require('chai').expect; @@ -12,7 +11,7 @@ describe('test/unit/src/state/LocalStateStorage.test.js', () => { let rootDir; beforeEach(async () => { - rootDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'compose-local-state-')); + rootDir = await fsp.mkdtemp(path.join(process.cwd(), 'compose-local-state-')); await ensureDir(path.join(rootDir, '.serverless')); }); diff --git a/test/unit/src/utils/cache-hash.test.js b/test/unit/src/utils/cache-hash.test.js index cef02ef..f0e266c 100644 --- a/test/unit/src/utils/cache-hash.test.js +++ b/test/unit/src/utils/cache-hash.test.js @@ -2,7 +2,6 @@ const fs = require('node:fs').promises; const crypto = require('node:crypto'); -const os = require('node:os'); const path = require('node:path'); const proxyquire = require('proxyquire'); const { expect } = require('chai'); @@ -25,7 +24,7 @@ describe('test/unit/src/utils/cache-hash.test.js', () => { let tmpDir; beforeEach(async () => { - tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'compose-cache-hash-')); + tmpDir = await fs.mkdtemp(path.join(process.cwd(), 'compose-cache-hash-')); }); afterEach(async () => { @@ -87,7 +86,7 @@ describe('test/unit/src/utils/cache-hash.test.js', () => { }); it('does not include file paths in cache hashes', async () => { - const otherDir = await fs.mkdtemp(path.join(os.tmpdir(), 'compose-cache-hash-other-')); + const otherDir = await fs.mkdtemp(path.join(process.cwd(), 'compose-cache-hash-other-')); try { await outputFile(path.join(tmpDir, 'one.txt'), 'content\n'); diff --git a/test/unit/src/utils/fs.test.js b/test/unit/src/utils/fs.test.js index 075ed3a..987a305 100644 --- a/test/unit/src/utils/fs.test.js +++ b/test/unit/src/utils/fs.test.js @@ -2,7 +2,6 @@ const fs = require('node:fs'); const fsp = fs.promises; -const os = require('node:os'); const path = require('node:path'); const proxyquire = require('proxyquire'); const sinon = require('sinon'); @@ -16,7 +15,7 @@ describe('test/unit/src/utils/fs.test.js', () => { let tmpDir; beforeEach(async () => { - tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'compose-fs-')); + tmpDir = await fsp.mkdtemp(path.join(process.cwd(), 'compose-fs-')); }); afterEach(async () => { diff --git a/test/unit/src/utils/glob.test.js b/test/unit/src/utils/glob.test.js index f45b778..9449b79 100644 --- a/test/unit/src/utils/glob.test.js +++ b/test/unit/src/utils/glob.test.js @@ -1,7 +1,6 @@ 'use strict'; const fs = require('node:fs').promises; -const os = require('node:os'); const path = require('node:path'); const { expect } = require('chai'); @@ -12,7 +11,7 @@ describe('test/unit/src/utils/glob.test.js', () => { let tmpDir; beforeEach(async () => { - tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'compose-glob-')); + tmpDir = await fs.mkdtemp(path.join(process.cwd(), 'compose-glob-')); }); afterEach(async () => { diff --git a/test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js b/test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js index e83c3ed..a180745 100644 --- a/test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js +++ b/test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js @@ -7,10 +7,6 @@ const sinon = require('sinon'); const expect = chai.expect; describe('test/unit/src/utils/serverless-utils/log-reporters/node/progress-reporter.test.js', () => { - afterEach(() => { - sinon.restore(); - }); - const loadProgressReporter = () => { const handlers = new Map(); const cliProgressFooter = { diff --git a/test/unit/src/utils/spawn.test.js b/test/unit/src/utils/spawn.test.js index 046fd36..45332b3 100644 --- a/test/unit/src/utils/spawn.test.js +++ b/test/unit/src/utils/spawn.test.js @@ -1,7 +1,6 @@ 'use strict'; const fs = require('fs').promises; -const os = require('os'); const path = require('path'); const { EventEmitter } = require('events'); const nodeStream = require('stream'); @@ -74,7 +73,7 @@ const assertRedaction = async ({ args, redacted, visible = [] }) => { describe('spawn', () => { it('executes PATH shims through cross-platform resolution', async () => { - const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'spawn-shim-')); + const tempDir = await fs.mkdtemp(path.join(process.cwd(), 'spawn-shim-')); const commandName = `spawn-shim-${process.pid}-${Date.now()}`; const commandPath = path.join( tempDir,