@teambit/jest 0.0.656 → 0.0.659
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@0.0.659/dist/jest.composition.js')]
|
package/dist/jest.tester.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
+
require("core-js/modules/es.array.flat.js");
|
|
6
|
+
|
|
5
7
|
require("core-js/modules/es.array.iterator.js");
|
|
6
8
|
|
|
9
|
+
require("core-js/modules/es.array.unscopables.flat.js");
|
|
10
|
+
|
|
7
11
|
require("core-js/modules/es.promise.js");
|
|
8
12
|
|
|
9
13
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -154,11 +158,10 @@ class JestTester {
|
|
|
154
158
|
|
|
155
159
|
buildTestsObj(aggregatedResult, components, testerContext, config) {
|
|
156
160
|
const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {
|
|
157
|
-
if (!testsFiles) return;
|
|
158
|
-
if ((testsFiles === null || testsFiles === void 0 ? void 0 : testsFiles.length) === 0) return;
|
|
161
|
+
if (!testsFiles) return undefined;
|
|
162
|
+
if ((testsFiles === null || testsFiles === void 0 ? void 0 : testsFiles.length) === 0) return undefined;
|
|
163
|
+
const errors = this.getErrors(testsFiles);
|
|
159
164
|
const tests = testsFiles.map(test => {
|
|
160
|
-
var _test$testExecError;
|
|
161
|
-
|
|
162
165
|
const file = new (_sources().AbstractVinyl)({
|
|
163
166
|
path: test.testFilePath,
|
|
164
167
|
contents: (0, _fsExtra().readFileSync)(test.testFilePath)
|
|
@@ -171,17 +174,29 @@ class JestTester {
|
|
|
171
174
|
return new (_testsResults().TestResult)(testResult.ancestorTitles, testResult.title, testResult.status, testResult.duration, isFailure ? undefined : error, isFailure ? error : undefined);
|
|
172
175
|
});
|
|
173
176
|
const filePath = (file === null || file === void 0 ? void 0 : file.basename) || test.testFilePath;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
|
|
178
|
+
const getError = () => {
|
|
179
|
+
var _test$testExecError, _test$testExecError2;
|
|
180
|
+
|
|
181
|
+
if (!test.testExecError) return undefined;
|
|
182
|
+
|
|
183
|
+
if (testerContext.watch) {
|
|
184
|
+
// for some reason, during watch ('bit start'), if a file has an error, the `test.testExecError` is `{}`
|
|
185
|
+
// (an empty object). the failureMessage contains the stringified error.
|
|
186
|
+
// @todo: consider to always use the failureMessage, regardless the context.watch.
|
|
187
|
+
return new (_error().JestError)(test.failureMessage);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
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);
|
|
177
191
|
};
|
|
178
|
-
return new (_testsResults().TestsFiles)(filePath, testResults, test.numPassingTests, test.numFailingTests, test.numPendingTests, test.perfStats.runtime, test.perfStats.slow, error);
|
|
179
|
-
}); // TODO @guy - fix this eslint error
|
|
180
|
-
// eslint-disable-next-line
|
|
181
192
|
|
|
193
|
+
const error = getError();
|
|
194
|
+
return new (_testsResults().TestsFiles)(filePath, testResults, test.numPassingTests, test.numFailingTests, test.numPendingTests, test.perfStats.runtime, test.perfStats.slow, error);
|
|
195
|
+
});
|
|
182
196
|
return {
|
|
183
197
|
componentId: component.id,
|
|
184
|
-
results: new (_testsResults().TestsResult)(tests, aggregatedResult.success, aggregatedResult.startTime)
|
|
198
|
+
results: new (_testsResults().TestsResult)(tests, aggregatedResult.success, aggregatedResult.startTime),
|
|
199
|
+
errors
|
|
185
200
|
};
|
|
186
201
|
});
|
|
187
202
|
return (0, _lodash().compact)(testsSuiteResult);
|
|
@@ -197,9 +212,7 @@ class JestTester {
|
|
|
197
212
|
type
|
|
198
213
|
} = test.testExecError;
|
|
199
214
|
errors.push(new (_error().JestError)(message, stack, code, type));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (test.failureMessage) {
|
|
215
|
+
} else if (test.failureMessage) {
|
|
203
216
|
errors.push(new (_error().JestError)(test.failureMessage));
|
|
204
217
|
}
|
|
205
218
|
|
|
@@ -236,26 +249,15 @@ class JestTester {
|
|
|
236
249
|
testMatch: this.patternsToArray(context.patterns)
|
|
237
250
|
});
|
|
238
251
|
const withEnv = Object.assign(jestConfigWithSpecs, config);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
errors: globalErrors
|
|
249
|
-
};
|
|
250
|
-
} catch (e) {
|
|
251
|
-
const components = context.components.map(comp => ({
|
|
252
|
-
componentId: comp.id
|
|
253
|
-
}));
|
|
254
|
-
return {
|
|
255
|
-
components,
|
|
256
|
-
errors: [e]
|
|
257
|
-
};
|
|
258
|
-
}
|
|
252
|
+
const testsOutPut = await this.jestModule.runCLI(withEnv, [this.jestConfig]);
|
|
253
|
+
const testResults = testsOutPut.results.testResults;
|
|
254
|
+
const componentsWithTests = this.attachTestsToComponent(context, testResults);
|
|
255
|
+
const componentTestResults = this.buildTestsObj(testsOutPut.results, componentsWithTests, context, jestConfigWithSpecs);
|
|
256
|
+
const allErrors = componentTestResults.map(comp => comp.errors || []).flat();
|
|
257
|
+
return {
|
|
258
|
+
components: componentTestResults,
|
|
259
|
+
errors: allErrors
|
|
260
|
+
};
|
|
259
261
|
}
|
|
260
262
|
|
|
261
263
|
async watch(context) {
|
package/dist/jest.tester.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["jest.tester.ts"],"names":["JestTester","constructor","id","jestConfig","jestModulePath","jestWorker","logger","jestModule","require","displayConfig","version","getVersion","attachTestsToComponent","testerContext","testResult","ComponentMap","as","components","component","componentSpecFiles","patterns","get","undefined","specs","filter","test","pattern","testFilePath","path","length","buildTestsObj","aggregatedResult","config","testsSuiteResult","toArray","map","testsFiles","tests","file","AbstractVinyl","contents","testResults","error","noStackTrace","isFailure","status","TestResult","ancestorTitles","title","duration","filePath","basename","failureMessage","testExecError","message","TestsFiles","numPassingTests","numFailingTests","numPendingTests","perfStats","runtime","slow","componentId","results","TestsResult","success","startTime","getErrors","reduce","errors","stack","code","type","push","JestError","onTestRunComplete","callback","_callback","context","rootDir","rootPath","console","warn","debug","runInBand","coverage","watch","watchAll","noCache","jestConfigWithSpecs","Object","assign","testMatch","patternsToArray","withEnv","testsOutPut","runCLI","componentsWithTests","componentTestResults","globalErrors","e","comp","Promise","resolve","workerApi","initiate","ui","stdout","stderr","stdin","cbFn","watchTestResults","loading","onTestComplete","err","p"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;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;;AAGO,MAAMA,UAAN,CAAmC;AAGxCC,EAAAA,WAAW,CACAC,EADA,EAEAC,UAFA,EAGDC,cAHC,EAIDC,UAJC,EAKDC,MALC,EAMT;AAAA,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} from 'fs-extra';\nimport minimatch from 'minimatch';\nimport { compact, flatten } from 'lodash';\nimport { proxy } from 'comlink';\nimport { Logger } from '@teambit/logger';\nimport { HarmonyWorker } from '@teambit/worker';\nimport { Tester, CallbackFn, TesterContext, Tests, ComponentPatternsMap } 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 { ComponentMap, ComponentID } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type jest from 'jest';\nimport { JestError } from './error';\nimport type { JestWorker } from './jest.worker';\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 ) {\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 getTestFile(path: string, testerContext: TesterContext): AbstractVinyl | undefined {\n // return testerContext.specFiles.toArray().reduce((acc: AbstractVinyl | undefined, [, specs]) => {\n // const file = specs.find((spec) => spec.path === path);\n // if (file) acc = file;\n // return acc;\n // }, undefined);\n // }\n\n private attachTestsToComponent(testerContext: TesterContext, testResult: JestTestResult[]) {\n return ComponentMap.as(testerContext.components, (component) => {\n const componentSpecFiles = testerContext.patterns.get(component);\n if (!componentSpecFiles) return undefined;\n const [, specs] = componentSpecFiles;\n return testResult.filter((test) => {\n return specs.filter((pattern) => minimatch(test.testFilePath, pattern.path)).length > 0;\n });\n });\n }\n\n private buildTestsObj(\n aggregatedResult: AggregatedResult,\n components: ComponentMap<JestTestResult[] | undefined>,\n testerContext: TesterContext,\n config?: any\n ) {\n const testsSuiteResult = components.toArray().map(([component, testsFiles]) => {\n if (!testsFiles) return;\n if (testsFiles?.length === 0) return;\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 error = {\n failureMessage: test.testExecError ? test.failureMessage : undefined,\n error: test.testExecError?.message,\n };\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 // TODO @guy - fix this eslint error\n // eslint-disable-next-line\n return {\n componentId: component.id,\n results: new TestsResult(tests, aggregatedResult.success, aggregatedResult.startTime),\n };\n });\n\n return compact(testsSuiteResult) as { componentId: ComponentID; results: TestsResult }[];\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 }\n 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 config: any = {\n rootDir: 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) config.runInBand = true;\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 const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context.patterns),\n });\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\n try {\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 const globalErrors = this.getErrors(testResults);\n return { components: componentTestResults, errors: globalErrors };\n } catch (e) {\n const components = context.components.map((comp) => ({ componentId: comp.id }));\n return { components, errors: [e as Error] };\n }\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 jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context.patterns),\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.patterns),\n context.rootPath,\n this.jestModulePath\n );\n } catch (err: any) {\n this.logger.error('jest.tester.watch() caught an error', err);\n }\n });\n }\n\n private patternsToArray(patterns: ComponentPatternsMap) {\n return flatten(patterns.toArray().map(([, pattern]) => pattern.map((p) => p.path)));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["jest.tester.ts"],"names":["JestTester","constructor","id","jestConfig","jestModulePath","jestWorker","logger","jestModule","require","displayConfig","version","getVersion","attachTestsToComponent","testerContext","testResult","ComponentMap","as","components","component","componentSpecFiles","patterns","get","undefined","specs","filter","test","pattern","testFilePath","path","length","buildTestsObj","aggregatedResult","config","testsSuiteResult","toArray","map","testsFiles","errors","getErrors","tests","file","AbstractVinyl","contents","testResults","error","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","reduce","code","type","push","onTestRunComplete","callback","_callback","context","rootDir","rootPath","console","warn","debug","runInBand","coverage","watchAll","noCache","jestConfigWithSpecs","Object","assign","testMatch","patternsToArray","withEnv","testsOutPut","runCLI","componentsWithTests","componentTestResults","allErrors","comp","flat","Promise","resolve","workerApi","initiate","ui","stdout","stderr","stdin","cbFn","globalErrors","watchTestResults","loading","onTestComplete","err","p"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;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;;AAGO,MAAMA,UAAN,CAAmC;AAGxCC,EAAAA,WAAW,CACAC,EADA,EAEAC,UAFA,EAGDC,cAHC,EAIDC,UAJC,EAKDC,MALC,EAMT;AAAA,SALSJ,EAKT,GALSA,EAKT;AAAA,SAJSC,UA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P;AACD;;AA9MuC","sourcesContent":["import { readFileSync } from 'fs-extra';\nimport minimatch from 'minimatch';\nimport { compact, flatten } from 'lodash';\nimport { proxy } from 'comlink';\nimport { Logger } from '@teambit/logger';\nimport { HarmonyWorker } from '@teambit/worker';\nimport { Tester, CallbackFn, TesterContext, Tests, ComponentPatternsMap, ComponentsResults } 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 { ComponentMap } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type jest from 'jest';\nimport { JestError } from './error';\nimport type { JestWorker } from './jest.worker';\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 ) {\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 getTestFile(path: string, testerContext: TesterContext): AbstractVinyl | undefined {\n // return testerContext.specFiles.toArray().reduce((acc: AbstractVinyl | undefined, [, specs]) => {\n // const file = specs.find((spec) => spec.path === path);\n // if (file) acc = file;\n // return acc;\n // }, undefined);\n // }\n\n private attachTestsToComponent(testerContext: TesterContext, testResult: JestTestResult[]) {\n return ComponentMap.as(testerContext.components, (component) => {\n const componentSpecFiles = testerContext.patterns.get(component);\n if (!componentSpecFiles) return undefined;\n const [, specs] = componentSpecFiles;\n return testResult.filter((test) => {\n return specs.filter((pattern) => minimatch(test.testFilePath, pattern.path)).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 config: any = {\n rootDir: 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) config.runInBand = true;\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 const jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context.patterns),\n });\n\n const withEnv = Object.assign(jestConfigWithSpecs, config);\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 const allErrors = componentTestResults.map((comp) => comp.errors || []).flat();\n return { components: componentTestResults, errors: allErrors };\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 jestConfigWithSpecs = Object.assign(jestConfig, {\n testMatch: this.patternsToArray(context.patterns),\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.patterns),\n context.rootPath,\n this.jestModulePath\n );\n } catch (err: any) {\n this.logger.error('jest.tester.watch() caught an error', err);\n }\n });\n }\n\n private patternsToArray(patterns: ComponentPatternsMap) {\n return flatten(patterns.toArray().map(([, pattern]) => pattern.map((p) => p.path)));\n }\n}\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/jest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.659",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/defender/jest",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.defender",
|
|
8
8
|
"name": "jest",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.659"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"jest-watcher": "26.6.2",
|
|
22
22
|
"@babel/runtime": "7.12.18",
|
|
23
23
|
"core-js": "^3.0.0",
|
|
24
|
-
"@teambit/cli": "0.0.
|
|
25
|
-
"@teambit/logger": "0.0.
|
|
26
|
-
"@teambit/worker": "0.0.
|
|
27
|
-
"@teambit/component": "0.0.
|
|
28
|
-
"@teambit/tester": "0.0.
|
|
29
|
-
"@teambit/tests-results": "0.0.
|
|
24
|
+
"@teambit/cli": "0.0.449",
|
|
25
|
+
"@teambit/logger": "0.0.539",
|
|
26
|
+
"@teambit/worker": "0.0.659",
|
|
27
|
+
"@teambit/component": "0.0.659",
|
|
28
|
+
"@teambit/tester": "0.0.659",
|
|
29
|
+
"@teambit/tests-results": "0.0.96"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/react": "^17.0.8",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/node": "12.20.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@teambit/legacy": "1.0.
|
|
42
|
+
"@teambit/legacy": "1.0.228",
|
|
43
43
|
"jest": "26.6.3",
|
|
44
44
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
45
45
|
"react": "^16.8.0 || ^17.0.0"
|
|
Binary file
|