mirror of https://github.com/embarklabs/embark.git
75 lines
2.5 KiB
JavaScript
75 lines
2.5 KiB
JavaScript
|
import sinon from 'sinon';
|
||
|
import assert from 'assert';
|
||
|
import { File, Types } from 'embark-utils';
|
||
|
import { fakeEmbark } from 'embark-testing';
|
||
|
import Compiler from '../src/';
|
||
|
|
||
|
const { embark, plugins } = fakeEmbark();
|
||
|
|
||
|
// Due to our `DAPP_PATH` dependency in `embark-utils` `dappPath()`, we need to
|
||
|
// ensure that this environment variable is defined.
|
||
|
process.env.DAPP_PATH = 'something';
|
||
|
|
||
|
describe('stack/compiler', () => {
|
||
|
|
||
|
let compiler, doneCb;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
compiler = new Compiler(embark, { plugins });
|
||
|
});
|
||
|
|
||
|
afterEach(() => {
|
||
|
embark.teardown();
|
||
|
sinon.restore();
|
||
|
});
|
||
|
|
||
|
test('it should use registered compiler', done => {
|
||
|
const fooCompiler = sinon.spy((files, options, cb) => cb(null, {
|
||
|
contractA: 'someResultA',
|
||
|
contractB: 'someResultB',
|
||
|
contractC: 'someResultC',
|
||
|
}));
|
||
|
|
||
|
embark.plugins.createPlugin('fooCompiler').registerCompiler('.foo', fooCompiler);
|
||
|
|
||
|
embark.events.request('compiler:contracts:compile', [
|
||
|
new File({filename: 'foo.foo', type: Types.dappFile, path: 'foo.foo'}),
|
||
|
new File({filename: 'foo2.foo', type: Types.dappFile, path: 'foo2.foo'}),
|
||
|
new File({filename: 'foo3.foo', type: Types.dappFile, path: 'foo3.foo'}),
|
||
|
], () => {
|
||
|
assert(fooCompiler.called);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('it should iterate over available compilers to find a match for a given source file', done => {
|
||
|
const fooCompiler = sinon.spy((files, options, cb) => cb(null, { fooContract: 'foo', }));
|
||
|
const barCompiler = sinon.spy((files, options, cb) => cb(null, { barContract: 'bar', }));
|
||
|
|
||
|
embark.plugins.createPlugin('fooCompiler').registerCompiler('.foo', fooCompiler);
|
||
|
embark.plugins.createPlugin('barCompiler').registerCompiler('.bar', barCompiler);
|
||
|
|
||
|
embark.events.request('compiler:contracts:compile', [
|
||
|
new File({filename: 'foo.bar', type: Types.dappFile, path: 'foo.bar'}),
|
||
|
], () => {
|
||
|
assert(fooCompiler.notCalled);
|
||
|
assert(barCompiler.called);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
test('it should not compile source files if there is no matching compiler', done => {
|
||
|
const fooCompiler = sinon.spy((files, options, cb) => cb(null, { fooContract: 'foo', }));
|
||
|
embark.plugins.createPlugin('fooCompiler').registerCompiler('.foo', fooCompiler);
|
||
|
|
||
|
const files = [
|
||
|
new File({filename: 'foo.bar', type: Types.dappFile, path: 'foo.bar'})
|
||
|
];
|
||
|
|
||
|
embark.events.request('compiler:contracts:compile', files, () => {
|
||
|
files.forEach(file => assert(!file.compiled));
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|