@teambit/tester 0.0.663 → 0.0.666

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { TesterAspect } from './tester.aspect';
2
- export type { Tester, Tests, TesterContext, CallbackFn, SpecFiles, ComponentPatternsMap, ComponentsResults, } from './tester';
2
+ export { Tests } from './tester';
3
+ export type { Tester, TesterContext, CallbackFn, SpecFiles, ComponentPatternsMap, ComponentsResults } from './tester';
3
4
  export type { TesterMain } from './tester.main.runtime';
4
5
  export type { TesterUI } from './tester.ui.runtime';
5
6
  export { TesterAspect };
package/dist/index.js CHANGED
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "TesterAspect", {
9
9
  return _tester().TesterAspect;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "Tests", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _tester2().Tests;
16
+ }
17
+ });
12
18
  exports.default = void 0;
13
19
 
14
20
  function _tester() {
@@ -21,6 +27,16 @@ function _tester() {
21
27
  return data;
22
28
  }
23
29
 
30
+ function _tester2() {
31
+ const data = require("./tester");
32
+
33
+ _tester2 = function () {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
39
+
24
40
  var _default = _tester().TesterAspect;
25
41
 
26
42
  exports.default = _default;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["TesterAspect"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;eAeeA,sB","sourcesContent":["import { TesterAspect } from './tester.aspect';\n\nexport type {\n Tester,\n Tests,\n TesterContext,\n CallbackFn,\n SpecFiles,\n ComponentPatternsMap,\n ComponentsResults,\n} from './tester';\nexport type { TesterMain } from './tester.main.runtime';\nexport type { TesterUI } from './tester.ui.runtime';\n\nexport { TesterAspect };\nexport default TesterAspect;\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["TesterAspect"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;eAMeA,sB","sourcesContent":["import { TesterAspect } from './tester.aspect';\n\nexport { Tests } from './tester';\nexport type { Tester, TesterContext, CallbackFn, SpecFiles, ComponentPatternsMap, ComponentsResults } from './tester';\nexport type { TesterMain } from './tester.main.runtime';\nexport type { TesterUI } from './tester.ui.runtime';\n\nexport { TesterAspect };\nexport default TesterAspect;\n"]}
package/dist/tester.d.ts CHANGED
@@ -2,10 +2,11 @@ import { Component, ComponentID, ComponentMap } from '@teambit/component';
2
2
  import { ExecutionContext } from '@teambit/envs';
3
3
  import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
4
4
  import { TestsResult } from '@teambit/tests-results';
5
- export declare type Tests = {
5
+ export declare class Tests {
6
6
  components: ComponentsResults[];
7
- errors?: Error[];
8
- };
7
+ constructor(components: ComponentsResults[]);
8
+ get errors(): Error[];
9
+ }
9
10
  export declare type ComponentsResults = {
10
11
  /**
11
12
  * component id.
package/dist/tester.js CHANGED
@@ -1,3 +1,25 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.array.flat.js");
4
+
5
+ require("core-js/modules/es.array.unscopables.flat.js");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.Tests = void 0;
11
+
12
+ class Tests {
13
+ constructor(components) {
14
+ this.components = components;
15
+ }
16
+
17
+ get errors() {
18
+ return this.components.map(comp => comp.errors || []).flat();
19
+ }
20
+
21
+ }
22
+
23
+ exports.Tests = Tests;
24
+
3
25
  //# sourceMappingURL=tester.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
1
+ {"version":3,"sources":["tester.ts"],"names":["Tests","constructor","components","errors","map","comp","flat"],"mappings":";;;;;;;;;;;AAKO,MAAMA,KAAN,CAAY;AACjBC,EAAAA,WAAW,CAAQC,UAAR,EAAyC;AAAA,SAAjCA,UAAiC,GAAjCA,UAAiC;AAAE;;AAC5C,MAANC,MAAM,GAAY;AACpB,WAAO,KAAKD,UAAL,CAAgBE,GAAhB,CAAqBC,IAAD,IAAUA,IAAI,CAACF,MAAL,IAAe,EAA7C,EAAiDG,IAAjD,EAAP;AACD;;AAJgB","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"]}
@@ -72,7 +72,7 @@ function _cliHighlight() {
72
72
  }
73
73
 
74
74
  function _tester() {
75
- const data = require("./tester.aspect");
75
+ const data = require("./tester");
76
76
 
77
77
  _tester = function () {
78
78
  return data;
@@ -81,6 +81,16 @@ function _tester() {
81
81
  return data;
82
82
  }
83
83
 
84
+ function _tester2() {
85
+ const data = require("./tester.aspect");
86
+
87
+ _tester2 = function () {
88
+ return data;
89
+ };
90
+
91
+ return data;
92
+ }
93
+
84
94
  function _utils() {
85
95
  const data = require("./utils");
86
96
 
@@ -157,16 +167,14 @@ class TesterService {
157
167
 
158
168
  if (testCount === 0 && !options.ui) {
159
169
  this.logger.consoleWarning(`no tests found for environment ${chalk.cyan(context.id)}\n`);
160
- return {
161
- components: []
162
- };
170
+ return new (_tester().Tests)([]);
163
171
  }
164
172
 
165
173
  if (!options.ui) this.logger.console(`testing ${componentWithTests} components with environment ${chalk.cyan(context.id)}\n`);
166
174
 
167
175
  const patterns = _component().ComponentMap.as(context.components, component => {
168
176
  const dir = this.workspace.componentDir(component.id);
169
- const componentPatterns = this.devFiles.getDevPatterns(component, _tester().TesterAspect.id);
177
+ const componentPatterns = this.devFiles.getDevPatterns(component, _tester2().TesterAspect.id);
170
178
  return componentPatterns.map(pattern => ({
171
179
  path: (0, _path().resolve)(dir, pattern),
172
180
  relative: pattern
@@ -1 +1 @@
1
- {"version":3,"sources":["tester.service.tsx"],"names":["chalk","require","OnTestsChanged","TesterService","constructor","workspace","patterns","logger","pubsub","devFiles","render","env","descriptor","getDescriptor","id","displayName","version","config","language","ignoreIllegals","environment","getTester","undefined","tester","icon","displayConfig","onTestRunComplete","callback","_callback","run","context","options","specFiles","ComponentMap","as","components","component","testCount","toArray","reduce","acc","specs","length","componentWithTests","ui","consoleWarning","cyan","console","dir","componentDir","componentPatterns","getDevPatterns","TesterAspect","map","pattern","path","relative","testerContext","Object","assign","release","rootPath","debug","watch","coverage","results","forEach","publish","testsChanged","componentId","toString","testsResults","loading","test"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AAEO,MAAMC,cAAc,GAAG,gBAAvB;;;AA0BA,MAAMC,aAAN,CAAmE;AAGxEC,EAAAA,WAAW,CACAC,SADA;AAET;AACJ;AACA;AACaC,EAAAA,QALA,EAODC,MAPC,EASDC,MATC,EAWDC,QAXC,EAYT;AAAA,SAXSJ,SAWT,GAXSA,SAWT;AAAA,SAPSC,QAOT,GAPSA,QAOT;AAAA,SALQC,MAKR,GALQA,MAKR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SADQC,QACR,GADQA,QACR;AAAA,kDAdK,QAcL;AAAA;AAAE;;AAIJC,EAAAA,MAAM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BuC,OAAD,IAAa;AACpC,cAAI,KAAKrC,SAAT,EAAoB,KAAKA,SAAL,CAAeqC,OAAf;AACpBA,UAAAA,OAAO,CAAC9B,UAAR,CAAmB+B,OAAnB,CAA4B9B,SAAD,IAAe;AACxC;AACA,iBAAK5B,MAAL,CAAY2D,OAAZ,CAAoBjE,cAApB,EAAoC;AAClCkE,cAAAA,YAAY,EAAE;AACZtD,gBAAAA,EAAE,EAAEsB,SAAS,CAACiC,WAAV,CAAsBC,QAAtB,EADQ;AAEZC,gBAAAA,YAAY,EAAEnC,SAAS,CAAC6B,OAFZ;AAGZO,gBAAAA,OAAO,EAAEpC,SAAS,CAACoC;AAHP;AADoB,aAApC;AAOD,WATD;AAUD,SAZD;AAaD;;AAED,aAAOjD,MAAM,CAACwC,KAAP,CAAaN,aAAb,CAAP;AACD;;AAED,UAAMQ,OAAO,GAAG,MAAM1C,MAAM,CAACkD,IAAP,CAAYhB,aAAZ,CAAtB;AAEA,WAAOQ,OAAP;AACD;;AAxHuE","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 { components: [] };\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"]}
1
+ {"version":3,"sources":["tester.service.tsx"],"names":["chalk","require","OnTestsChanged","TesterService","constructor","workspace","patterns","logger","pubsub","devFiles","render","env","descriptor","getDescriptor","id","displayName","version","config","language","ignoreIllegals","environment","getTester","undefined","tester","icon","displayConfig","onTestRunComplete","callback","_callback","run","context","options","specFiles","ComponentMap","as","components","component","testCount","toArray","reduce","acc","specs","length","componentWithTests","ui","consoleWarning","cyan","Tests","console","dir","componentDir","componentPatterns","getDevPatterns","TesterAspect","map","pattern","path","relative","testerContext","Object","assign","release","rootPath","debug","watch","coverage","results","forEach","publish","testsChanged","componentId","toString","testsResults","loading","test"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AA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,MAAAA,QAH2C;AAI3CwD,MAAAA,QAAQ,EAAE,KAAKzD,SAAL,CAAemD,IAJkB;AAK3CnD,MAAAA,SAAS,EAAE,KAAKA,SAL2B;AAM3C0D,MAAAA,KAAK,EAAEhC,OAAO,CAACgC,KAN4B;AAO3CC,MAAAA,KAAK,EAAEjC,OAAO,CAACiC,KAP4B;AAQ3CpB,MAAAA,EAAE,EAAEb,OAAO,CAACa,EAR+B;AAS3CqB,MAAAA,QAAQ,EAAElC,OAAO,CAACkC;AATyB,KAAvB,CAAtB;;AAYA,QAAIlC,OAAO,CAACiC,KAAR,IAAiBjC,OAAO,CAACa,EAAzB,IAA+BrB,MAAM,CAACyC,KAA1C,EAAiD;AAC/C,UAAIzC,MAAM,CAACG,iBAAX,EAA8B;AAC5B;AACAH,QAAAA,MAAM,CAACG,iBAAP,CAA0BwC,OAAD,IAAa;AACpC,cAAI,KAAKtC,SAAT,EAAoB,KAAKA,SAAL,CAAesC,OAAf;AACpBA,UAAAA,OAAO,CAAC/B,UAAR,CAAmBgC,OAAnB,CAA4B/B,SAAD,IAAe;AACxC;AACA,iBAAK5B,MAAL,CAAY4D,OAAZ,CAAoBlE,cAApB,EAAoC;AAClCmE,cAAAA,YAAY,EAAE;AACZvD,gBAAAA,EAAE,EAAEsB,SAAS,CAACkC,WAAV,CAAsBC,QAAtB,EADQ;AAEZC,gBAAAA,YAAY,EAAEpC,SAAS,CAAC8B,OAFZ;AAGZO,gBAAAA,OAAO,EAAErC,SAAS,CAACqC;AAHP;AADoB,aAApC;AAOD,WATD;AAUD,SAZD;AAaD;;AAED,aAAOlD,MAAM,CAACyC,KAAP,CAAaN,aAAb,CAAP;AACD;;AAED,UAAMQ,OAAO,GAAG,MAAM3C,MAAM,CAACmD,IAAP,CAAYhB,aAAZ,CAAtB;AAEA,WAAOQ,OAAP;AACD;;AAxHuE","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"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/tester",
3
- "version": "0.0.663",
3
+ "version": "0.0.666",
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.663"
9
+ "version": "0.0.666"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -24,20 +24,20 @@
24
24
  "@babel/runtime": "7.12.18",
25
25
  "core-js": "^3.0.0",
26
26
  "@teambit/documenter.ui.heading": "4.1.1",
27
- "@teambit/cli": "0.0.449",
28
- "@teambit/logger": "0.0.539",
29
- "@teambit/workspace": "0.0.663",
30
- "@teambit/component": "0.0.663",
31
- "@teambit/graphql": "0.0.663",
32
- "@teambit/builder": "0.0.663",
33
- "@teambit/dev-files": "0.0.663",
34
- "@teambit/envs": "0.0.663",
35
- "@teambit/tests-results": "0.0.96",
36
- "@teambit/ui": "0.0.663",
37
- "@teambit/compiler": "0.0.663",
27
+ "@teambit/cli": "0.0.450",
28
+ "@teambit/logger": "0.0.540",
29
+ "@teambit/workspace": "0.0.666",
30
+ "@teambit/component": "0.0.666",
31
+ "@teambit/graphql": "0.0.666",
32
+ "@teambit/builder": "0.0.666",
33
+ "@teambit/dev-files": "0.0.666",
34
+ "@teambit/envs": "0.0.666",
35
+ "@teambit/tests-results": "0.0.97",
36
+ "@teambit/ui": "0.0.666",
37
+ "@teambit/compiler": "0.0.666",
38
38
  "@teambit/bit-error": "0.0.394",
39
39
  "@teambit/defender.ui.test-loader": "0.0.490",
40
- "@teambit/defender.ui.test-table": "0.0.494",
40
+ "@teambit/defender.ui.test-table": "0.0.495",
41
41
  "@teambit/design.ui.alert-card": "0.0.14",
42
42
  "@teambit/design.ui.empty-box": "0.0.353",
43
43
  "@teambit/design.ui.separator": "0.0.351",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@apollo/client": "^3.0.0",
60
- "@teambit/legacy": "1.0.228",
60
+ "@teambit/legacy": "1.0.229",
61
61
  "react-dom": "^16.8.0 || ^17.0.0",
62
62
  "react": "^16.8.0 || ^17.0.0"
63
63
  },
@@ -85,7 +85,7 @@
85
85
  "react": "-"
86
86
  },
87
87
  "peerDependencies": {
88
- "@teambit/legacy": "1.0.228",
88
+ "@teambit/legacy": "1.0.229",
89
89
  "react-dom": "^16.8.0 || ^17.0.0",
90
90
  "react": "^16.8.0 || ^17.0.0"
91
91
  }
@@ -113,7 +113,7 @@ export class TesterService implements EnvService<Tests, TesterDescriptor> {
113
113
 
114
114
  if (testCount === 0 && !options.ui) {
115
115
  this.logger.consoleWarning(`no tests found for environment ${chalk.cyan(context.id)}\n`);
116
- return { components: [] };
116
+ return new Tests([]);
117
117
  }
118
118
 
119
119
  if (!options.ui)