Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbarke committed Jun 14, 2017
2 parents 15d13e0 + 01f7a06 commit 717a6c6
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 46 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The easiest way is to keep `karma-typescript` as a devDependency in `package.jso
{
"devDependencies": {
"karma": "^1.5.0",
"karma-typescript": "3.0.3"
"karma-typescript": "3.0.4"
}
}
```
Expand Down Expand Up @@ -557,6 +557,7 @@ These are the environments reported failing/working:
|Npm|Node.js|OS|Works|
|---|---|---|---|
|2.5.18|4.4.7|Unknown|No|
|2.14.7|4.2.1|Ubuntu 14.04|No|
|2.14.12|4.2.6|OSX 10.11.3|No|
|2.15.9|4.5.0|OSX 10.11.6|No|
|2.15.9|4.6.0|OSX 10.12.3|No|
Expand Down
10 changes: 5 additions & 5 deletions dist/bundler/dependency-walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var DependencyWalker = (function () {
var _this = this;
var dependencyCount = 0;
queue.forEach(function (queued) {
queued.item.dependencies = _this.findUnresolvedTsRequires(queued.emitOutput.sourceFile);
queued.item.dependencies = _this.findUnresolvedTsRequires(queued.emitOutput);
var resolvedModules = queued.emitOutput.sourceFile.resolvedModules;
if (resolvedModules && !queued.emitOutput.sourceFile.isDeclarationFile) {
if (resolvedModules && !queued.emitOutput.isDeclarationFile) {
if (lodash.isMap(resolvedModules)) {
resolvedModules.forEach(function (resolvedModule, moduleName) {
queued.item.dependencies.push(new bundle_item_1.BundleItem(moduleName, resolvedModule && resolvedModule.resolvedFileName));
Expand Down Expand Up @@ -77,9 +77,9 @@ var DependencyWalker = (function () {
onDependenciesCollected(moduleNames.concat(dynamicDependencies));
});
};
DependencyWalker.prototype.findUnresolvedTsRequires = function (sourceFile) {
DependencyWalker.prototype.findUnresolvedTsRequires = function (emitOutput) {
var dependencies = [];
if (ts.isDeclarationFile(sourceFile)) {
if (emitOutput.isDeclarationFile) {
return dependencies;
}
var visitNode = function (node) {
Expand All @@ -98,7 +98,7 @@ var DependencyWalker = (function () {
}
ts.forEachChild(node, visitNode);
};
visitNode(sourceFile);
visitNode(emitOutput.sourceFile);
return dependencies;
};
DependencyWalker.prototype.addDynamicDependencies = function (expressions, bundleItem, onDynamicDependenciesAdded) {
Expand Down
9 changes: 8 additions & 1 deletion dist/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var Compiler = (function () {
"Is there a mismatch between the Typescript compiler options and the Karma config?");
}
queued.callback({
isDeclarationFile: ts.isDeclarationFile(sourceFile),
isDeclarationFile: _this.fileExtensionIs(sourceFile.fileName, ".d.ts"),
outputText: _this.compiledFiles[queued.file.path],
sourceFile: sourceFile,
sourceMapText: _this.compiledFiles[queued.file.path + ".map"]
Expand Down Expand Up @@ -114,6 +114,13 @@ var Compiler = (function () {
}
}
};
Compiler.prototype.fileExtensionIs = function (path, extension) {
return path.length > extension.length && this.endsWith(path, extension);
};
Compiler.prototype.endsWith = function (str, suffix) {
var expectedPos = str.length - suffix.length;
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
};
return Compiler;
}());
exports.Compiler = Compiler;
15 changes: 5 additions & 10 deletions dist/karma/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ var path = require("path");
var istanbul_1 = require("istanbul");
var Reporter = (function () {
function Reporter(config, sharedProcessedFiles, threshold) {
this.coverageReporter = require("karma-coverage/lib/reporter");
this.remap = require("remap-istanbul/lib/remap");
this.writeReport = require("remap-istanbul/lib/writeReport");
var self = this;
// tslint:disable-next-line:only-arrow-functions
this.create = function (karmaConfig, helper, logger, emitter) {
this.create = function (logger) {
var coverageMap;
var remapOptions = config.remapOptions;
self.log = logger.create("reporter.karma-typescript");
if (!config.hasReporter("coverage")) {
self.coverageReporter(karmaConfig, helper, logger, emitter);
}
this.adapters = [];
this.onRunStart = function () {
coverageMap = new WeakMap();
Expand All @@ -36,11 +31,11 @@ var Reporter = (function () {
}
unmappedCollector.add(coverage);
var sourceStore = istanbul_1.Store.create("memory");
remapOptions.sources = sourceStore;
remapOptions.readFile = function (filepath) {
config.remapOptions.sources = sourceStore;
config.remapOptions.readFile = function (filepath) {
return sharedProcessedFiles[filepath];
};
var collector = self.remap(unmappedCollector.getFinalCoverage(), remapOptions);
var collector = self.remap(unmappedCollector.getFinalCoverage(), config.remapOptions);
if (results && config.hasCoverageThreshold && !threshold.check(browser, collector)) {
results.exitCode = 1;
}
Expand All @@ -63,7 +58,7 @@ var Reporter = (function () {
});
};
};
this.create.$inject = ["config", "helper", "logger", "emitter"];
this.create.$inject = ["logger"];
}
Reporter.prototype.getReportDestination = function (browser, reports, reportType) {
var reportConfig = reports[reportType];
Expand Down
16 changes: 16 additions & 0 deletions dist/shared/configuration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var lodash = require("lodash");
var log4js = require("log4js");
var lodash_1 = require("lodash");
var Configuration = (function () {
Expand Down Expand Up @@ -114,6 +115,7 @@ var Configuration = (function () {
this.exclude = this.karmaTypescriptConfig.exclude;
this.include = this.karmaTypescriptConfig.include;
this.tsconfig = this.karmaTypescriptConfig.tsconfig;
this.assertExclude();
};
Configuration.prototype.configurePreprocessor = function () {
var transformPath = function (filepath) {
Expand Down Expand Up @@ -156,6 +158,20 @@ var Configuration = (function () {
"'frameworks: [\"karma-typescript\"]' to your Karma config");
}
};
Configuration.prototype.assertExclude = function () {
if (this.exclude !== undefined) {
if (!Array.isArray(this.exclude)) {
throw new Error("The option 'karmaTypescriptConfig.exclude' must be an array of strings, got [" +
typeof this.exclude + "]: " + this.exclude);
}
this.exclude.forEach(function (item) {
if (!lodash.isString(item)) {
throw new Error("Expected a string in 'karmaTypescriptConfig.exclude', got [" +
typeof item + "]: " + item);
}
});
}
};
Configuration.prototype.assertDeprecatedOptions = function () {
if (this.bundlerOptions.ignoredModuleNames) {
throw new Error("The option 'karmaTypescriptConfig.bundlerOptions.ignoredModuleNames' has been " +
Expand Down
3 changes: 3 additions & 0 deletions dist/shared/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ var Project = (function () {
Project.prototype.parseConfigFileJson = function (configFileName, configFileJson, existingOptions) {
var tsconfig;
var basePath = this.resolveBasepath(configFileName);
if (existingOptions && existingOptions.baseUrl === ".") {
existingOptions.baseUrl = basePath;
}
this.extend("include", configFileJson.config, this.config);
this.extend("exclude", configFileJson.config, this.config);
if (ts.parseConfigFile) {
Expand Down
2 changes: 1 addition & 1 deletion examples/angular2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-angular2",
"version": "3.0.3",
"version": "3.0.4",
"description": "Example project for Angular2",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion examples/angularjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-angularjs",
"version": "3.0.3",
"version": "3.0.4",
"description": "Example project for AngularJS 1.5",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion examples/docker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-docker",
"version": "3.0.3",
"version": "3.0.4",
"description": "",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion examples/gulp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foobar",
"version": "3.0.3",
"version": "3.0.4",
"description": "Example project for running a sequence of gulp tasks, issue https://github.com/monounity/karma-typescript/issues/29",
"author": "https://github.com/kubut",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion examples/mocha/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-mocha",
"version": "3.0.3",
"version": "3.0.4",
"description": "",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-1.6.2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-1-6-2",
"version": "3.0.3",
"version": "3.0.4",
"description": "",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-latest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript-examples-latest",
"version": "3.0.3",
"version": "3.0.4",
"description": "",
"author": "monounity",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-typescript",
"version": "3.0.3",
"version": "3.0.4",
"description": "Simplifying running unit tests with coverage for Typescript projects.",
"main": "dist/index.js",
"keywords": [
Expand Down
11 changes: 6 additions & 5 deletions src/bundler/dependency-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Logger } from "log4js";

import pad = require("pad");

import { EmitOutput } from "../compiler/emit-output";
import { BundleItem } from "./bundle-item";
import { Queued } from "./queued";

Expand All @@ -31,11 +32,11 @@ export class DependencyWalker {

queue.forEach((queued) => {

queued.item.dependencies = this.findUnresolvedTsRequires(queued.emitOutput.sourceFile);
queued.item.dependencies = this.findUnresolvedTsRequires(queued.emitOutput);

let resolvedModules = (<any> queued.emitOutput.sourceFile).resolvedModules;

if (resolvedModules && !queued.emitOutput.sourceFile.isDeclarationFile) {
if (resolvedModules && !queued.emitOutput.isDeclarationFile) {

if (lodash.isMap(resolvedModules)) { // Typescript 2.2+
resolvedModules.forEach((resolvedModule: any, moduleName: string) => {
Expand Down Expand Up @@ -101,11 +102,11 @@ export class DependencyWalker {
});
}

private findUnresolvedTsRequires(sourceFile: ts.SourceFile): BundleItem[] {
private findUnresolvedTsRequires(emitOutput: EmitOutput): BundleItem[] {

let dependencies: BundleItem[] = [];

if ((<any> ts).isDeclarationFile(sourceFile)) {
if (emitOutput.isDeclarationFile) {
return dependencies;
}

Expand All @@ -132,7 +133,7 @@ export class DependencyWalker {
ts.forEachChild(node, visitNode);
};

visitNode(sourceFile);
visitNode(emitOutput.sourceFile);

return dependencies;
}
Expand Down
11 changes: 10 additions & 1 deletion src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Compiler {
}

queued.callback({
isDeclarationFile: (<any> ts).isDeclarationFile(sourceFile),
isDeclarationFile: this.fileExtensionIs(sourceFile.fileName, ".d.ts"),
outputText: this.compiledFiles[queued.file.path],
sourceFile,
sourceMapText: this.compiledFiles[queued.file.path + ".map"]
Expand Down Expand Up @@ -161,4 +161,13 @@ export class Compiler {
}
}
}

private fileExtensionIs(path: string, extension: string) {
return path.length > extension.length && this.endsWith(path, extension);
}

private endsWith(str: string, suffix: string) {
let expectedPos = str.length - suffix.length;
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
}
}
2 changes: 1 addition & 1 deletion src/compiler/emit-output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from "typescript";

export interface EmitOutput {
isDeclarationFile: string;
isDeclarationFile: boolean;
outputText: string;
sourceFile: ts.SourceFile;
sourceMapText: string;
Expand Down
17 changes: 5 additions & 12 deletions src/karma/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class Reporter {

public create: { (karmaConfig: ConfigOptions, helper: any, logger: any, emitter: any): void };

private coverageReporter = require("karma-coverage/lib/reporter");
private log: Logger;
private remap = require("remap-istanbul/lib/remap");
private writeReport = require("remap-istanbul/lib/writeReport");
Expand All @@ -23,17 +22,11 @@ export class Reporter {
let self = this;

// tslint:disable-next-line:only-arrow-functions
this.create = function (karmaConfig: ConfigOptions, helper: any, logger: any, emitter: any) {
this.create = function (logger: any) {

let coverageMap: WeakMap<any, any>;
let remapOptions = config.remapOptions;

self.log = logger.create("reporter.karma-typescript");

if (!config.hasReporter("coverage")) {
self.coverageReporter(karmaConfig, helper, logger, emitter);
}

this.adapters = [];

this.onRunStart = () => {
Expand Down Expand Up @@ -61,11 +54,11 @@ export class Reporter {
unmappedCollector.add(coverage);

let sourceStore = (<any> Store).create("memory");
remapOptions.sources = sourceStore;
remapOptions.readFile = (filepath: string) => {
config.remapOptions.sources = sourceStore;
config.remapOptions.readFile = (filepath: string) => {
return sharedProcessedFiles[filepath];
};
let collector = self.remap((<any> unmappedCollector).getFinalCoverage(), remapOptions);
let collector = self.remap((<any> unmappedCollector).getFinalCoverage(), config.remapOptions);

if (results && config.hasCoverageThreshold && !threshold.check(browser, collector)) {
results.exitCode = 1;
Expand Down Expand Up @@ -94,7 +87,7 @@ export class Reporter {
};
};

(<any> this.create).$inject = ["config", "helper", "logger", "emitter"];
(<any> this.create).$inject = ["logger"];
}

private getReportDestination(browser: any, reports: any, reportType: any) {
Expand Down
17 changes: 17 additions & 0 deletions src/shared/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as lodash from "lodash";
import * as log4js from "log4js";

import { ConfigOptions } from "karma";
Expand Down Expand Up @@ -165,6 +166,7 @@ export class Configuration {
this.exclude = this.karmaTypescriptConfig.exclude;
this.include = this.karmaTypescriptConfig.include;
this.tsconfig = this.karmaTypescriptConfig.tsconfig;
this.assertExclude();
}

private configurePreprocessor() {
Expand Down Expand Up @@ -218,6 +220,21 @@ export class Configuration {
}
}

private assertExclude() {
if (this.exclude !== undefined) {
if (!Array.isArray(this.exclude)) {
throw new Error("The option 'karmaTypescriptConfig.exclude' must be an array of strings, got [" +
typeof this.exclude + "]: " + this.exclude);
}
this.exclude.forEach((item) => {
if (!lodash.isString(item)) {
throw new Error("Expected a string in 'karmaTypescriptConfig.exclude', got [" +
typeof item + "]: " + item);
}
});
}
}

private assertDeprecatedOptions() {
if ((<any> this.bundlerOptions).ignoredModuleNames) {
throw new Error("The option 'karmaTypescriptConfig.bundlerOptions.ignoredModuleNames' has been " +
Expand Down
Loading

0 comments on commit 717a6c6

Please sign in to comment.