Skip to content

Commit

Permalink
fix: fix ci test to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Mar 19, 2020
1 parent dd277c6 commit d93ccc2
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 85 deletions.
25 changes: 12 additions & 13 deletions test/src/db/impl/dependencyRepositoryProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Dependency, IConnectionProvider } from '../../../../src/db';
import { DependencyRepositoryProvider } from '../../../../src/db/impl/dependencyRepositoryProvider';
import { Connection } from 'typeorm/connection/Connection';
import Mock = jest.Mock;

describe(`dependency repository provider`, () => {
const placeholder = `PLACEHOLDER`;

const getRepositoryMock = jest.fn();
const connectionSpy = ({
getRepository: getRepositoryMock,
} as any) as Connection;
const getConnectionMock = jest.fn();
const connectionProviderSpy = ({
getConnection: getConnectionMock,
} as any) as IConnectionProvider;
let dependencyRepositoryProvider: DependencyRepositoryProvider;
let getConnectionMock: Mock;
let getRepositoryMock: Mock;

beforeEach(() => {
getRepositoryMock = jest.fn();
getRepositoryMock.mockReturnValue(placeholder);
const connectionSpy = ({
getRepository: getRepositoryMock,
} as any) as Connection;
getConnectionMock = jest.fn();
getConnectionMock.mockResolvedValue(connectionSpy);
const connectionProviderSpy = ({
getConnection: getConnectionMock,
} as any) as IConnectionProvider;
dependencyRepositoryProvider = new DependencyRepositoryProvider(connectionProviderSpy);
getConnectionMock.mockReset();
getConnectionMock.mockResolvedValue(connectionSpy);
getRepositoryMock.mockReset();
getRepositoryMock.mockReturnValue(placeholder);
});

it(`should cache repo`, async () => {
Expand Down
26 changes: 12 additions & 14 deletions test/src/db/impl/dependencyVersionRepositoryProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { DependencyVersion, IConnectionProvider } from '../../../../src/db';
import { Connection } from 'typeorm/connection/Connection';
import Mock = jest.Mock;
import { DependencyVersionRepositoryProvider } from '../../../../src/db/impl/dependencyVersionRepositoryProvider';

describe(`dependency version repository provider`, () => {
const placeholder = `PLACEHOLDER`;

const getRepositoryMock = jest.fn();
const connectionSpy = ({
getRepository: getRepositoryMock,
} as any) as Connection;
const getConnectionMock = jest.fn();
const connectionProviderSpy = ({
getConnection: getConnectionMock,
} as any) as IConnectionProvider;
let dependencyVersionRepositoryProvider: DependencyVersionRepositoryProvider;
let getConnectionMock: Mock;
let getRepositoryMock: Mock;

beforeEach(() => {
getRepositoryMock = jest.fn();
getRepositoryMock.mockReturnValue(placeholder);
const connectionSpy = ({
getRepository: getRepositoryMock,
} as any) as Connection;
getConnectionMock = jest.fn();
getConnectionMock.mockResolvedValue(connectionSpy);
const connectionProviderSpy = ({
getConnection: getConnectionMock,
} as any) as IConnectionProvider;
dependencyVersionRepositoryProvider = new DependencyVersionRepositoryProvider(connectionProviderSpy);
getConnectionMock.mockReset();
getConnectionMock.mockResolvedValue(connectionSpy);
getRepositoryMock.mockReset();
getRepositoryMock.mockReturnValue(placeholder);
});

it(`should cache repo`, async () => {
Expand Down
24 changes: 11 additions & 13 deletions test/src/resolvers/cacheResolver/impl/cacheResolver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { Dependency, IDependencyRepositoryProvider } from '../../../../../src/db';
import { Repository } from 'typeorm';
import Mock = jest.Mock;
import { CacheResolver } from '../../../../../src/resolvers/cacheResolver/impl/cacheResolver';

describe(`cache resolver`, () => {
let cacheResolver: CacheResolver;
let findOneStub: Mock;
const findOneStub = jest.fn();
const repositorySpy = ({
findOne: findOneStub,
} as any) as Repository<Dependency>;
const dependencyRepositoryProviderSpy: IDependencyRepositoryProvider = {
getRepository: async (): Promise<Repository<Dependency>> => {
return repositorySpy;
},
};
const cacheResolver = new CacheResolver(dependencyRepositoryProviderSpy);

beforeEach(() => {
findOneStub = jest.fn();
const repositorySpy = ({
findOne: findOneStub,
} as any) as Repository<Dependency>;
const dependencyRepositoryProviderSpy: IDependencyRepositoryProvider = {
getRepository: async (): Promise<Repository<Dependency>> => {
return repositorySpy;
},
};
cacheResolver = new CacheResolver(dependencyRepositoryProviderSpy);
findOneStub.mockReset();
});

it(`should resolve if match in cache`, async () => {
Expand Down
49 changes: 49 additions & 0 deletions test/src/resolvers/ciResolver/impl/resolvers/appveyor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { AppVeyorResolver } from '../../../../../../src/resolvers/ciResolver/impl/resolvers/appveyor';
import { FS } from '../../../../../../src/container/nodeModulesContainer';

describe(`appveyor`, () => {
const repoPath = `placeholder`;
const fsMock = jest.fn();
const fsSpy = ({
promises: {
readFile: fsMock,
},
} as any) as FS;
const appVeyorResolver = new AppVeyorResolver(fsSpy);

beforeEach(() => {
fsMock.mockReset();
});

it(`should expose the proper name`, async () => {
expect(appVeyorResolver.resolverName).toBe(`appVeyor`);
});

it(`should resolve node js from travis configuration matrix`, async () => {
const versions = await appVeyorResolver.resolve({
repoPath,
});
expect(versions).toEqual([`4`, `6`, `1.0`]);
});

it(`should resolve node js from travis configuration`, async () => {
const versions = await appVeyorResolver.resolve({
repoPath,
});
expect(versions).toEqual([`8`]);
});

it(`should throw due to faulty configuration`, async () => {
const promise = appVeyorResolver.resolve({
repoPath,
});
await expect(promise).rejects.toBeInstanceOf(Error);
});

it(`should return undefined from non relevant repo`, async () => {
const versions = await appVeyorResolver.resolve({
repoPath,
});
expect(versions).toBeFalsy();
});
});
14 changes: 6 additions & 8 deletions test/src/resolvers/ciResolver/impl/targetMatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Mock = jest.Mock;
import { ILts } from '../../../../../src/utils/lts';
import { TargetMatcher } from '../../../../../src/resolvers/ciResolver/impl/targetMatcher';
// eslint-disable-next-line @typescript-eslint/quotes
Expand All @@ -8,15 +7,14 @@ const dateFormat = `YYYY-MM-DD`;
const packageReleaseDate = moment.utc(`2015-10-02`, dateFormat);

describe(`target matcher`, () => {
let targetMatcher: TargetMatcher;
let resolveLtsVersionMock: Mock;
const resolveLtsVersionMock = jest.fn();
const ltsMock = ({
resolveLtsVersion: resolveLtsVersionMock,
} as any) as ILts;
const targetMatcher = new TargetMatcher(ltsMock);

beforeEach(() => {
resolveLtsVersionMock = jest.fn();
const ltsMock = ({
resolveLtsVersion: resolveLtsVersionMock,
} as any) as ILts;
targetMatcher = new TargetMatcher(ltsMock);
resolveLtsVersionMock.mockReset();
});

it(`should match target node from candidates`, async () => {
Expand Down
6 changes: 1 addition & 5 deletions test/src/utils/lts/impl/lts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { Lts } from '../../../../../src/utils/lts/impl/lts';
const dateFormat = `YYYY-MM-DD`;

describe(`lts`, () => {
let lts: Lts;

beforeEach(() => {
lts = new Lts();
});
const lts = new Lts();

it(`should resolve to node 4`, async () => {
const versions = await lts.resolveLtsVersion({
Expand Down
14 changes: 6 additions & 8 deletions test/src/utils/packageInfo/impl/packageInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import Mock = jest.Mock;
import { PackageInfo } from '../../../../../src/utils/packageInfo/impl/packageInfo';
import { Pacote } from '../../../../../src/container/nodeModulesContainer';

describe(`package info`, () => {
let packageInfo: PackageInfo;
let manifestMock: Mock;
const manifestMock = jest.fn();
const pacoteSpy = ({
manifest: manifestMock,
} as any) as Pacote;
const packageInfo = new PackageInfo(pacoteSpy);

beforeEach(() => {
manifestMock = jest.fn();
const pacoteSpy = ({
manifest: manifestMock,
} as any) as Pacote;
packageInfo = new PackageInfo(pacoteSpy);
manifestMock.mockReset();
});

it(`should resolve package info properly`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ import * as fs from 'fs';
import { resourcesDir } from '../../../../../common';

describe(`appveyor`, () => {
let appVeyorResolver: AppVeyorResolver;

beforeEach(() => {
appVeyorResolver = new AppVeyorResolver(fs);
});

it(`should expose the proper name`, async () => {
expect(appVeyorResolver.resolverName).toBe(`appVeyor`);
});
const appVeyorResolver = new AppVeyorResolver(fs);

it(`should resolve node js from travis configuration matrix`, async () => {
const repoPath = path.join(resourcesDir, `appveyor`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { CircleCiResolver } from '../../../../../../src/resolvers/ciResolver/imp
import * as fs from 'fs';

describe(`circle ci`, () => {
let circleCiResolver: CircleCiResolver;

beforeEach(() => {
circleCiResolver = new CircleCiResolver(fs);
});
const circleCiResolver = new CircleCiResolver(fs);

it(`should expose the proper name`, async () => {
expect(circleCiResolver.resolverName).toBe(`circleCi`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { resourcesDir } from '../../../../../common';
import * as fs from 'fs';

describe(`github actions`, () => {
let githubActionsResolver: GithubActionsResolver;

beforeEach(() => {
githubActionsResolver = new GithubActionsResolver(fs);
});
const githubActionsResolver = new GithubActionsResolver(fs);

it(`should expose the proper name`, async () => {
expect(githubActionsResolver.resolverName).toBe(`githubActions`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { LTS_VERSION } from '../../../../../../src/resolvers/ciResolver';
import * as fs from 'fs';

describe(`travis ci`, () => {
let travisCiResolver: TravisCiResolver;

beforeEach(() => {
travisCiResolver = new TravisCiResolver(fs);
});
const travisCiResolver = new TravisCiResolver(fs);

it(`should expose the proper name`, async () => {
expect(travisCiResolver.resolverName).toBe(`travisCi`);
Expand Down

0 comments on commit d93ccc2

Please sign in to comment.