diff --git a/.github/workflows/pull-request-validation.yml b/.github/workflows/pull-request-validation.yml index 1abdfa85f2..520dd1b2e6 100644 --- a/.github/workflows/pull-request-validation.yml +++ b/.github/workflows/pull-request-validation.yml @@ -133,7 +133,7 @@ jobs: --forceExit \ --logHeapUsage \ --runInBand \ - --testPathPattern packages/\|__tests__/types/ + --testPathPattern=/packages/\ timeout-minutes: 10 - if: always() diff --git a/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts b/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts deleted file mode 100644 index 2547b57b02..0000000000 --- a/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { createStyleSet } from '../../../../packages/bundle'; - -createStyleSet({ cardEmphasisBackgroundColor: 'orange' }); diff --git a/__tests__/types/__typescript__/pass/correct-type-dir.tsx b/__tests__/types/__typescript__/pass/correct-type-dir.tsx deleted file mode 100644 index b3800be14d..0000000000 --- a/__tests__/types/__typescript__/pass/correct-type-dir.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import ReactWebChat from '../../../../packages/bundle'; - -; diff --git a/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx b/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx deleted file mode 100644 index e25efe31aa..0000000000 --- a/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { Components } from '../../../../packages/bundle'; - -const { SendTextBox } = Components; - -; diff --git a/__tests__/types/__typescript__/pass/import-create-direct-line.tsx b/__tests__/types/__typescript__/pass/import-create-direct-line.tsx deleted file mode 100644 index f2ca1ffd23..0000000000 --- a/__tests__/types/__typescript__/pass/import-create-direct-line.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import { createDirectLine } from '../../../../packages/bundle'; - -createDirectLine({ token: 'faketoken' }); diff --git a/jest.config.js b/jest.config.js index d1d68ea914..7441abd785 100644 --- a/jest.config.js +++ b/jest.config.js @@ -99,7 +99,8 @@ module.exports = { '/__tests__/html/__jest__', '/__tests__/html/assets', '/__tests__/setup/', - '/__tests__/types/__typescript__', + '/packages/bundle/__tests__/types/__typescript__/', + '/packages/core/__tests__/types/__typescript__/', '/packages/directlinespeech/__tests__/utilities/', '/packages/playground/', '/samples/' diff --git a/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx similarity index 54% rename from __tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx index 19edbd1c0e..1d19cac582 100644 --- a/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-bot-agent.tsx @@ -1,4 +1,4 @@ -import { createDirectLine } from '../../../../packages/bundle'; +import { createDirectLine } from '../../../../lib/index'; // "botAgent" is a forbidden option. createDirectLine({ botAgent: '123' }); diff --git a/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx similarity index 72% rename from __tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx index 1a39038f8c..c4b6fa5ad1 100644 --- a/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/create-direct-line-invalid-option.tsx @@ -1,4 +1,4 @@ -import { createDirectLine } from '../../../../packages/bundle'; +import { createDirectLine } from '../../../../lib/index'; // Object literal may only specify known properties, and 'invalid' does not exist in type 'Omit'. createDirectLine({ invalid: true }); diff --git a/__tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx similarity index 57% rename from __tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx index 8deb2e082f..9e79e58125 100644 --- a/__tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-prop-type-dir.tsx @@ -1,4 +1,6 @@ -import ReactWebChat from '../../../../packages/bundle'; +import React from 'react'; + +import ReactWebChat from '../../../../lib/index'; // "dir" must be a string of "ltr' | 'rtl' | 'auto'. ; diff --git a/__tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts similarity index 57% rename from __tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts rename to packages/bundle/__tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts index 69814abf8c..728a4d4661 100644 --- a/__tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-style-options-suggested-actions-stacked-overflow.ts @@ -1,4 +1,4 @@ -import { createStyleSet } from '../../../../packages/bundle'; +import { createStyleSet } from '../../../../lib/index'; // Related to #4081. createStyleSet({ suggestedActionsStackedOverflow: 'string' }); diff --git a/__tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx similarity index 64% rename from __tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx index 4493101f34..924f88479d 100644 --- a/__tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/invalid-type-for-use-style-options.tsx @@ -1,4 +1,4 @@ -import { hooks } from '../../../../packages/bundle'; +import { hooks } from '../../../../lib/index'; const [styleOptions] = hooks.useStyleOptions(); diff --git a/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx new file mode 100644 index 0000000000..ea6ebbd874 --- /dev/null +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx @@ -0,0 +1,8 @@ +import React from 'react'; + +import ReactWebChat from '../../../../lib/index-minimal'; + +// should not contains any children. + +
Hello, World
+
; diff --git a/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tmp.tsx similarity index 63% rename from __tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tmp.tsx index a6a1b5bf65..6ae8e3f886 100644 --- a/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat-in-minimal.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tmp.tsx @@ -1,4 +1,6 @@ -import ReactWebChat from '../../../../packages/bundle/lib/index-minimal'; +import React from 'react'; + +import ReactWebChat from '../../../../lib/index'; // should not contains any children. diff --git a/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx similarity index 63% rename from __tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx rename to packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx index 258b9340f2..6ae8e3f886 100644 --- a/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/no-children-for-react-web-chat.tsx @@ -1,4 +1,6 @@ -import ReactWebChat from '../../../../packages/bundle'; +import React from 'react'; + +import ReactWebChat from '../../../../lib/index'; // should not contains any children. diff --git a/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts b/packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts similarity index 58% rename from __tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts rename to packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts index 7b713a0383..b5b89209f9 100644 --- a/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal-for-hooks.ts @@ -1,4 +1,4 @@ -import { hooks } from '../../../../packages/bundle/lib/index-minimal'; +import { hooks } from '../../../../lib/index-minimal'; const [styleOptions] = hooks.useStyleOptions(); diff --git a/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts b/packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts similarity index 64% rename from __tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts rename to packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts index 15873a7973..9db592dce6 100644 --- a/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts +++ b/packages/bundle/__tests__/types/__typescript__/fail-once/no-full-bundle-style-options-in-minimal.ts @@ -1,4 +1,4 @@ -import { createStyleSet } from '../../../../packages/bundle/lib/index-minimal'; +import { createStyleSet } from '../../../../lib/index-minimal'; // "cardEmphasisBackgroundColor" is a style options only available in full bundle. createStyleSet({ cardEmphasisBackgroundColor: 'orange' }); diff --git a/packages/bundle/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts b/packages/bundle/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts new file mode 100644 index 0000000000..e12aa7c5a0 --- /dev/null +++ b/packages/bundle/__tests__/types/__typescript__/pass/additional-style-options-in-full.ts @@ -0,0 +1,3 @@ +import { createStyleSet } from '../../../../lib/index'; + +createStyleSet({ cardEmphasisBackgroundColor: 'orange' }); diff --git a/__tests__/types/__typescript__/pass/composition-with-store.tsx b/packages/bundle/__tests__/types/__typescript__/pass/composition-with-store.tsx similarity index 73% rename from __tests__/types/__typescript__/pass/composition-with-store.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/composition-with-store.tsx index c58e0e81c4..336f0e5dbf 100644 --- a/__tests__/types/__typescript__/pass/composition-with-store.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/composition-with-store.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import { Components, createStore } from '../../../../packages/bundle'; +import { Components, createStore } from '../../../../lib/index'; const { BasicWebChat, Composer } = Components; diff --git a/packages/bundle/__tests__/types/__typescript__/pass/correct-type-dir.tsx b/packages/bundle/__tests__/types/__typescript__/pass/correct-type-dir.tsx new file mode 100644 index 0000000000..f384830536 --- /dev/null +++ b/packages/bundle/__tests__/types/__typescript__/pass/correct-type-dir.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +import ReactWebChat from '../../../../lib/index'; + +; diff --git a/packages/bundle/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx b/packages/bundle/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx new file mode 100644 index 0000000000..15606accc0 --- /dev/null +++ b/packages/bundle/__tests__/types/__typescript__/pass/import-component-send-text-box.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +import { Components } from '../../../../lib/index'; + +const { SendTextBox } = Components; + +; diff --git a/packages/bundle/__tests__/types/__typescript__/pass/import-create-direct-line.tsx b/packages/bundle/__tests__/types/__typescript__/pass/import-create-direct-line.tsx new file mode 100644 index 0000000000..42810d5ea7 --- /dev/null +++ b/packages/bundle/__tests__/types/__typescript__/pass/import-create-direct-line.tsx @@ -0,0 +1,3 @@ +import { createDirectLine } from '../../../../lib/index'; + +createDirectLine({ token: 'faketoken' }); diff --git a/__tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx b/packages/bundle/__tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx similarity index 70% rename from __tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx index 43c6180145..9178e46e6c 100644 --- a/__tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/render-with-minimal-bundle.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import ReactWebChat, { createDirectLine } from '../../../../packages/bundle/lib/index-minimal'; +import ReactWebChat, { createDirectLine } from '../../../../lib/index-minimal'; const directLine = createDirectLine({ token: '...' }); const styleOptions = { accent: 'black' }; diff --git a/__tests__/types/__typescript__/pass/render-with-store.tsx b/packages/bundle/__tests__/types/__typescript__/pass/render-with-store.tsx similarity index 68% rename from __tests__/types/__typescript__/pass/render-with-store.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/render-with-store.tsx index 2f80f185fc..cfb47be094 100644 --- a/__tests__/types/__typescript__/pass/render-with-store.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/render-with-store.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import { Components, createStore } from '../../../../packages/bundle'; +import { Components, createStore } from '../../../../lib/index'; const { Composer } = Components; diff --git a/__tests__/types/__typescript__/pass/render-with-style-options.tsx b/packages/bundle/__tests__/types/__typescript__/pass/render-with-style-options.tsx similarity index 74% rename from __tests__/types/__typescript__/pass/render-with-style-options.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/render-with-style-options.tsx index 3f7d1d0aea..6f048c476d 100644 --- a/__tests__/types/__typescript__/pass/render-with-style-options.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/render-with-style-options.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import ReactWebChat, { createDirectLine } from '../../../../packages/bundle'; +import ReactWebChat, { createDirectLine } from '../../../../lib/index'; const directLine = createDirectLine({ token: '...' }); const styleOptions = { accent: 'black', cardEmphasisBackgroundColor: 'orange' }; diff --git a/__tests__/types/__typescript__/pass/render-with-style-set.tsx b/packages/bundle/__tests__/types/__typescript__/pass/render-with-style-set.tsx similarity index 87% rename from __tests__/types/__typescript__/pass/render-with-style-set.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/render-with-style-set.tsx index 2c7aa8f9c4..23675540ef 100644 --- a/__tests__/types/__typescript__/pass/render-with-style-set.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/render-with-style-set.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import ReactWebChat, { createDirectLine, createStyleSet } from '../../../../packages/bundle/lib/index-minimal'; +import ReactWebChat, { createDirectLine, createStyleSet } from '../../../../lib/index-minimal'; const directLine = createDirectLine({ token: '...' }); const styleOptions = { accent: 'black', cardEmphasisBackgroundColor: 'orange' }; diff --git a/__tests__/types/__typescript__/pass/render.tsx b/packages/bundle/__tests__/types/__typescript__/pass/render.tsx similarity index 64% rename from __tests__/types/__typescript__/pass/render.tsx rename to packages/bundle/__tests__/types/__typescript__/pass/render.tsx index 2c2ff1637c..2a6fb70043 100644 --- a/__tests__/types/__typescript__/pass/render.tsx +++ b/packages/bundle/__tests__/types/__typescript__/pass/render.tsx @@ -1,6 +1,7 @@ +import React from 'react'; import ReactDOM from 'react-dom'; -import ReactWebChat, { createDirectLine } from '../../../../packages/bundle'; +import ReactWebChat, { createDirectLine } from '../../../../lib/index'; const directLine = createDirectLine({ token: '...' }); diff --git a/__tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts b/packages/bundle/__tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts similarity index 65% rename from __tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts rename to packages/bundle/__tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts index 89a7fb4045..d898987f89 100644 --- a/__tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts +++ b/packages/bundle/__tests__/types/__typescript__/pass/use-style-options-with-full-bundle.ts @@ -1,4 +1,4 @@ -import { hooks } from '../../../../packages/bundle'; +import { hooks } from '../../../../lib/index'; const [styleOptions] = hooks.useStyleOptions(); diff --git a/__tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts b/packages/bundle/__tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts similarity index 81% rename from __tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts rename to packages/bundle/__tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts index 30ee59aecb..968804ef8b 100644 --- a/__tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts +++ b/packages/bundle/__tests__/types/__typescript__/pass/valid-style-options-suggested-actions-stacked-overflow.ts @@ -1,4 +1,4 @@ -import { createStyleSet } from '../../../../packages/bundle'; +import { createStyleSet } from '../../../../lib/index'; // Related to #4081. createStyleSet({ suggestedActionsStackedOverflow: 'auto' }); diff --git a/__tests__/types/tsconfig.json b/packages/bundle/__tests__/types/tsconfig.json similarity index 100% rename from __tests__/types/tsconfig.json rename to packages/bundle/__tests__/types/tsconfig.json diff --git a/__tests__/types/typescript.js b/packages/bundle/__tests__/types/typescript.js similarity index 100% rename from __tests__/types/typescript.js rename to packages/bundle/__tests__/types/typescript.js diff --git a/__tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts similarity index 85% rename from __tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts rename to packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts index 8c0e66b471..48684c8f4f 100644 --- a/__tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts +++ b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-bot.ts @@ -1,4 +1,4 @@ -import type { WebChatActivity } from '../../../../packages/core'; +import type { WebChatActivity } from '../../../../lib/index'; // All activities from bot must be from server. const activity: WebChatActivity = { diff --git a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts similarity index 86% rename from __tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts rename to packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts index 791d641723..01b94e8d4b 100644 --- a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts +++ b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-send-failed.ts @@ -1,4 +1,4 @@ -import type { WebChatActivity } from '../../../../packages/core'; +import type { WebChatActivity } from '../../../../lib/index'; // All activities that failed to send, are activities that never reach the server (a.k.a. activity-in-transit). const activity: WebChatActivity = { diff --git a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts similarity index 86% rename from __tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts rename to packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts index bb3658db05..cb68e8e30c 100644 --- a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts +++ b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sending.ts @@ -1,4 +1,4 @@ -import type { WebChatActivity } from '../../../../packages/core'; +import type { WebChatActivity } from '../../../../lib/index'; // All activities that are sending, are activities that did not reach the server yet (a.k.a. activity-in-transit). const activity: WebChatActivity = { diff --git a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts similarity index 86% rename from __tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts rename to packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts index e9f473274e..07a781b794 100644 --- a/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts +++ b/packages/core/__tests__/types/__typescript__/pass/direct-line-activity-from-user-sent.ts @@ -1,4 +1,4 @@ -import type { WebChatActivity } from '../../../../packages/core'; +import type { WebChatActivity } from '../../../../lib/index'; // All activities which are "sent", must be from server. const activity: WebChatActivity = { diff --git a/packages/core/__tests__/types/tsconfig.json b/packages/core/__tests__/types/tsconfig.json new file mode 100644 index 0000000000..aee0ec940f --- /dev/null +++ b/packages/core/__tests__/types/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strict": true + } +} diff --git a/packages/core/__tests__/types/typescript.js b/packages/core/__tests__/types/typescript.js new file mode 100644 index 0000000000..b0fe9c7597 --- /dev/null +++ b/packages/core/__tests__/types/typescript.js @@ -0,0 +1,96 @@ +const { join, relative } = require('path'); +const { readdir } = require('fs').promises; + +const ts = require('typescript'); + +function compile(...filenames) { + const program = ts.createProgram(filenames, { + allowSyntheticDefaultImports: true, + jsx: 'react', + noEmit: true, + skipLibCheck: true, + strict: true + }); + + const emitResult = program.emit(); + const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + const errors = []; + + allDiagnostics.forEach(diagnostic => { + if (diagnostic.file) { + const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + + errors.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + } else { + errors.push(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); + } + }); + + return errors; +} + +describe('compiling TypeScript files', () => { + describe('in /pass/ folder', () => { + let results; + + beforeEach(async () => { + const path = join(__dirname, '__typescript__/pass/'); + let files = []; + + try { + files = await readdir(path); + } catch (error) { + if (error.code !== 'ENOENT') { + throw error; + } + } + + results = {}; + + files.forEach(file => { + const fullPath = join(path, file); + + results[relative(path, fullPath)] = { errors: compile(fullPath) }; + }); + }); + + test('should pass', () => { + for (const filename of Object.keys(results)) { + expect(results).toHaveProperty([filename, 'errors'], []); + expect(results).toHaveProperty([filename, 'errors', 'length'], 0); + } + }); + }); + + describe('in /fail-once/ folder', () => { + let results; + + beforeEach(async () => { + const path = join(__dirname, '__typescript__/fail-once/'); + let files = []; + + try { + files = await readdir(path); + } catch (error) { + if (error.code !== 'ENOENT') { + throw error; + } + } + + results = {}; + + files.forEach(file => { + const fullPath = join(path, file); + + results[relative(path, fullPath)] = { errors: compile(fullPath) }; + }); + }); + + test('should fail only once', () => { + for (const filename of Object.keys(results)) { + expect(results).toHaveProperty([filename, 'errors', 'length'], 1); + } + }); + }); +});