diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 0a61b0f..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,97 +0,0 @@ -version: 2.1 - -aliases: - - &ignore-main-branch - branches: - ignore: main - - &only-main-branch - branches: - only: main - - &working_directory - working_directory: /home/circleci/project/ - -commands: - yarn-install: - description: Install cached yarn packages - steps: - - restore_cache: - keys: [ 'v3-{{ checksum "yarn.lock" }}' ] - - run: yarn - - yarn-save-cache: - description: Save yarn packages cache - steps: - - save_cache: - key: v3-{{ checksum "yarn.lock" }} - paths: [ '.yarn/cache' ] - -jobs: - test-and-build: - <<: *working_directory - docker: - - image: cimg/node:16.10.0 - steps: - - checkout - - yarn-install - - yarn-save-cache - - run: yarn build - - run: yarn test - - persist_to_workspace: - root: . - paths: - - packages/genesys-web-messaging-tester/lib - - packages/genesys-web-messaging-tester-cli/lib - - test-examples: - <<: *working_directory - docker: - - image: cimg/node:16.10.0 - steps: - - checkout - - yarn-install - - yarn-save-cache - - run: yarn build - - run: cd examples/cli && yarn execute - - run: cd examples/api && yarn test:js - - run: cd examples/api && yarn test:ts - - test-building-docs: - <<: *working_directory - docker: - - image: cimg/node:16.10.0 - steps: - - checkout - - yarn-install - - yarn-save-cache - - run: yarn build - - run: yarn build:docs - - publish: - <<: *working_directory - docker: - - image: cimg/node:16.10.0 - steps: - - checkout - - yarn-install - - attach_workspace: - at: . - - run: YARN_NPM_AUTH_TOKEN=$NPM_TOKEN yarn publish - -workflows: - build_and_test: - jobs: - - test-and-build: - filters: *ignore-main-branch - - test-building-docs: - filters: *ignore-main-branch - - test-examples: - filters: *ignore-main-branch - requires: - - test-and-build - main: - jobs: - - test-and-build: - filters: *only-main-branch - - publish: - requires: - - test-and-build diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml new file mode 100644 index 0000000..069f67f --- /dev/null +++ b/.github/workflows/on-push.yml @@ -0,0 +1,64 @@ +name: On Push + +on: [push] + +jobs: +# lint: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - name: Setup Node +# uses: actions/setup-node@v1 +# with: +# node-version: 16.x +# - run: yarn +# - run: yarn lint +# env: +# CI: true + + test-and-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 16.x + - run: yarn + - run: yarn build + - run: yarn test + + test-building-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 16.x + - run: yarn + - run: yarn build + - run: yarn build:docs + + test-examples: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 16.x + - run: yarn + - run: yarn build + - run: cd examples/cli && yarn execute + env: + DEPLOYMENT_ID: ${{ secrets.DEPLOYMENT_ID }} + REGION: ${{ secrets.REGION }} + - run: cd examples/api && yarn test:js + env: + DEPLOYMENT_ID: ${{ secrets.DEPLOYMENT_ID }} + REGION: ${{ secrets.REGION }} + - run: cd examples/api && yarn test:ts + env: + DEPLOYMENT_ID: ${{ secrets.DEPLOYMENT_ID }} + REGION: ${{ secrets.REGION }} diff --git a/.github/workflows/on-release.yml b/.github/workflows/on-release.yml new file mode 100644 index 0000000..cecad6f --- /dev/null +++ b/.github/workflows/on-release.yml @@ -0,0 +1,20 @@ +name: Publish Package to npmjs +on: + release: + types: [published] +jobs: + test-build-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + scope: '@ovotech' + - run: yarn + - run: yarn build + - run: yarn test + - run: yarn npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/examples/api/package.json b/examples/api/package.json index f7d414f..927181b 100644 --- a/examples/api/package.json +++ b/examples/api/package.json @@ -4,6 +4,7 @@ "private": true, "packageManager": "yarn@3.1.1", "scripts": { + "lint": "eslint 'src/**/*.ts'", "test": "jest __tests__", "test:js": "node ../api/src/js-script.js", "test:ts": "node -r ts-node/register ../api/src/ts-script.ts" diff --git a/package.json b/package.json index c38b2f9..03dc2aa 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ ], "scripts": { "test": "yarn workspaces foreach --verbose --exclude '@examples/*' run test", + "lint": "yarn workspaces foreach --verbose run lint", "build": "yarn workspaces foreach --verbose run build", "build:docs": "cp README.md packages/genesys-web-messaging-tester-cli/README.md && typedoc && yarn workspaces foreach --verbose run build:readme", "publish": "yarn workspaces foreach --no-private --verbose npm publish --tolerate-republish --access public" diff --git a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/configSectionValidated.spec.ts b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/configSectionValidated.spec.ts index 1e2140a..137a9e7 100644 --- a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/configSectionValidated.spec.ts +++ b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/configSectionValidated.spec.ts @@ -74,9 +74,7 @@ scenarios: scenario: - say: hi from scenario `); - await expect( - cli([...['node', '/path/to/cli'], ...['test-path']]), - ).rejects.toBeDefined(); + await expect(cli([...['node', '/path/to/cli'], ...['test-path']])).rejects.toBeDefined(); expect(capturedOutput.errOut.map(stripAnsi)).toStrictEqual([expectedError]); }); diff --git a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionLoaded.spec.ts b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionLoaded.spec.ts index 578db1c..36b42c7 100644 --- a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionLoaded.spec.ts +++ b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionLoaded.spec.ts @@ -55,12 +55,10 @@ describe('Test script YAML loaded', () => { throw new Error('force app to exit'); }); - await expect( - cli([...['node', '/path/to/cli'], ...['test-file.yml']]), - ).rejects.toBeDefined(); + await expect(cli([...['node', '/path/to/cli'], ...['test-file.yml']])).rejects.toBeDefined(); expect(capturedOutput.errOut.map(stripAnsi)).toStrictEqual([ - "error: command-argument value 'test-file.yml' is invalid for argument 'filePath'. File 'test-file.yml' is not readable\n" + "error: command-argument value 'test-file.yml' is invalid for argument 'filePath'. File 'test-file.yml' is not readable\n", ]); }); diff --git a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionValidated.spec.ts b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionValidated.spec.ts index 9b1e801..fd224f2 100644 --- a/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionValidated.spec.ts +++ b/packages/genesys-web-messaging-tester-cli/__tests__/yamlTestScript/scenarioSectionValidated.spec.ts @@ -64,9 +64,7 @@ config: deploymentId: xx region: xx `); - await expect( - cli([...['node', '/path/to/cli'], ...['test-path']]), - ).rejects.toBeDefined(); + await expect(cli([...['node', '/path/to/cli'], ...['test-path']])).rejects.toBeDefined(); expect(capturedOutput.errOut.map(stripAnsi)).toStrictEqual(['"scenarios" is required\n']); }); @@ -81,9 +79,7 @@ scenarios: - say: hi from scenario waitForReplyContaining: hello `); - await expect( - cli([...['node', '/path/to/cli'], ...['test-path']]), - ).rejects.toBeDefined(); + await expect(cli([...['node', '/path/to/cli'], ...['test-path']])).rejects.toBeDefined(); expect(capturedOutput.errOut.map(stripAnsi)).toStrictEqual([ '"scenarios.scenario-name[0]" must have 1 key\n', @@ -99,9 +95,7 @@ scenarios: scenario-name: - testing: 123 `); - await expect( - cli([...['node', '/path/to/cli'], ...['test-path']]), - ).rejects.toBeDefined(); + await expect(cli([...['node', '/path/to/cli'], ...['test-path']])).rejects.toBeDefined(); expect(capturedOutput.errOut.map(stripAnsi)).toStrictEqual([ '"scenarios.scenario-name[0].testing" is not allowed\n', diff --git a/packages/genesys-web-messaging-tester-cli/package.json b/packages/genesys-web-messaging-tester-cli/package.json index 24f714a..edd66cf 100644 --- a/packages/genesys-web-messaging-tester-cli/package.json +++ b/packages/genesys-web-messaging-tester-cli/package.json @@ -1,6 +1,6 @@ { "name": "@ovotech/genesys-web-messaging-tester-cli", - "version": "1.0.9", + "version": "1.0.10", "main": "lib/index.js", "types": "lib/index.d.ts", "license": "Apache-2.0", @@ -21,7 +21,8 @@ "build:readme": "cd ../.. && yarn build-readme ./packages/genesys-web-messaging-tester-cli/README.md https://github.com/ovotech/genesys-web-messaging-tester/tree/main", "test": "jest __tests__/", "test:execute": "ts-node src/index.ts ../../examples/cli/example.yml -id $DEPLOYMENT_ID -r $REGION -p 10", - "test:execute:help": "ts-node src/index.ts --help" + "test:execute:help": "ts-node src/index.ts --help", + "lint": "eslint 'src/**/*.ts'" }, "bin": { "web-messaging-tester": "lib/index.js" diff --git a/packages/genesys-web-messaging-tester-cli/src/cli.ts b/packages/genesys-web-messaging-tester-cli/src/cli.ts index cfe3055..2ccbb8c 100644 --- a/packages/genesys-web-messaging-tester-cli/src/cli.ts +++ b/packages/genesys-web-messaging-tester-cli/src/cli.ts @@ -19,7 +19,6 @@ import { validateSessionConfig } from './testScript/validateSessionConfig'; import { validateTestScript } from './testScript/validateTestScript'; import { ScenarioError, ScenarioSuccess } from './ScenarioResult'; import { validateGenesysEnvVariables } from './genesysPlatform/validateGenesysEnvVariables'; -import { configurePlatformClients } from './genesysPlatform/configurePlatformClients'; import { createConversationIdGetter, messageIdToConversationIdFactory, @@ -134,6 +133,12 @@ GENESYSCLOUD_OAUTHCLIENT_SECRET`, ui?.validatingAssociateConvoIdEnvValidationFailed(genesysEnvValidationResult.error), ); } else { + // Only load when required + // Also removes 'You are trying to `import` a file after the Jest environment has been torn down' error due to + // file-watcher it starts + const { configurePlatformClients } = await import( + './genesysPlatform/configurePlatformClients' + ); const clients = await configurePlatformClients(genesysEnvValidationResult.genesysVariables); const messageIdToConversationIdClient = messageIdToConversationIdFactory(clients); diff --git a/packages/genesys-web-messaging-tester-cli/src/genesysPlatform/configurePlatformClients.ts b/packages/genesys-web-messaging-tester-cli/src/genesysPlatform/configurePlatformClients.ts index 1bc66da..9c09dc9 100644 --- a/packages/genesys-web-messaging-tester-cli/src/genesysPlatform/configurePlatformClients.ts +++ b/packages/genesys-web-messaging-tester-cli/src/genesysPlatform/configurePlatformClients.ts @@ -10,6 +10,7 @@ export async function configurePlatformClients( auth: GenesysPlatformApiAuth, ): Promise<{ convoApi: platformClient.ConversationsApi }> { const apiClient = platformClient.ApiClient.instance; + apiClient.setEnvironment(auth.region); await apiClient.loginClientCredentialsGrant(auth.oAuthClientId, auth.oAuthClientSecret); diff --git a/packages/genesys-web-messaging-tester/package.json b/packages/genesys-web-messaging-tester/package.json index 5e84847..b706121 100644 --- a/packages/genesys-web-messaging-tester/package.json +++ b/packages/genesys-web-messaging-tester/package.json @@ -19,7 +19,8 @@ "scripts": { "build": "rm -rf ./lib && tsc -p tsconfig.json", "build:readme": "cd ../.. && yarn build-readme ./packages/genesys-web-messaging-tester/README.md https://github.com/ovotech/genesys-web-messaging-tester/tree/main", - "test": "jest __tests__/" + "test": "jest __tests__/", + "lint": "eslint 'src/**/*.ts'" }, "dependencies": { "debug": "^4.3.3",