From 82f5e2bab6ec7a95ea77d48ba434f9a45a9d5def Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:10:21 +0000 Subject: [PATCH 1/4] Add or update unit tests for sample.ts --- test/sample.test.ts | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/sample.test.ts diff --git a/test/sample.test.ts b/test/sample.test.ts new file mode 100644 index 0000000..4ddc4bf --- /dev/null +++ b/test/sample.test.ts @@ -0,0 +1,75 @@ +import { add, subtract } from '/home/runner/work/aws-genai-cicd-suite/aws-genai-cicd-suite/debugging/sample'; + +describe('add', () => { + it('should add two positive numbers correctly', () => { + expect(add(2, 3)).toBe(5); + }); + + it('should add two negative numbers correctly', () => { + expect(add(-2, -3)).toBe(-5); + }); + + it('should add a positive and a negative number correctly', () => { + expect(add(2, -3)).toBe(-1); + }); + + it('should add zero to a number correctly', () => { + expect(add(0, 5)).toBe(5); + expect(add(5, 0)).toBe(5); + }); +}); + +describe('subtract', () => { + it('should subtract two positive numbers correctly', () => { + expect(subtract(5, 3)).toBe(2); + }); + + it('should subtract two negative numbers correctly', () => { + expect(subtract(-5, -3)).toBe(-2); + }); + + it('should subtract a negative number from a positive number correctly', () => { + expect(subtract(5, -3)).toBe(8); + }); + + it('should subtract a positive number from a negative number correctly', () => { + expect(subtract(-5, 3)).toBe(-8); + }); + + it('should subtract zero from a number correctly', () => { + expect(subtract(5, 0)).toBe(5); + expect(subtract(0, 5)).toBe(-5); + }); +}); + +import { subtract } from '/home/runner/work/aws-genai-cicd-suite/aws-genai-cicd-suite/debugging/sample'; + +describe('subtract', () => { + it('should subtract two positive numbers correctly', () => { + expect(subtract(5, 3)).toBe(2); + }); + + it('should subtract two negative numbers correctly', () => { + expect(subtract(-10, -5)).toBe(-5); + }); + + it('should subtract a positive number from a negative number correctly', () => { + expect(subtract(-8, 3)).toBe(-11); + }); + + it('should subtract a negative number from a positive number correctly', () => { + expect(subtract(10, -4)).toBe(14); + }); + + it('should return 0 when subtracting the same number', () => { + expect(subtract(7, 7)).toBe(0); + }); + + it('should handle large numbers correctly', () => { + expect(subtract(1000000000, 500000000)).toBe(500000000); + }); + + it('should handle floating-point numbers correctly', () => { + expect(subtract(3.14, 1.57)).toBeCloseTo(1.57, 5); + }); +}); \ No newline at end of file From 2fbbead1850f13c55174e69afb8744f2abca1be9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:10:21 +0000 Subject: [PATCH 2/4] Add or update unit tests for testUtils.ts --- test/testUtils.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/testUtils.test.ts diff --git a/test/testUtils.test.ts b/test/testUtils.test.ts new file mode 100644 index 0000000..e69de29 From 0059be63ba03eb7affe0be93306359b35adfc9b3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:10:22 +0000 Subject: [PATCH 3/4] Add or update unit tests for utils.ts --- test/utils.test.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/utils.test.ts diff --git a/test/utils.test.ts b/test/utils.test.ts new file mode 100644 index 0000000..63f10ef --- /dev/null +++ b/test/utils.test.ts @@ -0,0 +1,42 @@ +import { shouldExcludeFile } from '@/debugging/utils'; + +describe('shouldExcludeFile', () => { + it('should return true if the filename matches any of the exclude patterns', () => { + const filename = 'src/components/Button.test.tsx'; + const excludePatterns = ['**/node_modules/**', '**/dist/**', '**/*.test.*']; + + expect(shouldExcludeFile(filename, excludePatterns)).toBe(true); + }); + + it('should return false if the filename does not match any of the exclude patterns', () => { + const filename = 'src/components/Button.tsx'; + const excludePatterns = ['**/node_modules/**', '**/dist/**']; + + expect(shouldExcludeFile(filename, excludePatterns)).toBe(false); + }); + + it('should handle wildcard patterns correctly', () => { + const filename = 'src/utils/helpers.ts'; + const excludePatterns = ['**/node_modules/**', '**/dist/**', 'src/utils/*']; + + expect(shouldExcludeFile(filename, excludePatterns)).toBe(true); + }); + + it('should handle empty exclude patterns', () => { + const filename = 'src/components/Button.tsx'; + const excludePatterns: string[] = []; + + expect(shouldExcludeFile(filename, excludePatterns)).toBe(false); + }); + + test.each` + filename | excludePatterns | expected + ${'src/components/Button.tsx'} | ${['**/node_modules/**', '**/dist/**', '**/*.tsx']} | ${true} + ${'src/utils/helpers.ts'} | ${['**/node_modules/**', '**/dist/**', 'src/utils/*']} | ${true} + ${'src/index.tsx'} | ${['**/node_modules/**', '**/dist/**', '**/*.test.*']} | ${false} + ${'src/tests/Button.test.tsx'} | ${['**/node_modules/**', '**/dist/**', '**/*.test.*']} | ${true} + ${'src/styles/global.css'} | ${[]} | ${false} + `('should return $expected for filename $filename and excludePatterns $excludePatterns', ({ filename, excludePatterns, expected }) => { + expect(shouldExcludeFile(filename, excludePatterns)).toBe(expected); + }); +}); \ No newline at end of file From 96cf43b5b9d7057b10eb6a0ce321e329ebc9641c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:10:23 +0000 Subject: [PATCH 4/4] Add or update README for auto-generated unit tests --- test/AUTO_GENERATED_TESTS_README.md | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/AUTO_GENERATED_TESTS_README.md diff --git a/test/AUTO_GENERATED_TESTS_README.md b/test/AUTO_GENERATED_TESTS_README.md new file mode 100644 index 0000000..33bd0fd --- /dev/null +++ b/test/AUTO_GENERATED_TESTS_README.md @@ -0,0 +1,73 @@ +# Auto-Generated Unit Tests + +This document provides an overview of the automatically generated unit tests for this project. + +## Generated Test Suites + +- **sample.test.ts**: Tests for `sample.ts` + - Location: `test/sample.test.ts` + - Source file: `debugging/sample.ts` + +- **testUtils.test.ts**: Tests for `testUtils.ts` + - Location: `test/testUtils.test.ts` + - Source file: `debugging/testUtils.ts` + +- **utils.test.ts**: Tests for `utils.ts` + - Location: `test/utils.test.ts` + - Source file: `debugging/utils.ts` + +## Test Coverage + +The following test coverage was achieved during the pre-flight phase: + +``` +{ + "lines": { + "total": 0, + "covered": 0, + "skipped": 0, + "pct": 100 + }, + "statements": { + "total": 0, + "covered": 0, + "skipped": 0, + "pct": 100 + }, + "functions": { + "total": 0, + "covered": 0, + "skipped": 0, + "pct": 100 + }, + "branches": { + "total": 0, + "covered": 0, + "skipped": 0, + "pct": 100 + } +} +``` + +## Test Results Summary + +Total tests: 33 +Passed tests: 3 +Failed tests: 30 + +## Running Tests Manually + +To run these unit tests manually, follow these steps: + +1. Ensure you have Node.js and npm installed on your system. +2. Navigate to the project root directory in your terminal. +3. Install the necessary dependencies by running: + ``` + npm install + ``` +4. Run the tests using the following command: + ``` + npm test + ``` + +This will execute all the unit tests in the `test` directory.