@teambit/jest 1.0.106 → 1.0.108

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.
@@ -0,0 +1,15 @@
1
+ import { compact } from 'lodash';
2
+ import { join, sep } from 'path';
3
+
4
+ export function getRootDirFromConfigPath(configPath: string): string {
5
+ const splitted = configPath.split('node_modules');
6
+ const last = splitted[splitted.length - 1];
7
+ const lastSplitted = compact(last.split(sep));
8
+ let lastModule = lastSplitted[0];
9
+ if (lastSplitted[0].startsWith('@')) {
10
+ lastModule = join(lastSplitted[0], lastSplitted[1]);
11
+ }
12
+ splitted[splitted.length - 1] = `${sep}${lastModule}`;
13
+ const final = splitted.join('node_modules');
14
+ return final;
15
+ }
package/dist/error.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare class JestError extends Error {
2
2
  readonly code?: unknown;
3
- readonly type?: string | undefined;
4
- constructor(message: string, stack?: string | null, code?: unknown, type?: string | undefined);
3
+ readonly type?: string;
4
+ constructor(message: string, stack?: string | null, code?: unknown, type?: string);
5
5
  get stack(): any;
6
6
  }
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -3,7 +3,7 @@ import { HarmonyWorker } from '@teambit/worker';
3
3
  import { Tester, CallbackFn, TesterContext, Tests } from '@teambit/tester';
4
4
  import { Component } from '@teambit/component';
5
5
  import type { JestWorker } from './jest.worker';
6
- export declare type JestTesterOptions = {
6
+ export type JestTesterOptions = {
7
7
  /**
8
8
  * array of patterns to test. (override the patterns provided by the context)
9
9
  */
@@ -32,7 +32,7 @@ export declare class JestTester implements Tester {
32
32
  displayName: string;
33
33
  _callback: CallbackFn | undefined;
34
34
  displayConfig(): string;
35
- version(): string;
35
+ version(): any;
36
36
  private attachTestsToComponent;
37
37
  private buildTestsObj;
38
38
  private getErrors;
@@ -121,7 +121,7 @@ class JestTester {
121
121
  buildTestsObj(aggregatedResult, components, testerContext, config) {
122
122
  const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {
123
123
  if (!testsFiles) return undefined;
124
- if ((testsFiles === null || testsFiles === void 0 ? void 0 : testsFiles.length) === 0) return undefined;
124
+ if (testsFiles?.length === 0) return undefined;
125
125
  const errors = this.getErrors(testsFiles);
126
126
  const tests = testsFiles.map(test => {
127
127
  const file = new (_sources().AbstractVinyl)({
@@ -135,9 +135,8 @@ class JestTester {
135
135
  const isFailure = testResult.status === 'failed';
136
136
  return new (_testsResults().TestResult)(testResult.ancestorTitles, testResult.title, testResult.status, testResult.duration, isFailure ? undefined : error, isFailure ? error : undefined);
137
137
  });
138
- const filePath = (file === null || file === void 0 ? void 0 : file.basename) || test.testFilePath;
138
+ const filePath = file?.basename || test.testFilePath;
139
139
  const getError = () => {
140
- var _test$testExecError, _test$testExecError2;
141
140
  if (!test.testExecError) return undefined;
142
141
  if (testerContext.watch) {
143
142
  // for some reason, during watch ('bit start'), if a file has an error, the `test.testExecError` is `{}`
@@ -145,7 +144,7 @@ class JestTester {
145
144
  // @todo: consider to always use the failureMessage, regardless the context.watch.
146
145
  return new (_error().JestError)(test.failureMessage);
147
146
  }
148
- return new (_error().JestError)((_test$testExecError = test.testExecError) === null || _test$testExecError === void 0 ? void 0 : _test$testExecError.message, (_test$testExecError2 = test.testExecError) === null || _test$testExecError2 === void 0 ? void 0 : _test$testExecError2.stack);
147
+ return new (_error().JestError)(test.testExecError?.message, test.testExecError?.stack);
149
148
  };
150
149
  const error = getError();
151
150
  return new (_testsResults().TestsFiles)(filePath, testResults, test.numPassingTests, test.numFailingTests, test.numPendingTests, test.perfStats.runtime, test.perfStats.slow, error);
@@ -238,7 +237,6 @@ class JestTester {
238
237
  async watch(context) {
239
238
  // eslint-disable-next-line
240
239
  return new Promise(async resolve => {
241
- var _context$envRuntime$e;
242
240
  const workerApi = this.jestWorker.initiate(context.ui ? {
243
241
  stdout: true,
244
242
  stderr: true,
@@ -251,7 +249,7 @@ class JestTester {
251
249
 
252
250
  // eslint-disable-next-line
253
251
  const jestConfig = require(this.jestConfig);
254
- const envRootDir = (_context$envRuntime$e = context.envRuntime.envAspectDefinition) === null || _context$envRuntime$e === void 0 ? void 0 : _context$envRuntime$e.aspectPath;
252
+ const envRootDir = context.envRuntime.envAspectDefinition?.aspectPath;
255
253
  if (!envRootDir) {
256
254
  this.logger.warn(`jest tester, envRootDir is not defined, for env ${context.envRuntime.id}`);
257
255
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_path","data","require","_fsExtra","_minimatch","_interopRequireDefault","_lodash","_comlink","_tester","_testsResults","_jestMessageUtil","_component","_sources","_error","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JestTester","constructor","id","jestConfig","jestModulePath","jestWorker","logger","opts","jestModule","displayConfig","readFileSync","version","getVersion","attachTestsToComponent","testerContext","testResult","ComponentMap","as","components","component","componentPatternValue","patterns","get","undefined","currComponent","patternEntry","resolvedPatterns","resolveComponentPattern","filter","test","resolvedPattern","minimatch","testFilePath","length","buildTestsObj","aggregatedResult","config","testsSuiteResult","toArray","map","testsFiles","errors","getErrors","tests","file","AbstractVinyl","path","contents","testResults","error","formatResultsErrors","noStackTrace","isFailure","status","TestResult","ancestorTitles","title","duration","filePath","basename","getError","_test$testExecError","_test$testExecError2","testExecError","watch","JestError","failureMessage","message","stack","TestsFiles","numPassingTests","numFailingTests","numPendingTests","perfStats","runtime","slow","componentId","results","TestsResult","success","startTime","compact","reduce","code","type","push","onTestRunComplete","callback","_callback","context","rootDir","rootPath","roots","console","warn","debug","runInBand","coverage","watchAll","noCache","jestConfigWithSpecs","assign","testMatch","patternsToArray","withEnv","testsOutPut","runCLI","componentsWithTests","componentTestResults","Tests","Promise","resolve","_context$envRuntime$e","workerApi","initiate","ui","stdout","stderr","stdin","envRootDir","envRuntime","envAspectDefinition","aspectPath","cbFn","proxy","globalErrors","watchTestResults","loading","onTestComplete","err","flatten","resolveSpecPaths","customPatterns","isEmpty","customPattern","rootDirs","componentDir","resolvePattern","paths","p","pattern","dir","exports"],"sources":["jest.tester.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { readFileSync } from 'fs-extra';\nimport minimatch from 'minimatch';\nimport { compact, flatten, isEmpty } from 'lodash';\nimport { proxy } from 'comlink';\nimport { Logger } from '@teambit/logger';\nimport { HarmonyWorker } from '@teambit/worker';\nimport { Tester, CallbackFn, TesterContext, Tests, ComponentsResults, ComponentPatternsEntry } from '@teambit/tester';\nimport { TestsFiles, TestResult, TestsResult } from '@teambit/tests-results';\nimport { TestResult as JestTestResult, AggregatedResult } from '@jest/test-result';\nimport { formatResultsErrors } from 'jest-message-util';\nimport { Component, ComponentMap } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\n// import { Environment } from '@teambit/envs';\n// import { EnvPolicyConfigObject, PeersAutoDetectPolicy } from '@teambit/dependency-resolver';\nimport type jest from 'jest';\nimport { JestError } from './error';\nimport type { JestWorker } from './jest.worker';\n\nexport type JestTesterOptions = {\n /**\n * array of patterns to test. (override the patterns provided by the context)\n */\n patterns?: string[];\n\n /**\n * add more root paths to look for tests.\n */\n roots?: string[];\n\n /**\n * A function that knows to resolve the paths of the spec files.\n * This usually used when you want only subset of your spec files to be used\n * (usually when you use multi tester with different specs files for each tester instance).\n */\n resolveSpecPaths?: (component: Component, context: TesterContext) => string[];\n};\n\nexport class JestTester implements Tester {\n private readonly jestModule: typeof jest;\n\n constructor(\n readonly id: string,\n readonly jestConfig: any,\n private jestModulePath: string,\n private jestWorker: HarmonyWorker<JestWorker>,\n private logger: Logger,\n private opts: JestTesterOptions = {}\n ) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n this.jestModule = require(jestModulePath);\n }\n\n configPath = this.jestConfig;\n\n displayName = 'Jest';\n\n _callback: CallbackFn | undefined;\n\n displayConfig() {\n return readFileSync(this.jestConfig, 'utf8');\n }\n\n version() {\n return this.jestModule.getVersion();\n }\n\n private attachTestsToComponent(testerContext: TesterContext, testResult: JestTestResult[]) {\n return ComponentMap.as(testerContext.components, (component) => {\n const componentPatternValue = testerContext.patterns.get(component);\n if (!componentPatternValue) return undefined;\n const [currComponent, patternEntry] = componentPatternValue;\n const resolvedPatterns = this.resolveComponentPattern(currComponent, patternEntry, testerContext);\n return testResult.filter((test) => {\n return resolvedPatterns.filter((resolvedPattern) => minimatch(test.testFilePath, resolvedPattern)).length > 0;\n });\n });\n }\n\n private buildTestsObj(\n aggregatedResult: AggregatedResult,\n components: ComponentMap<JestTestResult[] | undefined>,\n testerContext: TesterContext,\n config?: any\n ): ComponentsResults[] {\n const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {\n if (!testsFiles) return undefined;\n if (testsFiles?.length === 0) return undefined;\n const errors = this.getErrors(testsFiles);\n const tests = testsFiles.map((test) => {\n const file = new AbstractVinyl({ path: test.testFilePath, contents: readFileSync(test.testFilePath) });\n const testResults = test.testResults.map((testResult) => {\n const error = formatResultsErrors([testResult], config, { noStackTrace: true }) || undefined;\n const isFailure = testResult.status === 'failed';\n return new TestResult(\n testResult.ancestorTitles,\n testResult.title,\n testResult.status,\n testResult.duration,\n isFailure ? undefined : error,\n isFailure ? error : undefined\n );\n });\n const filePath = file?.basename || test.testFilePath;\n const getError = () => {\n if (!test.testExecError) return undefined;\n if (testerContext.watch) {\n // for some reason, during watch ('bit start'), if a file has an error, the `test.testExecError` is `{}`\n // (an empty object). the failureMessage contains the stringified error.\n // @todo: consider to always use the failureMessage, regardless the context.watch.\n return new JestError(test.failureMessage as string);\n }\n return new JestError(test.testExecError?.message, test.testExecError?.stack);\n };\n const error = getError();\n return new TestsFiles(\n filePath,\n testResults,\n test.numPassingTests,\n test.numFailingTests,\n test.numPendingTests,\n test.perfStats.runtime,\n test.perfStats.slow,\n error\n );\n });\n return {\n componentId: component.id,\n results: new TestsResult(tests, aggregatedResult.success, aggregatedResult.startTime),\n errors,\n };\n });\n\n return compact(testsSuiteResult);\n }\n\n private getErrors(testResult: JestTestResult[]): JestError[] {\n return testResult.reduce((errors: JestError[], test) => {\n if (test.testExecError) {\n const { message, stack, code, type } = test.testExecError;\n errors.push(new JestError(message, stack, code, type));\n } else if (test.failureMessage) {\n errors.push(new JestError(test.failureMessage));\n }\n return errors;\n }, []);\n }\n\n async onTestRunComplete(callback: CallbackFn) {\n this._callback = callback;\n }\n\n async test(context: TesterContext): Promise<Tests> {\n // const envRootDir = context.envRuntime.envAspectDefinition.aspectPath;\n\n const config: any = {\n // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins\n // from the env context\n // rootDir: envRootDir,\n // TODO: set it to envRootDir and make sure we can make the --coverage to work\n // with the current value as context.rootPath it will probably won't work correctly when using rootComponents:true (maybe even won't work at all)\n // TODO: when changing to envRootDir we have some issues with the react-native tests. so once changed again, it needs to be validated.\n rootDir: context.rootPath,\n // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)\n // TODO: consider change this to be an array of the components running dir.\n // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>\n // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)\n // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains \"node_modules\"\n // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)\n // TODO: didn't help)\n roots: [context.rootPath],\n };\n\n // eslint-disable-next-line no-console\n console.warn = (message: string) => {\n this.logger.warn(message);\n };\n\n if (context.debug) {\n config.debug = true;\n config.runInBand = true;\n }\n if (context.coverage) config.coverage = true;\n config.runInBand = true;\n\n if (context.watch) {\n config.watchAll = true;\n config.noCache = true;\n }\n // eslint-disable-next-line global-require,import/no-dynamic-require\n const jestConfig = require(this.jestConfig);\n\n // TODO: rollback this for now, as it makes issues.\n // TODO: it's mostly relevant for when the root components feature is enabled.\n // TODO: we might want to enable it only on that case (along with setting the env root dir as the root dir, above)\n // const moduleNameMapper = await this.calculateModuleNameMapper(\n // context.env,\n // context.rootPath,\n // context.additionalHostDependencies\n // );\n // jestConfig.moduleNameMapper = Object.assign({}, jestConfig.moduleNameMapper || {}, moduleNameMapper);\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context),\n });\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\n\n const testsOutPut = await this.jestModule.runCLI(withEnv, [this.jestConfig]);\n const testResults = testsOutPut.results.testResults;\n const componentsWithTests = this.attachTestsToComponent(context, testResults);\n const componentTestResults = this.buildTestsObj(\n testsOutPut.results,\n componentsWithTests,\n context,\n jestConfigWithSpecs\n );\n return new Tests(componentTestResults);\n }\n\n async watch(context: TesterContext): Promise<Tests> {\n // eslint-disable-next-line\n return new Promise(async (resolve) => {\n const workerApi = this.jestWorker.initiate(\n context.ui ? { stdout: true, stderr: true, stdin: true } : { stdout: false, stderr: false, stdin: false }\n );\n\n // eslint-disable-next-line\n const jestConfig = require(this.jestConfig);\n\n const envRootDir = context.envRuntime.envAspectDefinition?.aspectPath;\n if (!envRootDir) {\n this.logger.warn(`jest tester, envRootDir is not defined, for env ${context.envRuntime.id}`);\n }\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context),\n });\n\n try {\n const cbFn = proxy((results) => {\n if (!this._callback) return;\n const testResults = results.testResults;\n const componentsWithTests = this.attachTestsToComponent(context, testResults);\n const componentTestResults = this.buildTestsObj(results, componentsWithTests, context, jestConfigWithSpecs);\n const globalErrors = this.getErrors(testResults);\n const watchTestResults = {\n loading: false,\n errors: globalErrors,\n components: componentTestResults,\n };\n this._callback(watchTestResults);\n resolve(watchTestResults);\n });\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n await workerApi.onTestComplete(cbFn);\n\n await workerApi.watch(\n this.jestConfig,\n this.patternsToArray(context),\n context.rootPath,\n this.jestModulePath,\n envRootDir\n );\n } catch (err: any) {\n this.logger.error('jest.tester.watch() caught an error', err);\n }\n });\n }\n\n // private async calculateModuleNameMapper(\n // env: Environment,\n // rootPath: string,\n // additionalHostDependencies?: string[]\n // ): Promise<Record<string, Array<string>>> {\n // const peerDepsConfig: EnvPolicyConfigObject = await env.getDependencies();\n // const peersAutoDetectPolicy = new PeersAutoDetectPolicy(peerDepsConfig.peers || []);\n // const peers = Object.keys(peerDepsConfig.peerDependencies || {}).concat(peersAutoDetectPolicy?.names);\n // const depsToMap = peers.concat(additionalHostDependencies || []);\n\n // /**\n // * Try to resolve the dependency from the rootDir (the env dir) or from the root path (workspace/capsule root)\n // */\n // const mappedValues = ['<rootDir>/node_modules/$1', `${rootPath}/node_modules/$1`];\n\n // const moduleNameMapper = depsToMap.reduce((acc, peerName) => {\n // const keyName = `^(${peerName})$`;\n // acc[keyName] = mappedValues;\n // const internalPathKeyName = `^(${peerName}/.*)$`;\n // acc[internalPathKeyName] = mappedValues;\n // return acc;\n // }, {});\n\n // return moduleNameMapper;\n // }\n\n private patternsToArray(context: TesterContext): string[] {\n return flatten(\n context.patterns.toArray().map(([component, patternEntry]) => {\n return this.resolveComponentPattern(component, patternEntry, context);\n })\n );\n }\n\n private resolveComponentPattern(\n component: Component,\n patternEntry: ComponentPatternsEntry,\n context: TesterContext\n ): string[] {\n if (this.opts.resolveSpecPaths) {\n return this.opts.resolveSpecPaths(component, context);\n }\n const customPatterns = this.opts.patterns;\n // If pattern were provided to the specific instance of the tester, use them\n if (customPatterns && !isEmpty(customPatterns)) {\n customPatterns.map((customPattern) => {\n const rootDirs = this.opts.roots || [patternEntry.componentDir];\n return this.resolvePattern(customPattern, rootDirs);\n });\n }\n return patternEntry.paths.map((p) => p.path);\n }\n\n private resolvePattern(pattern: string, rootDirs: string[]) {\n return rootDirs.map((dir) => resolve(dir, pattern));\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAA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,QAAQ,CAAChG,GAAG,CAAEsG,GAAG,IAAK,IAAA9B,eAAO,EAAC8B,GAAG,EAAED,OAAO,CAAC,CAAC;EACrD;AACF;AAACE,OAAA,CAAA9I,UAAA,GAAAA,UAAA"}
1
+ {"version":3,"names":["_path","data","require","_fsExtra","_minimatch","_interopRequireDefault","_lodash","_comlink","_tester","_testsResults","_jestMessageUtil","_component","_sources","_error","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JestTester","constructor","id","jestConfig","jestModulePath","jestWorker","logger","opts","jestModule","displayConfig","readFileSync","version","getVersion","attachTestsToComponent","testerContext","testResult","ComponentMap","as","components","component","componentPatternValue","patterns","get","undefined","currComponent","patternEntry","resolvedPatterns","resolveComponentPattern","filter","test","resolvedPattern","minimatch","testFilePath","length","buildTestsObj","aggregatedResult","config","testsSuiteResult","toArray","map","testsFiles","errors","getErrors","tests","file","AbstractVinyl","path","contents","testResults","error","formatResultsErrors","noStackTrace","isFailure","status","TestResult","ancestorTitles","title","duration","filePath","basename","getError","testExecError","watch","JestError","failureMessage","message","stack","TestsFiles","numPassingTests","numFailingTests","numPendingTests","perfStats","runtime","slow","componentId","results","TestsResult","success","startTime","compact","reduce","code","type","push","onTestRunComplete","callback","_callback","context","rootDir","rootPath","roots","console","warn","debug","runInBand","coverage","watchAll","noCache","jestConfigWithSpecs","assign","testMatch","patternsToArray","withEnv","testsOutPut","runCLI","componentsWithTests","componentTestResults","Tests","Promise","resolve","workerApi","initiate","ui","stdout","stderr","stdin","envRootDir","envRuntime","envAspectDefinition","aspectPath","cbFn","proxy","globalErrors","watchTestResults","loading","onTestComplete","err","flatten","resolveSpecPaths","customPatterns","isEmpty","customPattern","rootDirs","componentDir","resolvePattern","paths","p","pattern","dir","exports"],"sources":["jest.tester.ts"],"sourcesContent":["import { resolve } from 'path';\nimport { readFileSync } from 'fs-extra';\nimport minimatch from 'minimatch';\nimport { compact, flatten, isEmpty } from 'lodash';\nimport { proxy } from 'comlink';\nimport { Logger } from '@teambit/logger';\nimport { HarmonyWorker } from '@teambit/worker';\nimport { Tester, CallbackFn, TesterContext, Tests, ComponentsResults, ComponentPatternsEntry } from '@teambit/tester';\nimport { TestsFiles, TestResult, TestsResult } from '@teambit/tests-results';\nimport { TestResult as JestTestResult, AggregatedResult } from '@jest/test-result';\nimport { formatResultsErrors } from 'jest-message-util';\nimport { Component, ComponentMap } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\n// import { Environment } from '@teambit/envs';\n// import { EnvPolicyConfigObject, PeersAutoDetectPolicy } from '@teambit/dependency-resolver';\nimport { JestError } from './error';\nimport type { JestWorker } from './jest.worker';\n\nexport type JestTesterOptions = {\n /**\n * array of patterns to test. (override the patterns provided by the context)\n */\n patterns?: string[];\n\n /**\n * add more root paths to look for tests.\n */\n roots?: string[];\n\n /**\n * A function that knows to resolve the paths of the spec files.\n * This usually used when you want only subset of your spec files to be used\n * (usually when you use multi tester with different specs files for each tester instance).\n */\n resolveSpecPaths?: (component: Component, context: TesterContext) => string[];\n};\n\nexport class JestTester implements Tester {\n private readonly jestModule: any;\n\n constructor(\n readonly id: string,\n readonly jestConfig: any,\n private jestModulePath: string,\n private jestWorker: HarmonyWorker<JestWorker>,\n private logger: Logger,\n private opts: JestTesterOptions = {}\n ) {\n // eslint-disable-next-line global-require,import/no-dynamic-require\n this.jestModule = require(jestModulePath);\n }\n\n configPath = this.jestConfig;\n\n displayName = 'Jest';\n\n _callback: CallbackFn | undefined;\n\n displayConfig() {\n return readFileSync(this.jestConfig, 'utf8');\n }\n\n version() {\n return this.jestModule.getVersion();\n }\n\n private attachTestsToComponent(testerContext: TesterContext, testResult: JestTestResult[]) {\n return ComponentMap.as(testerContext.components, (component) => {\n const componentPatternValue = testerContext.patterns.get(component);\n if (!componentPatternValue) return undefined;\n const [currComponent, patternEntry] = componentPatternValue;\n const resolvedPatterns = this.resolveComponentPattern(currComponent, patternEntry, testerContext);\n return testResult.filter((test) => {\n return resolvedPatterns.filter((resolvedPattern) => minimatch(test.testFilePath, resolvedPattern)).length > 0;\n });\n });\n }\n\n private buildTestsObj(\n aggregatedResult: AggregatedResult,\n components: ComponentMap<JestTestResult[] | undefined>,\n testerContext: TesterContext,\n config?: any\n ): ComponentsResults[] {\n const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {\n if (!testsFiles) return undefined;\n if (testsFiles?.length === 0) return undefined;\n const errors = this.getErrors(testsFiles);\n const tests = testsFiles.map((test) => {\n const file = new AbstractVinyl({ path: test.testFilePath, contents: readFileSync(test.testFilePath) });\n const testResults = test.testResults.map((testResult) => {\n const error = formatResultsErrors([testResult], config, { noStackTrace: true }) || undefined;\n const isFailure = testResult.status === 'failed';\n return new TestResult(\n testResult.ancestorTitles,\n testResult.title,\n testResult.status,\n testResult.duration,\n isFailure ? undefined : error,\n isFailure ? error : undefined\n );\n });\n const filePath = file?.basename || test.testFilePath;\n const getError = () => {\n if (!test.testExecError) return undefined;\n if (testerContext.watch) {\n // for some reason, during watch ('bit start'), if a file has an error, the `test.testExecError` is `{}`\n // (an empty object). the failureMessage contains the stringified error.\n // @todo: consider to always use the failureMessage, regardless the context.watch.\n return new JestError(test.failureMessage as string);\n }\n return new JestError(test.testExecError?.message, test.testExecError?.stack);\n };\n const error = getError();\n return new TestsFiles(\n filePath,\n testResults,\n test.numPassingTests,\n test.numFailingTests,\n test.numPendingTests,\n test.perfStats.runtime,\n test.perfStats.slow,\n error\n );\n });\n return {\n componentId: component.id,\n results: new TestsResult(tests, aggregatedResult.success, aggregatedResult.startTime),\n errors,\n };\n });\n\n return compact(testsSuiteResult);\n }\n\n private getErrors(testResult: JestTestResult[]): JestError[] {\n return testResult.reduce((errors: JestError[], test) => {\n if (test.testExecError) {\n const { message, stack, code, type } = test.testExecError;\n errors.push(new JestError(message, stack, code, type));\n } else if (test.failureMessage) {\n errors.push(new JestError(test.failureMessage));\n }\n return errors;\n }, []);\n }\n\n async onTestRunComplete(callback: CallbackFn) {\n this._callback = callback;\n }\n\n async test(context: TesterContext): Promise<Tests> {\n // const envRootDir = context.envRuntime.envAspectDefinition.aspectPath;\n\n const config: any = {\n // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins\n // from the env context\n // rootDir: envRootDir,\n // TODO: set it to envRootDir and make sure we can make the --coverage to work\n // with the current value as context.rootPath it will probably won't work correctly when using rootComponents:true (maybe even won't work at all)\n // TODO: when changing to envRootDir we have some issues with the react-native tests. so once changed again, it needs to be validated.\n rootDir: context.rootPath,\n // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)\n // TODO: consider change this to be an array of the components running dir.\n // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>\n // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)\n // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains \"node_modules\"\n // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)\n // TODO: didn't help)\n roots: [context.rootPath],\n };\n\n // eslint-disable-next-line no-console\n console.warn = (message: string) => {\n this.logger.warn(message);\n };\n\n if (context.debug) {\n config.debug = true;\n config.runInBand = true;\n }\n if (context.coverage) config.coverage = true;\n config.runInBand = true;\n\n if (context.watch) {\n config.watchAll = true;\n config.noCache = true;\n }\n // eslint-disable-next-line global-require,import/no-dynamic-require\n const jestConfig = require(this.jestConfig);\n\n // TODO: rollback this for now, as it makes issues.\n // TODO: it's mostly relevant for when the root components feature is enabled.\n // TODO: we might want to enable it only on that case (along with setting the env root dir as the root dir, above)\n // const moduleNameMapper = await this.calculateModuleNameMapper(\n // context.env,\n // context.rootPath,\n // context.additionalHostDependencies\n // );\n // jestConfig.moduleNameMapper = Object.assign({}, jestConfig.moduleNameMapper || {}, moduleNameMapper);\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context),\n });\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\n\n const testsOutPut = await this.jestModule.runCLI(withEnv, [this.jestConfig]);\n const testResults = testsOutPut.results.testResults;\n const componentsWithTests = this.attachTestsToComponent(context, testResults);\n const componentTestResults = this.buildTestsObj(\n testsOutPut.results,\n componentsWithTests,\n context,\n jestConfigWithSpecs\n );\n return new Tests(componentTestResults);\n }\n\n async watch(context: TesterContext): Promise<Tests> {\n // eslint-disable-next-line\n return new Promise(async (resolve) => {\n const workerApi = this.jestWorker.initiate(\n context.ui ? { stdout: true, stderr: true, stdin: true } : { stdout: false, stderr: false, stdin: false }\n );\n\n // eslint-disable-next-line\n const jestConfig = require(this.jestConfig);\n\n const envRootDir = context.envRuntime.envAspectDefinition?.aspectPath;\n if (!envRootDir) {\n this.logger.warn(`jest tester, envRootDir is not defined, for env ${context.envRuntime.id}`);\n }\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context),\n });\n\n try {\n const cbFn = proxy((results) => {\n if (!this._callback) return;\n const testResults = results.testResults;\n const componentsWithTests = this.attachTestsToComponent(context, testResults);\n const componentTestResults = this.buildTestsObj(results, componentsWithTests, context, jestConfigWithSpecs);\n const globalErrors = this.getErrors(testResults);\n const watchTestResults = {\n loading: false,\n errors: globalErrors,\n components: componentTestResults,\n };\n this._callback(watchTestResults);\n resolve(watchTestResults);\n });\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n await workerApi.onTestComplete(cbFn);\n\n await workerApi.watch(\n this.jestConfig,\n this.patternsToArray(context),\n context.rootPath,\n this.jestModulePath,\n envRootDir\n );\n } catch (err: any) {\n this.logger.error('jest.tester.watch() caught an error', err);\n }\n });\n }\n\n // private async calculateModuleNameMapper(\n // env: Environment,\n // rootPath: string,\n // additionalHostDependencies?: string[]\n // ): Promise<Record<string, Array<string>>> {\n // const peerDepsConfig: EnvPolicyConfigObject = await env.getDependencies();\n // const peersAutoDetectPolicy = new PeersAutoDetectPolicy(peerDepsConfig.peers || []);\n // const peers = Object.keys(peerDepsConfig.peerDependencies || {}).concat(peersAutoDetectPolicy?.names);\n // const depsToMap = peers.concat(additionalHostDependencies || []);\n\n // /**\n // * Try to resolve the dependency from the rootDir (the env dir) or from the root path (workspace/capsule root)\n // */\n // const mappedValues = ['<rootDir>/node_modules/$1', `${rootPath}/node_modules/$1`];\n\n // const moduleNameMapper = depsToMap.reduce((acc, peerName) => {\n // const keyName = `^(${peerName})$`;\n // acc[keyName] = mappedValues;\n // const internalPathKeyName = `^(${peerName}/.*)$`;\n // acc[internalPathKeyName] = mappedValues;\n // return acc;\n // }, {});\n\n // return moduleNameMapper;\n // }\n\n private patternsToArray(context: TesterContext): string[] {\n return flatten(\n context.patterns.toArray().map(([component, patternEntry]) => {\n return this.resolveComponentPattern(component, patternEntry, context);\n })\n );\n }\n\n private resolveComponentPattern(\n component: Component,\n patternEntry: ComponentPatternsEntry,\n context: TesterContext\n ): string[] {\n if (this.opts.resolveSpecPaths) {\n return this.opts.resolveSpecPaths(component, context);\n }\n const customPatterns = this.opts.patterns;\n // If pattern were provided to the specific instance of the tester, use them\n if (customPatterns && !isEmpty(customPatterns)) {\n customPatterns.map((customPattern) => {\n const rootDirs = this.opts.roots || [patternEntry.componentDir];\n return this.resolvePattern(customPattern, rootDirs);\n });\n }\n return patternEntry.paths.map((p) => p.path);\n }\n\n private resolvePattern(pattern: string, rootDirs: string[]) {\n return rootDirs.map((dir) => resolve(dir, pattern));\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,WAAA;E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uBAAuBA,CAC7BR,SAAoB,EACpBM,YAAoC,EACpC8D,OAAsB,EACZ;IACV,IAAI,IAAI,CAAChF,IAAI,CAACyH,gBAAgB,EAAE;MAC9B,OAAO,IAAI,CAACzH,IAAI,CAACyH,gBAAgB,CAAC7G,SAAS,EAAEoE,OAAO,CAAC;IACvD;IACA,MAAM0C,cAAc,GAAG,IAAI,CAAC1H,IAAI,CAACc,QAAQ;IACzC;IACA,IAAI4G,cAAc,IAAI,CAAC,IAAAC,iBAAO,EAACD,cAAc,CAAC,EAAE;MAC9CA,cAAc,CAAC1F,GAAG,CAAE4F,aAAa,IAAK;QACpC,MAAMC,QAAQ,GAAG,IAAI,CAAC7H,IAAI,CAACmF,KAAK,IAAI,CAACjE,YAAY,CAAC4G,YAAY,CAAC;QAC/D,OAAO,IAAI,CAACC,cAAc,CAACH,aAAa,EAAEC,QAAQ,CAAC;MACrD,CAAC,CAAC;IACJ;IACA,OAAO3G,YAAY,CAAC8G,KAAK,CAAChG,GAAG,CAAEiG,CAAC,IAAKA,CAAC,CAAC1F,IAAI,CAAC;EAC9C;EAEQwF,cAAcA,CAACG,OAAe,EAAEL,QAAkB,EAAE;IAC1D,OAAOA,QAAQ,CAAC7F,GAAG,CAAEmG,GAAG,IAAK,IAAA7B,eAAO,EAAC6B,GAAG,EAAED,OAAO,CAAC,CAAC;EACrD;AACF;AAACE,OAAA,CAAA3I,UAAA,GAAAA,UAAA"}
@@ -1 +1 @@
1
- {"version":3,"names":["_flatted","data","require","_worker","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JestWorker","constructor","onTestComplete","onTestCompleteCb","watch","jestConfigPath","testFiles","rootPath","jestModulePath","envRootDir","Promise","resolve","console","warn","jestConfig","jestModule","jestConfigWithSpecs","assign","testMatch","config","rootDir","roots","runInBand","silent","watchAll","watchPlugins","__dirname","specFiles","onComplete","results","json","parse","stringify","error","withEnv","res","runCLI","catch","err","exports","expose"],"sources":["jest.worker.ts"],"sourcesContent":["import { stringify, parse } from 'flatted';\nimport { expose } from '@teambit/worker';\nimport type jest from 'jest';\n\nexport class JestWorker {\n private onTestCompleteCb;\n\n onTestComplete(onTestComplete) {\n this.onTestCompleteCb = onTestComplete;\n // return this;\n }\n\n watch(\n jestConfigPath: string,\n testFiles: string[],\n rootPath: string,\n jestModulePath: string,\n envRootDir: string\n ): Promise<void> {\n return new Promise((resolve) => {\n // TODO: remove this after jest publish new version to npm: https://github.com/facebook/jest/pull/10804\n // eslint-disable-next-line\n console.warn = function () {};\n /* The path to the jest config file. */\n // eslint-disable-next-line import/no-dynamic-require,global-require\n const jestConfig = require(jestConfigPath);\n // eslint-disable-next-line import/no-dynamic-require,global-require\n const jestModule: typeof jest = require(jestModulePath);\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: testFiles,\n });\n\n const config: any = {\n // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins\n // from the env context\n rootDir: envRootDir,\n // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)\n // TODO: consider change this to be an array of the components running dir.\n // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>\n // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)\n // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains \"node_modules\"\n // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)\n // TODO: didn't help)\n roots: [rootPath],\n // useStderr: true,\n // TODO: check way to enable it\n runInBand: true,\n silent: false,\n watch: true,\n watchAll: true,\n watchPlugins: [\n [\n `${__dirname}/watch.js`,\n {\n specFiles: testFiles,\n onComplete: (results) => {\n if (!this.onTestCompleteCb) return;\n try {\n const json = parse(stringify(results));\n this.onTestCompleteCb(json);\n // disable eslint because we want to catch error but not print it on worker\n // eslint-disable-next-line\n } catch (error: any) {}\n },\n },\n ],\n ],\n };\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n const res = jestModule.runCLI(withEnv, [jestConfigPath]);\n // eslint-disable-next-line no-console\n res.catch((err) => console.error(err));\n resolve();\n });\n }\n}\n\nexpose(new JestWorker());\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAyC,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAE,MAAA,CAAAF,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAI,CAAA,2BAAAJ,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAK,CAAA,GAAAL,CAAA,CAAAM,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAJ,CAAA,GAAAI,CAAA,CAAAG,IAAA,CAAAR,CAAA,EAAAI,CAAA,uCAAAH,CAAA,SAAAA,CAAA,YAAAQ,SAAA,yEAAAL,CAAA,GAAAD,MAAA,GAAAO,MAAA,EAAAV,CAAA;AAGlC,MAAMW,UAAU,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,MAAM,CAACD,mBAAmB,EAAEG,MAAM,CAAC;MAC1D;MACA,MAAMgB,GAAG,GAAGpB,UAAU,CAACqB,MAAM,CAACF,OAAO,EAAE,CAAC7B,cAAc,CAAC,CAAC;MACxD;MACA8B,GAAG,CAACE,KAAK,CAAEC,GAAG,IAAK1B,OAAO,CAACqB,KAAK,CAACK,GAAG,CAAC,CAAC;MACtC3B,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;EACJ;AACF;AAAC4B,OAAA,CAAAvC,UAAA,GAAAA,UAAA;AAED,IAAAwC,gBAAM,EAAC,IAAIxC,UAAU,CAAC,CAAC,CAAC"}
1
+ {"version":3,"names":["_flatted","data","require","_worker","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","JestWorker","constructor","onTestComplete","onTestCompleteCb","watch","jestConfigPath","testFiles","rootPath","jestModulePath","envRootDir","Promise","resolve","console","warn","jestConfig","jestModule","jestConfigWithSpecs","assign","testMatch","config","rootDir","roots","runInBand","silent","watchAll","watchPlugins","__dirname","specFiles","onComplete","results","json","parse","stringify","error","withEnv","res","runCLI","catch","err","exports","expose"],"sources":["jest.worker.ts"],"sourcesContent":["import { stringify, parse } from 'flatted';\nimport { expose } from '@teambit/worker';\n\nexport class JestWorker {\n private onTestCompleteCb;\n\n onTestComplete(onTestComplete) {\n this.onTestCompleteCb = onTestComplete;\n // return this;\n }\n\n watch(\n jestConfigPath: string,\n testFiles: string[],\n rootPath: string,\n jestModulePath: string,\n envRootDir: string\n ): Promise<void> {\n return new Promise((resolve) => {\n // TODO: remove this after jest publish new version to npm: https://github.com/facebook/jest/pull/10804\n // eslint-disable-next-line\n console.warn = function () {};\n /* The path to the jest config file. */\n // eslint-disable-next-line import/no-dynamic-require,global-require\n const jestConfig = require(jestConfigPath);\n // eslint-disable-next-line import/no-dynamic-require,global-require\n const jestModule: any = require(jestModulePath);\n\n const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: testFiles,\n });\n\n const config: any = {\n // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins\n // from the env context\n rootDir: envRootDir,\n // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)\n // TODO: consider change this to be an array of the components running dir.\n // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>\n // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)\n // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains \"node_modules\"\n // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)\n // TODO: didn't help)\n roots: [rootPath],\n // useStderr: true,\n // TODO: check way to enable it\n runInBand: true,\n silent: false,\n watch: true,\n watchAll: true,\n watchPlugins: [\n [\n `${__dirname}/watch.js`,\n {\n specFiles: testFiles,\n onComplete: (results) => {\n if (!this.onTestCompleteCb) return;\n try {\n const json = parse(stringify(results));\n this.onTestCompleteCb(json);\n // disable eslint because we want to catch error but not print it on worker\n // eslint-disable-next-line\n } catch (error: any) {}\n },\n },\n ],\n ],\n };\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n const res = jestModule.runCLI(withEnv, [jestConfigPath]);\n // eslint-disable-next-line no-console\n res.catch((err) => console.error(err));\n resolve();\n });\n }\n}\n\nexpose(new JestWorker());\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAyC,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,E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EAAEZ;MACb,CAAC,CAAC;MAEF,MAAMa,MAAW,GAAG;QAClB;QACA;QACAC,OAAO,EAAEX,UAAU;QACnB;QACA;QACA;QACA;QACA;QACA;QACA;QACAY,KAAK,EAAE,CAACd,QAAQ,CAAC;QACjB;QACA;QACAe,SAAS,EAAE,IAAI;QACfC,MAAM,EAAE,KAAK;QACbnB,KAAK,EAAE,IAAI;QACXoB,QAAQ,EAAE,IAAI;QACdC,YAAY,EAAE,CACZ,CACG,GAAEC,SAAU,WAAU,EACvB;UACEC,SAAS,EAAErB,SAAS;UACpBsB,UAAU,EAAGC,OAAO,IAAK;YACvB,IAAI,CAAC,IAAI,CAAC1B,gBAAgB,EAAE;YAC5B,IAAI;cACF,MAAM2B,IAAI,GAAG,IAAAC,gBAAK,EAAC,IAAAC,oBAAS,EAACH,OAAO,CAAC,CAAC;cACtC,IAAI,CAAC1B,gBAAgB,CAAC2B,IAAI,CAAC;cAC3B;cACA;YACF,CAAC,CAAC,OAAOG,KAAU,EAAE,CAAC;UACxB;QACF,CAAC,CACF;MAEL,CAAC;MAED,MAAMC,OAAO,GAAGlD,MAAM,CAACiC,MAAM,CAACD,mBAAmB,EAAEG,MAAM,CAAC;MAC1D;MACA,MAAMgB,GAAG,GAAGpB,UAAU,CAACqB,MAAM,CAACF,OAAO,EAAE,CAAC7B,cAAc,CAAC,CAAC;MACxD;MACA8B,GAAG,CAACE,KAAK,CAAEC,GAAG,IAAK1B,OAAO,CAACqB,KAAK,CAACK,GAAG,CAAC,CAAC;MACtC3B,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;EACJ;AACF;AAAC4B,OAAA,CAAAvC,UAAA,GAAAA,UAAA;AAED,IAAAwC,gBAAM,EAAC,IAAIxC,UAAU,CAAC,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.106/dist/jest.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.106/dist/jest.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.108/dist/jest.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.108/dist/jest.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/dist/watch.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SpecFiles } from '@teambit/tester';
2
- export declare type PluginConfig = {
2
+ export type PluginConfig = {
3
3
  onComplete: (testSuite: any) => void;
4
4
  specFiles: SpecFiles;
5
5
  };
package/dist/watch.js CHANGED
@@ -27,7 +27,7 @@ class Watch {
27
27
  if (paths.includes(specFile)) return true;
28
28
  return false;
29
29
  });
30
- return component === null || component === void 0 ? void 0 : component[0];
30
+ return component?.[0];
31
31
  }
32
32
  apply(jestHooks) {
33
33
  // jestHooks.shouldRunTestSuite(async (testSuite) => {
package/dist/watch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Watch","constructor","stdin","stdout","config","_defineProperty","_stdin","_stdout","_specFiles","specFiles","_onComplete","onComplete","findComponent","specFile","component","toArray","find","specs","paths","map","spec","path","includes","apply","jestHooks","onTestRunComplete","results","module","exports"],"sources":["watch.ts"],"sourcesContent":["import { Prompt, WatchPlugin, JestHookSubscriber, UsageData } from 'jest-watcher';\nimport { SpecFiles } from '@teambit/tester';\n\nexport type PluginConfig = {\n onComplete: (testSuite: any) => void;\n specFiles: SpecFiles;\n};\n\nclass Watch implements WatchPlugin {\n _stdin: NodeJS.ReadStream;\n\n _stdout: NodeJS.WriteStream;\n\n _prompt: Prompt;\n\n _testResults: any;\n\n _usageInfo: UsageData;\n\n _specFiles: SpecFiles;\n\n _onComplete: (testSuite: any) => void;\n\n constructor({\n stdin,\n stdout,\n config,\n }: {\n stdin: NodeJS.ReadStream;\n stdout: NodeJS.WriteStream;\n config: PluginConfig;\n }) {\n this._stdin = stdin;\n this._stdout = stdout;\n this._specFiles = config.specFiles;\n this._onComplete = config.onComplete;\n }\n\n private findComponent(specFile: string) {\n const component = this._specFiles.toArray().find(([, specs]) => {\n const paths = specs.map((spec) => spec.path);\n if (paths.includes(specFile)) return true;\n return false;\n });\n return component?.[0];\n }\n\n apply(jestHooks: JestHookSubscriber) {\n // jestHooks.shouldRunTestSuite(async (testSuite) => {\n // const component = this.findComponent(testSuite.testPath);\n // if ((await component?.isModified()) || (await component?.isNew())) return true;\n // return false;\n // });\n\n jestHooks.onTestRunComplete((results) => {\n this._onComplete(results);\n });\n }\n}\n\nmodule.exports = Watch;\n"],"mappings":";;;;;AAQA,MAAMA,KAAK,CAAwB;EAejCC,WAAWA,CAAC;IACVC,KAAK;IACLC,MAAM;IACNC;EAKF,CAAC,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACD,IAAI,CAACC,MAAM,GAAGJ,KAAK;IACnB,IAAI,CAACK,OAAO,GAAGJ,MAAM;IACrB,IAAI,CAACK,UAAU,GAAGJ,MAAM,CAACK,SAAS;IAClC,IAAI,CAACC,WAAW,GAAGN,MAAM,CAACO,UAAU;EACtC;EAEQC,aAAaA,CAACC,QAAgB,EAAE;IACtC,MAAMC,SAAS,GAAG,IAAI,CAACN,UAAU,CAACO,OAAO,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,GAAGC,KAAK,CAAC,KAAK;MAC9D,MAAMC,KAAK,GAAGD,KAAK,CAACE,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACC,IAAI,CAAC;MAC5C,IAAIH,KAAK,CAACI,QAAQ,CAACT,QAAQ,CAAC,EAAE,OAAO,IAAI;MACzC,OAAO,KAAK;IACd,CAAC,CAAC;IACF,OAAOC,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAG,CAAC,CAAC;EACvB;EAEAS,KAAKA,CAACC,SAA6B,EAAE;IACnC;IACA;IACA;IACA;IACA;;IAEAA,SAAS,CAACC,iBAAiB,CAAEC,OAAO,IAAK;MACvC,IAAI,CAAChB,WAAW,CAACgB,OAAO,CAAC;IAC3B,CAAC,CAAC;EACJ;AACF;AAEAC,MAAM,CAACC,OAAO,GAAG5B,KAAK"}
1
+ {"version":3,"names":["Watch","constructor","stdin","stdout","config","_defineProperty","_stdin","_stdout","_specFiles","specFiles","_onComplete","onComplete","findComponent","specFile","component","toArray","find","specs","paths","map","spec","path","includes","apply","jestHooks","onTestRunComplete","results","module","exports"],"sources":["watch.ts"],"sourcesContent":["import { Prompt, WatchPlugin, JestHookSubscriber, UsageData } from 'jest-watcher';\nimport { SpecFiles } from '@teambit/tester';\n\nexport type PluginConfig = {\n onComplete: (testSuite: any) => void;\n specFiles: SpecFiles;\n};\n\nclass Watch implements WatchPlugin {\n _stdin: NodeJS.ReadStream;\n\n _stdout: NodeJS.WriteStream;\n\n _prompt: Prompt;\n\n _testResults: any;\n\n _usageInfo: UsageData;\n\n _specFiles: SpecFiles;\n\n _onComplete: (testSuite: any) => void;\n\n constructor({\n stdin,\n stdout,\n config,\n }: {\n stdin: NodeJS.ReadStream;\n stdout: NodeJS.WriteStream;\n config: PluginConfig;\n }) {\n this._stdin = stdin;\n this._stdout = stdout;\n this._specFiles = config.specFiles;\n this._onComplete = config.onComplete;\n }\n\n private findComponent(specFile: string) {\n const component = this._specFiles.toArray().find(([, specs]) => {\n const paths = specs.map((spec) => spec.path);\n if (paths.includes(specFile)) return true;\n return false;\n });\n return component?.[0];\n }\n\n apply(jestHooks: JestHookSubscriber) {\n // jestHooks.shouldRunTestSuite(async (testSuite) => {\n // const component = this.findComponent(testSuite.testPath);\n // if ((await component?.isModified()) || (await component?.isNew())) return true;\n // return false;\n // });\n\n jestHooks.onTestRunComplete((results) => {\n this._onComplete(results);\n });\n }\n}\n\nmodule.exports = Watch;\n"],"mappings":";;;;;AAQA,MAAMA,KAAK,CAAwB;EAejCC,WAAWA,CAAC;IACVC,KAAK;IACLC,MAAM;IACNC;EAKF,CAAC,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACD,IAAI,CAACC,MAAM,GAAGJ,KAAK;IACnB,IAAI,CAACK,OAAO,GAAGJ,MAAM;IACrB,IAAI,CAACK,UAAU,GAAGJ,MAAM,CAACK,SAAS;IAClC,IAAI,CAACC,WAAW,GAAGN,MAAM,CAACO,UAAU;EACtC;EAEQC,aAAaA,CAACC,QAAgB,EAAE;IACtC,MAAMC,SAAS,GAAG,IAAI,CAACN,UAAU,CAACO,OAAO,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,GAAGC,KAAK,CAAC,KAAK;MAC9D,MAAMC,KAAK,GAAGD,KAAK,CAACE,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACC,IAAI,CAAC;MAC5C,IAAIH,KAAK,CAACI,QAAQ,CAACT,QAAQ,CAAC,EAAE,OAAO,IAAI;MACzC,OAAO,KAAK;IACd,CAAC,CAAC;IACF,OAAOC,SAAS,GAAG,CAAC,CAAC;EACvB;EAEAS,KAAKA,CAACC,SAA6B,EAAE;IACnC;IACA;IACA;IACA;IACA;;IAEAA,SAAS,CAACC,iBAAiB,CAAEC,OAAO,IAAK;MACvC,IAAI,CAAChB,WAAW,CAACgB,OAAO,CAAC;IAC3B,CAAC,CAAC;EACJ;AACF;AAEAC,MAAM,CAACC,OAAO,GAAG5B,KAAK"}
package/error.ts ADDED
@@ -0,0 +1,9 @@
1
+ export class JestError extends Error {
2
+ constructor(message: string, stack?: string | null, public readonly code?: unknown, public readonly type?: string) {
3
+ super(message);
4
+ }
5
+
6
+ get stack() {
7
+ return this.stack;
8
+ }
9
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { JestTester } from './jest.tester';
2
+ export type { JestMain } from './jest.main.runtime';
3
+ export { JestAspect } from './jest.aspect';
package/jest.aspect.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const JestAspect = Aspect.create({
4
+ id: 'teambit.defender/jest',
5
+ });
@@ -0,0 +1,27 @@
1
+ import { MainRuntime } from '@teambit/cli';
2
+ import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
3
+ import { WorkerAspect, WorkerMain, HarmonyWorker } from '@teambit/worker';
4
+ import { JestAspect } from './jest.aspect';
5
+ import { JestTester, JestTesterOptions } from './jest.tester';
6
+ import type { JestWorker } from './jest.worker';
7
+
8
+ export const WORKER_NAME = 'jest';
9
+
10
+ export class JestMain {
11
+ constructor(private jestWorker: HarmonyWorker<JestWorker>, private logger: Logger) {}
12
+
13
+ createTester(jestConfig: any, jestModulePath = require.resolve('jest'), opts?: JestTesterOptions) {
14
+ return new JestTester(JestAspect.id, jestConfig, jestModulePath, this.jestWorker, this.logger, opts);
15
+ }
16
+
17
+ static runtime = MainRuntime;
18
+ static dependencies = [WorkerAspect, LoggerAspect];
19
+
20
+ static async provider([worker, loggerAspect]: [WorkerMain, LoggerMain]) {
21
+ const logger = loggerAspect.createLogger(JestAspect.id);
22
+ const jestWorker = worker.declareWorker<JestWorker>(WORKER_NAME, require.resolve('./jest.worker'));
23
+ return new JestMain(jestWorker, logger);
24
+ }
25
+ }
26
+
27
+ JestAspect.addRuntime(JestMain);
package/jest.tester.ts ADDED
@@ -0,0 +1,327 @@
1
+ import { resolve } from 'path';
2
+ import { readFileSync } from 'fs-extra';
3
+ import minimatch from 'minimatch';
4
+ import { compact, flatten, isEmpty } from 'lodash';
5
+ import { proxy } from 'comlink';
6
+ import { Logger } from '@teambit/logger';
7
+ import { HarmonyWorker } from '@teambit/worker';
8
+ import { Tester, CallbackFn, TesterContext, Tests, ComponentsResults, ComponentPatternsEntry } from '@teambit/tester';
9
+ import { TestsFiles, TestResult, TestsResult } from '@teambit/tests-results';
10
+ import { TestResult as JestTestResult, AggregatedResult } from '@jest/test-result';
11
+ import { formatResultsErrors } from 'jest-message-util';
12
+ import { Component, ComponentMap } from '@teambit/component';
13
+ import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
14
+ // import { Environment } from '@teambit/envs';
15
+ // import { EnvPolicyConfigObject, PeersAutoDetectPolicy } from '@teambit/dependency-resolver';
16
+ import { JestError } from './error';
17
+ import type { JestWorker } from './jest.worker';
18
+
19
+ export type JestTesterOptions = {
20
+ /**
21
+ * array of patterns to test. (override the patterns provided by the context)
22
+ */
23
+ patterns?: string[];
24
+
25
+ /**
26
+ * add more root paths to look for tests.
27
+ */
28
+ roots?: string[];
29
+
30
+ /**
31
+ * A function that knows to resolve the paths of the spec files.
32
+ * This usually used when you want only subset of your spec files to be used
33
+ * (usually when you use multi tester with different specs files for each tester instance).
34
+ */
35
+ resolveSpecPaths?: (component: Component, context: TesterContext) => string[];
36
+ };
37
+
38
+ export class JestTester implements Tester {
39
+ private readonly jestModule: any;
40
+
41
+ constructor(
42
+ readonly id: string,
43
+ readonly jestConfig: any,
44
+ private jestModulePath: string,
45
+ private jestWorker: HarmonyWorker<JestWorker>,
46
+ private logger: Logger,
47
+ private opts: JestTesterOptions = {}
48
+ ) {
49
+ // eslint-disable-next-line global-require,import/no-dynamic-require
50
+ this.jestModule = require(jestModulePath);
51
+ }
52
+
53
+ configPath = this.jestConfig;
54
+
55
+ displayName = 'Jest';
56
+
57
+ _callback: CallbackFn | undefined;
58
+
59
+ displayConfig() {
60
+ return readFileSync(this.jestConfig, 'utf8');
61
+ }
62
+
63
+ version() {
64
+ return this.jestModule.getVersion();
65
+ }
66
+
67
+ private attachTestsToComponent(testerContext: TesterContext, testResult: JestTestResult[]) {
68
+ return ComponentMap.as(testerContext.components, (component) => {
69
+ const componentPatternValue = testerContext.patterns.get(component);
70
+ if (!componentPatternValue) return undefined;
71
+ const [currComponent, patternEntry] = componentPatternValue;
72
+ const resolvedPatterns = this.resolveComponentPattern(currComponent, patternEntry, testerContext);
73
+ return testResult.filter((test) => {
74
+ return resolvedPatterns.filter((resolvedPattern) => minimatch(test.testFilePath, resolvedPattern)).length > 0;
75
+ });
76
+ });
77
+ }
78
+
79
+ private buildTestsObj(
80
+ aggregatedResult: AggregatedResult,
81
+ components: ComponentMap<JestTestResult[] | undefined>,
82
+ testerContext: TesterContext,
83
+ config?: any
84
+ ): ComponentsResults[] {
85
+ const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {
86
+ if (!testsFiles) return undefined;
87
+ if (testsFiles?.length === 0) return undefined;
88
+ const errors = this.getErrors(testsFiles);
89
+ const tests = testsFiles.map((test) => {
90
+ const file = new AbstractVinyl({ path: test.testFilePath, contents: readFileSync(test.testFilePath) });
91
+ const testResults = test.testResults.map((testResult) => {
92
+ const error = formatResultsErrors([testResult], config, { noStackTrace: true }) || undefined;
93
+ const isFailure = testResult.status === 'failed';
94
+ return new TestResult(
95
+ testResult.ancestorTitles,
96
+ testResult.title,
97
+ testResult.status,
98
+ testResult.duration,
99
+ isFailure ? undefined : error,
100
+ isFailure ? error : undefined
101
+ );
102
+ });
103
+ const filePath = file?.basename || test.testFilePath;
104
+ const getError = () => {
105
+ if (!test.testExecError) return undefined;
106
+ if (testerContext.watch) {
107
+ // for some reason, during watch ('bit start'), if a file has an error, the `test.testExecError` is `{}`
108
+ // (an empty object). the failureMessage contains the stringified error.
109
+ // @todo: consider to always use the failureMessage, regardless the context.watch.
110
+ return new JestError(test.failureMessage as string);
111
+ }
112
+ return new JestError(test.testExecError?.message, test.testExecError?.stack);
113
+ };
114
+ const error = getError();
115
+ return new TestsFiles(
116
+ filePath,
117
+ testResults,
118
+ test.numPassingTests,
119
+ test.numFailingTests,
120
+ test.numPendingTests,
121
+ test.perfStats.runtime,
122
+ test.perfStats.slow,
123
+ error
124
+ );
125
+ });
126
+ return {
127
+ componentId: component.id,
128
+ results: new TestsResult(tests, aggregatedResult.success, aggregatedResult.startTime),
129
+ errors,
130
+ };
131
+ });
132
+
133
+ return compact(testsSuiteResult);
134
+ }
135
+
136
+ private getErrors(testResult: JestTestResult[]): JestError[] {
137
+ return testResult.reduce((errors: JestError[], test) => {
138
+ if (test.testExecError) {
139
+ const { message, stack, code, type } = test.testExecError;
140
+ errors.push(new JestError(message, stack, code, type));
141
+ } else if (test.failureMessage) {
142
+ errors.push(new JestError(test.failureMessage));
143
+ }
144
+ return errors;
145
+ }, []);
146
+ }
147
+
148
+ async onTestRunComplete(callback: CallbackFn) {
149
+ this._callback = callback;
150
+ }
151
+
152
+ async test(context: TesterContext): Promise<Tests> {
153
+ // const envRootDir = context.envRuntime.envAspectDefinition.aspectPath;
154
+
155
+ const config: any = {
156
+ // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins
157
+ // from the env context
158
+ // rootDir: envRootDir,
159
+ // TODO: set it to envRootDir and make sure we can make the --coverage to work
160
+ // with the current value as context.rootPath it will probably won't work correctly when using rootComponents:true (maybe even won't work at all)
161
+ // TODO: when changing to envRootDir we have some issues with the react-native tests. so once changed again, it needs to be validated.
162
+ rootDir: context.rootPath,
163
+ // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)
164
+ // TODO: consider change this to be an array of the components running dir.
165
+ // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>
166
+ // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)
167
+ // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains "node_modules"
168
+ // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)
169
+ // TODO: didn't help)
170
+ roots: [context.rootPath],
171
+ };
172
+
173
+ // eslint-disable-next-line no-console
174
+ console.warn = (message: string) => {
175
+ this.logger.warn(message);
176
+ };
177
+
178
+ if (context.debug) {
179
+ config.debug = true;
180
+ config.runInBand = true;
181
+ }
182
+ if (context.coverage) config.coverage = true;
183
+ config.runInBand = true;
184
+
185
+ if (context.watch) {
186
+ config.watchAll = true;
187
+ config.noCache = true;
188
+ }
189
+ // eslint-disable-next-line global-require,import/no-dynamic-require
190
+ const jestConfig = require(this.jestConfig);
191
+
192
+ // TODO: rollback this for now, as it makes issues.
193
+ // TODO: it's mostly relevant for when the root components feature is enabled.
194
+ // TODO: we might want to enable it only on that case (along with setting the env root dir as the root dir, above)
195
+ // const moduleNameMapper = await this.calculateModuleNameMapper(
196
+ // context.env,
197
+ // context.rootPath,
198
+ // context.additionalHostDependencies
199
+ // );
200
+ // jestConfig.moduleNameMapper = Object.assign({}, jestConfig.moduleNameMapper || {}, moduleNameMapper);
201
+
202
+ const jestConfigWithSpecs = Object.assign(jestConfig, {
203
+ testMatch: this.patternsToArray(context),
204
+ });
205
+
206
+ const withEnv = Object.assign(jestConfigWithSpecs, config);
207
+
208
+ const testsOutPut = await this.jestModule.runCLI(withEnv, [this.jestConfig]);
209
+ const testResults = testsOutPut.results.testResults;
210
+ const componentsWithTests = this.attachTestsToComponent(context, testResults);
211
+ const componentTestResults = this.buildTestsObj(
212
+ testsOutPut.results,
213
+ componentsWithTests,
214
+ context,
215
+ jestConfigWithSpecs
216
+ );
217
+ return new Tests(componentTestResults);
218
+ }
219
+
220
+ async watch(context: TesterContext): Promise<Tests> {
221
+ // eslint-disable-next-line
222
+ return new Promise(async (resolve) => {
223
+ const workerApi = this.jestWorker.initiate(
224
+ context.ui ? { stdout: true, stderr: true, stdin: true } : { stdout: false, stderr: false, stdin: false }
225
+ );
226
+
227
+ // eslint-disable-next-line
228
+ const jestConfig = require(this.jestConfig);
229
+
230
+ const envRootDir = context.envRuntime.envAspectDefinition?.aspectPath;
231
+ if (!envRootDir) {
232
+ this.logger.warn(`jest tester, envRootDir is not defined, for env ${context.envRuntime.id}`);
233
+ }
234
+
235
+ const jestConfigWithSpecs = Object.assign(jestConfig, {
236
+ testMatch: this.patternsToArray(context),
237
+ });
238
+
239
+ try {
240
+ const cbFn = proxy((results) => {
241
+ if (!this._callback) return;
242
+ const testResults = results.testResults;
243
+ const componentsWithTests = this.attachTestsToComponent(context, testResults);
244
+ const componentTestResults = this.buildTestsObj(results, componentsWithTests, context, jestConfigWithSpecs);
245
+ const globalErrors = this.getErrors(testResults);
246
+ const watchTestResults = {
247
+ loading: false,
248
+ errors: globalErrors,
249
+ components: componentTestResults,
250
+ };
251
+ this._callback(watchTestResults);
252
+ resolve(watchTestResults);
253
+ });
254
+
255
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
256
+ await workerApi.onTestComplete(cbFn);
257
+
258
+ await workerApi.watch(
259
+ this.jestConfig,
260
+ this.patternsToArray(context),
261
+ context.rootPath,
262
+ this.jestModulePath,
263
+ envRootDir
264
+ );
265
+ } catch (err: any) {
266
+ this.logger.error('jest.tester.watch() caught an error', err);
267
+ }
268
+ });
269
+ }
270
+
271
+ // private async calculateModuleNameMapper(
272
+ // env: Environment,
273
+ // rootPath: string,
274
+ // additionalHostDependencies?: string[]
275
+ // ): Promise<Record<string, Array<string>>> {
276
+ // const peerDepsConfig: EnvPolicyConfigObject = await env.getDependencies();
277
+ // const peersAutoDetectPolicy = new PeersAutoDetectPolicy(peerDepsConfig.peers || []);
278
+ // const peers = Object.keys(peerDepsConfig.peerDependencies || {}).concat(peersAutoDetectPolicy?.names);
279
+ // const depsToMap = peers.concat(additionalHostDependencies || []);
280
+
281
+ // /**
282
+ // * Try to resolve the dependency from the rootDir (the env dir) or from the root path (workspace/capsule root)
283
+ // */
284
+ // const mappedValues = ['<rootDir>/node_modules/$1', `${rootPath}/node_modules/$1`];
285
+
286
+ // const moduleNameMapper = depsToMap.reduce((acc, peerName) => {
287
+ // const keyName = `^(${peerName})$`;
288
+ // acc[keyName] = mappedValues;
289
+ // const internalPathKeyName = `^(${peerName}/.*)$`;
290
+ // acc[internalPathKeyName] = mappedValues;
291
+ // return acc;
292
+ // }, {});
293
+
294
+ // return moduleNameMapper;
295
+ // }
296
+
297
+ private patternsToArray(context: TesterContext): string[] {
298
+ return flatten(
299
+ context.patterns.toArray().map(([component, patternEntry]) => {
300
+ return this.resolveComponentPattern(component, patternEntry, context);
301
+ })
302
+ );
303
+ }
304
+
305
+ private resolveComponentPattern(
306
+ component: Component,
307
+ patternEntry: ComponentPatternsEntry,
308
+ context: TesterContext
309
+ ): string[] {
310
+ if (this.opts.resolveSpecPaths) {
311
+ return this.opts.resolveSpecPaths(component, context);
312
+ }
313
+ const customPatterns = this.opts.patterns;
314
+ // If pattern were provided to the specific instance of the tester, use them
315
+ if (customPatterns && !isEmpty(customPatterns)) {
316
+ customPatterns.map((customPattern) => {
317
+ const rootDirs = this.opts.roots || [patternEntry.componentDir];
318
+ return this.resolvePattern(customPattern, rootDirs);
319
+ });
320
+ }
321
+ return patternEntry.paths.map((p) => p.path);
322
+ }
323
+
324
+ private resolvePattern(pattern: string, rootDirs: string[]) {
325
+ return rootDirs.map((dir) => resolve(dir, pattern));
326
+ }
327
+ }
package/jest.worker.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { stringify, parse } from 'flatted';
2
+ import { expose } from '@teambit/worker';
3
+
4
+ export class JestWorker {
5
+ private onTestCompleteCb;
6
+
7
+ onTestComplete(onTestComplete) {
8
+ this.onTestCompleteCb = onTestComplete;
9
+ // return this;
10
+ }
11
+
12
+ watch(
13
+ jestConfigPath: string,
14
+ testFiles: string[],
15
+ rootPath: string,
16
+ jestModulePath: string,
17
+ envRootDir: string
18
+ ): Promise<void> {
19
+ return new Promise((resolve) => {
20
+ // TODO: remove this after jest publish new version to npm: https://github.com/facebook/jest/pull/10804
21
+ // eslint-disable-next-line
22
+ console.warn = function () {};
23
+ /* The path to the jest config file. */
24
+ // eslint-disable-next-line import/no-dynamic-require,global-require
25
+ const jestConfig = require(jestConfigPath);
26
+ // eslint-disable-next-line import/no-dynamic-require,global-require
27
+ const jestModule: any = require(jestModulePath);
28
+
29
+ const jestConfigWithSpecs = Object.assign(jestConfig, {
30
+ testMatch: testFiles,
31
+ });
32
+
33
+ const config: any = {
34
+ // Setting the rootDir to the env root dir to make sure we can resolve all the jest presets/plugins
35
+ // from the env context
36
+ rootDir: envRootDir,
37
+ // Setting the roots (where to search for spec files) to the root path (either workspace or capsule root)
38
+ // TODO: consider change this to be an array of the components running dir.
39
+ // TODO: aka: in the workspace it will be something like <ws>/node_modules/<comp-package-name>/node_modules/<comp-package-name>
40
+ // TODO: see dependencyResolver.getRuntimeModulePath (this will make sure the peer deps resolved correctly)
41
+ // TODO: (@GiladShoham - when trying to set it to this paths, jest ignores it probably because the paths contains "node_modules"
42
+ // TODO: trying to set the https://jestjs.io/docs/27.x/configuration#testpathignorepatterns-arraystring to something else (as it contain node_modules by default)
43
+ // TODO: didn't help)
44
+ roots: [rootPath],
45
+ // useStderr: true,
46
+ // TODO: check way to enable it
47
+ runInBand: true,
48
+ silent: false,
49
+ watch: true,
50
+ watchAll: true,
51
+ watchPlugins: [
52
+ [
53
+ `${__dirname}/watch.js`,
54
+ {
55
+ specFiles: testFiles,
56
+ onComplete: (results) => {
57
+ if (!this.onTestCompleteCb) return;
58
+ try {
59
+ const json = parse(stringify(results));
60
+ this.onTestCompleteCb(json);
61
+ // disable eslint because we want to catch error but not print it on worker
62
+ // eslint-disable-next-line
63
+ } catch (error: any) {}
64
+ },
65
+ },
66
+ ],
67
+ ],
68
+ };
69
+
70
+ const withEnv = Object.assign(jestConfigWithSpecs, config);
71
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
72
+ const res = jestModule.runCLI(withEnv, [jestConfigPath]);
73
+ // eslint-disable-next-line no-console
74
+ res.catch((err) => console.error(err));
75
+ resolve();
76
+ });
77
+ }
78
+ }
79
+
80
+ expose(new JestWorker());
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/jest",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "homepage": "https://bit.cloud/teambit/defender/jest",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.defender",
8
8
  "name": "jest",
9
- "version": "1.0.106"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -17,31 +17,27 @@
17
17
  "minimatch": "3.0.5",
18
18
  "flatted": "3.1.0",
19
19
  "jest-watcher": "27.5.1",
20
- "core-js": "^3.0.0",
21
- "@babel/runtime": "7.20.0",
22
20
  "@teambit/harmony": "0.4.6",
23
- "@teambit/cli": "0.0.839",
24
- "@teambit/logger": "0.0.932",
25
- "@teambit/worker": "0.0.1143",
26
- "@teambit/component": "1.0.106",
27
- "@teambit/tester": "1.0.106",
28
- "@teambit/tests-results": "1.0.4"
21
+ "@teambit/tests-results": "1.0.4",
22
+ "@teambit/cli": "0.0.840",
23
+ "@teambit/logger": "0.0.933",
24
+ "@teambit/worker": "0.0.1144",
25
+ "@teambit/component": "1.0.108",
26
+ "@teambit/tester": "1.0.108"
29
27
  },
30
28
  "devDependencies": {
31
29
  "@types/lodash": "4.14.165",
32
- "@types/react": "^17.0.8",
33
- "@types/jest": "^26.0.0",
30
+ "@types/jest": "^29.2.2",
34
31
  "@types/fs-extra": "9.0.7",
35
32
  "@types/minimatch": "3.0.4",
36
- "@types/node": "12.20.4",
37
- "@types/react-dom": "^17.0.5",
38
- "@types/testing-library__jest-dom": "5.9.5"
33
+ "@types/testing-library__jest-dom": "^5.9.5",
34
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
39
35
  },
40
36
  "peerDependencies": {
41
- "@teambit/legacy": "1.0.624",
37
+ "@teambit/legacy": "1.0.625",
42
38
  "jest": "27.5.1",
43
- "react": "^16.8.0 || ^17.0.0",
44
- "react-dom": "^16.8.0 || ^17.0.0"
39
+ "react": "^17.0.0 || ^18.0.0",
40
+ "@types/react": "^18.2.12"
45
41
  },
46
42
  "license": "Apache-2.0",
47
43
  "optionalDependencies": {},
@@ -55,7 +51,7 @@
55
51
  },
56
52
  "private": false,
57
53
  "engines": {
58
- "node": ">=12.22.0"
54
+ "node": ">=16.0.0"
59
55
  },
60
56
  "repository": {
61
57
  "type": "git",
@@ -64,12 +60,9 @@
64
60
  "keywords": [
65
61
  "bit",
66
62
  "bit-aspect",
63
+ "bit-core-aspect",
67
64
  "components",
68
65
  "collaboration",
69
- "web",
70
- "react",
71
- "react-components",
72
- "angular",
73
- "angular-components"
66
+ "web"
74
67
  ]
75
68
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
package/watch.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { Prompt, WatchPlugin, JestHookSubscriber, UsageData } from 'jest-watcher';
2
+ import { SpecFiles } from '@teambit/tester';
3
+
4
+ export type PluginConfig = {
5
+ onComplete: (testSuite: any) => void;
6
+ specFiles: SpecFiles;
7
+ };
8
+
9
+ class Watch implements WatchPlugin {
10
+ _stdin: NodeJS.ReadStream;
11
+
12
+ _stdout: NodeJS.WriteStream;
13
+
14
+ _prompt: Prompt;
15
+
16
+ _testResults: any;
17
+
18
+ _usageInfo: UsageData;
19
+
20
+ _specFiles: SpecFiles;
21
+
22
+ _onComplete: (testSuite: any) => void;
23
+
24
+ constructor({
25
+ stdin,
26
+ stdout,
27
+ config,
28
+ }: {
29
+ stdin: NodeJS.ReadStream;
30
+ stdout: NodeJS.WriteStream;
31
+ config: PluginConfig;
32
+ }) {
33
+ this._stdin = stdin;
34
+ this._stdout = stdout;
35
+ this._specFiles = config.specFiles;
36
+ this._onComplete = config.onComplete;
37
+ }
38
+
39
+ private findComponent(specFile: string) {
40
+ const component = this._specFiles.toArray().find(([, specs]) => {
41
+ const paths = specs.map((spec) => spec.path);
42
+ if (paths.includes(specFile)) return true;
43
+ return false;
44
+ });
45
+ return component?.[0];
46
+ }
47
+
48
+ apply(jestHooks: JestHookSubscriber) {
49
+ // jestHooks.shouldRunTestSuite(async (testSuite) => {
50
+ // const component = this.findComponent(testSuite.testPath);
51
+ // if ((await component?.isModified()) || (await component?.isNew())) return true;
52
+ // return false;
53
+ // });
54
+
55
+ jestHooks.onTestRunComplete((results) => {
56
+ this._onComplete(results);
57
+ });
58
+ }
59
+ }
60
+
61
+ module.exports = Watch;