build single test bunding using Webpack context

This commit is contained in:
alecmerdler 2017-03-11 16:48:05 -08:00
parent b72cf7c04b
commit ade4216642
8 changed files with 81 additions and 31 deletions

View file

@ -30,8 +30,8 @@ module.exports = function(config) {
// static/lib resources
'static/lib/**/*.js',
// Tests
'static/js/**/*.spec.ts*',
// Single entrypoint for all tests
'static/test/test-index.ts',
// Tests utils
'static/test/**/*.js',
@ -41,7 +41,7 @@ module.exports = function(config) {
'static/lib/ngReact/react.ngReact.min.js': ['webpack'],
'static/lib/angular-moment.min.js': ['webpack'],
'node_modules/core-js/index.js': ['webpack'],
'static/js/**/*.spec.ts*': ['webpack'],
'static/test/test-index.ts': ['webpack'],
},
webpack: webpackConfig,
webpackMiddleware: {

View file

@ -16,6 +16,7 @@ import { QuayRun } from './quay-run.module';
import { BuildServiceImpl } from './services/build/build.service.impl';
import { AvatarServiceImpl } from './services/avatar/avatar.service.impl';
import { DockerfileServiceImpl } from './services/dockerfile/dockerfile.service.impl';
import { DataFileServiceImpl } from './services/datafile/datafile.service.impl';
/**
@ -40,6 +41,7 @@ import { DockerfileServiceImpl } from './services/dockerfile/dockerfile.service.
BuildServiceImpl,
AvatarServiceImpl,
DockerfileServiceImpl,
DataFileServiceImpl,
],
})
export class quay {

View file

@ -1,11 +1,11 @@
import { DatafileServiceImpl } from './datafile.service.impl';
import { DataFileServiceImpl } from './datafile.service.impl';
describe("DatafileServiceImpl", () => {
var datafileServiceImpl: DatafileServiceImpl;
describe("DataFileServiceImpl", () => {
var dataFileServiceImpl: DataFileServiceImpl;
beforeEach(() => {
datafileServiceImpl = new DatafileServiceImpl();
dataFileServiceImpl = new DataFileServiceImpl();
});
describe("blobToString", () => {

View file

@ -1,23 +1,36 @@
import { DatafileService } from './datafile.service';
import { DataFileService } from './datafile.service';
import { Injectable } from 'angular-ts-decorators';
declare const JSZip: (buf: any) => void;
declare const Zlib: any;
declare const Untar: (uint8Array: Uint8Array) => void;
export class DatafileServiceImpl implements DatafileService {
@Injectable(DataFileService.name)
export class DataFileServiceImpl implements DataFileService {
public blobToString(blob: any, callback: (result: string) => void): void {
var reader: FileReader = new FileReader();
reader.onload = (event: Event) => callback(reader.result);
reader.readAsText(blob);
}
public arrayToString(buf: any, callback: (result: string) => void): void {
var blob: Blob = new Blob([buf], {type: 'application/octet-binary'});
var reader = new FileReader();
reader.onload = (event: Event) => callback(event.target['result']);
reader.onerror = (event: Event) => callback(null);
reader.onabort = (event: Event) => callback(null);
reader.readAsText(blob);
}
public readDataArrayAsPossibleArchive(buf: any,
success: (result: any) => void,
failure: (error: any) => void): void {
this.tryAsZip(buf, success, () => {
this.tryAsTarGz(buf, success, () => {
this.tryAsTar(buf, success, failure);
});
});
}
public downloadDataFileAsArrayBuffer($scope: ng.IScope,
@ -25,7 +38,36 @@ export class DatafileServiceImpl implements DatafileService {
progress: (percent: number) => void,
error: () => void,
loaded: (uint8array: Uint8Array) => void): void {
var request: XMLHttpRequest = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onprogress = (e) => {
$scope.$apply(() => {
var percentLoaded;
if (e.lengthComputable) {
progress(e.loaded / e.total);
}
});
};
request.onerror = () => {
$scope.$apply(() => {
error();
});
};
request.onload = function() {
if (request.status == 200) {
$scope.$apply(() => {
var uint8array = new Uint8Array(request.response);
loaded(uint8array);
});
return;
}
};
request.send();
}
private getName(filePath: string): string {

View file

@ -6,7 +6,7 @@
* - Blob.js
* - zlib.js
*/
export abstract class DatafileService {
export abstract class DataFileService {
/**
* Convert a blob to a string.

View file

@ -1,22 +1,22 @@
import { DockerfileServiceImpl, DockerfileInfoImpl } from './dockerfile.service.impl';
import { DatafileService } from '../datafile/datafile.service';
import { DataFileService } from '../datafile/datafile.service';
import Spy = jasmine.Spy;
import { Mock } from 'ts-mocks';
describe("DockerfileServiceImpl", () => {
var dockerfileServiceImpl: DockerfileServiceImpl;
var datafileServiceMock: Mock<DatafileService>;
var datafileService: DatafileService;
var dataFileServiceMock: Mock<DataFileService>;
var dataFileService: DataFileService;
var configMock: any;
var fileReaderMock: FileReader;
beforeEach(() => {
datafileServiceMock = new Mock<DatafileService>();
datafileService = datafileServiceMock.Object;
dataFileServiceMock = new Mock<DataFileService>();
dataFileService = dataFileServiceMock.Object;
configMock = jasmine.createSpyObj('configMock', ['getDomain']);
fileReaderMock = new FileReader();
dockerfileServiceImpl = new DockerfileServiceImpl(datafileService, configMock, () => fileReaderMock);
dockerfileServiceImpl = new DockerfileServiceImpl(dataFileService, configMock, () => fileReaderMock);
});
describe("getDockerfile", () => {
@ -27,15 +27,15 @@ describe("DockerfileServiceImpl", () => {
var forDataSpy: Spy;
beforeEach(() => {
datafileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
dataFileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
failure([]);
});
datafileServiceMock.setup(mock => mock.arrayToString).is((buf, callback) => {
dataFileServiceMock.setup(mock => mock.arrayToString).is((buf, callback) => {
callback("");
});
datafileServiceMock.setup(mock => mock.blobToString).is((blob, callback) => {
dataFileServiceMock.setup(mock => mock.blobToString).is((blob, callback) => {
callback(blob.toString());
});
@ -54,7 +54,7 @@ describe("DockerfileServiceImpl", () => {
dockerfileServiceImpl.getDockerfile(file)
.then((dockerfile: DockerfileInfoImpl) => {
expect(readAsFileBufferSpy.calls.argsFor(0)[0]).toEqual(file);
expect(datafileService.readDataArrayAsPossibleArchive).toHaveBeenCalled();
expect(dataFileService.readDataArrayAsPossibleArchive).toHaveBeenCalled();
done();
})
.catch((error: string) => {
@ -66,7 +66,7 @@ describe("DockerfileServiceImpl", () => {
it("calls datafile service to convert file to string if given file is not an archive", (done) => {
dockerfileServiceImpl.getDockerfile(file)
.then((dockerfile: DockerfileInfoImpl) => {
expect((<Spy>datafileService.arrayToString).calls.argsFor(0)[0]).toEqual(file);
expect((<Spy>dataFileService.arrayToString).calls.argsFor(0)[0]).toEqual(file);
done();
})
.catch((error: string) => {
@ -101,7 +101,7 @@ describe("DockerfileServiceImpl", () => {
});
it("returns rejected promise if given archive file with no Dockerfile present in root directory", (done) => {
datafileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
dataFileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
success(invalidArchiveFile);
});
@ -117,14 +117,14 @@ describe("DockerfileServiceImpl", () => {
});
it("calls datafile service to convert blob to string if given file is an archive", (done) => {
datafileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
dataFileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
success(validArchiveFile);
});
dockerfileServiceImpl.getDockerfile(file)
.then((dockerfile: DockerfileInfoImpl) => {
expect(validArchiveFile[0].toBlob).toHaveBeenCalled();
expect((<Spy>datafileService.blobToString).calls.argsFor(0)[0]).toEqual(validArchiveFile[0].toBlob());
expect((<Spy>dataFileService.blobToString).calls.argsFor(0)[0]).toEqual(validArchiveFile[0].toBlob());
done();
})
.catch((error: string) => {
@ -136,7 +136,7 @@ describe("DockerfileServiceImpl", () => {
it("returns rejected promise if given archive file with invalid Dockerfile", (done) => {
forDataSpy.and.returnValue(null);
invalidArchiveFile[0].name = 'Dockerfile';
datafileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
dataFileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
success(invalidArchiveFile);
});
@ -152,7 +152,7 @@ describe("DockerfileServiceImpl", () => {
});
it("returns resolved promise of new DockerfileInfoImpl instance if given archive with valid Dockerfile", (done) => {
datafileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
dataFileServiceMock.setup(mock => mock.readDataArrayAsPossibleArchive).is((buf, success, failure) => {
success(validArchiveFile);
});

View file

@ -1,12 +1,12 @@
import { DockerfileService, DockerfileInfo } from './dockerfile.service';
import { Injectable } from 'angular-ts-decorators';
import { DatafileService } from '../datafile/datafile.service';
import { DataFileService } from '../datafile/datafile.service';
@Injectable(DockerfileService.name)
export class DockerfileServiceImpl implements DockerfileService {
constructor(private DataFileService: DatafileService,
constructor(private DataFileService: DataFileService,
private Config: any,
private fileReaderFactory: () => FileReader) {

View file

@ -0,0 +1,6 @@
declare var require: any;
// Require all modules ending in ".spec.ts" from the js directory and all subdirectories
var testsContext = require.context("../js", true, /\.spec\.ts$/);
testsContext.keys().forEach(testsContext);