Skip to content

Commit

Permalink
Browser and node testing works again.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Nov 24, 2019
1 parent e3752e5 commit 4470477
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 59 deletions.
10 changes: 7 additions & 3 deletions admin/cmds/update-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ const output = `"use strict";
import * as ethers from "./ethers";
if ((<any>global)._ethers == null) {
(<any>global)._ethers = ethers;
}
try {
const anyGlobal = (window as any);
if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
} catch (error) { }
export { ethers };
Expand Down
24 changes: 24 additions & 0 deletions karma-esm.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

module.exports = function(config) {
config.set({
frameworks: [ 'mocha' ],
files: [
{ pattern: "./packages/ethers/dist/ethers-all.esm.min.js", type: "module" },
{ pattern: "./packages/tests/dist/tests.esm.js", type: "module" }
],
reporters: [ 'progress' ],
port: 9876,
logLevel: config.LOG_INFO,
browsers: [ 'ChromeHeadless' ],
autoWatch: false,
singleRun: true,
/*
client: {
mocha: {
grep: 'utf',
}
}
*/
})
}
24 changes: 24 additions & 0 deletions karma-umd.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

module.exports = function(config) {
config.set({
frameworks: [ 'mocha' ],
files: [
"./packages/ethers/dist/ethers-all.umd.min.js",
"./packages/tests/dist/tests.umd.js",
],
reporters: [ 'progress' ],
port: 9876,
logLevel: config.LOG_INFO,
browsers: [ 'ChromeHeadless' ],
autoWatch: false,
singleRun: true,
/*
client: {
mocha: {
grep: 'utf',
}
}
*/
})
}
52 changes: 34 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
"auto-build": "node ./admin/cmds/reset-build.js && npm run build -- -w",
"bootstrap": "node ./admin/cmds/reset-build.js && node ./admin/cmds/update-depgraph && lerna bootstrap --hoist",
"build": "tsc --build ./tsconfig.project.json",
"build-cjs": "node ./admin/cmds/set-option cjs && npm run build",
"build-esm": "node ./admin/cmds/set-option esm && npm run build",
"build-all": "npm run build-esm && npm run build-cjs",

"_build-cjs": "node ./admin/cmds/set-option cjs && npm run build",
"_build-esm": "node ./admin/cmds/set-option esm && npm run build",
"_dist-min-all": "node ./admin/cmds/set-option.js browser-lang-all && rollup -c --configMinify && rollup -c --configMinify --configModule && mv ./packages/ethers/dist/ethers.umd.min.js ./packages/ethers/dist/ethers-all.umd.min.js && mv ./packages/ethers/dist/ethers.esm.min.js ./packages/ethers/dist/ethers-all.esm.min.js",
"_dist-min-en": "node ./admin/cmds/set-option.js browser-lang-en && rollup -c --configMinify && rollup -c --configMinify --configModule",
"_dist": "npm run _dist-min-all && npm run _dist-min-en && rollup -c && rollup -c --configModule",
"build-all": "node ./admin/cmds/update-exports.js && npm run _build-esm && npm run _build-cjs && npm run _dist",

"clean": "node ./admin/cmds/reset-build.js && tsc --build --clean ./tsconfig.project.json",
"_dist_prepare": "npm run clean && npm run bootstrap && npm run build && node ./admin/cmds/update-exports.js",

"_dist_ethers": "npm run _distMinLangAll && npm run _distMinLangEn && rollup -c && rollup -c --configModule",

"_dist_prepare": "npm run clean && npm run bootstrap && npm run build && node ./admin/cmds/update-exports.js",
"_dist_tests": "rollup -c --configTest && rollup -c --configTest --configMinify && rollup -c --configTest --configModule && rollup -c --configTest --configModule --configMinify",
"_test_prepare": "npm run _dist_prepare && npm run _dist_tests",
"_test_node": "cd packages/tests && mocha --no-colors --reporter ./reporter ./lib/test-*.js",
Expand All @@ -26,16 +33,22 @@
"old-test-phantomjs": "cd packages/tests && npm run dist-phantomjs && phantomjs --web-security=false ../../node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js ./test.html ./tests/reporter.js",
"old-test-aion": "npm run dist && npm run test-aion-node",
"old-test-aion-node": "cd packages/aion-tests && mocha --no-colors --reporter ../tests/tests/reporter ./tests/test-*.js",
"update-versions": "npm run _dist_prepare && node ./admin/cmds/update-versions",
"publish-all": "node ./admin/cmds/publish",
"_distMinLangAll": "node ./admin/cmds/set-option.js browser-lang-all && rollup -c --configMinify && rollup -c --configMinify --configModule && mv ./packages/ethers/dist/ethers.umd.min.js ./packages/ethers/dist/ethers-all.umd.min.js && mv ./packages/ethers/dist/ethers.esm.min.js ./packages/ethers/dist/ethers-all.esm.min.js",
"_distMinLangEn": "node ./admin/cmds/set-option.js browser-lang-en && rollup -c --configMinify && rollup -c --configMinify --configModule",
"_dist": "npm run build-all && npm run _distMinLangAll && npm run _distMinLangEn && rollup -c && rollup -c --configModule",
"_distTestBrowserEsm": "rollup -c rollup-tests.config.js --configModule",
"_distTestBrowserUmd": "rollup -c rollup-tests.config.js",
"_distTestBrowser": "npm run _distTestBrowserEsm && npm run _distTestBrowserUmd",

"_dist-tests-esm": "rollup -c rollup-tests.config.js --configModule",
"_dist-test-umd": "rollup -c rollup-tests.config.js",
"_test-browser-umd": "karma start --single-run --browsers ChromeHeadless karma-umd.conf.js",
"_test-browser-esm": "karma start --single-run --browsers ChromeHeadless karma-esm.conf.js",
"_test-node": "mocha --no-colors --reporter ./packages/tests/reporter ./packages/tests/lib/test-*.js",
"test-browser-umd": "npm run build-all && npm run _dist-test-umd && npm run _test-browser-umd",
"test-browser-esm": "npm run build-all && npm run _dist-test-esm && npm run _test-browser-esm",
"test-node": "npm run build-all && npm run _test-node",
"test": "if [ \"$TEST\" == \"\" ]; then npm run test-node; else npm run \"test-$TEST\"; fi",

"lock-versions": "node ./admin/cmds/lock-versions",
"build-docs": "flatworm docs.wrm docs",

"update-versions": "npm run _dist_prepare && node ./admin/cmds/update-versions",
"publish-all": "node ./admin/cmds/publish",
"sync-github": "node ./admin/cmds/cache-github"
},
"devDependencies": {
Expand All @@ -45,15 +58,14 @@
"aes-js": "3.0.0",
"browserify": "16.2.3",
"diff": "4.0.1",
"npm-packlist": "1.4.1",
"karma": "4.4.1",
"karma-chrome-launcher": "3.1.0",
"karma-mocha": "1.3.0",
"lerna": "^3.13.0",
"libnpm": "2.0.1",
"mocha": "^5.2.0",
"mocha-phantomjs-core": "2.1.2",
"scrypt-js": "3.0.0",
"semver": "^5.6.0",
"tar": "4.4.8",
"typescript": "3.6.2",
"npm-packlist": "1.4.1",
"rollup": "1.20.1",
"rollup-plugin-node-builtins": "2.1.2",
"rollup-plugin-commonjs": "10.0.2",
Expand All @@ -62,6 +74,10 @@
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-terser": "5.1.1",
"rollup-plugin-uglify": "6.0.2",
"rollup-pluginutils": "2.8.1"
"rollup-pluginutils": "2.8.1",
"scrypt-js": "3.0.0",
"semver": "^5.6.0",
"tar": "4.4.8",
"typescript": "3.6.2"
}
}
2 changes: 1 addition & 1 deletion packages/ethers/dist/ethers-all.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ethers/dist/ethers-all.umd.min.js

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions packages/ethers/dist/ethers.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12568,12 +12568,17 @@ var Wordlist = /** @class */ (function () {
name = lang.locale;
}
if (exportWordlist) {
var g = commonjsGlobal;
if (g._ethers && g._ethers.wordlists) {
if (!g._ethers.wordlists[name]) {
lib_esm$2.defineReadOnly(g._ethers.wordlists, name, lang);
try {
var anyGlobal = window;
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
lib_esm$2.defineReadOnly(anyGlobal._ethers.wordlists, name, lang);
}
}
}
catch (error) {
console.log("FOOBAR2", error);
}
}
};
return Wordlist;
Expand Down Expand Up @@ -18980,8 +18985,14 @@ var ethers = /*#__PURE__*/Object.freeze({
});

"use strict";
if (global._ethers == null) {
global._ethers = ethers;
try {
const anyGlobal = window;
if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
}
catch (error) {
console.log("FOOBAR", error);
}

export { BigNumber, Contract, ContractFactory, FixedNumber, Signer, VoidSigner, Wallet, browser_1$2 as Wordlist, index$1 as constants, errors, ethers, getDefaultProvider, logger$A as logger, index$2 as providers, utils$1 as utils, version$l as version, browser_2$1 as wordlists };
2 changes: 1 addition & 1 deletion packages/ethers/dist/ethers.esm.min.js

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions packages/ethers/dist/ethers.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13637,12 +13637,17 @@
name = lang.locale;
}
if (exportWordlist) {
var g = commonjsGlobal;
if (g._ethers && g._ethers.wordlists) {
if (!g._ethers.wordlists[name]) {
lib$3.defineReadOnly(g._ethers.wordlists, name, lang);
try {
var anyGlobal = window;
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
lib$3.defineReadOnly(anyGlobal._ethers.wordlists, name, lang);
}
}
}
catch (error) {
console.log("FOOBAR2", error);
}
}
};
return Wordlist;
Expand Down Expand Up @@ -21480,8 +21485,14 @@
// To modify this file, you must update ./admin/cmds/update-exports.js
var ethers$1 = __importStar(ethers);
exports.ethers = ethers$1;
if (commonjsGlobal._ethers == null) {
commonjsGlobal._ethers = ethers$1;
try {
var anyGlobal = window;
if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers$1;
}
}
catch (error) {
console.log("FOOBAR", error);
}
var ethers_1 = ethers;
exports.Signer = ethers_1.Signer;
Expand Down
2 changes: 1 addition & 1 deletion packages/ethers/dist/ethers.umd.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions packages/ethers/lib.esm/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"use strict";
// To modify this file, you must update ./admin/cmds/update-exports.js
import * as ethers from "./ethers";
if (global._ethers == null) {
global._ethers = ethers;
try {
const anyGlobal = window;
if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
}
catch (error) {
console.log("FOOBAR", error);
}
export { ethers };
export { Signer, Wallet, VoidSigner, getDefaultProvider, providers, Contract, ContractFactory, BigNumber, FixedNumber, constants, errors, logger, utils, wordlists,
Expand Down
10 changes: 8 additions & 2 deletions packages/ethers/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
// To modify this file, you must update ./admin/cmds/update-exports.js
var ethers = __importStar(require("./ethers"));
exports.ethers = ethers;
if (global._ethers == null) {
global._ethers = ethers;
try {
var anyGlobal = window;
if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
}
catch (error) {
console.log("FOOBAR", error);
}
var ethers_1 = require("./ethers");
exports.Signer = ethers_1.Signer;
Expand Down
10 changes: 8 additions & 2 deletions packages/ethers/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

import * as ethers from "./ethers";

if ((<any>global)._ethers == null) {
(<any>global)._ethers = ethers;
try {
const anyGlobal = (window as any);

if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
} catch (error) {
console.log("FOOBAR", error);
}

export { ethers };
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/lib.esm/browser-ethers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
console.log("Using global.ethers");
const anyGlobal = window;
const ethers = anyGlobal.ethers;
const ethers = anyGlobal._ethers;
export { ethers };
2 changes: 1 addition & 1 deletion packages/tests/lib/browser-ethers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Object.defineProperty(exports, "__esModule", { value: true });
console.log("Using global.ethers");
var anyGlobal = window;
var ethers = anyGlobal.ethers;
var ethers = anyGlobal._ethers;
exports.ethers = ethers;
2 changes: 1 addition & 1 deletion packages/tests/src.ts/browser-ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ console.log("Using global.ethers");

const anyGlobal = (window as any);

const ethers = anyGlobal.ethers;
const ethers = anyGlobal._ethers;

export { ethers }
13 changes: 9 additions & 4 deletions packages/wordlists/lib.esm/wordlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ export class Wordlist {
name = lang.locale;
}
if (exportWordlist) {
const g = global;
if (g._ethers && g._ethers.wordlists) {
if (!g._ethers.wordlists[name]) {
defineReadOnly(g._ethers.wordlists, name, lang);
try {
const anyGlobal = window;
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
defineReadOnly(anyGlobal._ethers.wordlists, name, lang);
}
}
}
catch (error) {
console.log("FOOBAR2", error);
}
}
}
}
13 changes: 9 additions & 4 deletions packages/wordlists/lib/wordlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ var Wordlist = /** @class */ (function () {
name = lang.locale;
}
if (exportWordlist) {
var g = global;
if (g._ethers && g._ethers.wordlists) {
if (!g._ethers.wordlists[name]) {
properties_1.defineReadOnly(g._ethers.wordlists, name, lang);
try {
var anyGlobal = window;
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
properties_1.defineReadOnly(anyGlobal._ethers.wordlists, name, lang);
}
}
}
catch (error) {
console.log("FOOBAR2", error);
}
}
};
return Wordlist;
Expand Down
12 changes: 7 additions & 5 deletions packages/wordlists/src.ts/wordlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export abstract class Wordlist {
static register(lang: Wordlist, name?: string): void {
if (!name) { name = lang.locale; }
if (exportWordlist) {
const g: any = (<any>global)
if (g._ethers && g._ethers.wordlists) {
if (!g._ethers.wordlists[name]) {
defineReadOnly(g._ethers.wordlists, name, lang);
try {
const anyGlobal = (window as any)
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
defineReadOnly(anyGlobal._ethers.wordlists, name, lang);
}
}
}
} catch (error) { }
}
}

Expand Down

0 comments on commit 4470477

Please sign in to comment.