mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-16 15:47:25 +00:00
test(@embark/stack/compiler): add tests for the compiler
This commit is contained in:
parent
f289a6fc6a
commit
2407df5d11
@ -34,9 +34,10 @@
|
|||||||
"clean": "npm run reset",
|
"clean": "npm run reset",
|
||||||
"lint": "npm-run-all lint:*",
|
"lint": "npm-run-all lint:*",
|
||||||
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
|
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
|
||||||
"qa": "npm-run-all lint typecheck _build",
|
"qa": "npm-run-all lint typecheck _build test",
|
||||||
"reset": "npx rimraf dist embark-*.tgz package",
|
"reset": "npx rimraf dist embark-*.tgz package",
|
||||||
"solo": "embark-solo",
|
"solo": "embark-solo",
|
||||||
|
"test": "jest",
|
||||||
"typecheck": "tsc",
|
"typecheck": "tsc",
|
||||||
"watch": "run-p watch:*",
|
"watch": "run-p watch:*",
|
||||||
"watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
|
"watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
|
||||||
@ -47,7 +48,13 @@
|
|||||||
"embark-utils": "^4.1.1"
|
"embark-utils": "^4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "7.6.4",
|
||||||
|
"babel-jest": "24.9.0",
|
||||||
|
"clone-deep": "4.0.0",
|
||||||
|
"cross-env": "5.2.0",
|
||||||
"embark-solo": "^4.1.1",
|
"embark-solo": "^4.1.1",
|
||||||
|
"embark-testing": "^4.1.1",
|
||||||
|
"jest": "24.9.0",
|
||||||
"npm-run-all": "4.1.5",
|
"npm-run-all": "4.1.5",
|
||||||
"rimraf": "3.0.0",
|
"rimraf": "3.0.0",
|
||||||
"tslint": "5.16.0",
|
"tslint": "5.16.0",
|
||||||
@ -57,5 +64,20 @@
|
|||||||
"node": ">=10.17.0 <12.0.0",
|
"node": ">=10.17.0 <12.0.0",
|
||||||
"npm": ">=6.11.3",
|
"npm": ">=6.11.3",
|
||||||
"yarn": ">=1.19.1"
|
"yarn": ">=1.19.1"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"collectCoverage": true,
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testMatch": [
|
||||||
|
"**/test/**/*.js"
|
||||||
|
],
|
||||||
|
"transform": {
|
||||||
|
"\\.(js|ts)$": [
|
||||||
|
"babel-jest",
|
||||||
|
{
|
||||||
|
"rootMode": "upward"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
74
packages/stack/compiler/test/compiler.spec.js
Normal file
74
packages/stack/compiler/test/compiler.spec.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user