From baf6f20066cc51c56974c5ee11512085aa0be02f Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Tue, 30 Apr 2019 16:04:54 +0200 Subject: [PATCH] refactor(@embark/test-runner): move test module into test-runner package --- packages/embark-core/constants.json | 4 -- packages/embark-test-runner/.npmrc | 4 ++ packages/embark-test-runner/README.md | 6 ++ packages/embark-test-runner/package.json | 70 +++++++++++++++++++ packages/embark-test-runner/src/constants.js | 2 + .../tests => embark-test-runner/src}/index.js | 6 +- .../src}/reporter.js | 2 +- .../src}/solc_test.js | 0 .../tests => embark-test-runner/src}/test.js | 11 +-- packages/embark-test-runner/tsconfig.json | 4 ++ packages/embark-test-runner/tslint.json | 3 + packages/embark/package.json | 1 + packages/embark/src/lib/core/engine.js | 2 +- 13 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 packages/embark-test-runner/.npmrc create mode 100644 packages/embark-test-runner/README.md create mode 100644 packages/embark-test-runner/package.json create mode 100644 packages/embark-test-runner/src/constants.js rename packages/{embark/src/lib/modules/tests => embark-test-runner/src}/index.js (97%) rename packages/{embark/src/lib/modules/tests => embark-test-runner/src}/reporter.js (98%) rename packages/{embark/src/lib/modules/tests => embark-test-runner/src}/solc_test.js (100%) rename packages/{embark/src/lib/modules/tests => embark-test-runner/src}/test.js (98%) create mode 100644 packages/embark-test-runner/tsconfig.json create mode 100644 packages/embark-test-runner/tslint.json diff --git a/packages/embark-core/constants.json b/packages/embark-core/constants.json index 44d87c7f1..c00927834 100644 --- a/packages/embark-core/constants.json +++ b/packages/embark-core/constants.json @@ -63,10 +63,6 @@ "initiated": "initiated", "restart": "restart" }, - "tests": { - "gasLimit": 6000000, - "coverageGasLimit": 4503599627370495 - }, "codeGenerator": { "gasLimit": 6000000 }, diff --git a/packages/embark-test-runner/.npmrc b/packages/embark-test-runner/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/embark-test-runner/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/embark-test-runner/README.md b/packages/embark-test-runner/README.md new file mode 100644 index 000000000..1cd449411 --- /dev/null +++ b/packages/embark-test-runner/README.md @@ -0,0 +1,6 @@ +# `embark-test-runner` + +Embark Testrunner + +Visit [embark.status.im](https://embark.status.im/) to get started with +[Embark](https://github.com/embark-framework/embark). diff --git a/packages/embark-test-runner/package.json b/packages/embark-test-runner/package.json new file mode 100644 index 000000000..1a56ef3ba --- /dev/null +++ b/packages/embark-test-runner/package.json @@ -0,0 +1,70 @@ +{ + "name": "embark-test-runner", + "version": "4.1.0-beta.0", + "author": "Iuri Matias ", + "contributors": [], + "description": "Embark Testrunner", + "homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-test-runner#readme", + "bugs": "https://github.com/embark-framework/embark/issues", + "keywords": [ + "blockchain", + "dapps", + "ethereum", + "ipfs", + "serverless", + "solc", + "solidity" + ], + "files": [ + "dist" + ], + "license": "MIT", + "repository": { + "directory": "packages/embark-test-runner", + "type": "git", + "url": "https://github.com/embark-framework/embark.git" + }, + "main": "./dist/index.js", + "scripts": { + "build": "cross-env BABEL_ENV=node babel src --extensions \".js,.ts\" --out-dir dist --root-mode upward --source-maps", + "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\"", + "package": "npm pack", + "// qa": "npm-run-all lint typecheck build package", + "qa": "npm-run-all lint build package", + "reset": "npx rimraf dist embark-*.tgz package", + "start": "npm run watch", + "// typecheck": "tsc", + "watch": "run-p watch:*", + "watch:build": "npm run build -- --verbose --watch", + "// watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch" + }, + "eslintConfig": { + "extends": "../../.eslintrc.json" + }, + "dependencies": { + "@babel/runtime-corejs2": "7.3.1", + "async": "2.6.1", + "embark-utils": "^4.1.0-beta.0", + "mocha": "5.2.0" + }, + "devDependencies": { + "@babel/cli": "7.2.3", + "@babel/core": "7.2.2", + "@types/async": "2.0.50", + "cross-env": "5.2.0", + "eslint": "5.7.0", + "npm-run-all": "4.1.5", + "rimraf": "2.6.3", + "tslint": "5.11.0", + "typescript": "3.3.1" + }, + "engines": { + "node": ">=8.12.0", + "npm": ">=6.4.1", + "yarn": ">=1.12.3" + } +} diff --git a/packages/embark-test-runner/src/constants.js b/packages/embark-test-runner/src/constants.js new file mode 100644 index 000000000..cddb5f991 --- /dev/null +++ b/packages/embark-test-runner/src/constants.js @@ -0,0 +1,2 @@ +export const COVERAGE_GAS_LIMIT = 4503599627370495; +export const GAS_LIMIT = 6000000; diff --git a/packages/embark/src/lib/modules/tests/index.js b/packages/embark-test-runner/src/index.js similarity index 97% rename from packages/embark/src/lib/modules/tests/index.js rename to packages/embark-test-runner/src/index.js index 72228e783..dce1816e2 100644 --- a/packages/embark/src/lib/modules/tests/index.js +++ b/packages/embark-test-runner/src/index.js @@ -6,7 +6,7 @@ const assert = require('assert'); const Test = require('./test'); const {EmbarkSpec, EmbarkApiSpec} = require('./reporter'); const SolcTest = require('./solc_test'); -const constants = require('embark-core/constants'); +import { COVERAGE_GAS_LIMIT, GAS_LIMIT } from './constants'; class TestRunner { constructor(embark, options) { @@ -156,7 +156,7 @@ class TestRunner { runJSTests(files, options, cb) { const self = this; const test = new Test({loglevel: options.loglevel, node: options.node, events: self.events, logger: self.logger, - config: self.embark.config, ipc: self.ipc, coverage: options.coverage, inProcess: options.inProcess}); + config: self.embark.config, ipc: self.ipc, coverage: options.coverage, inProcess: options.inProcess, dappPath: this.embark.fs.dappPath()}); async.waterfall([ function setupGlobalNamespace(next) { global.embark = test; @@ -207,7 +207,7 @@ class TestRunner { let fns = files.map((file) => { return (cb) => { const mocha = new Mocha(); - const gasLimit = options.coverage ? constants.tests.coverageGasLimit : constants.tests.gasLimit; + const gasLimit = options.coverage ? COVERAGE_GAS_LIMIT : GAS_LIMIT; const reporter = options.inProcess ? EmbarkApiSpec : EmbarkSpec; mocha.reporter(reporter, { events: self.events, diff --git a/packages/embark/src/lib/modules/tests/reporter.js b/packages/embark-test-runner/src/reporter.js similarity index 98% rename from packages/embark/src/lib/modules/tests/reporter.js rename to packages/embark-test-runner/src/reporter.js index fd2581461..4c63084d2 100644 --- a/packages/embark/src/lib/modules/tests/reporter.js +++ b/packages/embark-test-runner/src/reporter.js @@ -1,7 +1,7 @@ const Base = require('mocha/lib/reporters/base'); const ms = require('mocha/lib/ms'); const color = Base.color; -import {getAddressToContract, getTransactionParams} from 'embark-utils'; +import { getAddressToContract, getTransactionParams } from 'embark-utils'; class EmbarkApiSpec extends Base { constructor(runner, options) { diff --git a/packages/embark/src/lib/modules/tests/solc_test.js b/packages/embark-test-runner/src/solc_test.js similarity index 100% rename from packages/embark/src/lib/modules/tests/solc_test.js rename to packages/embark-test-runner/src/solc_test.js diff --git a/packages/embark/src/lib/modules/tests/test.js b/packages/embark-test-runner/src/test.js similarity index 98% rename from packages/embark/src/lib/modules/tests/test.js rename to packages/embark-test-runner/src/test.js index 23b316313..9c58f889f 100644 --- a/packages/embark/src/lib/modules/tests/test.js +++ b/packages/embark-test-runner/src/test.js @@ -1,8 +1,8 @@ import { deconstructUrl, prepareContractsConfig, AccountParser } from 'embark-utils'; const async = require('async'); -const constants = require('embark-core/constants'); const web3Utils = require('web3-utils'); +import { GAS_LIMIT } from './constants'; const BALANCE_10_ETHER_IN_HEX = '0x8AC7230489E80000'; @@ -24,6 +24,7 @@ class Test { this.provider = null; this.accounts = []; this.embarkjs = {}; + this.dappPath = options.dappPath; this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => { this.events.request("blockchain:getAccounts", cb); @@ -36,7 +37,7 @@ class Test { this.events.request('runcode:ready', next); }, (next) => { - this.gasLimit = constants.tests.gasLimit; + this.gasLimit = GAS_LIMIT; this.events.request('deploy:setGasLimit', this.gasLimit); if (this.options.node !== 'embark') { this.showNodeHttpWarning(); @@ -153,7 +154,7 @@ class Test { this.events.request("blockchain:get", (web3) => { if (accounts) { - self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3); + self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath); } else { self.simOptions.accounts = null; } @@ -353,7 +354,7 @@ class Test { abi: ${JSON.stringify(contract.abiDefinition)}, address: "${contract.deployedAddress || ""}" || undefined, from: "${contract.deploymentAccount || ""}" || web3.eth.defaultAccount, - gas: "${constants.tests.gasLimit}", + gas: "${GAS_LIMIT}", web3: web3 }); @@ -364,7 +365,7 @@ class Test { if (newContract.options.data && !newContract.options.data.startsWith('0x')) { newContract.options.data = '0x' + newContract.options.data; } - newContract.options.gas = "${constants.tests.gasLimit}"; + newContract.options.gas = "${GAS_LIMIT}"; } return newContract;`; this.events.request("runcode:eval", codeToRun, cb, false, true); diff --git a/packages/embark-test-runner/tsconfig.json b/packages/embark-test-runner/tsconfig.json new file mode 100644 index 000000000..52d43eaaa --- /dev/null +++ b/packages/embark-test-runner/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/embark-test-runner/tslint.json b/packages/embark-test-runner/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/embark-test-runner/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} diff --git a/packages/embark/package.json b/packages/embark/package.json index 7059841da..fe6899913 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -105,6 +105,7 @@ "embark-specialconfigs": "^4.1.0-beta.0", "embark-scaffolding": "^4.1.0-beta.0", "embark-ui": "^4.1.0-beta.0", + "embark-test-runner": "^4.1.0-beta.0", "embark-transaction-tracker": "^4.1.0-beta.0", "embark-utils": "^4.1.0-beta.0", "embark-vyper": "^4.0.0", diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 13a8ce2b6..afb67a423 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -324,7 +324,7 @@ class Engine { } testRunnerService(options) { - this.registerModule('tests', Object.assign(options, {ipc: this.ipc})); + this.registerModulePackage('embark-test-runner', Object.assign(options, {ipc: this.ipc})); } }