diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6b2a2a2..f1d3c60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,9 +31,6 @@ jobs: - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies run: npm audit signatures - - name: Test - run: npm test - - name: Release env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 13e36c7..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Test - -on: - [push, pull_request] - -jobs: - build_and_test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - cache: 'npm' - - - name: Install Dependencies - run: npm ci - - - name: Run Tests - run: npm test \ No newline at end of file diff --git a/README.md b/README.md index eab70ef..79ccf8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Avro Tools CLI ## Description -Avro Tools CLI is a command-line interface for validating and converting Avro schemas. Built with Node.js and Yargs, it offers a basic yet opinionated way to manage Avro schema files. +Avro Tools CLI is a command-line interface for validating and converting [Avro schemas](https://avro.apache.org/docs/#schemas). Built with Node.js and Yargs, it offers a basic yet opinionated way to manage Avro schema files. ## Features - Validate Avro schemas. @@ -56,9 +56,14 @@ Create an avroConfig.json file: } ``` -## Development -Node.js Version: xx.xx -ESM Modules +## Requirements +- Node.js version 14 or higher is required for this tool, as it relies on ECMAScript Modules (ESM) which have stable support from version 14 onwards. + +## Testing +The test suite for Avro Tools CLI is currently a work in progress. We use Jest for our testing framework, but please note that Jest's support for ECMAScript Modules (ESM) is still experimental. As a result, some tests may not yet achieve full coverage or may exhibit unexpected behavior. We are actively working to improve the test suite as the tooling evolves. + +For the latest information on Jest's ESM support, see their [official documentation](https://jestjs.io/docs/ecmascript-modules). + ## Local Setup ```bash diff --git a/__tests__/loadConfig.test.js b/__tests__/loadConfig.test.js new file mode 100644 index 0000000..d4af5c4 --- /dev/null +++ b/__tests__/loadConfig.test.js @@ -0,0 +1,23 @@ +// loadConfig.test.js +import { loadConfig } from './loadConfig'; +import fs from 'fs'; +import path from 'path'; + +jest.mock('fs'); +jest.mock('path'); + +describe('loadConfig', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('loads and parses a valid config file', () => { + fs.readFileSync.mockReturnValue(JSON.stringify({ include: ['test'] })); + path.resolve.mockReturnValue('path/to/config.json'); + + const config = loadConfig('config.json'); + expect(config).toEqual({ include: ['test'] }); + }); + + // More tests for error handling... +}); diff --git a/__tests__/main.test.js b/__tests__/main.test.js new file mode 100644 index 0000000..c0cbbf7 --- /dev/null +++ b/__tests__/main.test.js @@ -0,0 +1,19 @@ +// main.test.js +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import main from './main'; + +jest.mock('yargs'); +jest.mock('hideBin'); + +describe('main CLI', () => { + it('registers commands and options', () => { + // Call main and inspect yargs configuration + main(); + expect(yargs.command).toHaveBeenCalled(); + expect(yargs.option).toHaveBeenCalled(); + // Add more expectations based on your yargs setup + }); + + // More tests for CLI behavior... +}); diff --git a/__tests__/validate.test.js b/__tests__/validate.test.js new file mode 100644 index 0000000..976dba3 --- /dev/null +++ b/__tests__/validate.test.js @@ -0,0 +1,25 @@ +// validate.test.js +import validate, { readSchemaFile, isSchemaValid } from '../commands/validate'; +import avro from 'avsc'; +import fs from 'fs'; +import { glob } from 'glob'; +import chalk from 'chalk'; + +jest.mock('fs'); +jest.mock('avsc'); +jest.mock('glob'); + +describe('validate command', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('readSchemaFile reads and returns schema file content', () => { + fs.readFileSync.mockReturnValue('{"type": "record"}'); + const content = readSchemaFile('path/to/schema.avsc'); + expect(content).toBe('{"type": "record"}'); + expect(fs.readFileSync).toHaveBeenCalledWith('path/to/schema.avsc', 'utf8'); + }); + + // More tests for isSchemaValid and the command handler... +}); diff --git a/__tests__/validateSchema.test.js b/__tests__/validateSchema.test.js deleted file mode 100644 index e6aa4ca..0000000 --- a/__tests__/validateSchema.test.js +++ /dev/null @@ -1,25 +0,0 @@ -const { isSchemaValid } = require('../commands/validate.js'); - -describe('Avro Schema Validation Tests', () => { - test('validates a correct schema', () => { - const validSchemaData = JSON.stringify({ - type: 'record', - name: 'TestRecord', - fields: [ - { name: 'testField', type: 'string' } - ] - }); - expect(isSchemaValid(validSchemaData)).toBeTruthy(); - }); - - test('rejects an incorrect schema', () => { - const invalidSchemaData = JSON.stringify({ - type: 'record', - name: 'TestRecord', - fields: [ - { name: 'testField', type: 'invalidType' } // Use an invalid type here - ] - }); - expect(isSchemaValid(invalidSchemaData)).toBeFalsy(); - }); -}); diff --git a/package.json b/package.json index 8a8b170..1bfda5c 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,9 @@ "**/?(*.)+(spec|test).[tj]s?(x)" ] }, + "engines": { + "node": ">=14" + }, "release": { "branches": [ {