@teambit/jest 1.0.108 → 1.0.109

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 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.defender/jest-preview"]=t():e["teambit.defender/jest-preview"]=t()}(self,(()=>(()=>{"use strict";var e={93583:(e,t,o)=>{var r={id:"teambit.defender/jest@1.0.109",homepage:"https://bit.cloud/teambit/defender/jest",exported:!0};function n(){const e=i(o(87363));return n=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,n.__bit_component=r,i.__bit_component=r;const p=()=>n().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},n().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/brands/logo-jest.svg"}));p.__bit_component=r,t.Logo=p},87363:e=>{e.exports=React}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{compositions:()=>f,compositions_metadata:()=>l,overview:()=>u});var e={};o.r(e),o.d(e,{default:()=>c});var t=o(93583);o(87363);const n=MdxJsReact,i=TeambitMdxUiMdxScopeContext;var p=["components"];function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},s.apply(this,arguments)}var a={},d="wrapper";function c(e){var t=e.components,o=function(e,t){if(null==e)return{};var o,r,n=function(e,t){if(null==e)return{};var o,r,n={},i=Object.keys(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||(n[o]=e[o]);return n}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)o=i[r],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(n[o]=e[o])}return n}(e,p);return(0,n.mdx)(d,s({},a,o,{components:t,mdxType:"MDXLayout"}),(0,n.mdx)(i.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"}))}c.isMDXComponent=!0;const f=[t],u=[e],l={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),r})()));
@@ -1,5 +1,5 @@
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';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.109/dist/jest.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_jest@1.0.109/dist/jest.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/jest",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
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.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -19,11 +19,11 @@
19
19
  "jest-watcher": "27.5.1",
20
20
  "@teambit/harmony": "0.4.6",
21
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"
22
+ "@teambit/cli": "0.0.841",
23
+ "@teambit/logger": "0.0.934",
24
+ "@teambit/worker": "0.0.1145",
25
+ "@teambit/component": "1.0.109",
26
+ "@teambit/tester": "1.0.109"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/lodash": "4.14.165",
@@ -31,7 +31,7 @@
31
31
  "@types/fs-extra": "9.0.7",
32
32
  "@types/minimatch": "3.0.4",
33
33
  "@types/testing-library__jest-dom": "^5.9.5",
34
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
34
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@teambit/legacy": "1.0.625",
package/calc-root-dir.ts DELETED
@@ -1,15 +0,0 @@
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/error.ts DELETED
@@ -1,9 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- export { JestTester } from './jest.tester';
2
- export type { JestMain } from './jest.main.runtime';
3
- export { JestAspect } from './jest.aspect';
package/jest.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const JestAspect = Aspect.create({
4
- id: 'teambit.defender/jest',
5
- });
@@ -1,27 +0,0 @@
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 DELETED
@@ -1,327 +0,0 @@
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 DELETED
@@ -1,80 +0,0 @@
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/watch.ts DELETED
@@ -1,61 +0,0 @@
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;