From ce9938e464cb79ec7039dbe0ecb3e5fdd82d8ffd Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Tue, 1 Nov 2022 19:57:19 +1100 Subject: [PATCH] chore: move tests to separate package --- package-lock.json | 53 ++++++++++++++++++- packages/core/package.json | 3 +- packages/tests/.eslintrc.cjs | 6 +++ packages/tests/.mocharc.json | 11 ++++ packages/tests/.prettierignore | 4 ++ packages/tests/karma.conf.cjs | 55 ++++++++++++++++++++ packages/tests/package.json | 82 ++++++++++++++++++++++++++++++ packages/tests/tsconfig.dev.json | 8 +++ packages/tests/tsconfig.json | 54 ++++++++++++++++++++ packages/tests/tsconfig.karma.json | 6 +++ 10 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 packages/tests/.eslintrc.cjs create mode 100644 packages/tests/.mocharc.json create mode 100644 packages/tests/.prettierignore create mode 100644 packages/tests/karma.conf.cjs create mode 100644 packages/tests/package.json create mode 100644 packages/tests/tsconfig.dev.json create mode 100644 packages/tests/tsconfig.json create mode 100644 packages/tests/tsconfig.karma.json diff --git a/package-lock.json b/package-lock.json index 61feee4182..c654affc37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5283,6 +5283,10 @@ "resolved": "packages/interfaces", "link": true }, + "node_modules/@waku/tests": { + "resolved": "packages/tests", + "link": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -22396,7 +22400,6 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", - "@waku/create": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", "cspell": "^5.14.0", @@ -22606,6 +22609,33 @@ "node": ">=16.0.0", "npm": ">=7.0.0" } + }, + "packages/tests": { + "name": "@waku/tests", + "version": "0.0.1", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@waku/core": "*", + "@waku/create": "*", + "@waku/interfaces": "*" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "typescript": "^4.6.3" + }, + "engines": { + "node": ">=16" + } } }, "dependencies": { @@ -26845,7 +26875,6 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", - "@waku/create": "*", "@waku/interfaces": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", @@ -27031,6 +27060,26 @@ } } }, + "@waku/tests": { + "version": "file:packages/tests", + "requires": { + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "@waku/core": "*", + "@waku/create": "*", + "@waku/interfaces": "*", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "typescript": "^4.6.3" + } + }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", diff --git a/packages/core/package.json b/packages/core/package.json index 5f53b467ab..765c9f2b42 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -101,7 +101,6 @@ "node": ">=16" }, "dependencies": { - "@waku/interfaces": "*", "@chainsafe/libp2p-gossipsub": "^4.1.1", "@chainsafe/libp2p-noise": "^8.0.1", "@ethersproject/rlp": "^5.5.0", @@ -118,6 +117,7 @@ "@libp2p/websockets": "^3.0.3", "@multiformats/multiaddr": "^11.0.6", "@noble/secp256k1": "^1.3.4", + "@waku/interfaces": "*", "debug": "^4.3.4", "dns-query": "^0.11.2", "hi-base32": "^0.5.1", @@ -152,7 +152,6 @@ "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", - "@waku/create": "*", "app-root-path": "^3.0.0", "chai": "^4.3.4", "cspell": "^5.14.0", diff --git a/packages/tests/.eslintrc.cjs b/packages/tests/.eslintrc.cjs new file mode 100644 index 0000000000..324f1f526d --- /dev/null +++ b/packages/tests/.eslintrc.cjs @@ -0,0 +1,6 @@ +module.exports = { + parserOptions: { + tsconfigRootDir: __dirname, + project: "./tsconfig.dev.json", + }, +}; diff --git a/packages/tests/.mocharc.json b/packages/tests/.mocharc.json new file mode 100644 index 0000000000..db9dd73531 --- /dev/null +++ b/packages/tests/.mocharc.json @@ -0,0 +1,11 @@ +{ + "extension": ["ts"], + "spec": "src/**/*.spec.ts", + "require": ["ts-node/register", "isomorphic-fetch", "jsdom-global/register"], + "loader": "ts-node/esm", + "node-option": [ + "experimental-specifier-resolution=node", + "loader=ts-node/esm" + ], + "exit": true +} diff --git a/packages/tests/.prettierignore b/packages/tests/.prettierignore new file mode 100644 index 0000000000..fecb37a393 --- /dev/null +++ b/packages/tests/.prettierignore @@ -0,0 +1,4 @@ +build +bundle +dist +node_modules diff --git a/packages/tests/karma.conf.cjs b/packages/tests/karma.conf.cjs new file mode 100644 index 0000000000..febf1611b4 --- /dev/null +++ b/packages/tests/karma.conf.cjs @@ -0,0 +1,55 @@ +process.env.CHROME_BIN = require("puppeteer").executablePath(); +const webpack = require("webpack"); + +module.exports = function (config) { + config.set({ + frameworks: ["webpack", "mocha"], + files: ["src/lib/**/!(node).spec.ts"], + preprocessors: { + "src/lib/**/!(node).spec.ts": ["webpack"], + }, + envPreprocessor: ["CI"], + reporters: ["progress"], + browsers: ["ChromeHeadless"], + singleRun: true, + client: { + mocha: { + timeout: 6000, // Default is 2s + }, + }, + webpack: { + mode: "production", + module: { + rules: [ + { + test: /\.(js|tsx?)$/, + use: [ + { + loader: "ts-loader", + options: { configFile: "tsconfig.karma.json" }, + }, + ], + exclude: /(node_modules)|(node\.spec\.ts)/, + }, + { + test: /node\.spec\.ts$/, + use: "ignore-loader", + }, + ], + }, + plugins: [ + new webpack.DefinePlugin({ + "process.env.CI": process.env.CI || false, + }), + new webpack.ProvidePlugin({ + process: "process/browser.js", + }), + ], + resolve: { + extensions: [".ts", ".js"], + }, + stats: { warnings: false }, + devtool: "inline-source-map", + }, + }); +}; diff --git a/packages/tests/package.json b/packages/tests/package.json new file mode 100644 index 0000000000..9f7a134056 --- /dev/null +++ b/packages/tests/package.json @@ -0,0 +1,82 @@ +{ + "name": "@waku/tests", + "private": true, + "version": "0.0.1", + "description": "Waku tests", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "typesVersions": { + "*": { + "lib/*": [ + "dist/lib/*" + ] + } + }, + "type": "module", + "author": "Waku Team", + "homepage": "https://github.com/waku-org/js-waku/tree/master/packages/tests#readme", + "repository": { + "type": "git", + "url": "https://github.com/waku-org/js-waku.git" + }, + "bugs": { + "url": "https://github.com/waku-org/js-waku/issues" + }, + "license": "MIT OR Apache-2.0", + "keywords": [ + "waku", + "decentralized", + "secure", + "communication", + "web3", + "ethereum", + "dapps", + "privacy" + ], + "scripts": { + "build": "run-s build:**", + "build:esm": "tsc", + "fix": "run-s fix:*", + "fix:prettier": "prettier . --write", + "fix:lint": "eslint src --ext .ts --ext .cjs --fix", + "check": "run-s check:*", + "check:lint": "eslint src --ext .ts", + "check:prettier": "prettier . --list-different", + "check:spelling": "cspell \"{README.md,src/**/*.ts}\"", + "check:tsc": "tsc -p tsconfig.dev.json", + "test": "exit 0 # Tested in @waku/core", + "proto": "exit 0 # no proto", + "doc": "exit 0", + "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build", + "release": "exit 0" + }, + "engines": { + "node": ">=16" + }, + "dependencies": { + "@waku/interfaces": "*", + "@waku/core": "*", + "@waku/create": "*" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", + "cspell": "^5.14.0", + "eslint": "^8.6.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^4.0.2", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-prettier": "^4.0.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.1", + "typescript": "^4.6.3" + } +} diff --git a/packages/tests/tsconfig.dev.json b/packages/tests/tsconfig.dev.json new file mode 100644 index 0000000000..ffc27ef6ba --- /dev/null +++ b/packages/tests/tsconfig.dev.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "module": "esnext", + "noEmit": true + }, + "exclude": [] +} diff --git a/packages/tests/tsconfig.json b/packages/tests/tsconfig.json new file mode 100644 index 0000000000..7b01b30897 --- /dev/null +++ b/packages/tests/tsconfig.json @@ -0,0 +1,54 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "dist/", + "rootDir": "src", + "moduleResolution": "node", + "module": "es2020", + "declaration": true, + "sourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + "tsBuildInfoFile": "dist/.tsbuildinfo", + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + "strictFunctionTypes": true /* Enable strict checking of function types. */, + "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "forceConsistentCasingInFileNames": true, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + // Due to broken types in indirect dependencies + "skipLibCheck": true, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2020", "dom"], + "types": ["node", "mocha"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/test_utils"], + "compileOnSave": false, + "ts-node": { + "files": true + } +} diff --git a/packages/tests/tsconfig.karma.json b/packages/tests/tsconfig.karma.json new file mode 100644 index 0000000000..c540c783ff --- /dev/null +++ b/packages/tests/tsconfig.karma.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.dev", + "compilerOptions": { + "noEmit": false + } +}