feat: setup testcase
MODIFY
.babelrc
.babelrc
{
- "presets": ["@babel/preset-env"],
- "plugins": ["add-module-exports"]
+ "presets": [
+ [
+ "@babel/env",
+ {
+ "targets": {
+ "browsers": ["last 2 versions"]
+ }
+ }
+ ]
+ ],
+ "plugins": ["@babel/plugin-transform-runtime"]
}

MODIFY
package-lock.json
package-lock.json
"regenerator-transform": "0.13.3"
}
},
+ "@babel/plugin-transform-runtime": {
+ "version": "7.1.0",
+ "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.1.0.tgz",
+ "integrity": "sha512-WFLMgzu5DLQEah0lKTJzYb14vd6UiES7PTnXcvrPZ1VrwFeJ+mTbvr65fFAsXYMt2bIoOoC0jk76zY1S7HZjUg==",
+ "dev": true,
+ "requires": {
+ "@babel/helper-module-imports": "7.0.0",
+ "@babel/helper-plugin-utils": "7.0.0",
+ "resolve": "1.8.1",
+ "semver": "5.5.1"
+ }
+ },
"@babel/plugin-transform-shorthand-properties": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.0.0.tgz",
"source-map-support": "0.5.9"
}
},
+ "@babel/runtime": {
+ "version": "7.1.2",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.2.tgz",
+ "integrity": "sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==",
+ "requires": {
+ "regenerator-runtime": "0.12.1"
+ },
+ "dependencies": {
+ "regenerator-runtime": {
+ "version": "0.12.1",
+ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
+ "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
+ }
+ }
+ },
"@babel/template": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.1.0.tgz",
"babel-runtime": "6.26.0"
}
},
- "babel-plugin-add-module-exports": {
- "version": "0.2.1",
- "resolved": "https://registry.npmjs.org/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz",
- "integrity": "sha1-mumh9KjcZ/DN7E9K7aHkOl/2XiU=",
- "dev": true
- },
"babel-plugin-check-es2015-constants": {
"version": "6.22.0",
"resolved": "https://registry.npmjs.org/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz",
},
"chai": {
"version": "3.5.0",
- "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz",
+ "resolved": "http://registry.npmjs.org/chai/-/chai-3.5.0.tgz",
"integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=",
"dev": true,
"requires": {

MODIFY
package.json
package.json
"name": "@maticnetwork/matic.js",
"version": "0.0.1-beta.1",
"description": "Javascript developer library for interacting with Matic Network",
- "main": "index.js",
+ "main": "lib/index.js",
"directories": {
"lib": "./lib"
},
"scripts": {
"clean": "rm -rf lib",
- "build": "npm run lint && npm run clean && babel src/ --out-dir lib/ && npm run pack",
- "lint": "eslint src/**/*.js",
+ "babel:build": "babel src/ --out-dir lib/",
+ "build": "npm run lint && npm run clean && npm run pack",
+ "lint": "eslint src/**/*.js ./test/**/*.spec.js",
"test": "mocha --require @babel/register --colors ./test/**/*.spec.js",
"test:watch": "mocha --require @babel/register --colors -w ./test/**/*.spec.js",
"pack": "webpack && webpack --env build"
"homepage": "https://github.com/maticnetwork/matic.js#readme",
"dependencies": {
"@babel/polyfill": "7.0.0",
+ "@babel/runtime": "^7.1.2",
"ethereumjs-block": "^2.0.1",
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "^5.2.0",
"devDependencies": {
"@babel/cli": "7.1.0",
"@babel/core": "7.1.0",
+ "@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "7.1.0",
"@babel/register": "7.0.0",
"babel-eslint": "7.2.3",
"babel-loader": "8.0.0-beta.0",
- "babel-plugin-add-module-exports": "0.2.1",
- "chai": "3.5.0",
+ "chai": "^3.5.0",
"eslint": "5.6.0",
"eslint-config-standard": "12.0.0",
"eslint-loader": "2.1.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-node": "7.0.1",
"eslint-plugin-promise": "4.0.1",
- "mocha": "3.3.0",
+ "mocha": "^3.3.0",
"webpack": "4.1.0",
"webpack-cli": "2.0.10",
"yargs": "8.0.2"

MODIFY
src/index.js
src/index.js
@@ -21,8 +21,8 @@ const rlp = utils.rlp
export default class Matic {
constructor(options = {}) {
- this._throwIfNull(!options.maticProvider, "maticProvider is required")
- this._throwIfNull(!options.parentProvider, "parentProvider is required")
+ this._throwIfNull(options.maticProvider, "maticProvider is required")
+ this._throwIfNull(options.parentProvider, "parentProvider is required")
this._web3 = new Web3(options.maticProvider)
this._parentWeb3 = new Web3(options.parentProvider)

ADD
test/index.spec.js
+/* global describe, it, expect */
+
+import chai from "chai"
+
+import Matic from "../src"
+
+// set up chai
+chai.should()
+const expect = chai.expect
+
+describe("Matic", () => {
+ it("should throw error for no required options", () => {
+ expect(() => new Matic()).to.throw("maticProvider is required")
+ expect(
+ () => new Matic({ maticProvider: "http://localhost:8545" })
+ ).to.throw("parentProvider is required")
+ })
+})

MODIFY
webpack.config.js
webpack.config.js
/* global __dirname, require, module */
-const path = require("path");
-const env = require("yargs").argv.env; // use --env with webpack 2
-const packageJSON = require("./package.json");
+const path = require("path")
+const env = require("yargs").argv.env // use --env with webpack 2
-const libraryName = packageJSON.name;
+const libraryName = "matic.lib"
-let mode = "development";
-let outputFile;
+let mode = "development"
+let outputFile
if (env === "build") {
- mode = "production";
- outputFile = `${libraryName}.min.js`;
+ mode = "production"
+ outputFile = `${libraryName}.min.js`
} else {
- outputFile = `${libraryName}.js`;
+ outputFile = `${libraryName}.js`
}
const config = {
@@ -44,6 +43,6 @@ const config = {
modules: [path.resolve("./node_modules"), path.resolve("./src")],
extensions: [".json", ".js"]
}
-};
+}
-module.exports = config;
+module.exports = config

feat: setup testcase