Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…suite into main
  • Loading branch information
yike5460 committed Oct 9, 2024
2 parents 13eec73 + 96cf43b commit 7644df7
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/AUTO_GENERATED_TESTS_README.md
Original file line number Diff line number Diff line change
@@ -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.
75 changes: 75 additions & 0 deletions test/sample.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Empty file added test/testUtils.test.ts
Empty file.
42 changes: 42 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 7644df7

Please sign in to comment.