Skip to content

Commit

Permalink
feat(spies): add view-spy and compile-spy
Browse files Browse the repository at this point in the history
These have been moved from templating-resources.
  • Loading branch information
EisenbergEffect committed May 30, 2016
1 parent 14f453f commit fc81850
Show file tree
Hide file tree
Showing 28 changed files with 1,596 additions and 514 deletions.
42 changes: 29 additions & 13 deletions build/tasks/build.js
Expand Up @@ -9,16 +9,26 @@ var concat = require('gulp-concat');
var insert = require('gulp-insert');
var rename = require('gulp-rename');
var tools = require('aurelia-tools');
var gulpIgnore = require('gulp-ignore');

var jsName = paths.packageName + '.js';

function removeDTSPlugin(options) {
var found = options.plugins.find(function(x){
return x instanceof Array;
});

var index = options.plugins.indexOf(found);
options.plugins.splice(index, 1);
return options;
}

gulp.task('build-index', function(){
var importsToAdd = [];
var files = ['component-tester.js'].map(function(file){
return paths.root + file;
});

return gulp.src(files)
return gulp.src(paths.source)
.pipe(tools.sortFiles())
.pipe(gulpIgnore.exclude('aurelia-testing.js'))
.pipe(through2.obj(function(file, enc, callback) {
file.contents = new Buffer(tools.extractImports(file.contents.toString("utf8"), importsToAdd));
this.push(file);
Expand All @@ -31,27 +41,33 @@ gulp.task('build-index', function(){
.pipe(gulp.dest(paths.output));
});

gulp.task('build-es2015-temp', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.commonjs())))
.pipe(gulp.dest(paths.output + 'temp'));
});

gulp.task('build-es2015', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.es2015())))
return gulp.src(paths.source)
.pipe(to5(assign({}, removeDTSPlugin(compilerOptions.es2015()))))
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-commonjs', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.commonjs())))
return gulp.src(paths.source)
.pipe(to5(assign({}, removeDTSPlugin(compilerOptions.commonjs()))))
.pipe(gulp.dest(paths.output + 'commonjs'));
});

gulp.task('build-amd', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.amd())))
return gulp.src(paths.source)
.pipe(to5(assign({}, removeDTSPlugin(compilerOptions.amd()))))
.pipe(gulp.dest(paths.output + 'amd'));
});

gulp.task('build-system', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.system())))
return gulp.src(paths.source)
.pipe(to5(assign({}, removeDTSPlugin(compilerOptions.system()))))
.pipe(gulp.dest(paths.output + 'system'));
});

Expand All @@ -68,7 +84,7 @@ gulp.task('build', function(callback) {
return runSequence(
'clean',
'build-index',
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
['build-es2015-temp', 'build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
callback
);
Expand Down
70 changes: 67 additions & 3 deletions dist/amd/aurelia-testing.d.ts
@@ -1,13 +1,62 @@
declare module 'aurelia-testing' {
import * as LogManager from 'aurelia-logging';
import {
customAttribute,
View,
TargetInstruction
} from 'aurelia-templating';
import {
bootstrap
} from 'aurelia-bootstrapper';
import {
View
} from 'aurelia-templating';
import {
Aurelia
} from 'aurelia-framework';
import {
inject
} from 'aurelia-dependency-injection';
import {
DOM
} from 'aurelia-pal';

/**
* Attribute to be placed on any HTML element in a view to emit the View instance
* to the debug console, giving you insight into the live View instance, including
* all child views, live bindings, behaviors and more.
*/
export class ViewSpy {

/**
* Creates a new instance of ViewSpy.
*/
constructor();

/**
* Invoked when the target view is created.
* @param view The target view.
*/
created(view: any): any;

/**
* Invoked when the target view is bound.
* @param bindingContext The target view's binding context.
*/
bind(bindingContext: any): any;

/**
* Invoked when the target element is attached to the DOM.
*/
attached(): any;

/**
* Invoked when the target element is detached from the DOM.
*/
detached(): any;

/**
* Invoked when the target element is unbound.
*/
unbind(): any;
}
export const StageComponent: any;
export class ComponentTester {
bind: ((bindingContext: any) => void);
Expand All @@ -28,4 +77,19 @@ declare module 'aurelia-testing' {
manuallyHandleLifecycle(): ComponentTester;
create(): Promise<void>;
}

/**
* Attribute to be placed on any element to have it emit the View Compiler's
* TargetInstruction into the debug console, giving you insight into all the
* parsed bindings, behaviors and event handers for the targeted element.
*/
export class CompileSpy {

/**
* Creates and instanse of CompileSpy.
* @param element target element on where attribute is placed on.
* @param instruction instructions for how the target element should be enhanced.
*/
constructor(element: any, instruction: any);
}
}
131 changes: 4 additions & 127 deletions dist/amd/aurelia-testing.js
@@ -1,134 +1,11 @@
define(['exports', 'aurelia-bootstrapper', 'aurelia-templating', 'aurelia-framework'], function (exports, _aureliaBootstrapper, _aureliaTemplating, _aureliaFramework) {
define(['exports'], function (exports) {
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ComponentTester = exports.StageComponent = undefined;

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
exports.configure = configure;
function configure(config) {
config.globalResources('./compile-spy', './view-spy');
}

var StageComponent = exports.StageComponent = {
withResources: function withResources(resources) {
return new ComponentTester().withResources(resources);
}
};

var ComponentTester = exports.ComponentTester = function () {
function ComponentTester() {
_classCallCheck(this, ComponentTester);

this.configure = function (aurelia) {
return aurelia.use.standardConfiguration();
};

this._resources = [];
}

ComponentTester.prototype.bootstrap = function bootstrap(configure) {
this.configure = configure;
};

ComponentTester.prototype.withResources = function withResources(resources) {
this._resources = resources;
return this;
};

ComponentTester.prototype.inView = function inView(html) {
this._html = html;
return this;
};

ComponentTester.prototype.boundTo = function boundTo(bindingContext) {
this._bindingContext = bindingContext;
return this;
};

ComponentTester.prototype.manuallyHandleLifecycle = function manuallyHandleLifecycle() {
this._prepareLifecycle();
return this;
};

ComponentTester.prototype.create = function create() {
var _this = this;

return (0, _aureliaBootstrapper.bootstrap)(function (aurelia) {
return Promise.resolve(_this.configure(aurelia)).then(function () {
aurelia.use.globalResources(_this._resources);
return aurelia.start().then(function (a) {
var host = document.createElement('div');
host.innerHTML = _this._html;
document.body.appendChild(host);
aurelia.enhance(_this._bindingContext, host);
_this._rootView = aurelia.root;
_this.element = host.firstElementChild;
_this.viewModel = _this.element.au.controller.viewModel;
_this.dispose = function () {
return host.parentNode.removeChild(host);
};
return new Promise(function (resolve) {
return setTimeout(function () {
return resolve();
}, 0);
});
});
});
});
};

ComponentTester.prototype._prepareLifecycle = function _prepareLifecycle() {
var _this2 = this;

var bindPrototype = _aureliaTemplating.View.prototype.bind;
_aureliaTemplating.View.prototype.bind = function () {};
this.bind = function (bindingContext) {
return new Promise(function (resolve) {
_aureliaTemplating.View.prototype.bind = bindPrototype;
if (bindingContext !== undefined) {
_this2._bindingContext = bindingContext;
}
_this2._rootView.bind(_this2._bindingContext);
setTimeout(function () {
return resolve();
}, 0);
});
};

var attachedPrototype = _aureliaTemplating.View.prototype.attached;
_aureliaTemplating.View.prototype.attached = function () {};
this.attached = function () {
return new Promise(function (resolve) {
_aureliaTemplating.View.prototype.attached = attachedPrototype;
_this2._rootView.attached();
setTimeout(function () {
return resolve();
}, 0);
});
};

this.detached = function () {
return new Promise(function (resolve) {
_this2._rootView.detached();
setTimeout(function () {
return resolve();
}, 0);
});
};

this.unbind = function () {
return new Promise(function (resolve) {
_this2._rootView.unbind();
setTimeout(function () {
return resolve();
}, 0);
});
};
};

return ComponentTester;
}();
});
41 changes: 41 additions & 0 deletions dist/amd/compile-spy.js
@@ -0,0 +1,41 @@
define(['exports', 'aurelia-templating', 'aurelia-dependency-injection', 'aurelia-logging', 'aurelia-pal'], function (exports, _aureliaTemplating, _aureliaDependencyInjection, _aureliaLogging, _aureliaPal) {
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CompileSpy = undefined;

var LogManager = _interopRequireWildcard(_aureliaLogging);

function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};

if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
}
}

newObj.default = obj;
return newObj;
}
}

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var _dec, _dec2, _class;

var CompileSpy = exports.CompileSpy = (_dec = (0, _aureliaTemplating.customAttribute)('compile-spy'), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _aureliaTemplating.TargetInstruction), _dec(_class = _dec2(_class = function CompileSpy(element, instruction) {
_classCallCheck(this, CompileSpy);

LogManager.getLogger('compile-spy').info(element, instruction);
}) || _class) || _class);
});

0 comments on commit fc81850

Please sign in to comment.