From 0b27708573fd152eaecf43224de7ec8a1d0974a4 Mon Sep 17 00:00:00 2001 From: taub Date: Tue, 2 Jun 2026 14:10:17 -0400 Subject: [PATCH 01/10] add cursor dir to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 379644b..2287a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ coverage/ junit.xml package-lock.json .claude +.cursor/ \ No newline at end of file From 9d3a215fb26b86fb25ca1d06255299b41328743b Mon Sep 17 00:00:00 2001 From: taub Date: Tue, 2 Jun 2026 14:50:20 -0400 Subject: [PATCH 02/10] initial ESM upgrade. unit tests not included --- bin/run | 8 ++++---- eslint.config.js | 6 +++--- package.json | 3 ++- src/certificate.js | 19 ++++++++++--------- src/commands/certificate/fingerprint.js | 11 ++++++----- src/commands/certificate/generate.js | 12 ++++++------ src/commands/certificate/index.js | 4 ++-- src/commands/certificate/verify.js | 12 +++++++----- test/jest.setup.js | 2 +- 9 files changed, 41 insertions(+), 36 deletions(-) diff --git a/bin/run b/bin/run index d4ea366..16ef85b 100755 --- a/bin/run +++ b/bin/run @@ -11,8 +11,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const oclif = require('@oclif/core') +import { run, handle, flush } from '@oclif/core' -oclif.run() - .then(require('@oclif/core/flush')) - .catch(require('@oclif/core/handle')) +await run() + .then(flush) + .catch(handle) \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index e30b081..d6160da 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -10,10 +10,10 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const aioLibConfig = require('@adobe/eslint-config-aio-lib-config') -const pluginJest = require('eslint-plugin-jest') +import aioLibConfig from '@adobe/eslint-config-aio-lib-config' +import pluginJest from 'eslint-plugin-jest' -module.exports = [ +export default [ ...aioLibConfig, pluginJest.configs['flat/recommended'], { diff --git a/package.json b/package.json index 7b440a1..6f058f5 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "description": "Generate and validate private certificates, and public key pairs for use with Adobe IO Console", "repository": "adobe/aio-cli-plugin-certificate", "homepage": "https://github.com/adobe/aio-cli-plugin-certificate", + "type": "module", "dependencies": { "@oclif/core": "^4.9.0", "debug": "^4.3.3", - "fs-extra": "^9.0.0", + "fs-extra": "^11.3.5", "node-forge": "^1.3.0" }, "devDependencies": { diff --git a/src/certificate.js b/src/certificate.js index fb476f3..f69c32d 100644 --- a/src/certificate.js +++ b/src/certificate.js @@ -9,10 +9,10 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const debug = require('debug')('aio-cli-plugin-certificate:helpers') -const forge = require('node-forge') -const pki = forge.pki -const asn1 = forge.asn1 +import logDebug from 'debug' +import forge from 'node-forge' +const { pki, asn1 } = forge +const debug = logDebug('aio-cli-plugin-certificate:helpers') /** * Computes the SHA-1 digest of the entire DER-encoded x.509 certificate @@ -164,8 +164,9 @@ function verify (pemCert) { } } -module.exports = { - fingerprint, - generate, - verify -} +// module.exports = { +// fingerprint, +// generate, +// verify +// } +export { fingerprint, generate, verify } \ No newline at end of file diff --git a/src/commands/certificate/fingerprint.js b/src/commands/certificate/fingerprint.js index af78d5b..09dd847 100644 --- a/src/commands/certificate/fingerprint.js +++ b/src/commands/certificate/fingerprint.js @@ -10,11 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const { Command, Args } = require('@oclif/core') -const fs = require('fs-extra') -const debug = require('debug')('aio-cli-plugin-certificate:fingerprint') +import { Command, Args } from '@oclif/core' +import fs from 'fs-extra' +import logDebug from 'debug' +import * as cert from '../../certificate.js' -const cert = require('../../certificate') +const debug = logDebug('aio-cli-plugin-certificate:fingerprint') class FingerprintCommand extends Command { async run () { @@ -47,4 +48,4 @@ FingerprintCommand.args = { }) } -module.exports = FingerprintCommand +export default FingerprintCommand diff --git a/src/commands/certificate/generate.js b/src/commands/certificate/generate.js index 295d18a..f72c48a 100644 --- a/src/commands/certificate/generate.js +++ b/src/commands/certificate/generate.js @@ -10,11 +10,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const { Command, Flags } = require('@oclif/core') -const fs = require('fs-extra') -const debug = require('debug')('aio-cli-plugin-certificate:generate') - -const cert = require('../../certificate') +import { Command, Flags } from '@oclif/core' +import fs from 'fs-extra' +import logDebug from 'debug' +import * as cert from '../../certificate.js' +const debug = logDebug('aio-cli-plugin-certificate:generate') class GenerateCommand extends Command { async run () { @@ -79,4 +79,4 @@ GenerateCommand.flags = { }) } -module.exports = GenerateCommand +export default GenerateCommand diff --git a/src/commands/certificate/index.js b/src/commands/certificate/index.js index 2e4826c..1fe2518 100644 --- a/src/commands/certificate/index.js +++ b/src/commands/certificate/index.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const { Command, Help } = require('@oclif/core') +import { Command, Help } from '@oclif/core' class AIOCommand extends Command { async run () { @@ -21,4 +21,4 @@ class AIOCommand extends Command { AIOCommand.description = 'Generate, fingerprint, or verify a certificate for use with Adobe I/O' -module.exports = AIOCommand +export default AIOCommand diff --git a/src/commands/certificate/verify.js b/src/commands/certificate/verify.js index baf0cca..8015734 100644 --- a/src/commands/certificate/verify.js +++ b/src/commands/certificate/verify.js @@ -10,11 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -const { Command, Flags, Args } = require('@oclif/core') -const fs = require('fs-extra') -const debug = require('debug')('aio-cli-plugin-certificate:verify') +import { Command, Flags, Args } from '@oclif/core' +import fs from 'fs-extra' +import logDebug from 'debug' +const debug = logDebug('aio-cli-plugin-certificate:verify') -const cert = require('../../certificate') +import * as cert from '../../certificate.js' class VerifyCommand extends Command { async run () { @@ -77,4 +78,5 @@ VerifyCommand.args = { }) } -module.exports = VerifyCommand +// module.exports = VerifyCommand +export default VerifyCommand \ No newline at end of file diff --git a/test/jest.setup.js b/test/jest.setup.js index 737b267..bb99c32 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -1,4 +1,4 @@ -const { stdout } = require('stdout-stderr') +import stdout from 'stdout-stderr' beforeAll(() => stdout.start()) afterAll(() => stdout.stop()) From 82670d1a53f628bbb4173dcaa1d62cb48bb3bf2a Mon Sep 17 00:00:00 2001 From: taub Date: Wed, 3 Jun 2026 14:19:48 -0400 Subject: [PATCH 03/10] replace jest with vitest in package.json --- package.json | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 6f058f5..558206d 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,10 @@ "eslint": "^9", "eslint-plugin-jest": "^29", "eslint-plugin-jsdoc": "^48", - "jest": "^29", "neostandard": "^0", "oclif": "^4.0.0", - "stdout-stderr": "^0.1.9" + "stdout-stderr": "^0.1.9", + "vitest": "^4.1.8" }, "engines": { "node": ">=20" @@ -44,22 +44,9 @@ "scripts": { "posttest": "eslint src test", "test": "npm run unit-tests", - "unit-tests": "jest --ci", + "unit-tests": "vitest --ci", "prepack": "oclif manifest && oclif readme --no-aliases", "postpack": "rm -f oclif.manifest.json", "version": "oclif readme && git add README.md" - }, - "jest": { - "collectCoverage": true, - "testPathIgnorePatterns": [ - "/tests/fixtures/" - ], - "coveragePathIgnorePatterns": [ - "/tests/fixtures/" - ], - "testEnvironment": "node", - "setupFilesAfterEnv": [ - "./test/jest.setup.js" - ] } } From 774104d94b197dea449bb519c79919e9455eaadd Mon Sep 17 00:00:00 2001 From: taub Date: Wed, 3 Jun 2026 16:19:10 -0400 Subject: [PATCH 04/10] migrate tests from Jest to Vitest --- eslint.config.js | 12 +++- package.json | 5 +- test/commands/certificate/fingerprint.test.js | 60 ++++++++++++------- test/commands/certificate/generate.test.js | 14 ++--- test/commands/certificate/verify.test.js | 28 +++++---- test/jest.setup.js | 9 --- test/vitest.setup.js | 8 +++ vitest.config.js | 17 ++++++ 8 files changed, 98 insertions(+), 55 deletions(-) delete mode 100644 test/jest.setup.js create mode 100644 test/vitest.setup.js create mode 100644 vitest.config.js diff --git a/eslint.config.js b/eslint.config.js index d6160da..088dcf0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -11,11 +11,19 @@ governing permissions and limitations under the License. */ import aioLibConfig from '@adobe/eslint-config-aio-lib-config' -import pluginJest from 'eslint-plugin-jest' +import vitest from '@vitest/eslint-plugin' export default [ ...aioLibConfig, - pluginJest.configs['flat/recommended'], + { + files: ['test/**'], + ...vitest.configs.recommended, + languageOptions: { + globals: { + ...vitest.environments.env.globals + } + } + }, { rules: { 'jsdoc/no-defaults': 'off' diff --git a/package.json b/package.json index 558206d..21bf42e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "devDependencies": { "@adobe/eslint-config-aio-lib-config": "^5.0.0", "eslint": "^9", - "eslint-plugin-jest": "^29", + "@vitest/coverage-v8": "^4.1.8", + "@vitest/eslint-plugin": "^1", "eslint-plugin-jsdoc": "^48", "neostandard": "^0", "oclif": "^4.0.0", @@ -44,7 +45,7 @@ "scripts": { "posttest": "eslint src test", "test": "npm run unit-tests", - "unit-tests": "vitest --ci", + "unit-tests": "vitest run", "prepack": "oclif manifest && oclif readme --no-aliases", "postpack": "rm -f oclif.manifest.json", "version": "oclif readme && git add README.md" diff --git a/test/commands/certificate/fingerprint.test.js b/test/commands/certificate/fingerprint.test.js index 01762e3..1f3933c 100644 --- a/test/commands/certificate/fingerprint.test.js +++ b/test/commands/certificate/fingerprint.test.js @@ -10,11 +10,11 @@ governing permissions and limitations under the License. */ // const { stdout } = require('stdout-stderr') -const commandPath = '../../../src/commands/certificate/fingerprint' -let TheCommand -jest.isolateModules(() => { - TheCommand = require(commandPath) -}) +import { vi } from 'vitest' +import TheCommand from '../../../src/commands/certificate/fingerprint.js' +import mockFS from 'fs-extra' + +const commandPath = '../../../src/commands/certificate/fingerprint.js' const validCertPem = ` -----BEGIN CERTIFICATE----- @@ -52,24 +52,39 @@ test('args', async () => { expect(Object.keys(TheCommand.args)[0]).toBeDefined() }) -const mockConfig = { runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] }) } +const mockConfig = { runHook: vi.fn().mockResolvedValue({ successes: [], failures: [] }) } describe('instance methods - mock forge', () => { - let CommandUnderTest, command, handleError, mockFS, mockForge - jest.isolateModules(() => { - CommandUnderTest = require(commandPath) - mockFS = require('fs-extra') - mockForge = require('node-forge') - jest.mock('node-forge') + let CommandUnderTest, command, handleError, mockForge + + beforeAll(async () => { + vi.resetModules() + // vitest does not support isolateModules, so we have to build our own sandbox mock here + vi.doMock('node-forge', async (importOriginal) => { + const mod = await importOriginal() + const forge = mod.default ?? mod + return { + ...mod, + default: { + ...forge, + pki: { + ...forge.pki, + certificateFromPem: vi.fn() + } + } + } + }) + CommandUnderTest = (await import(commandPath)).default + mockForge = (await import('node-forge')).default }) beforeEach(() => { command = new CommandUnderTest([], mockConfig) - handleError = jest.spyOn(command, 'error') + handleError = vi.spyOn(command, 'error') }) afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) test('run missing args', async () => { @@ -96,27 +111,28 @@ describe('instance methods - mock forge', () => { }) describe('instance methods - real forge', () => { - let CommandUnderTest, command, handleError, mockFS - jest.isolateModules(() => { - mockFS = require('fs-extra') - jest.unmock('node-forge') - CommandUnderTest = require(commandPath) + let CommandUnderTest, command, handleError + + beforeAll(async () => { + vi.resetModules() + vi.doUnmock('node-forge') + CommandUnderTest = (await import(commandPath)).default }) beforeEach(() => { command = new CommandUnderTest([], mockConfig) - handleError = jest.spyOn(command, 'error') + handleError = vi.spyOn(command, 'error') }) afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) test('run with valid cert pem', async () => { mockFS.existsSync.mockReturnValue(true) mockFS.readFileSync.mockReturnValue(Buffer.from(validCertPem)) command.argv = ['file'] - const logSpy = jest.spyOn(command, 'log') + const logSpy = vi.spyOn(command, 'log') await expect(command.run()).resolves.toBeUndefined() expect(logSpy).toHaveBeenCalledWith(validCertFingerprint) expect(handleError).not.toHaveBeenCalled() diff --git a/test/commands/certificate/generate.test.js b/test/commands/certificate/generate.test.js index 53d548b..1320907 100644 --- a/test/commands/certificate/generate.test.js +++ b/test/commands/certificate/generate.test.js @@ -10,10 +10,10 @@ governing permissions and limitations under the License. */ // const { stdout } = require('stdout-stderr') -const TheCommand = require('../../../src/commands/certificate/generate') - -const mockFS = require('fs-extra') -const forge = require('node-forge') +import { vi } from 'vitest' +import TheCommand from '../../../src/commands/certificate/generate.js' +import mockFS from 'fs-extra' +import forge from 'node-forge' test('exports', async () => { expect(typeof TheCommand).toEqual('function') @@ -23,18 +23,18 @@ test('description', async () => { expect(TheCommand.description).toBeDefined() }) -const mockConfig = { runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] }) } +const mockConfig = { runHook: vi.fn().mockResolvedValue({ successes: [], failures: [] }) } describe('instance methods', () => { let command, handleError beforeEach(() => { command = new TheCommand([], mockConfig) - handleError = jest.spyOn(command, 'error') + handleError = vi.spyOn(command, 'error') }) afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) test('run -- no flags', async () => { diff --git a/test/commands/certificate/verify.test.js b/test/commands/certificate/verify.test.js index 81bb0d7..00887e5 100644 --- a/test/commands/certificate/verify.test.js +++ b/test/commands/certificate/verify.test.js @@ -10,11 +10,13 @@ governing permissions and limitations under the License. */ // const { stdout } = require('stdout-stderr') -const TheCommand = require('../../../src/commands/certificate/verify') +import { vi } from 'vitest' -const mockFS = require('fs-extra') -const mockForge = require('node-forge') -jest.mock('node-forge') +vi.mock('node-forge') + +import TheCommand from '../../../src/commands/certificate/verify.js' +import mockFS from 'fs-extra' +import mockForge from 'node-forge' const distantFuture = new Date() distantFuture.setFullYear(distantFuture.getFullYear() + 1) @@ -34,18 +36,18 @@ test('args', async () => { expect(Object.keys(TheCommand.args)[0]).toBeDefined() }) -const mockConfig = { runHook: jest.fn().mockResolvedValue({ successes: [], failures: [] }) } +const mockConfig = { runHook: vi.fn().mockResolvedValue({ successes: [], failures: [] }) } describe('instance methods', () => { let command, handleError beforeEach(() => { command = new TheCommand([], mockConfig) - handleError = jest.spyOn(command, 'error') + handleError = vi.spyOn(command, 'error') }) afterEach(() => { - jest.clearAllMocks() + vi.clearAllMocks() }) test('run missing args', async () => { @@ -75,7 +77,7 @@ describe('instance methods', () => { test('run with invalid file ( false & true )', async () => { mockFS.existsSync.mockReturnValue(true) - mockForge.pki.certificateFromPem.mockReturnValue({ verify: jest.fn(() => true), validity: {} }) + mockForge.pki.certificateFromPem.mockReturnValue({ verify: vi.fn(() => true), validity: {} }) mockForge.pki.verifyCertificateChain.mockReturnValue(true) command.argv = ['file'] await expect(command.run()).resolves.toBe(true) @@ -84,7 +86,7 @@ describe('instance methods', () => { test('run with invalid file ( true & false )', async () => { mockFS.existsSync.mockReturnValue(true) - mockForge.pki.certificateFromPem.mockReturnValue({ verify: jest.fn(() => true), validity: {} }) + mockForge.pki.certificateFromPem.mockReturnValue({ verify: vi.fn(() => true), validity: {} }) mockForge.pki.verifyCertificateChain.mockReturnValue(false) command.argv = ['file'] await expect(command.run()).resolves.toBe(false) @@ -95,7 +97,7 @@ describe('instance methods', () => { mockFS.existsSync.mockReturnValue(true) mockForge.pki.certificateFromPem.mockReturnValue({ - verify: jest.fn(() => true), + verify: vi.fn(() => true), validity: { notAfter: now, notBefore: distantPast @@ -110,7 +112,7 @@ describe('instance methods', () => { mockFS.existsSync.mockReturnValue(true) mockForge.pki.certificateFromPem.mockReturnValue({ - verify: jest.fn(() => true), + verify: vi.fn(() => true), validity: { notAfter: distantFuture, notBefore: now @@ -125,7 +127,7 @@ describe('instance methods', () => { mockFS.existsSync.mockReturnValue(true) mockForge.pki.certificateFromPem.mockReturnValue({ - verify: jest.fn(() => true), + verify: vi.fn(() => true), validity: { notAfter: distantFuture, notBefore: now @@ -140,7 +142,7 @@ describe('instance methods', () => { mockFS.existsSync.mockReturnValue(true) mockForge.pki.certificateFromPem.mockReturnValue({ - verify: jest.fn(() => true), + verify: vi.fn(() => true), validity: { notAfter: now, notBefore: distantPast diff --git a/test/jest.setup.js b/test/jest.setup.js deleted file mode 100644 index bb99c32..0000000 --- a/test/jest.setup.js +++ /dev/null @@ -1,9 +0,0 @@ -import stdout from 'stdout-stderr' - -beforeAll(() => stdout.start()) -afterAll(() => stdout.stop()) - -jest.setTimeout(30000) - -// dont touch the real fs -jest.mock('fs-extra') diff --git a/test/vitest.setup.js b/test/vitest.setup.js new file mode 100644 index 0000000..64be6a3 --- /dev/null +++ b/test/vitest.setup.js @@ -0,0 +1,8 @@ +import { stdout } from 'stdout-stderr' +import { beforeAll, afterAll, vi } from 'vitest' + +beforeAll(() => stdout.start()) +afterAll(() => stdout.stop()) + +// dont touch the real fs +vi.mock('fs-extra') diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 0000000..c2fefae --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,17 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + globals: true, + environment: 'node', + testTimeout: 30000, + setupFiles: ['./test/vitest.setup.js'], + include: ['test/**/*.test.js'], + exclude: ['**/node_modules/**', '**/tests/fixtures/**'], + coverage: { + enabled: true, + include: ['src/**'], + exclude: ['**/tests/fixtures/**'] + } + } +}) From 487425c7ad2de2f0ed6b1112a9e9a33ce4f8391e Mon Sep 17 00:00:00 2001 From: taub Date: Wed, 3 Jun 2026 16:20:20 -0400 Subject: [PATCH 05/10] lint fixes --- src/certificate.js | 2 +- src/commands/certificate/verify.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/certificate.js b/src/certificate.js index f69c32d..ea0e0eb 100644 --- a/src/certificate.js +++ b/src/certificate.js @@ -169,4 +169,4 @@ function verify (pemCert) { // generate, // verify // } -export { fingerprint, generate, verify } \ No newline at end of file +export { fingerprint, generate, verify } diff --git a/src/commands/certificate/verify.js b/src/commands/certificate/verify.js index 8015734..9f9043b 100644 --- a/src/commands/certificate/verify.js +++ b/src/commands/certificate/verify.js @@ -79,4 +79,4 @@ VerifyCommand.args = { } // module.exports = VerifyCommand -export default VerifyCommand \ No newline at end of file +export default VerifyCommand From d6d60f24d1ab974611698da362c4c21ff5c27272 Mon Sep 17 00:00:00 2001 From: taub Date: Wed, 3 Jun 2026 16:48:36 -0400 Subject: [PATCH 06/10] add test for index.js to bump test coverage back to 100% --- test/commands/certificate/index.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/commands/certificate/index.test.js diff --git a/test/commands/certificate/index.test.js b/test/commands/certificate/index.test.js new file mode 100644 index 0000000..76167b8 --- /dev/null +++ b/test/commands/certificate/index.test.js @@ -0,0 +1,25 @@ +import { vi } from 'vitest' +import TheCommand from '../../../src/commands/certificate/index.js' +import { Help } from '@oclif/core' + +describe('index', () => { + let showHelpSpy + + beforeEach(() => { + showHelpSpy = vi.spyOn(Help.prototype, 'showHelp').mockResolvedValue(undefined) + }) + + afterEach(() => { + showHelpSpy.mockRestore() + }) + + test('description', async () => { + expect(TheCommand.description).toEqual('Generate, fingerprint, or verify a certificate for use with Adobe I/O') + }) + + test('run Help command', async () => { + const command = new TheCommand([], { runHook: vi.fn().mockResolvedValue({ successes: [], failures: [] }) }) + await command.run() + expect(showHelpSpy).toHaveBeenCalledWith(['certificate', '--help']) + }) +}) From 8fb327ffb27466cfe4b41ccbe4593c700f0df76e Mon Sep 17 00:00:00 2001 From: taub Date: Wed, 3 Jun 2026 16:56:43 -0400 Subject: [PATCH 07/10] typo fixes, change name of bin/run for ESM compatibility --- bin/{run => run.js} | 2 +- src/certificate.js | 5 ----- src/commands/certificate/verify.js | 1 - test/vitest.setup.js | 2 +- vitest.config.js | 5 ++--- 5 files changed, 4 insertions(+), 11 deletions(-) rename bin/{run => run.js} (97%) diff --git a/bin/run b/bin/run.js similarity index 97% rename from bin/run rename to bin/run.js index 16ef85b..1d416d6 100755 --- a/bin/run +++ b/bin/run.js @@ -15,4 +15,4 @@ import { run, handle, flush } from '@oclif/core' await run() .then(flush) - .catch(handle) \ No newline at end of file + .catch(handle) diff --git a/src/certificate.js b/src/certificate.js index ea0e0eb..a8de2f4 100644 --- a/src/certificate.js +++ b/src/certificate.js @@ -164,9 +164,4 @@ function verify (pemCert) { } } -// module.exports = { -// fingerprint, -// generate, -// verify -// } export { fingerprint, generate, verify } diff --git a/src/commands/certificate/verify.js b/src/commands/certificate/verify.js index 9f9043b..f7c5973 100644 --- a/src/commands/certificate/verify.js +++ b/src/commands/certificate/verify.js @@ -78,5 +78,4 @@ VerifyCommand.args = { }) } -// module.exports = VerifyCommand export default VerifyCommand diff --git a/test/vitest.setup.js b/test/vitest.setup.js index 64be6a3..ba38828 100644 --- a/test/vitest.setup.js +++ b/test/vitest.setup.js @@ -4,5 +4,5 @@ import { beforeAll, afterAll, vi } from 'vitest' beforeAll(() => stdout.start()) afterAll(() => stdout.stop()) -// dont touch the real fs +// don't touch the real fs vi.mock('fs-extra') diff --git a/vitest.config.js b/vitest.config.js index c2fefae..35a8398 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -7,11 +7,10 @@ export default defineConfig({ testTimeout: 30000, setupFiles: ['./test/vitest.setup.js'], include: ['test/**/*.test.js'], - exclude: ['**/node_modules/**', '**/tests/fixtures/**'], + exclude: ['**/node_modules/**'], coverage: { enabled: true, - include: ['src/**'], - exclude: ['**/tests/fixtures/**'] + include: ['src/**'] } } }) From c5691d491e5f7e2b2586234c251721a9402712c3 Mon Sep 17 00:00:00 2001 From: taub Date: Thu, 4 Jun 2026 10:39:59 -0400 Subject: [PATCH 08/10] minor formatting fixes --- src/commands/certificate/generate.js | 1 + src/commands/certificate/verify.js | 4 +-- test/commands/certificate/fingerprint.test.js | 29 ++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/commands/certificate/generate.js b/src/commands/certificate/generate.js index f72c48a..5f57eb4 100644 --- a/src/commands/certificate/generate.js +++ b/src/commands/certificate/generate.js @@ -14,6 +14,7 @@ import { Command, Flags } from '@oclif/core' import fs from 'fs-extra' import logDebug from 'debug' import * as cert from '../../certificate.js' + const debug = logDebug('aio-cli-plugin-certificate:generate') class GenerateCommand extends Command { diff --git a/src/commands/certificate/verify.js b/src/commands/certificate/verify.js index f7c5973..524ab5d 100644 --- a/src/commands/certificate/verify.js +++ b/src/commands/certificate/verify.js @@ -13,10 +13,10 @@ governing permissions and limitations under the License. import { Command, Flags, Args } from '@oclif/core' import fs from 'fs-extra' import logDebug from 'debug' -const debug = logDebug('aio-cli-plugin-certificate:verify') - import * as cert from '../../certificate.js' +const debug = logDebug('aio-cli-plugin-certificate:verify') + class VerifyCommand extends Command { async run () { const { flags, args } = await this.parse(VerifyCommand) diff --git a/test/commands/certificate/fingerprint.test.js b/test/commands/certificate/fingerprint.test.js index 1f3933c..65eb449 100644 --- a/test/commands/certificate/fingerprint.test.js +++ b/test/commands/certificate/fingerprint.test.js @@ -11,11 +11,11 @@ governing permissions and limitations under the License. // const { stdout } = require('stdout-stderr') import { vi } from 'vitest' -import TheCommand from '../../../src/commands/certificate/fingerprint.js' import mockFS from 'fs-extra' +// we don't import the command up here to allow for some tests to run with isolated mocks +// since vitest doesn't support isolateModules const commandPath = '../../../src/commands/certificate/fingerprint.js' - const validCertPem = ` -----BEGIN CERTIFICATE----- MIIDMTCCAhmgAwIBAgIHAWVCcDJVYDANBgkqhkiG9w0BAQsFADAdMRswGQYDVQQD @@ -40,16 +40,25 @@ B9+DCYg= ` const validCertFingerprint = '38f65e26bd3869ec3ca029cc0b3df98de29172b9' -test('exports', async () => { - expect(typeof TheCommand).toEqual('function') -}) +describe('basic functionality', () => { + let TheCommand -test('description', async () => { - expect(TheCommand.description).toBeDefined() -}) + beforeAll(async () => { + vi.resetModules() + TheCommand = (await import(commandPath)).default + }) -test('args', async () => { - expect(Object.keys(TheCommand.args)[0]).toBeDefined() + test('exports', async () => { + expect(typeof TheCommand).toEqual('function') + }) + + test('description', async () => { + expect(TheCommand.description).toBeDefined() + }) + + test('args', async () => { + expect(Object.keys(TheCommand.args)[0]).toBeDefined() + }) }) const mockConfig = { runHook: vi.fn().mockResolvedValue({ successes: [], failures: [] }) } From e94318851f27e5f45b82df216cc6a214a2d4485e Mon Sep 17 00:00:00 2001 From: taub Date: Thu, 4 Jun 2026 15:22:22 -0400 Subject: [PATCH 09/10] remove old commented lines + add missing newline --- .gitignore | 2 +- test/commands/certificate/verify.test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2287a0b..4efe13f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ coverage/ junit.xml package-lock.json .claude -.cursor/ \ No newline at end of file +.cursor/ diff --git a/test/commands/certificate/verify.test.js b/test/commands/certificate/verify.test.js index 00887e5..c69ff9a 100644 --- a/test/commands/certificate/verify.test.js +++ b/test/commands/certificate/verify.test.js @@ -9,7 +9,6 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -// const { stdout } = require('stdout-stderr') import { vi } from 'vitest' vi.mock('node-forge') From 3532b32a0b7c977e4c9a4c2a3de4350340061e68 Mon Sep 17 00:00:00 2001 From: taub Date: Thu, 4 Jun 2026 16:27:40 -0400 Subject: [PATCH 10/10] add copyright comment to new files --- test/commands/certificate/index.test.js | 12 ++++++++++++ test/vitest.setup.js | 12 ++++++++++++ vitest.config.js | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/test/commands/certificate/index.test.js b/test/commands/certificate/index.test.js index 76167b8..7f522bf 100644 --- a/test/commands/certificate/index.test.js +++ b/test/commands/certificate/index.test.js @@ -1,3 +1,15 @@ +/* +Copyright 2026 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + import { vi } from 'vitest' import TheCommand from '../../../src/commands/certificate/index.js' import { Help } from '@oclif/core' diff --git a/test/vitest.setup.js b/test/vitest.setup.js index ba38828..e01c3bd 100644 --- a/test/vitest.setup.js +++ b/test/vitest.setup.js @@ -1,3 +1,15 @@ +/* +Copyright 2026 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + import { stdout } from 'stdout-stderr' import { beforeAll, afterAll, vi } from 'vitest' diff --git a/vitest.config.js b/vitest.config.js index 35a8398..8796074 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -1,3 +1,15 @@ +/* +Copyright 2026 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + import { defineConfig } from 'vitest/config' export default defineConfig({