Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JST-112: Drop imports using .js extensions and… #527

Merged
merged 11 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Configure node.js
uses: actions/setup-node@v3
with:
node-version: '16.19.0'
node-version: "16.19.0"

- name: Install browsers and graphic environment
run: |
Expand All @@ -38,15 +38,15 @@ jobs:
- name: Configure python
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"

- name: Install goth
run: |
pip install goth
rm -rf ../goth/assets
python -m goth create-assets ../goth/assets
sed -Ezi 's/(use\-proxy:\s)(True)/\1False/mg' ../goth/assets/goth-config.yml
sed -Ezi 's/(use\-prerelease:\s)(false)/\1true\n release-tag: "0.13.0-rc9"/mg' ../goth/assets/goth-config.yml
sed -Ezi 's/(use\-prerelease:\s)(false)/\1true\n release-tag: "0.13.0-rc10"/mg' ../goth/assets/goth-config.yml

- name: Disconnect Docker containers from default network
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ package-lock.json
.vscode

#Nuxt
/examples/adv-web-example/.nuxt
/examples/adv-web-example/.nuxt
6 changes: 0 additions & 6 deletions .mocharc.json

This file was deleted.

4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "ts-jest",
"testEnvironment": "node"
}
39 changes: 16 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
"version": "0.7.1",
"description": "NodeJS API for Next Golem",
"repository": "https://github.com/golemfactory/yajsapi",
"main": "dist/index.js",
"main": "dist/yajsapi.cjs.js",
"browser": "dist/yajsapi.min.js",
"module": "dist/yajsapi.es.js",
"types": "dist/index.d.ts",
"jsdelivr": "dist/yajsapi.min.js",
"unpkg": "dist/yajsapi.min.js",
"scripts": {
"build": "tsc && rollup --config rollup.config.js",
"build": "rollup -c",
"dev": "rollup -c -w",
"docs": "typedoc yajsapi/ --plugin typedoc-plugin-merge-modules --plugin typedoc-theme-hierarchy",
"docs:md": "typedoc yajsapi/ --plugin typedoc-plugin-markdown --plugin .docs/typedoc-clear-references.cjs --hideBreadcrumbs true && node .docs/summary-generator.cjs",
"test": "ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts --file tests/unit/_setup.ts 'tests/+(unit|integration)/**.+(spec|test).ts'",
"test:unit": "ts-mocha -p tsconfig.json --file tests/unit/_setup.ts --exit tests/unit/**.test.ts",
"test:integration": "ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts tests/integration/**.spec.ts",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "jest --config tests/unit/jest.config.json",
"test:integration": "jest --config tests/integration/jest.config.json tests/integration/**.spec.ts --runInBand --forceExit",
"test:integration:no-goth": "jest tests/integration/**.spec.ts --testTimeout=180000 --runInBand --forceExit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout is defined in test/integration/jest.config.json so probably not needed here..

"test:cypress": "cypress run",
"cov": "nyc --cache false ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts --file tests/unit/_setup.ts 'tests/+(unit|integration)/**.+(spec|test).ts'",
"cov:integration": "nyc --cache false --exclude tests ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts tests/integration/**.spec.ts",
"cov:unit:html": "nyc --reporter=html --cache false ts-mocha --exit -p tsconfig.json --file tests/unit/_setup.ts tests/unit/**.test.ts",
"cov:integration:html": "nyc --reporter=html --cache false ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts tests/integration/**.spec.ts",
"cov:all:html": "nyc --reporter=html --cache false ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts 'tests/+(unit|integration)/**.+(spec|test).ts'",
"cov:lcov": "nyc --reporter=lcov --cache false ts-mocha --exit -p tsconfig.json --file tests/integration/_setup.ts tests/unit/**.test.ts",
"lint": "eslint .",
"format": "prettier yajsapi/"
},
Expand All @@ -33,9 +30,9 @@
"engines": {
"node": ">=16.0.0"
},
"type": "module",
"dependencies": {
"@rauschma/stringio": "^1.4.0",
"@types/eventsource": "^1.1.11",
"axios": "^1.1.3",
"bottleneck": "^2.19.5",
"collect.js": "^4.34.3",
Expand All @@ -46,39 +43,35 @@
"pino": "^8.11.0",
"pino-pretty": "^10.0.1",
"tmp": "^0.2.1",
"ts-jest": "^29.1.1",
"uuid": "^9.0.0",
"ya-ts-client": "^0.5.3"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^25.0.3",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@types/mocha": "^10.0.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.2",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"buffer": "^6.0.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai-spies": "^1.0.0",
"chai-uuid": "^1.0.6",
"cypress": "12.17.1",
"eslint": "~8.45.0",
"eslint-config-prettier": "^8.5.0",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"jest": "^29.6.2",
"prettier": "^3.0.0",
"quibble": "^0.7.0",
"rollup": "^3.3.0",
"rollup": "^3.26.3",
"rollup-plugin-ignore": "^1.0.10",
"rollup-plugin-polyfill-node": "^0.12.0",
"rollup-plugin-visualizer": "^5.9.0",
"stream-browserify": "^3.0.0",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"tslint-config-prettier": "^1.18.0",
Expand Down
39 changes: 0 additions & 39 deletions rollup.config.js

This file was deleted.

57 changes: 57 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import alias from "@rollup/plugin-alias";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import nodePolyfills from "rollup-plugin-polyfill-node";
import pkg from "./package.json" assert { type: "json" };
import ignore from "rollup-plugin-ignore";

/**
* Looking for plugins?
*
* Check: {@link https://github.com/rollup/awesome}
*/

export default [
// Browser
{
input: "yajsapi/index.ts",
output: {
inlineDynamicImports: true,
file: pkg.browser,
name: "yajsapi",
sourcemap: true,
format: "es",
},
plugins: [
ignore(["tmp", "pino", "eventsource"]),
alias({
entries: [
{ find: "stream", replacement: "stream-browserify" },
{ find: /RedisDatastore/, replacement: "tests/mock/utils/empty_default.js" },
{ find: /IORedisConnection/, replacement: "tests/mock/utils/empty_default.js" },
{ find: /RedisConnection/, replacement: "tests/mock/utils/empty_default.js" },
{ find: /src\/api\/provider-api$/, replacement: "." },
{ find: /\.\/gftp.js/, replacement: "tests/mock/utils/empty.js" },
],
}),
nodeResolve({ browser: true, preferBuiltins: true }),
commonjs(),
nodePolyfills(),
json(), // Required because one our dependencies (bottleneck) loads its own 'version.json'
typescript({ tsconfig: "./tsconfig.json" }),
terser({ keep_classnames: true }),
],
},
// NodeJS
{
input: "yajsapi/index.ts",
output: [
{ file: pkg.main, format: "cjs", sourcemap: true },
{ file: pkg.module, format: "es", sourcemap: true },
],
plugins: [typescript({ tsconfig: "./tsconfig.json" })],
},
];
30 changes: 22 additions & 8 deletions tests/goth/goth.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { ChildProcess, spawn } from "child_process";

type EnvironmentSettings = { apiKey: string; basePath: string; subnetTag: string; gsbUrl: string; path: string };

export class Goth {
private gothProcess?: ChildProcess;

constructor(private readonly gothConfig) {}
async start(): Promise<{ apiKey: string; basePath: string; subnetTag: string; gsbUrl: string; path: string }> {

async start(): Promise<EnvironmentSettings> {
return new Promise((resolve, reject) => {
const startTime = Date.now();
console.log("\x1b[33mStarting goth process...");
console.log("\x1b[33mRun command:\x1b[0m \x1b[36m", `python -m goth start ${this.gothConfig}`);
this.gothProcess = spawn("python", ["-m", "goth", "start", this.gothConfig], {
env: { ...process.env, PYTHONUNBUFFERED: "1" },
});
this.gothProcess.on("spawn", () => console.log("Goth spawned successfully"));
this.gothProcess?.stdout?.setEncoding("utf-8");
this.gothProcess?.stderr?.setEncoding("utf-8");

this.gothProcess?.stdout?.on("data", (data) => {
const regexp =
/YAGNA_APPKEY=(\w+) YAGNA_API_URL=(http:\/\/127\.0{0,3}\.0{0,3}.0{0,2}1:\d+) GSB_URL=(tcp:\/\/\d+\.\d+\.\d+\.\d+:\d+) PATH=(.*) YAGNA_SUBNET=(\w+)/g;
Expand All @@ -29,10 +34,17 @@ export class Goth {
process.env["GSB_URL"] = gsbUrl;
process.env["PATH"] = `${path}:${process.env["PATH"]}`;
process.env["YAGNA_SUBNET"] = subnetTag;
// Note: rinkeby is a test network which is dead, but our goth runners exist on a custom deployment of this network
process.env["PAYMENT_NETWORK"] = "rinkeby";

const settings = { apiKey, basePath, subnetTag, gsbUrl, path };

console.log(
`\x1b[33mGoth has been successfully started in ${((Date.now() - startTime) / 1000).toFixed(0)}s.\n`
`\x1b[33mGoth has been successfully started in ${((Date.now() - startTime) / 1000).toFixed(0)}s. Resulting settings:`,
settings
);
resolve({ apiKey, basePath, subnetTag, gsbUrl, path });

resolve(settings);
}
});
this.gothProcess?.stderr?.on("data", (data) => {
Expand All @@ -43,19 +55,21 @@ export class Goth {
if (gftpVolume) process.env["GOTH_GFTP_VOLUME"] = gftpVolume + "/out/";
console.log("\x1b[33m[goth]\x1b[0m " + data.replace(/[\n\t\r]/g, ""));
});
this.gothProcess.on("error", (error) => reject(error.toString()));
this.gothProcess.on("close", (code) => reject(`Goth process exit with code ${code}`));
this.gothProcess.on("exit", (code) => reject(`Goth process exit with code ${code}`));
this.gothProcess.on("error", (error) => reject("Failed to spawn Goth" + error.toString()));
this.gothProcess.on("close", (code) => console.info(`Goth process exit with code ${code}`));
this.gothProcess.on("exit", (code) => console.info(`Goth process exit with code ${code}`));
});
}

async end() {
this.gothProcess?.kill("SIGINT");
return new Promise((resolve) => {
return new Promise<void>((resolve) => {
this.gothProcess?.on("close", () => {
this.gothProcess?.stdout?.removeAllListeners();
this.gothProcess?.stderr?.removeAllListeners();
this.gothProcess?.removeAllListeners();
resolve(console.log(`\x1b[33mGoth has been terminated`));
console.log(`\x1b[33mGoth has been terminated`);
resolve();
});
});
}
Expand Down
28 changes: 11 additions & 17 deletions tests/integration/_setup.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { Goth } from "../goth/goth.js";
import { Goth } from "../goth/goth";
import { resolve } from "path";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";

chai.use(chaiAsPromised);
const gothConfig = resolve("../goth/assets/goth-config.yml");
const goth = new Goth(gothConfig);
const timeoutPromise = (seconds: number) =>
new Promise((_resolve, reject) => {
setTimeout(() => reject(new Error(`The timeout was reached and the racing promise has rejected after ${seconds} seconds`)), seconds * 1000);
});

before(async function () {
this.timeout(180000);
await goth.start();
});
after(async function () {
this.timeout(180000);
await goth.end();
});
export default async function setUpGoth() {
const gothConfig = resolve("../goth/assets/goth-config.yml");
globalThis.__GOTH = new Goth(gothConfig);

beforeEach(function () {
console.log(`\n\n\xa0\xa0Trying to test: \x1b[32mIt ${this.currentTest?.title} ...\n\n`);
});
// Start Goth, but don't wait for an eternity
return await Promise.race([globalThis.__GOTH.start(), timeoutPromise(60)]);
}
17 changes: 17 additions & 0 deletions tests/integration/_setupLogging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Helper which allows replacing the default logger implemented in jest with the standard one for the duration of the test
*
* It was needed because of the way Goth tests are implemented - producing a lot of output on the console during the test
* which is considered as an issue when using jest. Once we change the way we store Goth related logs, then we'll be
* able to remove this file.
*/

const jestConsole = console;

beforeAll(() => {
global.console = require("console");
});

afterAll(() => {
global.console = jestConsole;
});
3 changes: 3 additions & 0 deletions tests/integration/_teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default async function tearDownGoth() {
await globalThis.__GOTH.end();
}
Loading
Loading