From 792f1a8d7d550fbaea956765b88f84fe7fa62850 Mon Sep 17 00:00:00 2001 From: Gabriel Samson Date: Tue, 24 Aug 2021 12:56:32 -0700 Subject: [PATCH] Improve external developer experience (#81) * Support external dx * Add external DX workflow * Add --ignore-optional * [core] Add jest moduleNameMapper * Fix typo * Add yarn link * no ci * [destinations] Add subscriptions to jest module map * yarn exec install * dash-dash * ignore browser destinations when calling build: * replicate manual test flow * Switch to yarn install * Move browser-destination jest config to file and conditionally run tests * [ci] sleep after bootstrapping * --no-ci bootstrap * Add subscriptions path * Update README.md * Reformat jest.config.js with 4 spaces * Add newline to jest.config.js --- .github/workflows/ext.yml | 32 ++++++++++++++++++++ README.md | 7 ++++- lerna.json | 3 ++ packages/browser-destinations/jest.config.js | 27 +++++++++++++++++ packages/browser-destinations/package.json | 14 +-------- packages/cli/package.json | 2 +- packages/core/package.json | 6 +++- packages/destination-actions/package.json | 3 +- packages/destination-actions/tsconfig.json | 3 +- 9 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ext.yml create mode 100644 packages/browser-destinations/jest.config.js diff --git a/.github/workflows/ext.yml b/.github/workflows/ext.yml new file mode 100644 index 0000000000..9dc1e05045 --- /dev/null +++ b/.github/workflows/ext.yml @@ -0,0 +1,32 @@ +name: Test External + +on: [push] + +jobs: + install-and-test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + + - name: Install + run: yarn --ignore-engines --ignore-optional + + - name: Bootstrap + run: yarn bootstrap --no-ci + + - name: Test + run: yarn test + + - name: Build + run: NODE_ENV=production yarn build --ignore @segment/browser-destinations diff --git a/README.md b/README.md index a7ab36ed09..548372cea0 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,14 @@ This project is a monorepo with multiple packages using Yarn Workspaces: - `packages/cli` - a set of command line tools for interacting with the repo - `packages/core` - the core runtime engine for actions, including mapping-kit transforms - `packages/destinations-actions` - destination definitions and their actions +- `packages/destinations-subscriptions` - validates events against an action's subscription AST ``` -$ yarn install +git clone https://github.com/segmentio/action-destinations.git +cd action-destinations +yarn --ignore-engines --ignore-optional +yarn bootstrap +yarn test ``` ## Test Actions Locally diff --git a/lerna.json b/lerna.json index 389e0c59b2..ee9c01a4fb 100644 --- a/lerna.json +++ b/lerna.json @@ -4,6 +4,9 @@ "useWorkspaces": true, "version": "independent", "command": { + "bootstrap": { + "npmClientArgs": ["--ignore-engines", "--ignore-optional"] + }, "version": { "allowBranch": "main" } diff --git a/packages/browser-destinations/jest.config.js b/packages/browser-destinations/jest.config.js new file mode 100644 index 0000000000..28a7a92259 --- /dev/null +++ b/packages/browser-destinations/jest.config.js @@ -0,0 +1,27 @@ +module.exports = async () => { + const config = { + rootDir: './', + moduleNameMapper: { + '@segment/actions-core': '/../core/src/index.ts' + }, + transform: { + '^.+\\.[t|j]sx?$': 'babel-jest' + }, + transformIgnorePatterns: [ + '/node_modules/(?!@segment/analytics-next).+\\.js$' + ], + forceExit: true + } + + try { + await import('@segment/analytics-next') + } catch (_) { + config.testPathIgnorePatterns = [ + '/node_modules/', + '/src/' + ] + console.warn('optional dependency @segment/analytics-next not found, ignoring all tests') + } + + return config +} diff --git a/packages/browser-destinations/package.json b/packages/browser-destinations/package.json index 3265c138db..7d065b5eab 100644 --- a/packages/browser-destinations/package.json +++ b/packages/browser-destinations/package.json @@ -22,7 +22,7 @@ "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rm -rf dist", "prepublishOnly": "yarn build", - "test": "jest", + "test": "jest --passWithNoTests", "typecheck": "tsc --noEmit", "dev": "concurrently \"webpack serve\" \"webpack -c webpack.config.js --watch\"" }, @@ -68,17 +68,5 @@ "singleQuote": true, "trailingComma": "none", "printWidth": 120 - }, - "jest": { - "moduleNameMapper": { - "@segment/actions-core": "/../core/src/index.ts" - }, - "transform": { - "^.+\\.[t|j]sx?$": "babel-jest" - }, - "transformIgnorePatterns": [ - "/node_modules/(?!@segment/analytics-next).+\\.js$" - ], - "forceExit": true } } diff --git a/packages/cli/package.json b/packages/cli/package.json index 76062eb149..2d09981e37 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -57,7 +57,6 @@ "@oclif/errors": "^1", "@oclif/plugin-help": "^3", "@segment/action-destinations": "^3.6.1", - "@segment/browser-destinations": "^3.6.0", "chalk": "^4.1.1", "chokidar": "^3.5.1", "execa": "^5.1.1", @@ -79,6 +78,7 @@ }, "optionalDependencies": { "@segment/actions-core": "^3.6.0", + "@segment/browser-destinations": "^3.6.0", "@segment/control-plane-service-client": "github:segmentio/control-plane-service-js-client.git#master" }, "oclif": { diff --git a/packages/core/package.json b/packages/core/package.json index 7634322669..be5e5214bc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -71,6 +71,10 @@ "testEnvironment": "node", "modulePathIgnorePatterns": [ "/dist/" - ] + ], + "moduleNameMapper": { + "@segment/ajv-human-errors": "/../ajv-human-errors", + "@segment/destination-subscriptions": "/../destination-subscriptions/src" + } } } diff --git a/packages/destination-actions/package.json b/packages/destination-actions/package.json index e59804950f..299612e5ad 100644 --- a/packages/destination-actions/package.json +++ b/packages/destination-actions/package.json @@ -51,7 +51,8 @@ "/dist/" ], "moduleNameMapper": { - "@segment/actions-core": "/../core/src/index.ts" + "@segment/actions-core": "/../core/src/index.ts", + "@segment/destination-subscriptions": "/../destination-subscriptions/src" }, "setupFilesAfterEnv": [ "/test/setup-after-env.ts" diff --git a/packages/destination-actions/tsconfig.json b/packages/destination-actions/tsconfig.json index f9b39acaae..7ce2f70a2c 100644 --- a/packages/destination-actions/tsconfig.json +++ b/packages/destination-actions/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@segment/actions-core": ["../core/src"] + "@segment/actions-core": ["../core/src"], + "@segment/destination-subscriptions": ["../destination-subscriptions/src"] } }, "exclude": [],