Use dist files in browser tests.
This commit is contained in:
parent
4809325bee
commit
22bd0c76dd
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
|
basePath: "./output/karma",
|
||||||
frameworks: [ 'mocha' ],
|
frameworks: [ 'mocha' ],
|
||||||
files: [
|
files: [
|
||||||
{ pattern: "./packages/ethers/dist/ethers-all.esm.min.js", type: "module" },
|
{ pattern: "./ethers.esm.js", type: "module" },
|
||||||
{ pattern: "./packages/tests/dist/tests.esm.js", type: "module" }
|
{ pattern: "./tests.esm.js", type: "module" }
|
||||||
],
|
],
|
||||||
reporters: [ 'karma' ],
|
reporters: [ 'karma' ],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
|
basePath: "./output/karma",
|
||||||
frameworks: [ 'mocha' ],
|
frameworks: [ 'mocha' ],
|
||||||
files: [
|
files: [
|
||||||
"./packages/ethers/dist/ethers-all.umd.min.js",
|
"./ethers.umd.js",
|
||||||
"./packages/tests/dist/tests.umd.js",
|
"./tests.umd.js",
|
||||||
],
|
],
|
||||||
reporters: [ 'karma' ],
|
reporters: [ 'karma' ],
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -41,7 +42,7 @@ module.exports = function(config) {
|
|||||||
/*
|
/*
|
||||||
client: {
|
client: {
|
||||||
mocha: {
|
mocha: {
|
||||||
grep: 'Etherscan',
|
grep: 'Test WebSocketProvider',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -25,6 +25,7 @@ const path_1 = require("path");
|
|||||||
const zlib_1 = __importDefault(require("zlib"));
|
const zlib_1 = __importDefault(require("zlib"));
|
||||||
const log_1 = require("../log");
|
const log_1 = require("../log");
|
||||||
const path_2 = require("../path");
|
const path_2 = require("../path");
|
||||||
|
const utils_1 = require("../utils");
|
||||||
const config = {
|
const config = {
|
||||||
dirs: [
|
dirs: [
|
||||||
"./input/easyseed-bip39",
|
"./input/easyseed-bip39",
|
||||||
@ -51,6 +52,9 @@ const config = {
|
|||||||
console.log(` - Added ${key} (${data[key].length} bytes)`);
|
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
|
// 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/browser-data.json"), JSON.stringify(data));
|
||||||
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
|
fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
|
||||||
|
1
misc/admin/lib/cmds/setup-karma-tests.d.ts
vendored
Normal file
1
misc/admin/lib/cmds/setup-karma-tests.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export {};
|
37
misc/admin/lib/cmds/setup-karma-tests.js
Normal file
37
misc/admin/lib/cmds/setup-karma-tests.js
Normal file
@ -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"));
|
||||||
|
});
|
||||||
|
})();
|
@ -16,6 +16,7 @@ import zlib from "zlib";
|
|||||||
|
|
||||||
import { colorify } from "../log";
|
import { colorify } from "../log";
|
||||||
import { resolve } from "../path";
|
import { resolve } from "../path";
|
||||||
|
import { mkdir } from "../utils";
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
dirs: [
|
dirs: [
|
||||||
@ -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
|
// 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/browser-data.json"), JSON.stringify(data));
|
||||||
fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
|
fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data));
|
||||||
|
27
misc/admin/src.ts/cmds/setup-karma-tests.ts
Normal file
27
misc/admin/src.ts/cmds/setup-karma-tests.ts
Normal file
@ -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
package.json
17
package.json
@ -16,14 +16,14 @@
|
|||||||
"_build-cjs": "node ./misc/admin/lib/cmds/echo 'Building CommonJS libraries...' && node ./misc/admin/lib/cmds/set-build-option cjs && npm run build",
|
"_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",
|
"_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",
|
"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-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-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-umd": "npm run _test-dist && npm run _test-browser-umd",
|
||||||
"test-browser-esm": "npm run _test-dist && npm run _test-browser-esm",
|
"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-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-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",
|
"test": "npm run build-all && npm run test-node",
|
||||||
"build-docs": "flatworm docs.wrm docs",
|
"build-docs": "flatworm docs.wrm docs",
|
||||||
"serve-docs": "node ./misc/admin/lib/cmds/serve-docs.js",
|
"serve-docs": "node ./misc/admin/lib/cmds/serve-docs.js",
|
||||||
@ -31,7 +31,7 @@
|
|||||||
"spell-check": "node ./misc/admin/lib/cmds/spell-check.js",
|
"spell-check": "node ./misc/admin/lib/cmds/spell-check.js",
|
||||||
"_reset-build": "node ./misc/admin/lib/cmds/set-build-option cjs",
|
"_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",
|
"_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-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-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",
|
"_build-dist": "node ./misc/admin/lib/cmds/echo 'Building dist files...' && npm run build-dist-libs && npm run build-dist-shims",
|
||||||
@ -54,22 +54,20 @@
|
|||||||
"aws-sdk": "2.137.0",
|
"aws-sdk": "2.137.0",
|
||||||
"diff": "4.0.1",
|
"diff": "4.0.1",
|
||||||
"flatworm": "0.0.2-beta.5",
|
"flatworm": "0.0.2-beta.5",
|
||||||
"jison": "^0.4.18",
|
"jison": "0.4.18",
|
||||||
"karma": "5.1.0",
|
"karma": "5.2.3",
|
||||||
"karma-chrome-launcher": "3.1.0",
|
"karma-chrome-launcher": "3.1.0",
|
||||||
"karma-mocha": "2.0.1",
|
"karma-mocha": "2.0.1",
|
||||||
"libnpmpublish": "3.0.1",
|
"libnpmpublish": "3.0.1",
|
||||||
"mocha": "^7.1.1",
|
"mocha": "^7.1.1",
|
||||||
"nyc": "15.1.0",
|
"nyc": "15.1.0",
|
||||||
"rollup": "1.20.1",
|
"rollup": "2.33.2",
|
||||||
"rollup-plugin-node-polyfills": "0.2.1",
|
"rollup-plugin-node-polyfills": "0.2.1",
|
||||||
"rollup-plugin-sourcemaps": "0.6.3",
|
"rollup-plugin-sourcemaps": "0.6.3",
|
||||||
"scrypt-js": "3.0.1",
|
"scrypt-js": "3.0.1",
|
||||||
"semver": "^5.6.0",
|
"semver": "^5.6.0",
|
||||||
"typescript": "3.8.3",
|
"typescript": "3.8.3",
|
||||||
"uglify-es": "3.3.9",
|
"uglify-es": "3.3.9"
|
||||||
"webpack": "^4.44.2",
|
|
||||||
"webpack-cli": "4.1.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/parser": "7.8.4",
|
"@babel/parser": "7.8.4",
|
||||||
@ -81,7 +79,6 @@
|
|||||||
"aes-js": "3.0.0",
|
"aes-js": "3.0.0",
|
||||||
"bech32": "1.1.4",
|
"bech32": "1.1.4",
|
||||||
"bn.js": "^4.4.0",
|
"bn.js": "^4.4.0",
|
||||||
"browserify-zlib": "^0.2.0",
|
|
||||||
"elliptic": "6.5.3",
|
"elliptic": "6.5.3",
|
||||||
"hash.js": "1.1.3",
|
"hash.js": "1.1.3",
|
||||||
"js-sha3": "0.5.7",
|
"js-sha3": "0.5.7",
|
||||||
|
@ -4,14 +4,6 @@
|
|||||||
|
|
||||||
import * as ethers from "./ethers";
|
import * as ethers from "./ethers";
|
||||||
|
|
||||||
try {
|
|
||||||
const anyGlobal = (window as any);
|
|
||||||
|
|
||||||
if (anyGlobal._ethers == null) {
|
|
||||||
anyGlobal._ethers = ethers;
|
|
||||||
}
|
|
||||||
} catch (error) { }
|
|
||||||
|
|
||||||
export { ethers };
|
export { ethers };
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
let ethers: any = { };
|
|
||||||
|
|
||||||
const w = (window as any);
|
|
||||||
if (w._ethers == null) {
|
|
||||||
console.log("WARNING: @ethersproject/hardware-wallet requires ethers loaded first");
|
|
||||||
} else {
|
|
||||||
ethers = w._ethers;
|
|
||||||
}
|
|
||||||
|
|
||||||
export { ethers }
|
|
@ -1,9 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
console.log("Using global.ethers");
|
|
||||||
|
|
||||||
const anyGlobal = (window as any);
|
|
||||||
|
|
||||||
const ethers = anyGlobal._ethers;
|
|
||||||
|
|
||||||
export { ethers }
|
|
@ -149,7 +149,7 @@ function getConfig() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const configs = [
|
const configs = [
|
||||||
// getEsmConfig(),
|
getEsmConfig(),
|
||||||
getUmdConfig()
|
getUmdConfig()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -8,7 +8,19 @@ import nodePolyfills from "rollup-plugin-node-polyfills";
|
|||||||
|
|
||||||
import json from "@rollup/plugin-json";
|
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 = [
|
const plugins = [
|
||||||
json(),
|
json(),
|
||||||
/*
|
/*
|
||||||
@ -34,19 +46,20 @@ function getConfig(format, input, mainFields) {
|
|||||||
input: input,
|
input: input,
|
||||||
output: {
|
output: {
|
||||||
file: ("./packages/tests/dist/tests." + format + ".js"),
|
file: ("./packages/tests/dist/tests." + format + ".js"),
|
||||||
format: format,
|
name: "testing",
|
||||||
name: "testing"
|
format,
|
||||||
|
globals
|
||||||
},
|
},
|
||||||
context: "window",
|
context: "window",
|
||||||
treeshake: false,
|
treeshake: false,
|
||||||
|
external: [ "ethers" ],
|
||||||
plugins: plugins
|
plugins: plugins
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const configs = [
|
const configs = [
|
||||||
getConfig("umd", "./packages/tests/lib/index.js", [ "_browser-all", "browser", "main" ]),
|
getConfig("umd"),
|
||||||
getConfig("esm", "./packages/tests/lib.esm/index.js", undefined),
|
getConfig("esm"),
|
||||||
];
|
];
|
||||||
|
|
||||||
export default configs;
|
export default configs;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user