Skip to content

Commit

Permalink
feature: add unit tests for multi injects
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Mar 19, 2020
1 parent 68f2288 commit eb393ac
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ src
!**/*.d.ts
.lintstagedrc
test/
testInteg
testE2E
# config files
tslint.json
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
"pretest:e2e": "yarn run lint",
"test:unit": "yarn jest 'test/.*\\.spec\\.ts'",
"test:e2e": "yarn jest 'testE2E/.*\\.spec\\.ts'",
"test": "yarn jest 'test/.*\\.spec\\.ts' 'testE2E/.*\\.spec\\.ts'",
"test:integ": "yarn jest 'testInteg/.*\\.spec\\.ts'",
"test": "yarn jest 'test/.*\\.spec\\.ts' 'testInteg/.*\\.spec\\.ts' 'testE2E/.*\\.spec\\.ts'",
"clean:cover": "rm -rf coverage",
"precover": "yarn run clean:cover && yarn run lint",
"precover:unit": "yarn run clean:cover && yarn run lint",
"precover:e2e": "yarn run clean:cover && yarn run lint",
"cover:e2e": "yarn jest --coverage 'testE2E/.*\\.spec\\.ts'",
"cover:integ": "yarn jest --coverage 'testInteg/.*\\.spec\\.ts'",
"cover:unit": "yarn jest --coverage 'test/.*\\.spec\\.ts'",
"cover": "yarn jest --coverage 'test/.*\\.spec\\.ts' 'testE2E/.*\\.spec\\.ts'",
"cover": "yarn jest --coverage 'test/.*\\.spec\\.ts' 'testInteg/.*\\.spec\\.ts' 'testE2E/.*\\.spec\\.ts'",
"prelint": "yarn run format:check",
"lint": "yarn eslint . --ext .ts",
"lint:fix": "yarn eslint . --fix --ext .ts",
Expand Down
38 changes: 38 additions & 0 deletions test/src/container/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { container } from '../../../src/container';
import { IEntity } from '../../../src/db/interfaces/entity';
import { Dependency, DependencyVersion } from '../../../src/db';
import { ISpecificCIResolver } from '../../../src/resolvers/ciResolver';
import { TravisCiResolver } from '../../../src/resolvers/ciResolver/impl/resolvers/travis';
import { GithubActionsResolver } from '../../../src/resolvers/ciResolver/impl/resolvers/github';
import { CircleCiResolver } from '../../../src/resolvers/ciResolver/impl/resolvers/circle';
import { AppVeyorResolver } from '../../../src/resolvers/ciResolver/impl/resolvers/appveyor';

describe(`container`, () => {
beforeEach(() => {
container.snapshot();
});

afterEach(() => {
container.restore();
});

it(`Should inject all entities`, () => {
const entities = container.getAll(IEntity);
expect(entities.length).toBe(2);
expect(entities).toContain(Dependency);
expect(entities).toContain(DependencyVersion);
});

it(`Should inject all specific ci resolvers`, () => {
const entities = container.getAll(ISpecificCIResolver);
expect(entities).toHaveLength(4);
expect(entities).toEqual(
expect.arrayContaining([
expect.any(AppVeyorResolver),
expect.any(CircleCiResolver),
expect.any(GithubActionsResolver),
expect.any(TravisCiResolver),
])
);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["src", "test", "testE2E"]
"include": ["src", "test", "testE2E", "testInteg"]
}

0 comments on commit eb393ac

Please sign in to comment.