Skip to content

Commit

Permalink
chore(sdk): simpler way to run test command (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Feb 3, 2023
1 parent 0392ac9 commit 439d2b7
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/aptos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"compile": "tsc -p .",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"build": "sentio build",
"build_all": "yarn lerna run --scope=@sentio-example/aptos build --include-dependencies",
"cli": "ts-node --files src/cli.ts"
Expand Down
2 changes: 1 addition & 1 deletion examples/aurory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": "true",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"gen": "sentio gen",
"build": "sentio build",
"test": "sentio test",
"upload": "sentio upload",
"build_all": "yarn lerna run --scope=@sentio-example/aurory build --include-dependencies"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/sui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"compile": "tsc -p .",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"build": "sentio build",
"build_all": "yarn lerna run --scope=@sentio-example/sui build --include-dependencies"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/wormhole/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"compile": "tsc -p .",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"build": "yarn sentio build",
"build_all": "yarn lerna run --scope=@sentio-example/wormhole build --include-dependencies"
},
Expand Down
7 changes: 3 additions & 4 deletions examples/x2y2-complex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "module",
"scripts": {
"compile": "tsc -p .",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"build": "yarn install && sentio build",
"test": "sentio test",
"build": "sentio build",
"upload": "sentio upload",
"tsnode": "yarn ts-node",
"build_all": "yarn lerna run --scope=@sentio-example/x2y2-complex build --include-dependencies"
Expand All @@ -16,7 +16,6 @@
"@sentio/sdk": "^2.0.0-development"
},
"devDependencies": {
"@sentio/cli": "^2.0.0-development",
"ts-node": "^10.8.0"
"@sentio/cli": "^2.0.0-development"
}
}
5 changes: 2 additions & 3 deletions examples/x2y2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": "true",
"scripts": {
"compile": "tsc -p .",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"build": "sentio build",
"upload": "sentio upload",
"tsnode": "yarn ts-node-esm",
Expand All @@ -16,7 +16,6 @@
"@sentio/sdk": "^2.0.0-development"
},
"devDependencies": {
"@sentio/cli": "^2.0.0-development",
"ts-node": "^10.8.0"
"@sentio/cli": "^2.0.0-development"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"lint-staged": "^13.0.3",
"prettier": "^2.8.1",
"prettier-plugin-sh": "^0.12.8",
"prettier-plugin-sort-json": "^1.0.0",
"semantic-release": "^19.0.5",
"semantic-release-monorepo": "^7.0.5",
"ts-jest": "^29.0.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"pub": "yarn build && yarn publish --no-git-tag-version"
},
"dependencies": {
"@types/jest": "^29.0.0",
"command-line-args": "^5.2.1",
"command-line-usage": "^6.1.3",
"express": "^4.18.2",
Expand All @@ -24,9 +25,9 @@
"open": "^8.4.0",
"tsup": "npm:@sentio/tsup@^6.5.0",
"chalk": "^5.2.0",
"@types/jest": "^29.0.0",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"@jest/types": "^29.4.1",
"ts-node": "^10.9.1"
},
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { runCreate } from './commands/run-create.js'
import { runVersion } from './commands/run-version.js'
import { runLogin } from './commands/run-login.js'
import { runUpload } from './commands/run-upload.js'
import { runTest } from './commands/run-test.js'

const mainDefinitions = [{ name: 'command', defaultOption: true }]
const mainOptions = commandLineArgs(mainDefinitions, {
Expand All @@ -27,9 +28,11 @@ if (!mainOptions.command) {
if (mainOptions.command === 'login') {
runLogin(argv)
} else if (mainOptions.command === 'create') {
runCreate(argv)
await runCreate(argv)
} else if (mainOptions.command === 'version') {
runVersion(argv)
} else if (mainOptions.command === 'test') {
runTest(argv)
} else {
// For all the commands that need read project configs
// TODO move them to their own modules
Expand Down Expand Up @@ -110,6 +113,7 @@ function usage() {
'sentio upload\t\t\t\tbuild and upload processor to sentio',
'sentio gen\t\t\t\tgenerate abi',
'sentio build\t\t\t\tgenerate abi and build',
'sentio test\t\t\t\trun tests',
'sentio version\t\t\tcurrent cli version',
],
},
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/commands/run-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { execSync } from 'child_process'
import path from 'path'
import { getPackageRoot } from '../utils.js'

export function runTest(argv: string[]) {
const defaultJest = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/jest.config.js')
// if config not existed copy that
execSync(`NODE_OPTIONS=--experimental-vm-modules yarn jest` + argv.join(' '), { stdio: 'inherit' })
}
2 changes: 1 addition & 1 deletion packages/cli/templates/aptos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"gen": "sentio gen",
"build": "sentio build",
"upload": "sentio upload"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"gen": "sentio gen",
"build": "sentio build",
"upload": "sentio upload"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/raw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"gen": "sentio gen",
"build": "sentio build",
"upload": "sentio upload"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
"test": "sentio test",
"gen": "sentio gen",
"build": "sentio build",
"upload": "sentio upload"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-solana/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
export default {
preset: 'ts-jest/presets/default-esm',
modulePathIgnorePatterns: ['<rootDir>/dist/'],
modulePathIgnorePatterns: ['<rootDir>/lib/'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/src/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
export default {
preset: 'ts-jest/presets/default-esm',
modulePathIgnorePatterns: ['<rootDir>/dist/'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
}
13 changes: 10 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7435,7 +7435,7 @@ jest-worker@^29.4.1:
merge-stream "^2.0.0"
supports-color "^8.0.0"

jest@^29.0.0, jest@^29.4.1:
jest@^29.4.1:
version "29.4.1"
resolved "https://registry.yarnpkg.com/jest/-/jest-29.4.1.tgz#bb34baca8e05901b49c02c62f1183a6182ea1785"
integrity sha512-cknimw7gAXPDOmj0QqztlxVtBVCw2lYY9CeIE5N6kD+kET1H4H79HSNISJmijb1HF+qk+G+ploJgiDi5k/fRlg==
Expand Down Expand Up @@ -9464,6 +9464,13 @@ prettier-plugin-sh@^0.12.8:
sh-syntax "^0.3.6"
synckit "^0.8.1"

prettier-plugin-sort-json@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-plugin-sort-json/-/prettier-plugin-sort-json-1.0.0.tgz#fe677d5537b6d79d12ffaf1604046a3d3ee2427c"
integrity sha512-XgcaF/Sojax1vD6j53wNIByx0rp7ecang+A8W0eM+Ks3yBFu/qXjJNvUtC1lEWeYbNfmRs/d8FyYJCYozAVENw==
dependencies:
"@types/prettier" "^2.7.2"

prettier@^2.3.1:
version "2.8.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632"
Expand Down Expand Up @@ -11031,7 +11038,7 @@ ts-invariant@^0.10.3:
dependencies:
tslib "^2.1.0"

ts-jest@^29.0.0, ts-jest@^29.0.5:
ts-jest@^29.0.5:
version "29.0.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.0.5.tgz#c5557dcec8fe434fcb8b70c3e21c6b143bfce066"
integrity sha512-PL3UciSgIpQ7f6XjVOmbi96vmDHUqAyqDr8YxzopDqX3kfgYtX1cuNeBjP+L9sFXi6nzsGGA6R3fP3DDDJyrxA==
Expand All @@ -11045,7 +11052,7 @@ ts-jest@^29.0.0, ts-jest@^29.0.5:
semver "7.x"
yargs-parser "^21.0.1"

ts-node@^10.8.0, ts-node@^10.9.1:
ts-node@^10.9.1:
version "10.9.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
Expand Down

0 comments on commit 439d2b7

Please sign in to comment.