Can't use externalized aspect
matthewadams opened this issue · comments
Trying to use an aspect defined in an external file & failing.
Failing test can be found at https://github.com/SciSpike/aspect.js/blob/external-aspects/test/advices/sync_advices.spec.ts#L305
(that's in forked repo https://github.com/SciSpike/aspect.js, branch external-aspects
).
Code is effectively
// in file external_aspect.ts
import { aroundMethod, Metadata } from "../../lib";
import { expect } from "chai";
export default class ExternalAspect {
@aroundMethod({ classNamePattern: /.*/, methodNamePattern: /.*/ })
around(metadata: Metadata) {
expect(this).to.deep.equal(ExternalAspect.prototype);
expect(metadata.className).to.equal('Demo');
expect(metadata.method.name).to.equal('get');
expect(metadata.method.args).to.deep.equal([42, 1.618]);
expect(metadata.method.invoke).to.be.a('function');
metadata.method.proceed = false
metadata.method.result = 'ExternalAspect'
}
}
Failing test code is
import ExternalAspect from './external_aspect'
// ...
describe('AroundAdvice', () => {
// ...
it('should invoke the external advice with the appropriate metadata', () => {
let demo: any;
@Wove()
class Demo {
get(foo: any, bar: any): string { return 'Demo' }
}
demo = new Demo();
expect(demo.get(42, 1.618)).to.equal('ExternalAspect');
});
});
// ...
Created similar test using inline aspect that's passing at https://github.com/SciSpike/aspect.js/blob/external-aspects/test/advices/sync_advices.spec.ts#L279.
Everything works properly in the example I just pushed.
Ok. It looks like the key difference is that instead of using
import ExternalAspect from './external_aspect'
The form of the import
statement needs to be
import './external_aspect'
Case closed! :)
#66 proves this