@teambit/mocha 0.0.0-00d7d9c4768b039156ff4761d4e835bc014cfc7b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm.mjs ADDED
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line import/no-unresolved
2
+ import cjsModule from './index.js';
3
+
4
+ export const MochaAspect = cjsModule.MochaAspect;
5
+
6
+ export default cjsModule;
@@ -0,0 +1,4 @@
1
+ import { MochaAspect } from './mocha.aspect';
2
+ export type { MochaMain } from './mocha.main.runtime';
3
+ export default MochaAspect;
4
+ export { MochaAspect };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "MochaAspect", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _mocha().MochaAspect;
10
+ }
11
+ });
12
+ exports.default = void 0;
13
+ function _mocha() {
14
+ const data = require("./mocha.aspect");
15
+ _mocha = function () {
16
+ return data;
17
+ };
18
+ return data;
19
+ }
20
+ var _default = exports.default = _mocha().MochaAspect;
21
+
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mocha","data","require","_default","exports","default","MochaAspect"],"sources":["index.ts"],"sourcesContent":["import { MochaAspect } from './mocha.aspect';\n\nexport type { MochaMain } from './mocha.main.runtime';\nexport default MochaAspect;\nexport { MochaAspect };\n"],"mappings":";;;;;;;;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6C,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAG9BC,oBAAW","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+ export declare const MochaAspect: Aspect;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MochaAspect = void 0;
7
+ function _harmony() {
8
+ const data = require("@teambit/harmony");
9
+ _harmony = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ const MochaAspect = exports.MochaAspect = _harmony().Aspect.create({
15
+ id: 'teambit.defender/mocha'
16
+ });
17
+
18
+ //# sourceMappingURL=mocha.aspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_harmony","data","require","MochaAspect","exports","Aspect","create","id"],"sources":["mocha.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const MochaAspect = Aspect.create({\n id: 'teambit.defender/mocha',\n});\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAGE,iBAAM,CAACC,MAAM,CAAC;EACvCC,EAAE,EAAE;AACN,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const Logo: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Logo = void 0;
7
+ function _react() {
8
+ const data = _interopRequireDefault(require("react"));
9
+ _react = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
16
+ style: {
17
+ height: '100%',
18
+ display: 'flex',
19
+ justifyContent: 'center'
20
+ }
21
+ }, /*#__PURE__*/_react().default.createElement("img", {
22
+ style: {
23
+ width: 70
24
+ },
25
+ src: "https://static.bit.dev/extensions-icons/mocha.svg"
26
+ }));
27
+ exports.Logo = Logo;
28
+
29
+ //# sourceMappingURL=mocha.composition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","data","_interopRequireDefault","require","e","__esModule","default","Logo","createElement","style","height","display","justifyContent","width","src","exports"],"sources":["mocha.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/mocha.svg\" />\n </div>\n);\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0B,SAAAC,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEnB,MAAMG,IAAI,GAAGA,CAAA,kBAClBP,MAAA,GAAAM,OAAA,CAAAE,aAAA;EAAKC,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxEZ,MAAA,GAAAM,OAAA,CAAAE,aAAA;EAAKC,KAAK,EAAE;IAAEI,KAAK,EAAE;EAAG,CAAE;EAACC,GAAG,EAAC;AAAmD,CAAE,CACjF,CACN;AAACC,OAAA,CAAAR,IAAA,GAAAA,IAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ ---
2
+ description: A Mocha tester for components
3
+ labels: ['aspect', 'tester']
4
+ ---
@@ -0,0 +1,13 @@
1
+ import type { TransformOptions } from '@babel/core';
2
+ import type Mocha from 'mocha';
3
+ import { Logger, LoggerMain } from '@teambit/logger';
4
+ import { MochaTester } from './mocha.tester';
5
+ export declare class MochaMain {
6
+ private logger;
7
+ constructor(logger: Logger);
8
+ createTester(mochaConfig?: Mocha.MochaOptions, babelConfig?: TransformOptions, mochaModule?: any): MochaTester;
9
+ static slots: never[];
10
+ static dependencies: import("@teambit/harmony").Aspect[];
11
+ static runtime: import("@teambit/harmony").RuntimeDefinition;
12
+ static provider([loggerMain]: [LoggerMain]): Promise<MochaMain>;
13
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MochaMain = void 0;
7
+ function _cli() {
8
+ const data = require("@teambit/cli");
9
+ _cli = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _logger() {
15
+ const data = require("@teambit/logger");
16
+ _logger = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _mocha() {
22
+ const data = require("./mocha.aspect");
23
+ _mocha = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _mocha2() {
29
+ const data = require("./mocha.tester");
30
+ _mocha2 = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
36
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
37
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
38
+ class MochaMain {
39
+ constructor(logger) {
40
+ this.logger = logger;
41
+ }
42
+ createTester(mochaConfig = {}, babelConfig = {},
43
+ // eslint-disable-next-line global-require
44
+ mochaModule = require('mocha')) {
45
+ return new (_mocha2().MochaTester)(_mocha().MochaAspect.id, this.logger, mochaConfig, babelConfig, mochaModule);
46
+ }
47
+ static async provider([loggerMain]) {
48
+ const logger = loggerMain.createLogger(_mocha().MochaAspect.id);
49
+ return new MochaMain(logger);
50
+ }
51
+ }
52
+ exports.MochaMain = MochaMain;
53
+ _defineProperty(MochaMain, "slots", []);
54
+ _defineProperty(MochaMain, "dependencies", [_logger().LoggerAspect]);
55
+ _defineProperty(MochaMain, "runtime", _cli().MainRuntime);
56
+ _mocha().MochaAspect.addRuntime(MochaMain);
57
+
58
+ //# sourceMappingURL=mocha.main.runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cli","data","require","_logger","_mocha","_mocha2","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","MochaMain","constructor","logger","createTester","mochaConfig","babelConfig","mochaModule","MochaTester","MochaAspect","id","provider","loggerMain","createLogger","exports","LoggerAspect","MainRuntime","addRuntime"],"sources":["mocha.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport type { TransformOptions } from '@babel/core';\nimport type Mocha from 'mocha';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { MochaAspect } from './mocha.aspect';\nimport { MochaTester } from './mocha.tester';\n\nexport class MochaMain {\n constructor(private logger: Logger) {}\n\n createTester(\n mochaConfig: Mocha.MochaOptions = {},\n babelConfig: TransformOptions = {},\n // eslint-disable-next-line global-require\n mochaModule = require('mocha')\n ) {\n return new MochaTester(MochaAspect.id, this.logger, mochaConfig, babelConfig, mochaModule);\n }\n\n static slots = [];\n static dependencies = [LoggerAspect];\n static runtime = MainRuntime;\n static async provider([loggerMain]: [LoggerMain]) {\n const logger = loggerMain.createLogger(MochaAspect.id);\n return new MochaMain(logger);\n }\n}\n\nMochaAspect.addRuntime(MochaMain);\n"],"mappings":";;;;;;AAAA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;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G,CAAC,CAAC;EAClC;EACAC,WAAW,GAAG7B,OAAO,CAAC,OAAO,CAAC,EAC9B;IACA,OAAO,KAAI8B,qBAAW,EAACC,oBAAW,CAACC,EAAE,EAAE,IAAI,CAACP,MAAM,EAAEE,WAAW,EAAEC,WAAW,EAAEC,WAAW,CAAC;EAC5F;EAKA,aAAaI,QAAQA,CAAC,CAACC,UAAU,CAAe,EAAE;IAChD,MAAMT,MAAM,GAAGS,UAAU,CAACC,YAAY,CAACJ,oBAAW,CAACC,EAAE,CAAC;IACtD,OAAO,IAAIT,SAAS,CAACE,MAAM,CAAC;EAC9B;AACF;AAACW,OAAA,CAAAb,SAAA,GAAAA,SAAA;AAAAnB,eAAA,CAnBYmB,SAAS,WAYL,EAAE;AAAAnB,eAAA,CAZNmB,SAAS,kBAaE,CAACc,sBAAY,CAAC;AAAAjC,eAAA,CAbzBmB,SAAS,aAcHe,kBAAW;AAO9BP,oBAAW,CAACQ,UAAU,CAAChB,SAAS,CAAC","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ import { Logger } from '@teambit/logger';
2
+ import { Tester, CallbackFn, TesterContext, Tests } from '@teambit/tester';
3
+ import Mocha from 'mocha';
4
+ import type { TransformOptions } from '@babel/core';
5
+ export declare class MochaTester implements Tester {
6
+ readonly id: string;
7
+ private logger;
8
+ readonly mochaConfig: Mocha.MochaOptions;
9
+ /**
10
+ * babel config are needed when the spec files are not native javascript and need to be compiled.
11
+ * pass the same config you pass to your babel compiler if you're using one.
12
+ */
13
+ private babelConfig;
14
+ private MochaModule;
15
+ _callback: CallbackFn | undefined;
16
+ displayName: string;
17
+ constructor(id: string, logger: Logger, mochaConfig: Mocha.MochaOptions,
18
+ /**
19
+ * babel config are needed when the spec files are not native javascript and need to be compiled.
20
+ * pass the same config you pass to your babel compiler if you're using one.
21
+ */
22
+ babelConfig: TransformOptions, MochaModule: typeof Mocha);
23
+ test(context: TesterContext): Promise<Tests>;
24
+ /**
25
+ * @todo: make this work. currently, it doesn't update the UI upon changes.
26
+ */
27
+ onTestRunComplete(callback: CallbackFn): Promise<void>;
28
+ private runMochaOnOneFile;
29
+ version(): string;
30
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MochaTester = void 0;
7
+ function _tester() {
8
+ const data = require("@teambit/tester");
9
+ _tester = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _mocha() {
15
+ const data = _interopRequireDefault(require("mocha"));
16
+ _mocha = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _register() {
22
+ const data = _interopRequireDefault(require("@babel/register"));
23
+ _register = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _testsResults() {
29
+ const data = require("@teambit/tests-results");
30
+ _testsResults = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _pMapSeries() {
36
+ const data = _interopRequireDefault(require("p-map-series"));
37
+ _pMapSeries = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _lodash() {
43
+ const data = require("lodash");
44
+ _lodash = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
50
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
51
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
52
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
53
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
54
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
55
+ class MochaTester {
56
+ constructor(id, logger, mochaConfig,
57
+ /**
58
+ * babel config are needed when the spec files are not native javascript and need to be compiled.
59
+ * pass the same config you pass to your babel compiler if you're using one.
60
+ */
61
+ babelConfig, MochaModule) {
62
+ this.id = id;
63
+ this.logger = logger;
64
+ this.mochaConfig = mochaConfig;
65
+ this.babelConfig = babelConfig;
66
+ this.MochaModule = MochaModule;
67
+ _defineProperty(this, "_callback", void 0);
68
+ _defineProperty(this, "displayName", 'Mocha');
69
+ }
70
+ async test(context) {
71
+ if (context.ui) {
72
+ // @todo: maybe support UI tests at some point
73
+ return new (_tester().Tests)([]);
74
+ }
75
+ this.logger.clearStatusLine();
76
+ const specsPerComp = context.specFiles.toArray();
77
+ (0, _register().default)(_objectSpread({
78
+ extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
79
+ }, this.babelConfig));
80
+ const componentsResults = await (0, _pMapSeries().default)(specsPerComp, async ([component, files]) => {
81
+ const testsFiles = await (0, _pMapSeries().default)(files, async file => {
82
+ try {
83
+ return await this.runMochaOnOneFile(file);
84
+ } catch (err) {
85
+ const errMsg = `Mocha found an error while working on "${file.path}". ${err.message}`;
86
+ this.logger.error(errMsg, err);
87
+ this.logger.consoleFailure(errMsg);
88
+ return new (_testsResults().TestsFiles)(file.relative, [], 0, 0, 0, undefined, undefined, err);
89
+ }
90
+ });
91
+ const allComponentErrors = testsFiles.map(testFile => testFile.error || testFile.tests.map(test => test.failureErrOrStr)).flat();
92
+ return {
93
+ componentId: component.id,
94
+ results: new (_testsResults().TestsResult)(testsFiles),
95
+ errors: (0, _lodash().compact)(allComponentErrors)
96
+ };
97
+ });
98
+ return new (_tester().Tests)(componentsResults);
99
+ }
100
+
101
+ /**
102
+ * @todo: make this work. currently, it doesn't update the UI upon changes.
103
+ */
104
+ // async watch(context: TesterContext): Promise<Tests> {
105
+ // const results = await this.test(context);
106
+ // if (this._callback) {
107
+ // this._callback(results);
108
+ // }
109
+ // return results;
110
+ // }
111
+
112
+ async onTestRunComplete(callback) {
113
+ this._callback = callback;
114
+ }
115
+ async runMochaOnOneFile(file) {
116
+ const mocha = new this.MochaModule(this.mochaConfig);
117
+ mocha.addFile(file.path);
118
+ const testResults = [];
119
+ const handleTest = test => {
120
+ const state = test.state;
121
+ if (!state) {
122
+ throw new Error(`the test.state of "${test.title}", file "${file.path}" is neither passed nor failed`);
123
+ }
124
+ testResults.push(new (_testsResults().TestResult)(test.titlePath(), test.title, state, test.duration, undefined, test.err));
125
+ };
126
+ return new Promise(resolve => {
127
+ const runner = mocha.run().on('test end', test => handleTest(test)).on('fail', test => {
128
+ if (test.type !== 'test') {
129
+ // otherwise, it was handled already in "test end" event.
130
+ // this is mainly for test.type of "hook", e.g. "before", "after", "beforeAll", "afterAll"
131
+ handleTest(test);
132
+ }
133
+ }).on('end', function () {
134
+ const stats = runner.stats;
135
+ if (!stats) throw new Error('stats is missing');
136
+ const testsFile = new (_testsResults().TestsFiles)(file.relative, testResults, stats.passes, stats.failures, stats.pending, stats.duration);
137
+ resolve(testsFile);
138
+ });
139
+ });
140
+ }
141
+ version() {
142
+ // @ts-ignore
143
+ return _mocha().default.prototype.version || 'N/A';
144
+ }
145
+ }
146
+ exports.MochaTester = MochaTester;
147
+
148
+ //# sourceMappingURL=mocha.tester.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_tester","data","require","_mocha","_interopRequireDefault","_register","_testsResults","_pMapSeries","_lodash","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","MochaTester","constructor","id","logger","mochaConfig","babelConfig","MochaModule","test","context","ui","Tests","clearStatusLine","specsPerComp","specFiles","toArray","babelRegister","extensions","componentsResults","pMapSeries","component","files","testsFiles","file","runMochaOnOneFile","err","errMsg","path","message","error","consoleFailure","TestsFiles","relative","undefined","allComponentErrors","map","testFile","tests","failureErrOrStr","flat","componentId","results","TestsResult","errors","compact","onTestRunComplete","callback","_callback","mocha","addFile","testResults","handleTest","state","Error","title","TestResult","titlePath","duration","Promise","resolve","runner","run","on","type","stats","testsFile","passes","failures","pending","version","Mocha","prototype","exports"],"sources":["mocha.tester.ts"],"sourcesContent":["import { Logger } from '@teambit/logger';\nimport { ComponentsResults, Tester, CallbackFn, TesterContext, Tests } from '@teambit/tester';\nimport Mocha, { Test } from 'mocha';\nimport babelRegister from '@babel/register';\nimport type { TransformOptions } from '@babel/core';\nimport { TestResult, TestsFiles, TestsResult } from '@teambit/tests-results';\nimport pMapSeries from 'p-map-series';\nimport { AbstractVinyl } from '@teambit/component.sources';\nimport { compact } from 'lodash';\n\nexport class MochaTester implements Tester {\n _callback: CallbackFn | undefined;\n displayName = 'Mocha';\n constructor(\n readonly id: string,\n private logger: Logger,\n readonly mochaConfig: Mocha.MochaOptions,\n /**\n * babel config are needed when the spec files are not native javascript and need to be compiled.\n * pass the same config you pass to your babel compiler if you're using one.\n */\n private babelConfig: TransformOptions,\n private MochaModule: typeof Mocha\n ) {}\n async test(context: TesterContext): Promise<Tests> {\n if (context.ui) {\n // @todo: maybe support UI tests at some point\n return new Tests([]);\n }\n this.logger.clearStatusLine();\n const specsPerComp = context.specFiles.toArray();\n babelRegister({\n extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'],\n ...this.babelConfig,\n });\n const componentsResults: ComponentsResults[] = await pMapSeries(specsPerComp, async ([component, files]) => {\n const testsFiles: TestsFiles[] = await pMapSeries(files, async (file) => {\n try {\n return await this.runMochaOnOneFile(file);\n } catch (err: any) {\n const errMsg = `Mocha found an error while working on \"${file.path}\". ${err.message}`;\n this.logger.error(errMsg, err);\n this.logger.consoleFailure(errMsg);\n return new TestsFiles(file.relative, [], 0, 0, 0, undefined, undefined, err);\n }\n });\n const allComponentErrors = testsFiles\n .map((testFile) => testFile.error || testFile.tests.map((test) => test.failureErrOrStr as Error))\n .flat();\n return {\n componentId: component.id,\n results: new TestsResult(testsFiles),\n errors: compact(allComponentErrors),\n };\n });\n return new Tests(componentsResults);\n }\n\n /**\n * @todo: make this work. currently, it doesn't update the UI upon changes.\n */\n // async watch(context: TesterContext): Promise<Tests> {\n // const results = await this.test(context);\n // if (this._callback) {\n // this._callback(results);\n // }\n // return results;\n // }\n\n async onTestRunComplete(callback: CallbackFn) {\n this._callback = callback;\n }\n\n private async runMochaOnOneFile(file: AbstractVinyl): Promise<TestsFiles> {\n const mocha = new this.MochaModule(this.mochaConfig);\n mocha.addFile(file.path);\n const testResults: TestResult[] = [];\n const handleTest = (test: Test) => {\n const state = test.state;\n if (!state) {\n throw new Error(`the test.state of \"${test.title}\", file \"${file.path}\" is neither passed nor failed`);\n }\n testResults.push(new TestResult(test.titlePath(), test.title, state, test.duration, undefined, test.err));\n };\n return new Promise((resolve) => {\n const runner = mocha\n .run()\n .on('test end', (test) => handleTest(test))\n .on('fail', (test) => {\n if (test.type !== 'test') {\n // otherwise, it was handled already in \"test end\" event.\n // this is mainly for test.type of \"hook\", e.g. \"before\", \"after\", \"beforeAll\", \"afterAll\"\n handleTest(test);\n }\n })\n .on('end', function () {\n const stats = runner.stats;\n if (!stats) throw new Error('stats is missing');\n const testsFile = new TestsFiles(\n file.relative,\n testResults,\n stats.passes,\n stats.failures,\n stats.pending,\n stats.duration\n );\n resolve(tests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AAO,CAACM,SAAS,CAAC;MACpB,CAAC,CAAC;IACN,CAAC,CAAC;EACJ;EAEAI,OAAOA,CAAA,EAAW;IAChB;IACA,OAAOC,gBAAK,CAACC,SAAS,CAACF,OAAO,IAAI,KAAK;EACzC;AACF;AAACG,OAAA,CAAAvE,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_mocha@00d7d9c4768b039156ff4761d4e835bc014cfc7b/dist/mocha.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.defender_mocha@00d7d9c4768b039156ff4761d4e835bc014cfc7b/dist/mocha.docs.mdx';
3
+
4
+ export const compositions = [compositions_0];
5
+ export const overview = [overview_0];
6
+
7
+ export const compositions_metadata = {"compositions":[{"displayName":"Logo","identifier":"Logo"}]};
package/esm.mjs ADDED
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line import/no-unresolved
2
+ import cjsModule from './index.js';
3
+
4
+ export const MochaAspect = cjsModule.MochaAspect;
5
+
6
+ export default cjsModule;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ export const Logo = () => (
4
+ <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>
5
+ <img style={{ width: 70 }} src="https://static.bit.dev/extensions-icons/mocha.svg" />
6
+ </div>
7
+ );
package/mocha.docs.mdx ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ description: A Mocha tester for components
3
+ labels: ['aspect', 'tester']
4
+ ---
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@teambit/mocha",
3
+ "version": "0.0.0-00d7d9c4768b039156ff4761d4e835bc014cfc7b",
4
+ "homepage": "https://bit.cloud/teambit/defender/mocha",
5
+ "main": "dist/index.js",
6
+ "componentId": {
7
+ "scope": "teambit.defender",
8
+ "name": "mocha",
9
+ "version": "00d7d9c4768b039156ff4761d4e835bc014cfc7b"
10
+ },
11
+ "dependencies": {
12
+ "@babel/core": "7.19.6",
13
+ "@babel/register": "7.18.9",
14
+ "lodash": "4.17.21",
15
+ "p-map-series": "2.1.0",
16
+ "@teambit/harmony": "0.4.7",
17
+ "@teambit/tests-results": "1.0.5",
18
+ "@teambit/cli": "0.0.0-3cb4db843a6b295e8cef7c664665ba1cc5a24bf8",
19
+ "@teambit/logger": "0.0.0-bf6b41084a3d909148e52814659c2a825f262588",
20
+ "@teambit/component.sources": "0.0.0-79b2b00cbac4f76df0b7b33d67121074ad0fb03d",
21
+ "@teambit/tester": "0.0.0-31a153b93b99f2c4c4abebb886bab2fc2c965518"
22
+ },
23
+ "devDependencies": {
24
+ "@types/lodash": "4.14.165",
25
+ "@types/mocha": "9.1.0",
26
+ "@teambit/harmony.envs.core-aspect-env": "0.0.69"
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^17.0.0 || ^18.0.0",
30
+ "mocha": "10.2.0",
31
+ "@types/react": "^17.0.73",
32
+ "@types/mocha": "10.0.1"
33
+ },
34
+ "license": "Apache-2.0",
35
+ "optionalDependencies": {},
36
+ "peerDependenciesMeta": {},
37
+ "exports": {
38
+ ".": {
39
+ "node": {
40
+ "require": "./dist/index.js",
41
+ "import": "./dist/esm.mjs"
42
+ },
43
+ "default": "./dist/index.js"
44
+ },
45
+ "./dist/*": "./dist/*",
46
+ "./artifacts/*": "./artifacts/*",
47
+ "./*": "./*.ts"
48
+ },
49
+ "private": false,
50
+ "engines": {
51
+ "node": ">=16.0.0"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/teambit/bit"
56
+ },
57
+ "keywords": [
58
+ "bit",
59
+ "bit-aspect",
60
+ "bit-core-aspect",
61
+ "components",
62
+ "collaboration",
63
+ "web"
64
+ ]
65
+ }
@@ -0,0 +1,41 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
11
+ const src: string;
12
+ export default src;
13
+ }
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
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
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }