Skip to content

Commit 2f59d74

Browse files
authored
Merge pull request #3 from suites-dev/refactor/separate-tests
Separate Tests
2 parents be96d1a + f832c7c commit 2f59d74

36 files changed

+188
-110
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ examples/
105105
└── advanced-mock-config/ # Advanced .mock().final() and .impl() patterns
106106
```
107107

108-
Each example contains:
109-
110-
- `src/types.ts` - Domain types
111-
- `src/user.service.ts` - Business logic
112-
- `src/user.validator.ts` - Validation logic
113-
- `src/user.repository.ts` - Data access
114-
- `src/user.solitary.spec.ts` - Solitary unit tests
115-
- `src/user.sociable.spec.ts` - Sociable unit tests
108+
Each example contains two directories:
109+
110+
**`src/`** - Application code being tested:
111+
112+
- `types.ts` - Domain types and interfaces
113+
- `user.service.ts` - Business logic layer
114+
- `user.validator.ts` - Validation logic
115+
- `user.repository.ts` - Data access layer
116+
117+
**`tests/`** - Tests demonstrating Suites usage:
118+
119+
- `user.solitary.spec.ts` - Solitary unit tests (all dependencies mocked)
120+
- `user.sociable.spec.ts` - Sociable unit tests (real collaborators, external I/O mocked)
116121

117122
## Prerequisites
118123

advanced-mock-config/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ All tests should pass, demonstrating both testing strategies with advanced mock
2727

2828
## Project Structure
2929

30+
**`src/`** - Application code being tested:
31+
3032
```
3133
src/
32-
├── types.ts # User types and interfaces
33-
├── user.validator.ts # Validation logic (no dependencies)
34-
├── user.repository.ts # Data access (token injection)
35-
├── user.service.ts # Business logic (class injections)
36-
├── user.solitary.spec.ts # Solitary unit tests with mock config
37-
└── user.sociable.spec.ts # Sociable unit tests with mock config
34+
├── types.ts # User types and interfaces
35+
├── user.validator.ts # Validation logic (no dependencies)
36+
├── user.repository.ts # Data access (token injection)
37+
└── user.service.ts # Business logic (class injections)
38+
```
39+
40+
**`tests/`** - Tests demonstrating Suites advanced mock configuration:
41+
42+
```
43+
tests/
44+
├── user.solitary.spec.ts # Solitary tests with .mock().final() and .mock().impl()
45+
└── user.sociable.spec.ts # Sociable tests with .mock().final() and .mock().impl()
3846
```
3947

4048
## Mock Configuration Patterns

advanced-mock-config/jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
testRegex: '.spec.ts$',
3+
testRegex: 'tests/.*\\.spec\\.ts$',
44
transform: {
55
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }]
66
},
77
collectCoverageFrom: [
88
'src/**/*.ts',
9-
'!src/**/*.spec.ts',
109
'!src/types.ts'
1110
]
1211
};

advanced-mock-config/src/user.sociable.spec.ts renamed to advanced-mock-config/tests/user.sociable.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
import { type Mocked, TestBed } from '@suites/unit';
10-
import { UserService } from './user.service';
11-
import { UserValidator } from './user.validator';
12-
import { UserRepository } from './user.repository';
13-
import { Database, DATABASE_TOKEN, User } from './types';
10+
import { UserService } from '../src/user.service';
11+
import { UserValidator } from '../src/user.validator';
12+
import { UserRepository } from '../src/user.repository';
13+
import { Database, DATABASE_TOKEN, User } from '../src/types';
1414

1515
describe('User Service Unit Spec (Sociable Tests)', () => {
1616
/**

advanced-mock-config/src/user.solitary.spec.ts renamed to advanced-mock-config/tests/user.solitary.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77

88
import { type Mocked, TestBed } from "@suites/unit";
9-
import { UserService } from "./user.service";
10-
import { UserRepository } from "./user.repository";
11-
import { UserValidator } from "./user.validator";
12-
import { UserValidationResult } from "./types";
9+
import { UserService } from "../src/user.service";
10+
import { UserRepository } from "../src/user.repository";
11+
import { UserValidator } from "../src/user.validator";
12+
import { UserValidationResult } from "../src/types";
1313

1414
describe("User Service Unit Spec (Solitary Tests)", () => {
1515
/**
@@ -158,3 +158,4 @@ describe("User Service Unit Spec (Solitary Tests)", () => {
158158
* - Full call inspection available
159159
* - Use for: flexible defaults with per-test overrides
160160
*/
161+

advanced-mock-config/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"include": [
1717
"src/**/*.ts",
18+
"tests/**/*.ts",
1819
"global.d.ts"
1920
]
2021
}

inversify-jest/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ All tests should pass, demonstrating both solitary and sociable testing strategi
2525

2626
## Project Structure
2727

28+
**`src/`** - Application code being tested:
29+
2830
```
2931
src/
30-
├── types.ts # User types and interfaces
31-
├── user.validator.ts # Validation logic (no dependencies)
32-
├── user.repository.ts # Data access (token injection)
33-
├── user.service.ts # Business logic (class injections)
34-
├── user.solitary.spec.ts # Solitary unit tests
35-
└── user.sociable.spec.ts # Sociable unit tests
32+
├── types.ts # User types and interfaces
33+
├── user.validator.ts # Validation logic (no dependencies)
34+
├── user.repository.ts # Data access (token injection)
35+
└── user.service.ts # Business logic (class injections)
36+
```
37+
38+
**`tests/`** - Tests demonstrating Suites usage:
39+
40+
```
41+
tests/
42+
├── user.solitary.spec.ts # Solitary unit tests (all dependencies mocked)
43+
└── user.sociable.spec.ts # Sociable unit tests (real collaborators)
3644
```
3745

3846
## Key Patterns

inversify-jest/jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
testRegex: '.spec.ts$',
3+
testRegex: 'tests/.*\\.spec\\.ts$',
44
transform: {
55
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }]
66
},
77
collectCoverageFrom: [
88
'src/**/*.ts',
9-
'!src/**/*.spec.ts',
109
'!src/types.ts'
1110
]
1211
};

inversify-vitest/src/user.sociable.spec.ts renamed to inversify-jest/tests/user.sociable.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { type Mocked, TestBed } from '@suites/unit';
2-
import { UserService } from './user.service';
3-
import { UserValidator } from './user.validator';
4-
import { UserRepository } from './user.repository';
5-
import { Database, DATABASE_TOKEN } from './types';
2+
import { UserService } from '../src/user.service';
3+
import { UserValidator } from '../src/user.validator';
4+
import { UserRepository } from '../src/user.repository';
5+
import { Database, DATABASE_TOKEN } from '../src/types';
66

77
describe('User Service Unit Spec (Sociable Tests)', () => {
88
let userService: UserService;
@@ -51,3 +51,4 @@ describe('User Service Unit Spec (Sociable Tests)', () => {
5151
).rejects.toThrow('Name must be at least 2 characters');
5252
});
5353
});
54+

nestjs-jest/src/user.solitary.spec.ts renamed to inversify-jest/tests/user.solitary.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type Mocked, TestBed } from '@suites/unit';
2-
import { UserService } from './user.service';
3-
import { UserRepository } from './user.repository';
4-
import { UserValidator } from './user.validator';
2+
import { UserService } from '../src/user.service';
3+
import { UserRepository } from '../src/user.repository';
4+
import { UserValidator } from '../src/user.validator';
55

66
describe('User Service Unit Spec (Solitary Tests)', () => {
77
let userService: UserService;
@@ -59,3 +59,4 @@ describe('User Service Unit Spec (Solitary Tests)', () => {
5959
).rejects.toThrow('User with this email already exists');
6060
});
6161
});
62+

0 commit comments

Comments
 (0)