Skip to content

Commit

Permalink
Use dist files in browser tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Nov 17, 2020
1 parent 4809325 commit 22bd0c7
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 51 deletions.
5 changes: 3 additions & 2 deletions karma-esm.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module.exports = function(config) {
config.set({
basePath: "./output/karma",
frameworks: [ 'mocha' ],
files: [
{ pattern: "./packages/ethers/dist/ethers-all.esm.min.js", type: "module" },
{ pattern: "./packages/tests/dist/tests.esm.js", type: "module" }
{ pattern: "./ethers.esm.js", type: "module" },
{ pattern: "./tests.esm.js", type: "module" }
],
reporters: [ 'karma' ],
plugins: [
Expand Down
7 changes: 4 additions & 3 deletions karma-umd.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module.exports = function(config) {
config.set({
basePath: "./output/karma",
frameworks: [ 'mocha' ],
files: [
"./packages/ethers/dist/ethers-all.umd.min.js",
"./packages/tests/dist/tests.umd.js",
"./ethers.umd.js",
"./tests.umd.js",
],
reporters: [ 'karma' ],
plugins: [
Expand Down Expand Up @@ -41,7 +42,7 @@ module.exports = function(config) {
/*
client: {
mocha: {
grep: 'Etherscan',
grep: 'Test WebSocketProvider',
}
}
*/
Expand Down
4 changes: 4 additions & 0 deletions misc/admin/lib/cmds/bundle-testcases.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const path_1 = require("path");
const zlib_1 = __importDefault(require("zlib"));
const log_1 = require("../log");
const path_2 = require("../path");
const utils_1 = require("../utils");
const config = {
dirs: [
"./input/easyseed-bip39",
Expand All @@ -51,6 +52,9 @@ const config = {
console.log(` - Added ${key} (${data[key].length} bytes)`);
});
});
utils_1.mkdir(path_2.resolve("packages/testcases/lib"));
utils_1.mkdir(path_2.resolve("packages/testcases/lib._esm"));
utils_1.mkdir(path_2.resolve("packages/testcases/lib.esm"));
// We write it out to all needed places
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data));
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
Expand Down
1 change: 1 addition & 0 deletions misc/admin/lib/cmds/setup-karma-tests.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
37 changes: 37 additions & 0 deletions misc/admin/lib/cmds/setup-karma-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = require("../path");
const utils_1 = require("../utils");
function copy(src, dst, transform) {
let data = fs_1.default.readFileSync(path_1.resolve(src));
if (transform) {
data = Buffer.from(transform(data.toString()));
}
fs_1.default.writeFileSync(dst, data);
}
(function () {
return __awaiter(this, void 0, void 0, function* () {
yield utils_1.mkdir(path_1.resolve("output/karma"));
copy(path_1.resolve("packages/ethers/dist/ethers.esm.js"), path_1.resolve("output/karma/ethers.esm.js"));
copy(path_1.resolve("packages/tests/dist/tests.esm.js"), path_1.resolve("output/karma/tests.esm.js"), (data) => {
return data.replace(/^(import [^;]* from ')(ethers)(';)/, (all, prefix, id, suffix) => {
return prefix + "./ethers.esm.js" + suffix;
});
});
copy(path_1.resolve("packages/ethers/dist/ethers.umd.js"), path_1.resolve("output/karma/ethers.umd.js"));
copy(path_1.resolve("packages/tests/dist/tests.umd.js"), path_1.resolve("output/karma/tests.umd.js"));
});
})();
5 changes: 5 additions & 0 deletions misc/admin/src.ts/cmds/bundle-testcases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import zlib from "zlib";

import { colorify } from "../log";
import { resolve } from "../path";
import { mkdir } from "../utils";

const config = {
dirs: [
Expand Down Expand Up @@ -45,6 +46,10 @@ const config = {
});
});

mkdir(resolve("packages/testcases/lib"));
mkdir(resolve("packages/testcases/lib._esm"));
mkdir(resolve("packages/testcases/lib.esm"));

// We write it out to all needed places
fs.writeFileSync(resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data));
fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
Expand Down
27 changes: 27 additions & 0 deletions misc/admin/src.ts/cmds/setup-karma-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

import fs from "fs";

import { resolve } from "../path";
import { mkdir } from "../utils";

function copy(src: string, dst: string, transform?: (data: string) => string): void {
let data = fs.readFileSync(resolve(src));
if (transform) {
data = Buffer.from(transform(data.toString()));
}
fs.writeFileSync(dst, data);
}

(async function() {
await mkdir(resolve("output/karma"));

copy(resolve("packages/ethers/dist/ethers.esm.js"), resolve("output/karma/ethers.esm.js"));
copy(resolve("packages/tests/dist/tests.esm.js"), resolve("output/karma/tests.esm.js"), (data) => {
return data.replace(/^(import [^;]* from ')(ethers)(';)/, (all, prefix, id, suffix) => {
return prefix + "./ethers.esm.js" + suffix;
});
});

copy(resolve("packages/ethers/dist/ethers.umd.js"), resolve("output/karma/ethers.umd.js"));
copy(resolve("packages/tests/dist/tests.umd.js"), resolve("output/karma/tests.umd.js"));
})();
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
"_build-cjs": "node ./misc/admin/lib/cmds/echo 'Building CommonJS libraries...' && node ./misc/admin/lib/cmds/set-build-option cjs && npm run build",
"_build-esm": "node ./misc/admin/lib/cmds/echo 'Building ES modules libraries...' && node ./misc/admin/lib/cmds/set-build-option esm && npm run build",
"clean": "node ./misc/admin/lib/cmds/echo 'Cleaning all build files...' && rm -rf packages/*/lib packages/*/lib._esm packages/*/lib.esm packages/*/node_modules packages/*/dist/*.js packages/*/tsconfig.tsbuildinfo node_modules .package_node_modules package-lock.json",
"_test-dist": "node ./misc/admin/lib/cmds/bundle-testcases && rollup -c rollup-tests.config.js",
"_test-dist": "rollup -c rollup-tests.config.js && node ./misc/admin/lib/cmds/setup-karma-tests",
"_test-browser-umd": "karma start --single-run --browsers HeadlessLittleLiar karma-umd.conf.js",
"_test-browser-esm": "karma start --single-run --browsers HeadlessLittleLiar karma-esm.conf.js",
"test-browser-umd": "npm run _test-dist && npm run _test-browser-umd",
"test-browser-esm": "npm run _test-dist && npm run _test-browser-esm",
"test-coverage": "nyc --report-dir=output --reporter=lcov --reporter=text mocha --reporter ./packages/tests/reporter-keepalive ./packages/tests/lib/test-*.js | tee output/summary.txt",
"test-node": "mocha --no-colors --reporter ./packages/tests/reporter ./packages/tests/lib/test-*.js",
"test-react": "npm run _test-dist && npm run build-dist-shims && pushd misc/ReactNativeTestApp && ./run-tests.sh && popd",
"test-react": "npm run _test-dist && pushd misc/ReactNativeTestApp && ./run-tests.sh && popd",
"test": "npm run build-all && npm run test-node",
"build-docs": "flatworm docs.wrm docs",
"serve-docs": "node ./misc/admin/lib/cmds/serve-docs.js",
"upload-docs": " node ./admin/cmds/upload-docs.js",
"spell-check": "node ./misc/admin/lib/cmds/spell-check.js",
"_reset-build": "node ./misc/admin/lib/cmds/set-build-option cjs",
"_esm-alias": "node ./misc/admin/lib/cmds/echo 'Bundling ESM elliptic (lib._esm/browser-elliptic.js)...' && rollup -c rollup-pre-alias.config.js && node misc/admin/lib/cmds/esm-alias",
"build-libs": "node ./misc/admin/lib/cmds/update-exports.js && node ./misc/admin/lib/cmds/bundle-testcases && npm run _build-cjs && npm run _build-esm && npm _reset-build && node packages/asm/generate.js && npm run _esm-alias && chmod 755 packages/*/lib/bin/*.js",
"build-libs": "node ./misc/admin/lib/cmds/update-exports.js && node ./misc/admin/lib/cmds/bundle-testcases && npm run _build-cjs && npm run _build-esm && npm run _reset-build && node packages/asm/generate.js && npm run _esm-alias && chmod 755 packages/*/lib/bin/*.js",
"build-dist-shims": "rollup -c rollup-shims.config.js && uglifyjs --compress --mangle --output ./packages/shims/dist/index.min.js -- ./packages/shims/dist/index.js",
"build-dist-libs": "rollup -c rollup-dist.config.js && uglifyjs packages/ethers/dist/ethers.umd.js --output packages/ethers/dist/ethers.umd.min.js --source-map 'content=packages/ethers/dist/ethers.umd.js.map' && uglifyjs packages/ethers/dist/ethers.esm.js --output packages/ethers/dist/ethers.esm.min.js --source-map 'content=packages/ethers/dist/ethers.esm.js.map'",
"_build-dist": "node ./misc/admin/lib/cmds/echo 'Building dist files...' && npm run build-dist-libs && npm run build-dist-shims",
Expand All @@ -54,22 +54,20 @@
"aws-sdk": "2.137.0",
"diff": "4.0.1",
"flatworm": "0.0.2-beta.5",
"jison": "^0.4.18",
"karma": "5.1.0",
"jison": "0.4.18",
"karma": "5.2.3",
"karma-chrome-launcher": "3.1.0",
"karma-mocha": "2.0.1",
"libnpmpublish": "3.0.1",
"mocha": "^7.1.1",
"nyc": "15.1.0",
"rollup": "1.20.1",
"rollup": "2.33.2",
"rollup-plugin-node-polyfills": "0.2.1",
"rollup-plugin-sourcemaps": "0.6.3",
"scrypt-js": "3.0.1",
"semver": "^5.6.0",
"typescript": "3.8.3",
"uglify-es": "3.3.9",
"webpack": "^4.44.2",
"webpack-cli": "4.1.0"
"uglify-es": "3.3.9"
},
"dependencies": {
"@babel/parser": "7.8.4",
Expand All @@ -81,7 +79,6 @@
"aes-js": "3.0.0",
"bech32": "1.1.4",
"bn.js": "^4.4.0",
"browserify-zlib": "^0.2.0",
"elliptic": "6.5.3",
"hash.js": "1.1.3",
"js-sha3": "0.5.7",
Expand Down
8 changes: 0 additions & 8 deletions packages/ethers/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

import * as ethers from "./ethers";

try {
const anyGlobal = (window as any);

if (anyGlobal._ethers == null) {
anyGlobal._ethers = ethers;
}
} catch (error) { }

export { ethers };

export {
Expand Down
12 changes: 0 additions & 12 deletions packages/hardware-wallets/src.ts/browser-ethers.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/tests/src.ts/browser-ethers.ts

This file was deleted.

2 changes: 1 addition & 1 deletion rollup-dist.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function getConfig() {
}
*/
const configs = [
// getEsmConfig(),
getEsmConfig(),
getUmdConfig()
];

Expand Down
25 changes: 19 additions & 6 deletions rollup-tests.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ import nodePolyfills from "rollup-plugin-node-polyfills";

import json from "@rollup/plugin-json";

function getConfig(format, input, mainFields) {
function getConfig(format) {

// ESM config
let input = "./packages/tests/lib.esm/index.js";
let mainFields = undefined;
let globals = undefined;

if (format === "umd") {
input = "./packages/tests/lib/index.js";
mainFields = [ "browser", "main" ];
globals = { ethers: "ethers" };
}

const plugins = [
json(),
/*
Expand All @@ -34,19 +46,20 @@ function getConfig(format, input, mainFields) {
input: input,
output: {
file: ("./packages/tests/dist/tests." + format + ".js"),
format: format,
name: "testing"
name: "testing",
format,
globals
},
context: "window",
treeshake: false,
external: [ "ethers" ],
plugins: plugins
};
}

const configs = [
getConfig("umd", "./packages/tests/lib/index.js", [ "_browser-all", "browser", "main" ]),
getConfig("esm", "./packages/tests/lib.esm/index.js", undefined),
getConfig("umd"),
getConfig("esm"),
];

export default configs;

0 comments on commit 22bd0c7

Please sign in to comment.