From 68ced237fbd1c4fe0bc25324deafca99d87f8321 Mon Sep 17 00:00:00 2001 From: Barrie Treloar Date: Thu, 11 Jul 2019 09:53:39 +0930 Subject: [PATCH 1/3] fix(karma): add retainLines to babelPreprocessor When a test fails under Karma the console stacktrace contains incorrect line numbers making debugging impossible. Applying fix manually as described in https://github.com/chriscasola/karma/commit/67d1cfe5bc4a85c039bb4d8af36b366879aa6cc0 closes aurelia/templating#670 --- karma.conf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/karma.conf.js b/karma.conf.js index e15c014b..088fce3d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -36,6 +36,7 @@ module.exports = function(config) { 'babelPreprocessor': { options: { sourceMap: 'inline', + retainLines: true, presets: [ 'es2015-loose', 'stage-1'], plugins: [ 'syntax-flow', From 1c746184aff0489e4cc0feab1667d2dfa4b55553 Mon Sep 17 00:00:00 2001 From: Barrie Treloar Date: Thu, 11 Jul 2019 12:32:19 +0930 Subject: [PATCH 2/3] Attempt at getting InlineView test working. --- test/view-strategy.spec.js | 46 ++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/test/view-strategy.spec.js b/test/view-strategy.spec.js index 3909678b..9905002d 100644 --- a/test/view-strategy.spec.js +++ b/test/view-strategy.spec.js @@ -4,7 +4,7 @@ import { ResourceLoadContext, ViewCompileInstruction } from '../src/instructions import { ViewCompiler } from '../src/view-compiler'; import { ViewEngine } from '../src/view-engine'; import { ViewResources } from '../src/view-resources'; -import { StaticViewStrategy } from '../src/view-strategy'; +import { InlineViewStrategy, StaticViewStrategy } from '../src/view-strategy'; import './setup'; import { ViewEngineHooksResource } from '../src/view-engine-hooks-resource'; import { metadata } from 'aurelia-metadata'; @@ -14,11 +14,13 @@ import { _hyphenate } from '../src/util'; describe('ViewLocator', () => { /**@type {ViewEngine} */ let viewEngine; - let container = new Container(); - let appResources = new ViewResources(); + /**@type {Container} */ + let container; + /**@type {ViewResources} */ + let appResources; beforeEach(() => { - let bindingLanguage = new class extends BindingLanguage { + const bindingLanguage = new class extends BindingLanguage { createAttributeInstruction () {} inspectAttribute (resources, tagName, attrName, attrValue) { return { attrName, attrValue}; @@ -27,11 +29,13 @@ describe('ViewLocator', () => { }; container = new Container(); appResources = new ViewResources(); - viewEngine = { - container: container, - appResources: appResources, - viewCompiler: new ViewCompiler(bindingLanguage, appResources) - }; + viewEngine = new ViewEngine( + null, // no loader + container, + new ViewCompiler(bindingLanguage, appResources), + null, // no moduleAnalyzer + appResources + ); }); describe('StaticViewStrategy', () => { @@ -344,4 +348,28 @@ describe('ViewLocator', () => { .catch(done.fail); }); }); + + describe('InlineViewStrategy', () => { + it('loads', (done) => { + let strategy = new InlineViewStrategy( + '' + ); + class El {} + strategy + .loadViewFactory(viewEngine, ViewCompileInstruction.normal, new ResourceLoadContext(), El) + .then((factory) => { + // TODO: Remove Console + // eslint-disable-next-line no-console + console.log(`factory.resources.elements=${JSON.stringify(factory.resources.elements, null, 2)}`); + + expect(factory.resources.getElement('el').target).toBe(El); + }).catch(ex => { + // TODO: Remove Console + // eslint-disable-next-line no-console + console.log('ex', ex.message); + + expect(ex.message).not.toContain('Cannot determine default view strategy for object.'); + }).then(done); + }); + }); }); From 74fc4793bf39814061b48ea4e9ed5d1381326fca Mon Sep 17 00:00:00 2001 From: Barrie Treloar Date: Mon, 15 Jul 2019 11:32:55 +0930 Subject: [PATCH 3/3] Use inlineView decorator for tests. --- test/view-strategy.spec.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/view-strategy.spec.js b/test/view-strategy.spec.js index 9905002d..0d6ee5da 100644 --- a/test/view-strategy.spec.js +++ b/test/view-strategy.spec.js @@ -1,8 +1,10 @@ import { Container } from 'aurelia-dependency-injection'; import { BindingLanguage } from '../src/binding-language'; +import { inlineView } from '../src/decorators'; import { ResourceLoadContext, ViewCompileInstruction } from '../src/instructions'; import { ViewCompiler } from '../src/view-compiler'; import { ViewEngine } from '../src/view-engine'; +import { ViewLocator } from '../src/view-locator'; import { ViewResources } from '../src/view-resources'; import { InlineViewStrategy, StaticViewStrategy } from '../src/view-strategy'; import './setup'; @@ -351,15 +353,23 @@ describe('ViewLocator', () => { describe('InlineViewStrategy', () => { it('loads', (done) => { - let strategy = new InlineViewStrategy( - '' - ); class El {} + inlineView('')(El); + const viewLocator = new ViewLocator(); + const strategy = viewLocator.getViewStrategy(El); + expect(strategy instanceof InlineViewStrategy).toBe(true); strategy .loadViewFactory(viewEngine, ViewCompileInstruction.normal, new ResourceLoadContext(), El) .then((factory) => { // TODO: Remove Console // eslint-disable-next-line no-console + // TODO: Remove Console + // eslint-disable-next-line no-console + console.log(`factory`, factory); + // TODO: Remove Console + // eslint-disable-next-line no-console + console.log(`factory.resources`, factory.resources); + console.log(`factory.resources.elements=${JSON.stringify(factory.resources.elements, null, 2)}`); expect(factory.resources.getElement('el').target).toBe(El);