@deot/dev-tester 2.4.0 → 2.5.0

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.cjs CHANGED
@@ -33,7 +33,7 @@ const ALL_PACKAGE = "All Packages";
33
33
  const { prompt, registerPrompt } = inquirer;
34
34
  const getOptions = async () => {
35
35
  const isDev = process.env.NODE_ENV === "development";
36
- const { packageFolderNames } = devShared.Locals.impl();
36
+ const { packageFolderNames, subpackagesMap } = devShared.Locals.impl();
37
37
  const packages$ = [ALL_PACKAGE, ...packageFolderNames];
38
38
  const question = [
39
39
  {
@@ -49,6 +49,23 @@ const getOptions = async () => {
49
49
  });
50
50
  }
51
51
  },
52
+ {
53
+ type: "autocomplete",
54
+ message: `Select Subpackage To ${isDev ? "Develop" : "Test"}:`,
55
+ name: "subpackageFolderName",
56
+ default: "",
57
+ when: (answers) => {
58
+ return !!subpackagesMap[answers.packageFolderName].length;
59
+ },
60
+ source: (answers, input) => {
61
+ const subpackages = [ALL_PACKAGE, ...subpackagesMap[answers.packageFolderName]];
62
+ input = input || "";
63
+ return new Promise(($resolve) => {
64
+ let filter = input ? subpackages.filter((item) => item.includes(input)) : subpackages;
65
+ $resolve(filter);
66
+ });
67
+ }
68
+ },
52
69
  {
53
70
  type: "confirm",
54
71
  message: "Watch Mode?",
@@ -68,6 +85,7 @@ const getOptions = async () => {
68
85
  registerPrompt("autocomplete", autocomplete);
69
86
  let result = await prompt(question);
70
87
  result.packageFolderName = result.packageFolderName == ALL_PACKAGE ? void 0 : result.packageFolderName;
88
+ result.subpackageFolderName = result.subpackageFolderName == ALL_PACKAGE ? void 0 : result.subpackageFolderName;
71
89
  result.watch = result.watch || isDev;
72
90
  return result;
73
91
  };
@@ -86,10 +104,12 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
86
104
  ...promptOptions
87
105
  };
88
106
  }
89
- const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
107
+ const { cwd, workspace, packageOptionsMap, packageDirsMap, subpackagesMap } = locals;
90
108
  const { environment, coverage, watch, dryRun } = options;
91
109
  options.packageFolderName = devShared.Locals.getPackageFolderName(options.packageName) || options.packageFolderName;
92
110
  options.workspace = workspace;
111
+ options.subpackageFolderName = options.subpackageFolderName || options.subpackage;
112
+ options.subpackagesMap = subpackagesMap;
93
113
  const packageOptions = packageOptionsMap[options.packageFolderName];
94
114
  const packageDir = packageDirsMap[options.packageFolderName];
95
115
  if (workspace && cwd !== packageDir && packageOptions?.scripts?.["test"]) {
@@ -101,19 +121,17 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
101
121
  if (!options.workspace)
102
122
  delete options.workspace;
103
123
  delete options.packageName;
124
+ delete options.subpackage;
104
125
  const isDev = process.env.NODE_ENV === "development";
105
126
  const NODE_ENV = process.env.NODE_ENV || "TEST";
106
- const TEST_OPTIONS = encodeURIComponent(JSON.stringify(options));
107
127
  if (dryRun) {
108
- const command = `cross-env NODE_ENV=${NODE_ENV} TEST_OPTIONS=${TEST_OPTIONS} vitest ` + [
128
+ const command = `cross-env NODE_ENV=${NODE_ENV} TEST_OPTIONS=${encodeURIComponent(JSON.stringify(options))} vitest ` + [
109
129
  "--passWithNoTests",
110
130
  `${!(watch || isDev) ? "--watch=false" : ""}`
111
131
  ].join(" ");
112
132
  devShared.Shell.spawn(`echo ${command}`);
113
133
  return;
114
134
  }
115
- process.env.NODE_ENV = process.env.NODE_ENV || "TEST";
116
- process.env.TEST_OPTIONS = TEST_OPTIONS;
117
135
  let options$ = {
118
136
  environment,
119
137
  coverage: {
@@ -127,8 +145,16 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
127
145
  } else if (fs.existsSync(`${cwd}/test.config.ts`)) {
128
146
  options$.config = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./test.config.ts"));
129
147
  } else {
148
+ const { vuePackage, reactPackage } = options;
149
+ const packageName = devShared.Locals.getPackageName(options.packageFolderName);
150
+ const isVuePackage = typeof vuePackage === "string" && (packageName === locals.packageName || packageName === `${locals.packageName}-*` || vuePackage === "*" || vuePackage.split(",").includes(packageName));
151
+ const isReactPackage = typeof reactPackage === "string" && (packageName === locals.packageName || packageName === `${locals.packageName}-*` || reactPackage === "*" || reactPackage.split(",").includes(packageName));
152
+ options.useVue = !!isVuePackage;
153
+ options.useReact = !!isReactPackage;
130
154
  options$.config = path__namespace.relative(cwd, path__namespace.resolve(dirname, "../shared.config.ts"));
131
155
  }
156
+ process.env.NODE_ENV = NODE_ENV;
157
+ process.env.TEST_OPTIONS = encodeURIComponent(JSON.stringify(options));
132
158
  await node.startVitest("test", [], options$);
133
159
  }, {
134
160
  onError: (e) => {
package/dist/index.es.js CHANGED
@@ -10,7 +10,7 @@ const ALL_PACKAGE = "All Packages";
10
10
  const { prompt, registerPrompt } = inquirer;
11
11
  const getOptions = async () => {
12
12
  const isDev = process.env.NODE_ENV === "development";
13
- const { packageFolderNames } = Locals.impl();
13
+ const { packageFolderNames, subpackagesMap } = Locals.impl();
14
14
  const packages$ = [ALL_PACKAGE, ...packageFolderNames];
15
15
  const question = [
16
16
  {
@@ -26,6 +26,23 @@ const getOptions = async () => {
26
26
  });
27
27
  }
28
28
  },
29
+ {
30
+ type: "autocomplete",
31
+ message: `Select Subpackage To ${isDev ? "Develop" : "Test"}:`,
32
+ name: "subpackageFolderName",
33
+ default: "",
34
+ when: (answers) => {
35
+ return !!subpackagesMap[answers.packageFolderName].length;
36
+ },
37
+ source: (answers, input) => {
38
+ const subpackages = [ALL_PACKAGE, ...subpackagesMap[answers.packageFolderName]];
39
+ input = input || "";
40
+ return new Promise(($resolve) => {
41
+ let filter = input ? subpackages.filter((item) => item.includes(input)) : subpackages;
42
+ $resolve(filter);
43
+ });
44
+ }
45
+ },
29
46
  {
30
47
  type: "confirm",
31
48
  message: "Watch Mode?",
@@ -45,6 +62,7 @@ const getOptions = async () => {
45
62
  registerPrompt("autocomplete", autocomplete);
46
63
  let result = await prompt(question);
47
64
  result.packageFolderName = result.packageFolderName == ALL_PACKAGE ? void 0 : result.packageFolderName;
65
+ result.subpackageFolderName = result.subpackageFolderName == ALL_PACKAGE ? void 0 : result.subpackageFolderName;
48
66
  result.watch = result.watch || isDev;
49
67
  return result;
50
68
  };
@@ -63,10 +81,12 @@ const run = (options) => Utils.autoCatch(async () => {
63
81
  ...promptOptions
64
82
  };
65
83
  }
66
- const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
84
+ const { cwd, workspace, packageOptionsMap, packageDirsMap, subpackagesMap } = locals;
67
85
  const { environment, coverage, watch, dryRun } = options;
68
86
  options.packageFolderName = Locals.getPackageFolderName(options.packageName) || options.packageFolderName;
69
87
  options.workspace = workspace;
88
+ options.subpackageFolderName = options.subpackageFolderName || options.subpackage;
89
+ options.subpackagesMap = subpackagesMap;
70
90
  const packageOptions = packageOptionsMap[options.packageFolderName];
71
91
  const packageDir = packageDirsMap[options.packageFolderName];
72
92
  if (workspace && cwd !== packageDir && packageOptions?.scripts?.["test"]) {
@@ -78,19 +98,17 @@ const run = (options) => Utils.autoCatch(async () => {
78
98
  if (!options.workspace)
79
99
  delete options.workspace;
80
100
  delete options.packageName;
101
+ delete options.subpackage;
81
102
  const isDev = process.env.NODE_ENV === "development";
82
103
  const NODE_ENV = process.env.NODE_ENV || "TEST";
83
- const TEST_OPTIONS = encodeURIComponent(JSON.stringify(options));
84
104
  if (dryRun) {
85
- const command = `cross-env NODE_ENV=${NODE_ENV} TEST_OPTIONS=${TEST_OPTIONS} vitest ` + [
105
+ const command = `cross-env NODE_ENV=${NODE_ENV} TEST_OPTIONS=${encodeURIComponent(JSON.stringify(options))} vitest ` + [
86
106
  "--passWithNoTests",
87
107
  `${!(watch || isDev) ? "--watch=false" : ""}`
88
108
  ].join(" ");
89
109
  Shell.spawn(`echo ${command}`);
90
110
  return;
91
111
  }
92
- process.env.NODE_ENV = process.env.NODE_ENV || "TEST";
93
- process.env.TEST_OPTIONS = TEST_OPTIONS;
94
112
  let options$ = {
95
113
  environment,
96
114
  coverage: {
@@ -104,8 +122,16 @@ const run = (options) => Utils.autoCatch(async () => {
104
122
  } else if (fs.existsSync(`${cwd}/test.config.ts`)) {
105
123
  options$.config = path.relative(cwd, path.resolve(cwd, "./test.config.ts"));
106
124
  } else {
125
+ const { vuePackage, reactPackage } = options;
126
+ const packageName = Locals.getPackageName(options.packageFolderName);
127
+ const isVuePackage = typeof vuePackage === "string" && (packageName === locals.packageName || packageName === `${locals.packageName}-*` || vuePackage === "*" || vuePackage.split(",").includes(packageName));
128
+ const isReactPackage = typeof reactPackage === "string" && (packageName === locals.packageName || packageName === `${locals.packageName}-*` || reactPackage === "*" || reactPackage.split(",").includes(packageName));
129
+ options.useVue = !!isVuePackage;
130
+ options.useReact = !!isReactPackage;
107
131
  options$.config = path.relative(cwd, path.resolve(dirname, "../shared.config.ts"));
108
132
  }
133
+ process.env.NODE_ENV = NODE_ENV;
134
+ process.env.TEST_OPTIONS = encodeURIComponent(JSON.stringify(options));
109
135
  await startVitest("test", [], options$);
110
136
  }, {
111
137
  onError: (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-tester",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,12 +20,14 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@deot/dev-shared": "^2.4.0",
24
- "@vitest/coverage-istanbul": "^0.34.2",
23
+ "@deot/dev-react": "^2.5.0",
24
+ "@deot/dev-shared": "^2.5.0",
25
+ "@deot/dev-vue": "^2.5.0",
26
+ "@vitest/coverage-istanbul": "^0.34.3",
25
27
  "cross-env": "^7.0.3",
26
28
  "inquirer": "^9.2.10",
27
29
  "inquirer-autocomplete-prompt": "^3.0.0",
28
30
  "jsdom": "^22.1.0",
29
- "vitest": "^0.34.2"
31
+ "vitest": "^0.34.3"
30
32
  }
31
33
  }
package/shared.config.ts CHANGED
@@ -1,27 +1,80 @@
1
1
  import * as path from 'node:path';
2
2
  import { createRequire } from "node:module";
3
- import { defineConfig, configDefaults } from 'vitest/config';
3
+ import { defineConfig, configDefaults, mergeConfig } from 'vitest/config';
4
4
  import type { UserConfig } from 'vite';
5
5
 
6
+ import vue from '@vitejs/plugin-vue';
7
+ import vueJSX from '@vitejs/plugin-vue-jsx';
8
+ import react from '@vitejs/plugin-react-swc';
9
+
10
+ /**
11
+ * https://github.com/vuejs/core/issues/8303
12
+ * to fix error: ReferenceError: __name is not defined
13
+ */
14
+ let __defProp = Object.defineProperty;
15
+ let __name = (target: any, value: any) => __defProp(target, 'name', { value, configurable: true });
16
+ globalThis.__name = globalThis.__name || __name;
17
+
18
+ const getViteConfig = (options: any) => {
19
+ return options.useVue
20
+ ? defineConfig({ plugins: [vue(), vueJSX()] })
21
+ : options.useReact
22
+ ? defineConfig({ plugins: [react()] })
23
+ : {};
24
+ };
6
25
  const cwd = process.cwd();
7
26
 
8
27
  // options
9
28
  const options = JSON.parse(decodeURIComponent(process.env.TEST_OPTIONS || '{}'));
10
- const { workspace, packageFolderName } = options;
29
+ const { workspace, packageFolderName, subpackageFolderName, subpackagesMap } = options;
30
+
31
+ let tests: string[] = [];
32
+ let collects: string[] = [];
33
+
34
+ const TEST_PATTEN = `**/*.{test,spec}.[jt]s?(x)`;
35
+ const COLLECT_PATTEN = `**/*.[jt]s?(x)`;
36
+
37
+ if (workspace) {
38
+ let prefixDir = `${workspace}/${packageFolderName || '*'}`;
39
+ tests.push(`${prefixDir}/__tests__/${TEST_PATTEN}`);
40
+ collects.push(`${prefixDir}/src/${COLLECT_PATTEN}`);
11
41
 
12
- const testDirPrefix = workspace
13
- ? `${workspace}/${packageFolderName || '*'}/__tests__`
14
- : `__tests__`;
42
+ if (packageFolderName === '*') {
43
+ Object.keys(subpackagesMap).forEach((packageFolderName$: string) => {
44
+ let subpackages = subpackagesMap[packageFolderName$];
45
+ if (subpackages.length) {
46
+ let prefixDir$ = `${workspace}/${packageFolderName$}`;
47
+ let subpackagesPatten = `{${subpackages.join(',')},}`;
15
48
 
16
- const collectDirPrefix = workspace
17
- ? `${workspace}/${packageFolderName || '*'}/src`
18
- : `src`;
49
+ tests.push(`${prefixDir$}/${subpackagesPatten}/__tests__/${TEST_PATTEN}`);
50
+ collects.push(`${prefixDir$}/${subpackagesPatten}/${COLLECT_PATTEN}`);
51
+ collects.push(`${prefixDir$}/index*.ts`);
52
+ }
53
+ });
54
+ } else if (subpackagesMap[packageFolderName].length) {
55
+ if (subpackageFolderName) {
56
+ tests = [];
57
+ collects = [];
19
58
 
59
+ tests.push(`${prefixDir}/${subpackageFolderName}/__tests__/${TEST_PATTEN}`);
60
+ collects.push(`${prefixDir}/${subpackageFolderName}/${COLLECT_PATTEN}`);
61
+ } else {
62
+ let subpackages = subpackagesMap[packageFolderName];
63
+ let subpackagesPatten = `{${subpackages.join(',')},}`;
64
+ tests.push(`${prefixDir}/${subpackagesPatten}/__tests__/${TEST_PATTEN}`);
65
+ collects.push(`${prefixDir}/${subpackagesPatten}/${COLLECT_PATTEN}`);
66
+ collects.push(`${prefixDir}/index*.ts`);
67
+ }
68
+ }
69
+ } else {
70
+ tests.push(`__tests__/${TEST_PATTEN}`);
71
+ collects.push(`src/${COLLECT_PATTEN}`);
72
+ }
20
73
  // alias
21
74
  const replacement = (name: string) => path.resolve(cwd, `./packages/${name}/src`);
22
75
  const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
23
76
 
24
- export default defineConfig({
77
+ export default mergeConfig(getViteConfig(options), defineConfig({
25
78
  resolve: workspace
26
79
  ? {
27
80
  alias: [
@@ -39,9 +92,7 @@ export default defineConfig({
39
92
  : {},
40
93
  test: {
41
94
  globals: true,
42
- include: [
43
- `${testDirPrefix}/**.(spec|test).[jt]s?(x)`
44
- ],
95
+ include: tests,
45
96
  coverage: {
46
97
  enabled: true,
47
98
  provider: 'istanbul',
@@ -50,10 +101,12 @@ export default defineConfig({
50
101
  statements: 95,
51
102
  functions: 95,
52
103
  lines: 95,
53
- include: [
54
- `${collectDirPrefix}/**/*.ts`
55
- ],
56
- exclude: configDefaults.coverage.exclude
104
+ include: collects,
105
+ exclude: [
106
+ `**/examples/**`,
107
+ ...configDefaults.coverage.exclude!
108
+ ]
57
109
  }
58
110
  }
59
- }) as UserConfig;
111
+ }) as UserConfig);
112
+