refactor(@embark/core): migrate console module tests to jets and embark-testing

This commit is contained in:
Pascal Precht 2020-01-20 16:41:44 +01:00 committed by Iuri Matias
parent bef582d312
commit 63e83dcfce
4 changed files with 62 additions and 71 deletions

View File

@ -36,12 +36,11 @@
"ci": "npm run qa",
"clean": "npm run reset",
"lint": "npm-run-all lint:*",
"lint:js": "eslint src/",
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
"qa": "npm-run-all lint _typecheck _build test",
"reset": "npx rimraf .nyc_output coverage dist embark-*.tgz package",
"solo": "embark-solo",
"test": "nyc --reporter=html --reporter=json mocha \"dist/test/**/*.js\" --exit --no-timeouts --require source-map-support/register"
"test": "jest"
},
"eslintConfig": {
"extends": "../../../.eslintrc.json"
@ -49,7 +48,6 @@
"dependencies": {
"@babel/runtime-corejs3": "7.7.4",
"@types/json-stringify-safe": "5.0.0",
"async": "2.6.1",
"chalk": "2.4.2",
"core-js": "3.4.3",
"embark-core": "^5.1.0-nightly.4",
@ -59,14 +57,14 @@
"json-stringify-safe": "5.0.1"
},
"devDependencies": {
"@babel/core": "7.7.4",
"babel-jest": "24.9.0",
"embark-logger": "^5.1.0-nightly.1",
"embark-solo": "^5.1.0-nightly.1",
"eslint": "5.7.0",
"mocha": "6.2.2",
"embark-testing": "^5.1.0-nightly.1",
"jest": "24.9.0",
"npm-run-all": "4.1.5",
"nyc": "13.1.0",
"rimraf": "3.0.0",
"source-map-support": "0.5.13",
"tslint": "5.20.1",
"typescript": "3.7.2"
},
@ -75,11 +73,19 @@
"npm": ">=6.11.3",
"yarn": ">=1.19.1"
},
"nyc": {
"exclude": [
"**/node_modules/**",
"coverage/**",
"dist/test/**"
"jest": {
"collectCoverage": true,
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.js"
],
"transform": {
"\\.(js|ts)$": [
"babel-jest",
{
"rootMode": "upward"
}
]
}
}
}

View File

@ -1,58 +0,0 @@
/*globals describe, it*/
import Console from '../lib';
import { Logger } from 'embark-logger';
import { joinPath, setUpEnv } from 'embark-utils';
import assert from 'assert';
import { version } from '../../package.json';
setUpEnv(joinPath(__dirname, '../../../../embark'));
describe('embark.Console', function() {
let logger = new Logger({logLevel: 'error'});
let ipc = {
isServer: () => { return true; },
broadcast: () => {},
on: () => {},
isClient: () => { return false; }
};
let events = {once: () => {}, setCommandHandler: () => {}, emit: () => {}, on: () => {}, request: () => {}};
let plugins = {
logger: logger,
createPlugin: () => { return {registerAPICall: () => {}}; },
getPluginsProperty: () => { return []; }
};
let embarkObject = {
registerAPICall: () => {},
events: events,
logger: plugins.logger,
fs: {
existsSync: () => { return false; },
dappPath: () => { return "ok"; }
},
registerConsoleCommand: (_cmd, _opt) => {},
embarkConfig: {
options: {
solc: {
"optimize": true,
"optimize-runs": 200
}
}
}
};
let console = new Console(embarkObject, {plugins, version, ipc, events, logger});
describe('#executeCmd', function() {
describe('command: help', function() {
it('it should provide a help text', function(done) {
console.executeCmd('help', function(_err, output) {
let lines = output.split('\n');
assert.equal(lines[0], 'Welcome to Embark ' + version);
assert.equal(lines[2], 'possible commands are:');
done();
});
});
});
});
});

View File

@ -0,0 +1,40 @@
/*globals describe, it*/
import assert from 'assert';
import { fakeEmbark } from 'embark-testing';
import Console from '../src/lib';
import { version } from '../package.json';
// 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('core/console', () => {
const { embark, plugins } = fakeEmbark();
let console;
beforeEach(() => {
console = new Console(embark, {
ipc: embark.config.ipc,
events: embark.events,
plugins: embark.plugins,
logger: embark.logger,
version
});
});
afterEach(() => {
embark.teardown();
});
it('it should provide a help text', (done) => {
console.executeCmd('help', (_err, output) => {
let lines = output.split('\n');
assert.equal(lines[0], 'Welcome to Embark ' + version);
assert.equal(lines[2], 'possible commands are:');
done();
});
});
});

View File

@ -10,6 +10,9 @@
"src/lib/**/*"
],
"references": [
{
"path": "../../utils/testing"
},
{
"path": "../core"
},