@teambit/tester 0.0.802 → 0.0.805

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tester.d.ts CHANGED
@@ -74,6 +74,15 @@ export interface TesterContext extends ExecutionContext {
74
74
  * array of patterns to test.
75
75
  */
76
76
  patterns: ComponentPatternsMap;
77
+ /**
78
+ *
79
+ * additional test host dependencies
80
+ * This can be used in cases when you want specific dependencies to be resolved from the env during testing
81
+ * but you don't want these dependencies as peer dependencies of the component (as they are not used during runtime)
82
+ * An example for this is @angular/compiler, which during running tests you want to resolve from the env, but you don't
83
+ * need it during component runtime.
84
+ */
85
+ additionalHostDependencies?: string[];
77
86
  }
78
87
  /**
79
88
  * tester interface allows extensions to implement a component tester into bit.
@@ -1 +1 @@
1
- {"version":3,"names":["Tests","constructor","components","errors","map","comp","flat"],"sources":["tester.ts"],"sourcesContent":["import { Component, ComponentID, ComponentMap } from '@teambit/component';\nimport { ExecutionContext } from '@teambit/envs';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { TestsResult } from '@teambit/tests-results';\n\nexport class Tests {\n constructor(public components: ComponentsResults[]) {}\n get errors(): Error[] {\n return this.components.map((comp) => comp.errors || []).flat();\n }\n}\n\nexport type ComponentsResults = {\n /**\n * component id.\n */\n componentId: ComponentID;\n /**\n * test results for the component.\n */\n results?: TestsResult;\n /**\n * aggregated errors from all files\n */\n errors?: Error[];\n\n /**\n * loading.\n */\n loading?: boolean;\n};\n\nexport type SpecFiles = ComponentMap<AbstractVinyl[]>;\nexport type ComponentPatternsMap = ComponentMap<{ path: string; relative: string }[]>;\n\nexport interface TesterContext extends ExecutionContext {\n /**\n * whether the tester run for release (during bit build/tag) or not (during bit test command).\n */\n release: boolean;\n\n /**\n * list of components to test.\n */\n components: Component[];\n\n /**\n * component workspace.\n */\n // workspace: Workspace;\n\n /**\n * defines whether tester is expected to run in quiet mode.\n */\n quiet?: boolean;\n\n /**\n * list of spec files to test.\n */\n specFiles: SpecFiles;\n\n /**\n * rootPath of the component workspace or the capsule root dir (during build).\n */\n rootPath: string;\n\n /**\n * determines whether tester is expected to run in debug mode.\n */\n debug?: boolean;\n\n /**\n * is start from ui\n */\n ui?: boolean;\n\n /**\n * determines whether to start the tester in watch mode.\n */\n watch?: boolean;\n\n /**\n * whether the tester should show code coverage\n */\n coverage?: boolean;\n\n /**\n * array of patterns to test.\n */\n patterns: ComponentPatternsMap;\n}\n\n/**\n * tester interface allows extensions to implement a component tester into bit.\n */\nexport interface Tester {\n /**\n * display name of the tester.\n */\n displayName?: string;\n\n /**\n * icon of the tester.\n */\n icon?: string;\n\n /**\n * serialized config of the tester.\n */\n displayConfig?(): string;\n\n /**\n * path to the config in the filesystem.\n */\n configPath?: string;\n\n /**\n * id of the tester.\n */\n id: string;\n\n /**\n * on test run complete. (applies only during watch)\n * @param callback\n */\n onTestRunComplete?(callback: CallbackFn): Promise<void>;\n\n /**\n * execute tests on all components in the given execution context.\n */\n test(context: TesterContext): Promise<Tests>;\n\n /**\n * watch tests on all components\n */\n watch?(context: TesterContext): Promise<Tests>;\n /**\n * return the tester version.\n */\n version(): string;\n}\nexport type CallbackFn = (testSuite: Tests) => void;\n"],"mappings":";;;;;;;;;;;AAKO,MAAMA,KAAN,CAAY;EACjBC,WAAW,CAAQC,UAAR,EAAyC;IAAA,KAAjCA,UAAiC,GAAjCA,UAAiC;EAAE;;EAC5C,IAANC,MAAM,GAAY;IACpB,OAAO,KAAKD,UAAL,CAAgBE,GAAhB,CAAqBC,IAAD,IAAUA,IAAI,CAACF,MAAL,IAAe,EAA7C,EAAiDG,IAAjD,EAAP;EACD;;AAJgB"}
1
+ {"version":3,"names":["Tests","constructor","components","errors","map","comp","flat"],"sources":["tester.ts"],"sourcesContent":["import { Component, ComponentID, ComponentMap } from '@teambit/component';\nimport { ExecutionContext } from '@teambit/envs';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { TestsResult } from '@teambit/tests-results';\n\nexport class Tests {\n constructor(public components: ComponentsResults[]) {}\n get errors(): Error[] {\n return this.components.map((comp) => comp.errors || []).flat();\n }\n}\n\nexport type ComponentsResults = {\n /**\n * component id.\n */\n componentId: ComponentID;\n /**\n * test results for the component.\n */\n results?: TestsResult;\n /**\n * aggregated errors from all files\n */\n errors?: Error[];\n\n /**\n * loading.\n */\n loading?: boolean;\n};\n\nexport type SpecFiles = ComponentMap<AbstractVinyl[]>;\nexport type ComponentPatternsMap = ComponentMap<{ path: string; relative: string }[]>;\n\nexport interface TesterContext extends ExecutionContext {\n /**\n * whether the tester run for release (during bit build/tag) or not (during bit test command).\n */\n release: boolean;\n\n /**\n * list of components to test.\n */\n components: Component[];\n\n /**\n * component workspace.\n */\n // workspace: Workspace;\n\n /**\n * defines whether tester is expected to run in quiet mode.\n */\n quiet?: boolean;\n\n /**\n * list of spec files to test.\n */\n specFiles: SpecFiles;\n\n /**\n * rootPath of the component workspace or the capsule root dir (during build).\n */\n rootPath: string;\n\n /**\n * determines whether tester is expected to run in debug mode.\n */\n debug?: boolean;\n\n /**\n * is start from ui\n */\n ui?: boolean;\n\n /**\n * determines whether to start the tester in watch mode.\n */\n watch?: boolean;\n\n /**\n * whether the tester should show code coverage\n */\n coverage?: boolean;\n\n /**\n * array of patterns to test.\n */\n patterns: ComponentPatternsMap;\n\n /**\n *\n * additional test host dependencies\n * This can be used in cases when you want specific dependencies to be resolved from the env during testing\n * but you don't want these dependencies as peer dependencies of the component (as they are not used during runtime)\n * An example for this is @angular/compiler, which during running tests you want to resolve from the env, but you don't\n * need it during component runtime.\n */\n additionalHostDependencies?: string[];\n}\n\n/**\n * tester interface allows extensions to implement a component tester into bit.\n */\nexport interface Tester {\n /**\n * display name of the tester.\n */\n displayName?: string;\n\n /**\n * icon of the tester.\n */\n icon?: string;\n\n /**\n * serialized config of the tester.\n */\n displayConfig?(): string;\n\n /**\n * path to the config in the filesystem.\n */\n configPath?: string;\n\n /**\n * id of the tester.\n */\n id: string;\n\n /**\n * on test run complete. (applies only during watch)\n * @param callback\n */\n onTestRunComplete?(callback: CallbackFn): Promise<void>;\n\n /**\n * execute tests on all components in the given execution context.\n */\n test(context: TesterContext): Promise<Tests>;\n\n /**\n * watch tests on all components\n */\n watch?(context: TesterContext): Promise<Tests>;\n /**\n * return the tester version.\n */\n version(): string;\n}\nexport type CallbackFn = (testSuite: Tests) => void;\n"],"mappings":";;;;;;;;;;;AAKO,MAAMA,KAAN,CAAY;EACjBC,WAAW,CAAQC,UAAR,EAAyC;IAAA,KAAjCA,UAAiC,GAAjCA,UAAiC;EAAE;;EAC5C,IAANC,MAAM,GAAY;IACpB,OAAO,KAAKD,UAAL,CAAgBE,GAAhB,CAAqBC,IAAD,IAAUA,IAAI,CAACF,MAAL,IAAe,EAA7C,EAAiDG,IAAjD,EAAP;EACD;;AAJgB"}
@@ -181,6 +181,12 @@ class TesterService {
181
181
  }));
182
182
  });
183
183
 
184
+ let additionalHostDependencies = [];
185
+
186
+ if (context.env.getAdditionalTestHostDependencies && typeof context.env.getAdditionalTestHostDependencies === 'function') {
187
+ additionalHostDependencies = await context.env.getAdditionalTestHostDependencies();
188
+ }
189
+
184
190
  const testerContext = Object.assign(context, {
185
191
  release: false,
186
192
  specFiles,
@@ -190,7 +196,8 @@ class TesterService {
190
196
  debug: options.debug,
191
197
  watch: options.watch,
192
198
  ui: options.ui,
193
- coverage: options.coverage
199
+ coverage: options.coverage,
200
+ additionalHostDependencies
194
201
  });
195
202
 
196
203
  if (options.watch && options.ui && tester.watch) {
@@ -1 +1 @@
1
- {"version":3,"names":["chalk","require","OnTestsChanged","TesterService","constructor","workspace","patterns","logger","pubsub","devFiles","render","env","descriptor","getDescriptor","id","displayName","version","highlight","config","language","ignoreIllegals","environment","getTester","undefined","tester","icon","displayConfig","onTestRunComplete","callback","_callback","run","context","options","specFiles","ComponentMap","as","components","component","detectTestFiles","testCount","toArray","reduce","acc","specs","length","componentWithTests","ui","consoleWarning","cyan","Tests","console","dir","componentDir","componentPatterns","getDevPatterns","TesterAspect","map","pattern","path","resolve","relative","testerContext","Object","assign","release","rootPath","debug","watch","coverage","results","forEach","publish","testsChanged","componentId","toString","testsResults","loading","test"],"sources":["tester.service.tsx"],"sourcesContent":["import { Logger } from '@teambit/logger';\nimport { resolve } from 'path';\nimport React from 'react';\nimport { Text, Newline } from 'ink';\nimport { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';\nimport { ComponentMap } from '@teambit/component';\nimport { Workspace } from '@teambit/workspace';\nimport highlight from 'cli-highlight';\nimport { PubSubEngine } from 'graphql-subscriptions';\nimport { DevFilesMain } from '@teambit/dev-files';\nimport { Tester, Tests, CallbackFn } from './tester';\nimport { TesterAspect } from './tester.aspect';\nimport { TesterOptions } from './tester.main.runtime';\nimport { detectTestFiles } from './utils';\n\nconst chalk = require('chalk');\n\nexport const OnTestsChanged = 'OnTestsChanged';\n\nexport type TesterDescriptor = {\n /**\n * id of the tester (e.g. jest/mocha)\n */\n id: string;\n\n /**\n * display name of the tester (e.g. Jest / Mocha)\n */\n displayName: string;\n\n /**\n * icon of the configured tester.\n */\n icon: string;\n\n /**\n * string containing the config for display.\n */\n config: string;\n\n version?: string;\n};\n\nexport class TesterService implements EnvService<Tests, TesterDescriptor> {\n name = 'tester';\n\n constructor(\n readonly workspace: Workspace,\n /**\n * regex used to identify which files to test.\n */\n readonly patterns: string[],\n\n private logger: Logger,\n\n private pubsub: PubSubEngine,\n\n private devFiles: DevFilesMain\n ) {}\n\n _callback: CallbackFn | undefined;\n\n render(env: EnvDefinition) {\n const descriptor = this.getDescriptor(env);\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured tester: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text underline color=\"cyan\">\n tester config:\n </Text>\n <Newline />\n <Text>\n {/* refactor a separate component which highlights for cli */}\n {highlight(descriptor?.config || '', { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n getDescriptor(environment: EnvDefinition) {\n if (!environment.env.getTester) return undefined;\n const tester: Tester = environment.env.getTester();\n\n return {\n id: tester.id || '',\n displayName: tester.displayName || '',\n icon: tester.icon || '',\n config: tester.displayConfig ? tester.displayConfig() : '',\n version: tester.version ? tester.version() : '?',\n };\n }\n\n onTestRunComplete(callback: CallbackFn) {\n this._callback = callback;\n }\n\n async run(context: ExecutionContext, options: TesterOptions): Promise<Tests> {\n const tester: Tester = context.env.getTester();\n const specFiles = ComponentMap.as(context.components, (component) => {\n return detectTestFiles(component, this.devFiles);\n });\n const testCount = specFiles.toArray().reduce((acc, [, specs]) => acc + specs.length, 0);\n\n const componentWithTests = specFiles.toArray().reduce((acc: number, [, specs]) => {\n if (specs.length > 0) acc += 1;\n return acc;\n }, 0);\n\n if (testCount === 0 && !options.ui) {\n this.logger.consoleWarning(`no tests found for environment ${chalk.cyan(context.id)}\\n`);\n return new Tests([]);\n }\n\n if (!options.ui)\n this.logger.console(`testing ${componentWithTests} components with environment ${chalk.cyan(context.id)}\\n`);\n\n const patterns = ComponentMap.as(context.components, (component) => {\n const dir = this.workspace.componentDir(component.id);\n const componentPatterns = this.devFiles.getDevPatterns(component, TesterAspect.id);\n return componentPatterns.map((pattern: string) => ({ path: resolve(dir, pattern), relative: pattern }));\n });\n\n const testerContext = Object.assign(context, {\n release: false,\n specFiles,\n patterns,\n rootPath: this.workspace.path,\n workspace: this.workspace,\n debug: options.debug,\n watch: options.watch,\n ui: options.ui,\n coverage: options.coverage,\n });\n\n if (options.watch && options.ui && tester.watch) {\n if (tester.onTestRunComplete) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n tester.onTestRunComplete((results) => {\n if (this._callback) this._callback(results);\n results.components.forEach((component) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.pubsub.publish(OnTestsChanged, {\n testsChanged: {\n id: component.componentId.toString(),\n testsResults: component.results,\n loading: component.loading,\n },\n });\n });\n });\n }\n\n return tester.watch(testerContext);\n }\n\n const results = await tester.test(testerContext);\n\n return results;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AAEO,MAAMC,cAAc,GAAG,gBAAvB;;;AA0BA,MAAMC,aAAN,CAAmE;EAGxEC,WAAW,CACAC,SADA;EAET;AACJ;AACA;EACaC,QALA,EAODC,MAPC,EASDC,MATC,EAWDC,QAXC,EAYT;IAAA,KAXSJ,SAWT,GAXSA,SAWT;IAAA,KAPSC,QAOT,GAPSA,QAOT;IAAA,KALQC,MAKR,GALQA,MAKR;IAAA,KAHQC,MAGR,GAHQA,MAGR;IAAA,KADQC,QACR,GADQA,QACR;IAAA,8CAdK,QAcL;IAAA;EAAE;;EAIJC,MAAM,CAACC,GAAD,EAAqB;IACzB,MAAMC,UAAU,GAAG,KAAKC,aAAL,CAAmBF,GAAnB,CAAnB;IACA,oBACE,+BAAC,WAAD;MAAM,GAAG,EAAEC,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAEE;IAAvB,gBACE,+BAAC,WAAD;MAAM,KAAK,EAAC;IAAZ,yBADF,eAEE,+BAAC,WAAD,QACGF,UADH,aACGA,UADH,uBACGA,UAAU,CAAEE,EADf,QACqBF,UADrB,aACqBA,UADrB,uBACqBA,UAAU,CAAEG,WADjC,SACiDH,UADjD,aAC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,OAAO,GAAG,MAAM7C,MAAM,CAACqD,IAAP,CAAYhB,aAAZ,CAAtB;IAEA,OAAOQ,OAAP;EACD;;AAxHuE"}
1
+ {"version":3,"names":["chalk","require","OnTestsChanged","TesterService","constructor","workspace","patterns","logger","pubsub","devFiles","render","env","descriptor","getDescriptor","id","displayName","version","highlight","config","language","ignoreIllegals","environment","getTester","undefined","tester","icon","displayConfig","onTestRunComplete","callback","_callback","run","context","options","specFiles","ComponentMap","as","components","component","detectTestFiles","testCount","toArray","reduce","acc","specs","length","componentWithTests","ui","consoleWarning","cyan","Tests","console","dir","componentDir","componentPatterns","getDevPatterns","TesterAspect","map","pattern","path","resolve","relative","additionalHostDependencies","getAdditionalTestHostDependencies","testerContext","Object","assign","release","rootPath","debug","watch","coverage","results","forEach","publish","testsChanged","componentId","toString","testsResults","loading","test"],"sources":["tester.service.tsx"],"sourcesContent":["import { Logger } from '@teambit/logger';\nimport { resolve } from 'path';\nimport React from 'react';\nimport { Text, Newline } from 'ink';\nimport { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';\nimport { ComponentMap } from '@teambit/component';\nimport { Workspace } from '@teambit/workspace';\nimport highlight from 'cli-highlight';\nimport { PubSubEngine } from 'graphql-subscriptions';\nimport { DevFilesMain } from '@teambit/dev-files';\nimport { Tester, Tests, CallbackFn } from './tester';\nimport { TesterAspect } from './tester.aspect';\nimport { TesterOptions } from './tester.main.runtime';\nimport { detectTestFiles } from './utils';\n\nconst chalk = require('chalk');\n\nexport const OnTestsChanged = 'OnTestsChanged';\n\nexport type TesterDescriptor = {\n /**\n * id of the tester (e.g. jest/mocha)\n */\n id: string;\n\n /**\n * display name of the tester (e.g. Jest / Mocha)\n */\n displayName: string;\n\n /**\n * icon of the configured tester.\n */\n icon: string;\n\n /**\n * string containing the config for display.\n */\n config: string;\n\n version?: string;\n};\n\nexport class TesterService implements EnvService<Tests, TesterDescriptor> {\n name = 'tester';\n\n constructor(\n readonly workspace: Workspace,\n /**\n * regex used to identify which files to test.\n */\n readonly patterns: string[],\n\n private logger: Logger,\n\n private pubsub: PubSubEngine,\n\n private devFiles: DevFilesMain\n ) {}\n\n _callback: CallbackFn | undefined;\n\n render(env: EnvDefinition) {\n const descriptor = this.getDescriptor(env);\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured tester: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text underline color=\"cyan\">\n tester config:\n </Text>\n <Newline />\n <Text>\n {/* refactor a separate component which highlights for cli */}\n {highlight(descriptor?.config || '', { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n getDescriptor(environment: EnvDefinition) {\n if (!environment.env.getTester) return undefined;\n const tester: Tester = environment.env.getTester();\n\n return {\n id: tester.id || '',\n displayName: tester.displayName || '',\n icon: tester.icon || '',\n config: tester.displayConfig ? tester.displayConfig() : '',\n version: tester.version ? tester.version() : '?',\n };\n }\n\n onTestRunComplete(callback: CallbackFn) {\n this._callback = callback;\n }\n\n async run(context: ExecutionContext, options: TesterOptions): Promise<Tests> {\n const tester: Tester = context.env.getTester();\n const specFiles = ComponentMap.as(context.components, (component) => {\n return detectTestFiles(component, this.devFiles);\n });\n const testCount = specFiles.toArray().reduce((acc, [, specs]) => acc + specs.length, 0);\n\n const componentWithTests = specFiles.toArray().reduce((acc: number, [, specs]) => {\n if (specs.length > 0) acc += 1;\n return acc;\n }, 0);\n\n if (testCount === 0 && !options.ui) {\n this.logger.consoleWarning(`no tests found for environment ${chalk.cyan(context.id)}\\n`);\n return new Tests([]);\n }\n\n if (!options.ui)\n this.logger.console(`testing ${componentWithTests} components with environment ${chalk.cyan(context.id)}\\n`);\n\n const patterns = ComponentMap.as(context.components, (component) => {\n const dir = this.workspace.componentDir(component.id);\n const componentPatterns = this.devFiles.getDevPatterns(component, TesterAspect.id);\n return componentPatterns.map((pattern: string) => ({ path: resolve(dir, pattern), relative: pattern }));\n });\n\n let additionalHostDependencies = [];\n if (\n context.env.getAdditionalTestHostDependencies &&\n typeof context.env.getAdditionalTestHostDependencies === 'function'\n ) {\n additionalHostDependencies = await context.env.getAdditionalTestHostDependencies();\n }\n\n const testerContext = Object.assign(context, {\n release: false,\n specFiles,\n patterns,\n rootPath: this.workspace.path,\n workspace: this.workspace,\n debug: options.debug,\n watch: options.watch,\n ui: options.ui,\n coverage: options.coverage,\n additionalHostDependencies,\n });\n\n if (options.watch && options.ui && tester.watch) {\n if (tester.onTestRunComplete) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n tester.onTestRunComplete((results) => {\n if (this._callback) this._callback(results);\n results.components.forEach((component) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.pubsub.publish(OnTestsChanged, {\n testsChanged: {\n id: component.componentId.toString(),\n testsResults: component.results,\n loading: component.loading,\n },\n });\n });\n });\n }\n\n return tester.watch(testerContext);\n }\n\n const results = await tester.test(testerContext);\n\n return results;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AAEO,MAAMC,cAAc,GAAG,gBAAvB;;;AA0BA,MAAMC,aAAN,CAAmE;EAGxEC,WAAW,CACAC,SADA;EAET;AACJ;AACA;EACaC,QALA,EAODC,MAPC,EASDC,MATC,EAWDC,QAXC,EAYT;IAAA,KAXSJ,SA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;MAQ3CvB,EAAE,EAAEd,OAAO,CAACc,EAR+B;MAS3CwB,QAAQ,EAAEtC,OAAO,CAACsC,QATyB;MAU3CT;IAV2C,CAAvB,CAAtB;;IAaA,IAAI7B,OAAO,CAACqC,KAAR,IAAiBrC,OAAO,CAACc,EAAzB,IAA+BtB,MAAM,CAAC6C,KAA1C,EAAiD;MAC/C,IAAI7C,MAAM,CAACG,iBAAX,EAA8B;QAC5B;QACAH,MAAM,CAACG,iBAAP,CAA0B4C,OAAD,IAAa;UACpC,IAAI,KAAK1C,SAAT,EAAoB,KAAKA,SAAL,CAAe0C,OAAf;UACpBA,OAAO,CAACnC,UAAR,CAAmBoC,OAAnB,CAA4BnC,SAAD,IAAe;YACxC;YACA,KAAK7B,MAAL,CAAYiE,OAAZ,CAAoBvE,cAApB,EAAoC;cAClCwE,YAAY,EAAE;gBACZ5D,EAAE,EAAEuB,SAAS,CAACsC,WAAV,CAAsBC,QAAtB,EADQ;gBAEZC,YAAY,EAAExC,SAAS,CAACkC,OAFZ;gBAGZO,OAAO,EAAEzC,SAAS,CAACyC;cAHP;YADoB,CAApC;UAOD,CATD;QAUD,CAZD;MAaD;;MAED,OAAOtD,MAAM,CAAC6C,KAAP,CAAaN,aAAb,CAAP;IACD;;IAED,MAAMQ,OAAO,GAAG,MAAM/C,MAAM,CAACuD,IAAP,CAAYhB,aAAZ,CAAtB;IAEA,OAAOQ,OAAP;EACD;;AAjIuE"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/tester",
3
- "version": "0.0.802",
3
+ "version": "0.0.805",
4
4
  "homepage": "https://bit.dev/teambit/defender/tester",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.defender",
8
8
  "name": "tester",
9
- "version": "0.0.802"
9
+ "version": "0.0.805"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -25,19 +25,19 @@
25
25
  "@teambit/harmony": "0.3.3",
26
26
  "@teambit/design.ui.separator": "0.0.354",
27
27
  "@teambit/documenter.ui.heading": "4.1.1",
28
- "@teambit/cli": "0.0.534",
29
- "@teambit/logger": "0.0.627",
30
- "@teambit/workspace": "0.0.802",
31
- "@teambit/component": "0.0.802",
32
- "@teambit/defender.ui.test-compare": "0.0.42",
33
- "@teambit/graphql": "0.0.802",
34
- "@teambit/builder": "0.0.802",
35
- "@teambit/dev-files": "0.0.802",
36
- "@teambit/envs": "0.0.802",
28
+ "@teambit/cli": "0.0.536",
29
+ "@teambit/logger": "0.0.629",
30
+ "@teambit/workspace": "0.0.805",
31
+ "@teambit/component": "0.0.805",
32
+ "@teambit/defender.ui.test-compare": "0.0.44",
33
+ "@teambit/graphql": "0.0.805",
34
+ "@teambit/builder": "0.0.805",
35
+ "@teambit/dev-files": "0.0.805",
36
+ "@teambit/envs": "0.0.805",
37
37
  "@teambit/tests-results": "0.0.97",
38
- "@teambit/ui": "0.0.802",
39
- "@teambit/compiler": "0.0.802",
40
- "@teambit/component-compare": "0.0.50",
38
+ "@teambit/ui": "0.0.805",
39
+ "@teambit/compiler": "0.0.805",
40
+ "@teambit/component-compare": "0.0.53",
41
41
  "@teambit/bit-error": "0.0.394",
42
42
  "@teambit/defender.ui.test-loader": "0.0.490",
43
43
  "@teambit/defender.ui.test-table": "0.0.495",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@apollo/client": "^3.0.0",
64
- "@teambit/legacy": "1.0.316",
64
+ "@teambit/legacy": "1.0.319",
65
65
  "react-dom": "^16.8.0 || ^17.0.0",
66
66
  "react": "^16.8.0 || ^17.0.0"
67
67
  },
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_tester@0.0.802/dist/tester.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_tester@0.0.802/dist/tester.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_tester@0.0.805/dist/tester.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_tester@0.0.805/dist/tester.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -125,6 +125,14 @@ export class TesterService implements EnvService<Tests, TesterDescriptor> {
125
125
  return componentPatterns.map((pattern: string) => ({ path: resolve(dir, pattern), relative: pattern }));
126
126
  });
127
127
 
128
+ let additionalHostDependencies = [];
129
+ if (
130
+ context.env.getAdditionalTestHostDependencies &&
131
+ typeof context.env.getAdditionalTestHostDependencies === 'function'
132
+ ) {
133
+ additionalHostDependencies = await context.env.getAdditionalTestHostDependencies();
134
+ }
135
+
128
136
  const testerContext = Object.assign(context, {
129
137
  release: false,
130
138
  specFiles,
@@ -135,6 +143,7 @@ export class TesterService implements EnvService<Tests, TesterDescriptor> {
135
143
  watch: options.watch,
136
144
  ui: options.ui,
137
145
  coverage: options.coverage,
146
+ additionalHostDependencies,
138
147
  });
139
148
 
140
149
  if (options.watch && options.ui && tester.watch) {