@teambit/mocha 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.
- package/dist/mocha.composition.d.ts +2 -2
- package/dist/mocha.main.runtime.d.ts +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/index.ts +5 -0
- package/mocha.aspect.ts +5 -0
- package/mocha.main.runtime.ts +29 -0
- package/mocha.tester.ts +116 -0
- package/package.json +16 -23
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare const Logo: () =>
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare const Logo: () => JSX.Element;
|
@@ -6,7 +6,7 @@ export declare class MochaMain {
|
|
6
6
|
private logger;
|
7
7
|
constructor(logger: Logger);
|
8
8
|
createTester(mochaConfig?: Mocha.MochaOptions, babelConfig?: TransformOptions, mochaModule?: any): MochaTester;
|
9
|
-
static slots:
|
9
|
+
static slots: any[];
|
10
10
|
static dependencies: import("@teambit/harmony").Aspect[];
|
11
11
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
12
12
|
static provider([loggerMain]: [LoggerMain]): Promise<MochaMain>;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_mocha@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_mocha@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_mocha@1.0.108/dist/mocha.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.defender_mocha@1.0.108/dist/mocha.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/index.ts
ADDED
package/mocha.aspect.ts
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import { MainRuntime } from '@teambit/cli';
|
2
|
+
import type { TransformOptions } from '@babel/core';
|
3
|
+
import type Mocha from 'mocha';
|
4
|
+
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
5
|
+
import { MochaAspect } from './mocha.aspect';
|
6
|
+
import { MochaTester } from './mocha.tester';
|
7
|
+
|
8
|
+
export class MochaMain {
|
9
|
+
constructor(private logger: Logger) {}
|
10
|
+
|
11
|
+
createTester(
|
12
|
+
mochaConfig: Mocha.MochaOptions = {},
|
13
|
+
babelConfig: TransformOptions = {},
|
14
|
+
// eslint-disable-next-line global-require
|
15
|
+
mochaModule = require('mocha')
|
16
|
+
) {
|
17
|
+
return new MochaTester(MochaAspect.id, this.logger, mochaConfig, babelConfig, mochaModule);
|
18
|
+
}
|
19
|
+
|
20
|
+
static slots = [];
|
21
|
+
static dependencies = [LoggerAspect];
|
22
|
+
static runtime = MainRuntime;
|
23
|
+
static async provider([loggerMain]: [LoggerMain]) {
|
24
|
+
const logger = loggerMain.createLogger(MochaAspect.id);
|
25
|
+
return new MochaMain(logger);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
MochaAspect.addRuntime(MochaMain);
|
package/mocha.tester.ts
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
import { Logger } from '@teambit/logger';
|
2
|
+
import { ComponentsResults, Tester, CallbackFn, TesterContext, Tests } from '@teambit/tester';
|
3
|
+
import Mocha, { Test } from 'mocha';
|
4
|
+
import babelRegister from '@babel/register';
|
5
|
+
import type { TransformOptions } from '@babel/core';
|
6
|
+
import { TestResult, TestsFiles, TestsResult } from '@teambit/tests-results';
|
7
|
+
import pMapSeries from 'p-map-series';
|
8
|
+
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
9
|
+
import { compact } from 'lodash';
|
10
|
+
|
11
|
+
export class MochaTester implements Tester {
|
12
|
+
_callback: CallbackFn | undefined;
|
13
|
+
displayName = 'Mocha';
|
14
|
+
constructor(
|
15
|
+
readonly id: string,
|
16
|
+
private logger: Logger,
|
17
|
+
readonly 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
|
+
private babelConfig: TransformOptions,
|
23
|
+
private MochaModule: typeof Mocha
|
24
|
+
) {}
|
25
|
+
async test(context: TesterContext): Promise<Tests> {
|
26
|
+
if (context.ui) {
|
27
|
+
// @todo: maybe support UI tests at some point
|
28
|
+
return new Tests([]);
|
29
|
+
}
|
30
|
+
this.logger.clearStatusLine();
|
31
|
+
const specsPerComp = context.specFiles.toArray();
|
32
|
+
babelRegister({
|
33
|
+
extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'],
|
34
|
+
...(this.babelConfig || {}),
|
35
|
+
});
|
36
|
+
const componentsResults: ComponentsResults[] = await pMapSeries(specsPerComp, async ([component, files]) => {
|
37
|
+
const testsFiles: TestsFiles[] = await pMapSeries(files, async (file) => {
|
38
|
+
try {
|
39
|
+
return await this.runMochaOnOneFile(file);
|
40
|
+
} catch (err: any) {
|
41
|
+
const errMsg = `Mocha found an error while working on "${file.path}". ${err.message}`;
|
42
|
+
this.logger.error(errMsg, err);
|
43
|
+
this.logger.consoleFailure(errMsg);
|
44
|
+
return new TestsFiles(file.relative, [], 0, 0, 0, undefined, undefined, err);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
const allComponentErrors = testsFiles
|
48
|
+
.map((testFile) => testFile.error || testFile.tests.map((test) => test.failureErrOrStr as Error))
|
49
|
+
.flat();
|
50
|
+
return {
|
51
|
+
componentId: component.id,
|
52
|
+
results: new TestsResult(testsFiles),
|
53
|
+
errors: compact(allComponentErrors),
|
54
|
+
};
|
55
|
+
});
|
56
|
+
return new Tests(componentsResults);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* @todo: make this work. currently, it doesn't update the UI upon changes.
|
61
|
+
*/
|
62
|
+
// async watch(context: TesterContext): Promise<Tests> {
|
63
|
+
// const results = await this.test(context);
|
64
|
+
// if (this._callback) {
|
65
|
+
// this._callback(results);
|
66
|
+
// }
|
67
|
+
// return results;
|
68
|
+
// }
|
69
|
+
|
70
|
+
async onTestRunComplete(callback: CallbackFn) {
|
71
|
+
this._callback = callback;
|
72
|
+
}
|
73
|
+
|
74
|
+
private async runMochaOnOneFile(file: AbstractVinyl): Promise<TestsFiles> {
|
75
|
+
const mocha = new this.MochaModule(this.mochaConfig);
|
76
|
+
mocha.addFile(file.path);
|
77
|
+
const testResults: TestResult[] = [];
|
78
|
+
const handleTest = (test: Test) => {
|
79
|
+
const state = test.state;
|
80
|
+
if (!state) {
|
81
|
+
throw new Error(`the test.state of "${test.title}", file "${file.path}" is neither passed nor failed`);
|
82
|
+
}
|
83
|
+
testResults.push(new TestResult(test.titlePath(), test.title, state, test.duration, undefined, test.err));
|
84
|
+
};
|
85
|
+
return new Promise((resolve) => {
|
86
|
+
const runner = mocha
|
87
|
+
.run()
|
88
|
+
.on('test end', (test) => handleTest(test))
|
89
|
+
.on('fail', (test) => {
|
90
|
+
if (test.type !== 'test') {
|
91
|
+
// otherwise, it was handled already in "test end" event.
|
92
|
+
// this is mainly for test.type of "hook", e.g. "before", "after", "beforeAll", "afterAll"
|
93
|
+
handleTest(test);
|
94
|
+
}
|
95
|
+
})
|
96
|
+
.on('end', function () {
|
97
|
+
const stats = runner.stats;
|
98
|
+
if (!stats) throw new Error('stats is missing');
|
99
|
+
const testsFile = new TestsFiles(
|
100
|
+
file.relative,
|
101
|
+
testResults,
|
102
|
+
stats.passes,
|
103
|
+
stats.failures,
|
104
|
+
stats.pending,
|
105
|
+
stats.duration
|
106
|
+
);
|
107
|
+
resolve(testsFile);
|
108
|
+
});
|
109
|
+
});
|
110
|
+
}
|
111
|
+
|
112
|
+
version(): string {
|
113
|
+
// @ts-ignore
|
114
|
+
return Mocha.prototype.version || 'N/A';
|
115
|
+
}
|
116
|
+
}
|
package/package.json
CHANGED
@@ -1,40 +1,36 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/mocha",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.108",
|
4
4
|
"homepage": "https://bit.cloud/teambit/defender/mocha",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.defender",
|
8
8
|
"name": "mocha",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.108"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"@babel/core": "7.19.6",
|
13
|
-
"mocha": "9.2.0",
|
14
13
|
"@babel/register": "7.18.9",
|
15
14
|
"lodash": "4.17.21",
|
16
15
|
"p-map-series": "2.1.0",
|
17
|
-
"core-js": "^3.0.0",
|
18
|
-
"@babel/runtime": "7.20.0",
|
19
16
|
"@teambit/harmony": "0.4.6",
|
20
|
-
"@teambit/
|
21
|
-
"@teambit/
|
22
|
-
"@teambit/
|
23
|
-
"@teambit/
|
17
|
+
"@teambit/tests-results": "1.0.4",
|
18
|
+
"@teambit/cli": "0.0.840",
|
19
|
+
"@teambit/logger": "0.0.933",
|
20
|
+
"@teambit/tester": "1.0.108"
|
24
21
|
},
|
25
22
|
"devDependencies": {
|
26
|
-
"@types/react": "^17.0.8",
|
27
23
|
"@types/mocha": "9.1.0",
|
28
24
|
"@types/lodash": "4.14.165",
|
29
|
-
"@types/
|
30
|
-
"@types/
|
31
|
-
"@
|
32
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
25
|
+
"@types/jest": "^29.2.2",
|
26
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
27
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
33
28
|
},
|
34
29
|
"peerDependencies": {
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"react
|
30
|
+
"react": "^17.0.0 || ^18.0.0",
|
31
|
+
"mocha": "10.2.0",
|
32
|
+
"@types/react": "^18.2.12",
|
33
|
+
"@teambit/legacy": "1.0.624"
|
38
34
|
},
|
39
35
|
"license": "Apache-2.0",
|
40
36
|
"optionalDependencies": {},
|
@@ -48,7 +44,7 @@
|
|
48
44
|
},
|
49
45
|
"private": false,
|
50
46
|
"engines": {
|
51
|
-
"node": ">=
|
47
|
+
"node": ">=16.0.0"
|
52
48
|
},
|
53
49
|
"repository": {
|
54
50
|
"type": "git",
|
@@ -57,12 +53,9 @@
|
|
57
53
|
"keywords": [
|
58
54
|
"bit",
|
59
55
|
"bit-aspect",
|
56
|
+
"bit-core-aspect",
|
60
57
|
"components",
|
61
58
|
"collaboration",
|
62
|
-
"web"
|
63
|
-
"react",
|
64
|
-
"react-components",
|
65
|
-
"angular",
|
66
|
-
"angular-components"
|
59
|
+
"web"
|
67
60
|
]
|
68
61
|
}
|
package/tsconfig.json
CHANGED
@@ -1,38 +1,33 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
3
|
"lib": [
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"DOM.Iterable",
|
8
|
-
"ScriptHost"
|
4
|
+
"esnext",
|
5
|
+
"dom",
|
6
|
+
"dom.Iterable"
|
9
7
|
],
|
10
|
-
"target": "
|
11
|
-
"module": "
|
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
|
-
"
|
14
|
+
"skipLibCheck": true,
|
20
15
|
"moduleResolution": "node",
|
21
16
|
"esModuleInterop": true,
|
22
|
-
"rootDir": ".",
|
23
17
|
"resolveJsonModule": true,
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
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
|
-
"
|
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<
|
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
|
+
}
|