@teambit/component.testing.mock-components 0.0.16 → 0.0.17

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/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { mockComponents } from './mock-components';
1
+ export { mockComponents, modifyMockedComponents } from './mock-components';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockComponents = void 0;
3
+ exports.modifyMockedComponents = exports.mockComponents = void 0;
4
4
  var mock_components_1 = require("./mock-components");
5
5
  Object.defineProperty(exports, "mockComponents", { enumerable: true, get: function () { return mock_components_1.mockComponents; } });
6
+ Object.defineProperty(exports, "modifyMockedComponents", { enumerable: true, get: function () { return mock_components_1.modifyMockedComponents; } });
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,qDAA2E;AAAlE,iHAAA,cAAc,OAAA;AAAE,yHAAA,sBAAsB,OAAA"}
@@ -1,8 +1,14 @@
1
1
  /**
2
2
  * create dummy components, add, link and compile them.
3
- * if `numOfComponents` is more than one, the components will depend on each other.
3
+ * if `numOfComponents` is more than one, the components will depend on each other. by default, it's one.
4
4
  */
5
5
  export declare function mockComponents(workspacePath: string, { numOfComponents, additionalStr }?: {
6
6
  numOfComponents?: number;
7
7
  additionalStr?: string;
8
8
  }): Promise<void>;
9
+ /**
10
+ * make the mocked components modified by appending the `additionalStr` to the component files
11
+ */
12
+ export declare function modifyMockedComponents(workspacePath: string, additionalStr?: string, { numOfComponents }?: {
13
+ numOfComponents?: number;
14
+ }): Promise<void>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.mockComponents = void 0;
15
+ exports.modifyMockedComponents = exports.mockComponents = void 0;
16
16
  const compiler_1 = require("@teambit/compiler");
17
17
  const harmony_testing_load_aspect_1 = require("@teambit/harmony.testing.load-aspect");
18
18
  const workspace_1 = __importDefault(require("@teambit/workspace"));
@@ -22,9 +22,33 @@ const p_map_series_1 = __importDefault(require("p-map-series"));
22
22
  const path_1 = __importDefault(require("path"));
23
23
  /**
24
24
  * create dummy components, add, link and compile them.
25
- * if `numOfComponents` is more than one, the components will depend on each other.
25
+ * if `numOfComponents` is more than one, the components will depend on each other. by default, it's one.
26
26
  */
27
27
  function mockComponents(workspacePath, { numOfComponents = 1, additionalStr = '' } = {}) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const compsDirs = yield createComponents(workspacePath, { numOfComponents, additionalStr });
30
+ const workspace = yield (0, harmony_testing_load_aspect_1.loadAspect)(workspace_1.default, workspacePath);
31
+ yield (0, p_map_series_1.default)(compsDirs, (compDir) => __awaiter(this, void 0, void 0, function* () {
32
+ yield workspace.track({ rootDir: compDir });
33
+ }));
34
+ yield workspace.bitMap.write();
35
+ const install = yield (0, harmony_testing_load_aspect_1.loadAspect)(install_1.InstallAspect, workspacePath);
36
+ yield install.link({ rewire: true });
37
+ const compiler = yield (0, harmony_testing_load_aspect_1.loadAspect)(compiler_1.CompilerAspect, workspacePath);
38
+ yield compiler.compileOnWorkspace();
39
+ });
40
+ }
41
+ exports.mockComponents = mockComponents;
42
+ /**
43
+ * make the mocked components modified by appending the `additionalStr` to the component files
44
+ */
45
+ function modifyMockedComponents(workspacePath, additionalStr = ' ', { numOfComponents = 1 } = {}) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield createComponents(workspacePath, { numOfComponents, additionalStr });
48
+ });
49
+ }
50
+ exports.modifyMockedComponents = modifyMockedComponents;
51
+ function createComponents(workspacePath, { numOfComponents = 1, additionalStr = '' } = {}) {
28
52
  return __awaiter(this, void 0, void 0, function* () {
29
53
  const getImp = (index) => {
30
54
  if (index === numOfComponents)
@@ -33,20 +57,13 @@ function mockComponents(workspacePath, { numOfComponents = 1, additionalStr = ''
33
57
  return `const ${nextComp} = require('../${nextComp}');
34
58
  module.exports = () => 'comp${index}${additionalStr} and ' + ${nextComp}();`;
35
59
  };
36
- const workspace = yield (0, harmony_testing_load_aspect_1.loadAspect)(workspace_1.default, workspacePath);
37
60
  const numOfComponentsArr = Array(numOfComponents).fill(null);
38
- yield (0, p_map_series_1.default)(numOfComponentsArr, (val, key) => __awaiter(this, void 0, void 0, function* () {
61
+ return (0, p_map_series_1.default)(numOfComponentsArr, (val, key) => __awaiter(this, void 0, void 0, function* () {
39
62
  const i = key + 1;
40
63
  const compDir = path_1.default.join(workspacePath, `comp${i}`);
41
64
  yield fs_extra_1.default.outputFile(path_1.default.join(compDir, `index.js`), getImp(i));
42
- yield workspace.track({ rootDir: compDir });
65
+ return compDir;
43
66
  }));
44
- yield workspace.bitMap.write();
45
- const install = yield (0, harmony_testing_load_aspect_1.loadAspect)(install_1.InstallAspect, workspacePath);
46
- yield install.link({ rewire: true });
47
- const compiler = yield (0, harmony_testing_load_aspect_1.loadAspect)(compiler_1.CompilerAspect, workspacePath);
48
- yield compiler.compileOnWorkspace();
49
67
  });
50
68
  }
51
- exports.mockComponents = mockComponents;
52
69
  //# sourceMappingURL=mock-components.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mock-components.js","sourceRoot":"","sources":["../mock-components.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAiE;AACjE,sFAAkE;AAClE,mEAAgE;AAChE,8CAA8D;AAC9D,wDAA0B;AAC1B,gEAAsC;AACtC,gDAAwB;AAExB;;;GAGG;AACH,SAAsB,cAAc,CAAC,aAAqB,EAAE,EAAE,eAAe,GAAG,CAAC,EAAE,aAAa,GAAG,EAAE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,GAAG,CAAC,EAAE,GAAG,EAAE;;QACnH,MAAM,gBAAgB,CAAC,aAAa,EAAE,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC;IAC5E,CAAC;CAAA;AAFD,wDAEC;AAED,SAAe,gBAAgB,CAC7B,aAAqB,EACrB,EAAE,eAAe,GAAG,CAAC,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,EAAE;;QAEhD,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,EAAE;YACvB,IAAI,KAAK,KAAK,eAAe;gBAAE,OAAO,+BAA+B,KAAK,GAAG,aAAa,IAAI,CAAC;YAC/F,MAAM,QAAQ,GAAG,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC;YACpC,OAAO,SAAS,QAAQ,kBAAkB,QAAQ;8BACxB,KAAK,GAAG,aAAa,YAAY,QAAQ,KAAK,CAAC;QAC3E,CAAC,CAAC;QAEF,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,IAAA,sBAAU,EAAC,kBAAkB,EAAE,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;YACvD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;YAClB,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YACrD,MAAM,kBAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/D,OAAO,OAAO,CAAC;QACjB,CAAC,CAAA,CAAC,CAAC;IACL,CAAC;CAAA"}
package/index.ts CHANGED
@@ -1 +1 @@
1
- export { mockComponents } from './mock-components';
1
+ export { mockComponents, modifyMockedComponents } from './mock-components';
@@ -8,9 +8,33 @@ import path from 'path';
8
8
 
9
9
  /**
10
10
  * create dummy components, add, link and compile them.
11
- * if `numOfComponents` is more than one, the components will depend on each other.
11
+ * if `numOfComponents` is more than one, the components will depend on each other. by default, it's one.
12
12
  */
13
13
  export async function mockComponents(workspacePath: string, { numOfComponents = 1, additionalStr = '' } = {}) {
14
+ const compsDirs = await createComponents(workspacePath, { numOfComponents, additionalStr });
15
+ const workspace: Workspace = await loadAspect(WorkspaceAspect, workspacePath);
16
+ await pMapSeries(compsDirs, async (compDir) => {
17
+ await workspace.track({ rootDir: compDir });
18
+ });
19
+ await workspace.bitMap.write();
20
+ const install: InstallMain = await loadAspect(InstallAspect, workspacePath);
21
+ await install.link({ rewire: true });
22
+
23
+ const compiler: CompilerMain = await loadAspect(CompilerAspect, workspacePath);
24
+ await compiler.compileOnWorkspace();
25
+ }
26
+
27
+ /**
28
+ * make the mocked components modified by appending the `additionalStr` to the component files
29
+ */
30
+ export async function modifyMockedComponents(workspacePath: string, additionalStr = ' ', { numOfComponents = 1 } = {}) {
31
+ await createComponents(workspacePath, { numOfComponents, additionalStr });
32
+ }
33
+
34
+ async function createComponents(
35
+ workspacePath: string,
36
+ { numOfComponents = 1, additionalStr = '' } = {}
37
+ ): Promise<string[]> {
14
38
  const getImp = (index) => {
15
39
  if (index === numOfComponents) return `module.exports = () => 'comp${index}${additionalStr}';`;
16
40
  const nextComp = `comp${index + 1}`;
@@ -18,18 +42,11 @@ export async function mockComponents(workspacePath: string, { numOfComponents =
18
42
  module.exports = () => 'comp${index}${additionalStr} and ' + ${nextComp}();`;
19
43
  };
20
44
 
21
- const workspace: Workspace = await loadAspect(WorkspaceAspect, workspacePath);
22
45
  const numOfComponentsArr = Array(numOfComponents).fill(null);
23
- await pMapSeries(numOfComponentsArr, async (val, key) => {
46
+ return pMapSeries(numOfComponentsArr, async (val, key) => {
24
47
  const i = key + 1;
25
48
  const compDir = path.join(workspacePath, `comp${i}`);
26
49
  await fs.outputFile(path.join(compDir, `index.js`), getImp(i));
27
- await workspace.track({ rootDir: compDir });
50
+ return compDir;
28
51
  });
29
- await workspace.bitMap.write();
30
- const install: InstallMain = await loadAspect(InstallAspect, workspacePath);
31
- await install.link({ rewire: true });
32
-
33
- const compiler: CompilerMain = await loadAspect(CompilerAspect, workspacePath);
34
- await compiler.compileOnWorkspace();
35
52
  }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@teambit/component.testing.mock-components",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "homepage": "https://bit.dev/teambit/component/testing/mock-components",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "testing/mock-components",
9
- "version": "0.0.16"
9
+ "version": "0.0.17"
10
10
  },
11
11
  "dependencies": {
12
12
  "fs-extra": "10.0.0",
13
13
  "p-map-series": "2.1.0",
14
- "@teambit/harmony.testing.load-aspect": "0.0.15"
14
+ "@teambit/harmony.testing.load-aspect": "0.0.16"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/fs-extra": "9.0.7",