pob 22.0.0 → 22.1.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [22.1.1](https://github.com/christophehurpeau/pob/compare/pob@22.1.0...pob@22.1.1) (2024-06-08)
7
+
8
+ Version bump for dependency: @pob/root
9
+
10
+
11
+ ## [22.1.0](https://github.com/christophehurpeau/pob/compare/pob@22.0.0...pob@22.1.0) (2024-06-08)
12
+
13
+ ### Features
14
+
15
+ * **pob:** add __mocks__ folder in eslint config ([0b1b337](https://github.com/christophehurpeau/pob/commit/0b1b3373cb9fbe6abf1f520f5a84bc4de26d7756))
16
+ * **pob:** add vitest dependency and very basic vite config ([ea23527](https://github.com/christophehurpeau/pob/commit/ea23527fa6c69b6e9c89a1f1287dd8aac696a3f3))
17
+
18
+ Version bump for dependency: @pob/root
19
+
20
+
6
21
  ## [22.0.0](https://github.com/christophehurpeau/pob/compare/pob@21.1.0...pob@22.0.0) (2024-06-07)
7
22
 
8
23
  ### Bug Fixes
@@ -417,7 +417,11 @@ export default class CommonLintGenerator extends Generator {
417
417
  const testsOverride =
418
418
  this.options.testing || globalTesting
419
419
  ? {
420
- files: [`**/*.test.${ext}`, `__tests__/**/*.${ext}`],
420
+ files: [
421
+ `**/*.test.${ext}`,
422
+ `__tests__/**/*.${ext}`,
423
+ `**/__mocks__/**/*.${ext}`,
424
+ ],
421
425
  ...(testRunner == null || testRunner === "jest"
422
426
  ? { env: { jest: true } }
423
427
  : {}),
@@ -249,7 +249,11 @@ export default class CommonTestingGenerator extends Generator {
249
249
  !isJestRunner ||
250
250
  (globalTesting && !enableForMonorepo)
251
251
  ) {
252
- packageUtils.removeDevDependencies(pkg, ["jest", "@types/jest"]);
252
+ packageUtils.removeDevDependencies(pkg, [
253
+ "jest",
254
+ "@types/jest",
255
+ "vitest",
256
+ ]);
253
257
 
254
258
  delete pkg.jest;
255
259
  this.fs.delete(this.destinationPath("jest.config.js"));
@@ -339,6 +343,7 @@ export default class CommonTestingGenerator extends Generator {
339
343
  };
340
344
 
341
345
  const jestConfigPath = this.destinationPath("jest.config.json");
346
+ const vitestConfigPath = this.destinationPath("vite.config.js");
342
347
  packageUtils.addOrRemoveDevDependencies(
343
348
  pkg,
344
349
  this.options.enable &&
@@ -347,6 +352,14 @@ export default class CommonTestingGenerator extends Generator {
347
352
  ["jest", "@types/jest"],
348
353
  );
349
354
 
355
+ packageUtils.addOrRemoveDevDependencies(
356
+ pkg,
357
+ this.options.enable &&
358
+ (enableForMonorepo || !globalTesting) &&
359
+ testRunner === "vitest",
360
+ ["vitest"],
361
+ );
362
+
350
363
  if (!this.options.enable) {
351
364
  // if (inMonorepo) {
352
365
  // if (pkg.scripts.test === 'echo "No tests"') {
@@ -384,247 +397,263 @@ export default class CommonTestingGenerator extends Generator {
384
397
  packageUtils.addScripts(pkg, {
385
398
  test: "yarn workspaces foreach --parallel -Av run test",
386
399
  });
387
- } else if (this.options.monorepo) {
388
- const shouldUseExperimentalVmModules = pkg.type === "module";
389
-
390
- packageUtils.addScripts(pkg, {
391
- test: createTestCommand({
392
- workspacesPattern,
393
- shouldUseExperimentalVmModules,
394
- }),
395
- "test:watch": createTestCommand({
396
- workspacesPattern,
397
- shouldUseExperimentalVmModules,
398
- watch: true,
399
- }),
400
- "test:coverage": createTestCommand({
401
- workspacesPattern,
402
- shouldUseExperimentalVmModules,
403
- coverage: true,
404
- }),
405
- "test:coverage:lcov": createTestCommand({
406
- workspacesPattern,
407
- shouldUseExperimentalVmModules,
408
- coverageLcov: true,
409
- }),
410
- "test:coverage:json": createTestCommand({
411
- workspacesPattern,
412
- shouldUseExperimentalVmModules,
413
- coverageJson: true,
414
- }),
415
- });
416
-
417
- if (isJestRunner) {
418
- hasReact = yoConfigPobMonorepo.packageNames.some((pkgName) =>
419
- pkgName.startsWith("react-"),
420
- );
421
-
422
- const jestConfig = this.fs.readJSON(jestConfigPath, pkg.jest ?? {});
423
- delete pkg.jest;
424
-
425
- const srcDirectory = this.options.srcDirectory;
426
- Object.assign(jestConfig, {
427
- cacheDirectory: "./node_modules/.cache/jest",
428
- testEnvironment: "node",
429
- testMatch: [
430
- `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/__tests__/**/*.${
431
- transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
432
- }${hasReact ? "?(x)" : ""}`,
433
- `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/*.test.${
434
- transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
435
- }${hasReact ? "?(x)" : ""}`,
436
- ],
437
- });
438
-
439
- if (shouldUseExperimentalVmModules) {
440
- jestConfig.extensionsToTreatAsEsm = [
441
- transpileWithBabel && ".ts",
442
- transpileWithBabel && hasReact && ".tsx",
443
- ].filter(Boolean);
444
- } else {
445
- delete jestConfig.extensionsToTreatAsEsm;
446
- }
447
-
448
- if (tsTestUtil === "swc" && !transpileWithBabel && withTypescript) {
449
- jestConfig.transform = {
450
- [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
451
- };
452
- } else if (jestConfig.transform) {
453
- jestConfig.transform = Object.fromEntries(
454
- Object.entries(jestConfig.transform).filter(
455
- ([key, value]) =>
456
- value !== "@swc/jest" &&
457
- !(Array.isArray(value) && value[0] === "@swc/jest"),
458
- ),
459
- );
460
- if (Object.keys(jestConfig.transform).length === 0) {
461
- delete jestConfig.transform;
462
- }
463
- }
464
-
465
- writeAndFormatJson(this.fs, jestConfigPath, jestConfig);
466
- }
467
400
  } else {
468
- const tsconfigTestPath = this.destinationPath("tsconfig.test.json");
469
- if (testRunner === "node" && withTypescript) {
470
- const nodeVersion = this.options.onlyLatestLTS ? "20" : "18";
401
+ if (this.testRunner === "vitest") {
471
402
  copyAndFormatTpl(
472
403
  this.fs,
473
- this.templatePath("tsconfig.test.json.ejs"),
474
- tsconfigTestPath,
404
+ this.templatePath("vite.config.js.ejs"),
405
+ vitestConfigPath,
475
406
  {
476
- nodeVersion,
407
+ srcDirectory: this.options.srcDirectory,
477
408
  },
478
409
  );
479
- } else {
480
- this.fs.delete(tsconfigTestPath);
481
410
  }
482
411
 
483
- if (globalTesting) {
484
- if (pkg.scripts) {
485
- delete pkg.scripts["generate:test-coverage"];
486
- delete pkg.scripts["test:watch"];
487
- delete pkg.scripts["test:coverage"];
488
- }
489
- packageUtils.addScripts(pkg, {
490
- test: `yarn ../../ run test -- ${path
491
- .relative("../..", ".")
492
- .replace("\\", "/")}`,
493
- });
494
- } else {
495
- const withTypescript =
496
- pkg.pob?.envs?.length > 0 ||
497
- pkg.pob?.bundler === "rollup-babel" ||
498
- pkg.pob?.typescript;
499
-
500
- const shouldUseExperimentalVmModules =
501
- pkg.type === "module" && !inMonorepo;
412
+ if (this.options.monorepo) {
413
+ const shouldUseExperimentalVmModules = pkg.type === "module";
502
414
 
503
415
  packageUtils.addScripts(pkg, {
504
- test: createTestCommand({ shouldUseExperimentalVmModules }),
416
+ test: createTestCommand({
417
+ workspacesPattern,
418
+ shouldUseExperimentalVmModules,
419
+ }),
505
420
  "test:watch": createTestCommand({
421
+ workspacesPattern,
506
422
  shouldUseExperimentalVmModules,
507
423
  watch: true,
508
424
  }),
509
425
  "test:coverage": createTestCommand({
426
+ workspacesPattern,
510
427
  shouldUseExperimentalVmModules,
511
428
  coverage: true,
512
429
  }),
513
430
  "test:coverage:lcov": createTestCommand({
431
+ workspacesPattern,
514
432
  shouldUseExperimentalVmModules,
515
433
  coverageLcov: true,
516
434
  }),
517
435
  "test:coverage:json": createTestCommand({
436
+ workspacesPattern,
518
437
  shouldUseExperimentalVmModules,
519
438
  coverageJson: true,
520
439
  }),
521
440
  });
522
441
 
523
- if (testRunner === "jest") {
524
- const srcDirectory = this.options.build
525
- ? this.options.srcDirectory
526
- : "lib";
442
+ if (isJestRunner) {
443
+ hasReact = yoConfigPobMonorepo.packageNames.some((pkgName) =>
444
+ pkgName.startsWith("react-"),
445
+ );
527
446
 
528
447
  const jestConfig = this.fs.readJSON(jestConfigPath, pkg.jest ?? {});
529
448
  delete pkg.jest;
449
+
450
+ const srcDirectory = this.options.srcDirectory;
530
451
  Object.assign(jestConfig, {
531
452
  cacheDirectory: "./node_modules/.cache/jest",
453
+ testEnvironment: "node",
532
454
  testMatch: [
533
- `<rootDir>/${srcDirectory}/**/__tests__/**/*.${
534
- withTypescript ? "ts" : "?(m)js"
455
+ `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/__tests__/**/*.${
456
+ transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
535
457
  }${hasReact ? "?(x)" : ""}`,
536
- `<rootDir>/${srcDirectory}/**/*.test.${
537
- withTypescript ? "ts" : "?(m)js"
458
+ `<rootDir>/${workspacesPattern}/*/@(${srcDirectory}|lib)/**/*.test.${
459
+ transpileWithBabel ? "(ts|js|cjs|mjs)" : "(js|cjs|mjs)"
538
460
  }${hasReact ? "?(x)" : ""}`,
539
461
  ],
540
- collectCoverageFrom: [
541
- `${srcDirectory}/**/*.${withTypescript ? "ts" : "?(m)js"}${
542
- hasReact ? "?(x)" : ""
543
- }`,
544
- ],
545
- moduleFileExtensions: [
546
- withTypescript && "ts",
547
- withTypescript && hasReact && "tsx",
548
- "js",
549
- // 'jsx',
550
- "json",
551
- ].filter(Boolean),
552
- // transform: {
553
- // [`^.+\\.ts${hasReact ? 'x?' : ''}$`]: 'babel-jest',
554
- // },
555
462
  });
556
- if (transpileWithEsbuild) {
557
- jestConfig.transform = {
558
- [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: [
559
- "jest-esbuild",
560
- {
561
- format: shouldUseExperimentalVmModules ? "esm" : "cjs",
562
- },
563
- ],
564
- };
565
- } else if (!transpileWithBabel && !withTypescript) {
566
- delete jestConfig.transform;
567
- } else {
568
- if (
569
- tsTestUtil === "swc" &&
570
- !transpileWithBabel &&
571
- withTypescript
572
- ) {
573
- jestConfig.transform = {
574
- [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
575
- };
576
- } else if (jestConfig.transform) {
577
- jestConfig.transform = Object.fromEntries(
578
- Object.entries(jestConfig.transform).filter(
579
- ([key, value]) =>
580
- value !== "@swc/jest" &&
581
- !(Array.isArray(value) && value[0] === "@swc/jest"),
582
- ),
583
- );
584
- if (Object.keys(jestConfig.transform).length === 0) {
585
- delete jestConfig.transform;
586
- }
587
- }
588
-
589
- if (jestConfig.transform) {
590
- jestConfig.transform = Object.fromEntries(
591
- Object.entries(jestConfig.transform).filter(
592
- ([key, value]) =>
593
- !(
594
- value &&
595
- Array.isArray(value) &&
596
- value[0] === "jest-esbuild"
597
- ),
598
- ),
599
- );
600
- if (Object.keys(jestConfig.transform).length === 0) {
601
- delete jestConfig.transform;
602
- }
603
- }
604
- }
605
463
 
606
464
  if (shouldUseExperimentalVmModules) {
607
465
  jestConfig.extensionsToTreatAsEsm = [
608
- withTypescript && ".ts",
609
- withTypescript && hasReact && ".tsx",
466
+ transpileWithBabel && ".ts",
467
+ transpileWithBabel && hasReact && ".tsx",
610
468
  ].filter(Boolean);
611
469
  } else {
612
470
  delete jestConfig.extensionsToTreatAsEsm;
613
471
  }
614
472
 
615
- if (
616
- !pkg.pob?.envs ||
617
- pkg.pob?.envs.length === 0 ||
618
- pkg.pob?.envs.some((env) => env.target === "node")
619
- ) {
620
- // jestConfig.testEnvironment = 'node'; this is the default now
621
- delete jestConfig.testEnvironment;
622
- } else {
623
- delete jestConfig.testEnvironment;
473
+ if (tsTestUtil === "swc" && !transpileWithBabel && withTypescript) {
474
+ jestConfig.transform = {
475
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
476
+ };
477
+ } else if (jestConfig.transform) {
478
+ jestConfig.transform = Object.fromEntries(
479
+ Object.entries(jestConfig.transform).filter(
480
+ ([key, value]) =>
481
+ value !== "@swc/jest" &&
482
+ !(Array.isArray(value) && value[0] === "@swc/jest"),
483
+ ),
484
+ );
485
+ if (Object.keys(jestConfig.transform).length === 0) {
486
+ delete jestConfig.transform;
487
+ }
624
488
  }
625
489
 
626
490
  writeAndFormatJson(this.fs, jestConfigPath, jestConfig);
627
491
  }
492
+ } else {
493
+ const tsconfigTestPath = this.destinationPath("tsconfig.test.json");
494
+ if (testRunner === "node" && withTypescript) {
495
+ const nodeVersion = this.options.onlyLatestLTS ? "20" : "18";
496
+ copyAndFormatTpl(
497
+ this.fs,
498
+ this.templatePath("tsconfig.test.json.ejs"),
499
+ tsconfigTestPath,
500
+ {
501
+ nodeVersion,
502
+ },
503
+ );
504
+ } else {
505
+ this.fs.delete(tsconfigTestPath);
506
+ }
507
+
508
+ if (globalTesting) {
509
+ if (pkg.scripts) {
510
+ delete pkg.scripts["generate:test-coverage"];
511
+ delete pkg.scripts["test:watch"];
512
+ delete pkg.scripts["test:coverage"];
513
+ }
514
+ packageUtils.addScripts(pkg, {
515
+ test: `yarn ../../ run test -- ${path
516
+ .relative("../..", ".")
517
+ .replace("\\", "/")}`,
518
+ });
519
+ } else {
520
+ const withTypescript =
521
+ pkg.pob?.envs?.length > 0 ||
522
+ pkg.pob?.bundler === "rollup-babel" ||
523
+ pkg.pob?.typescript;
524
+
525
+ const shouldUseExperimentalVmModules =
526
+ pkg.type === "module" && !inMonorepo;
527
+
528
+ packageUtils.addScripts(pkg, {
529
+ test: createTestCommand({ shouldUseExperimentalVmModules }),
530
+ "test:watch": createTestCommand({
531
+ shouldUseExperimentalVmModules,
532
+ watch: true,
533
+ }),
534
+ "test:coverage": createTestCommand({
535
+ shouldUseExperimentalVmModules,
536
+ coverage: true,
537
+ }),
538
+ "test:coverage:lcov": createTestCommand({
539
+ shouldUseExperimentalVmModules,
540
+ coverageLcov: true,
541
+ }),
542
+ "test:coverage:json": createTestCommand({
543
+ shouldUseExperimentalVmModules,
544
+ coverageJson: true,
545
+ }),
546
+ });
547
+
548
+ if (testRunner === "jest") {
549
+ const srcDirectory = this.options.build
550
+ ? this.options.srcDirectory
551
+ : "lib";
552
+
553
+ const jestConfig = this.fs.readJSON(
554
+ jestConfigPath,
555
+ pkg.jest ?? {},
556
+ );
557
+ delete pkg.jest;
558
+ Object.assign(jestConfig, {
559
+ cacheDirectory: "./node_modules/.cache/jest",
560
+ testMatch: [
561
+ `<rootDir>/${srcDirectory}/**/__tests__/**/*.${
562
+ withTypescript ? "ts" : "?(m)js"
563
+ }${hasReact ? "?(x)" : ""}`,
564
+ `<rootDir>/${srcDirectory}/**/*.test.${
565
+ withTypescript ? "ts" : "?(m)js"
566
+ }${hasReact ? "?(x)" : ""}`,
567
+ ],
568
+ collectCoverageFrom: [
569
+ `${srcDirectory}/**/*.${withTypescript ? "ts" : "?(m)js"}${
570
+ hasReact ? "?(x)" : ""
571
+ }`,
572
+ ],
573
+ moduleFileExtensions: [
574
+ withTypescript && "ts",
575
+ withTypescript && hasReact && "tsx",
576
+ "js",
577
+ // 'jsx',
578
+ "json",
579
+ ].filter(Boolean),
580
+ // transform: {
581
+ // [`^.+\\.ts${hasReact ? 'x?' : ''}$`]: 'babel-jest',
582
+ // },
583
+ });
584
+ if (transpileWithEsbuild) {
585
+ jestConfig.transform = {
586
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: [
587
+ "jest-esbuild",
588
+ {
589
+ format: shouldUseExperimentalVmModules ? "esm" : "cjs",
590
+ },
591
+ ],
592
+ };
593
+ } else if (!transpileWithBabel && !withTypescript) {
594
+ delete jestConfig.transform;
595
+ } else {
596
+ if (
597
+ tsTestUtil === "swc" &&
598
+ !transpileWithBabel &&
599
+ withTypescript
600
+ ) {
601
+ jestConfig.transform = {
602
+ [hasReact ? "^.+\\.tsx?$" : "^.+\\.ts$"]: ["@swc/jest"],
603
+ };
604
+ } else if (jestConfig.transform) {
605
+ jestConfig.transform = Object.fromEntries(
606
+ Object.entries(jestConfig.transform).filter(
607
+ ([key, value]) =>
608
+ value !== "@swc/jest" &&
609
+ !(Array.isArray(value) && value[0] === "@swc/jest"),
610
+ ),
611
+ );
612
+ if (Object.keys(jestConfig.transform).length === 0) {
613
+ delete jestConfig.transform;
614
+ }
615
+ }
616
+
617
+ if (jestConfig.transform) {
618
+ jestConfig.transform = Object.fromEntries(
619
+ Object.entries(jestConfig.transform).filter(
620
+ ([key, value]) =>
621
+ !(
622
+ value &&
623
+ Array.isArray(value) &&
624
+ value[0] === "jest-esbuild"
625
+ ),
626
+ ),
627
+ );
628
+ if (Object.keys(jestConfig.transform).length === 0) {
629
+ delete jestConfig.transform;
630
+ }
631
+ }
632
+ }
633
+
634
+ if (shouldUseExperimentalVmModules) {
635
+ jestConfig.extensionsToTreatAsEsm = [
636
+ withTypescript && ".ts",
637
+ withTypescript && hasReact && ".tsx",
638
+ ].filter(Boolean);
639
+ } else {
640
+ delete jestConfig.extensionsToTreatAsEsm;
641
+ }
642
+
643
+ if (
644
+ !pkg.pob?.envs ||
645
+ pkg.pob?.envs.length === 0 ||
646
+ pkg.pob?.envs.some((env) => env.target === "node")
647
+ ) {
648
+ // jestConfig.testEnvironment = 'node'; this is the default now
649
+ delete jestConfig.testEnvironment;
650
+ } else {
651
+ delete jestConfig.testEnvironment;
652
+ }
653
+
654
+ writeAndFormatJson(this.fs, jestConfigPath, jestConfig);
655
+ }
656
+ }
628
657
  }
629
658
  }
630
659
  }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ setupFiles: ["<%= srcDirectory %>/tests/setup.ts"],
6
+ include: ["<%= srcDirectory %>/**/__tests__/**/*.ts?(x)", "<%= srcDirectory %>/**/*.test.ts?(x)"],
7
+ coverage: {
8
+ include: ["<%= srcDirectory %>/**/*.ts?(x)"],
9
+ reportsDirectory: "docs/coverage",
10
+ reporter: (process.env.POB_VITEST_COVERAGE || "json,text").split(","),
11
+ },
12
+ },
13
+ });
@@ -213,6 +213,10 @@ export default class PobLibGenerator extends Generator {
213
213
  when: !this.updateOnly || this.pobjson.testing?.runner === undefined,
214
214
  default: this.pobjson.testing?.runner || "jest",
215
215
  choices: [
216
+ {
217
+ name: "Vitest",
218
+ value: "vitest",
219
+ },
216
220
  {
217
221
  name: "Jest",
218
222
  value: "jest",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pob",
3
- "version": "22.0.0",
3
+ "version": "22.1.1",
4
4
  "description": "Pile of bones, library generator with git/babel/typescript/typedoc/readme/jest",
5
5
  "keywords": [
6
6
  "skeleton"
@@ -64,7 +64,7 @@
64
64
  "mem-fs-editor": "11.0.1",
65
65
  "minimist": "1.2.8",
66
66
  "parse-author": "2.0.0",
67
- "pob-dependencies": "13.0.0",
67
+ "pob-dependencies": "13.1.0",
68
68
  "prettier": "3.3.1",
69
69
  "semver": "7.6.2",
70
70
  "validate-npm-package-name": "^5.0.0",
@@ -73,7 +73,7 @@
73
73
  "yeoman-generator": "7.2.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@pob/root": "12.0.0",
76
+ "@pob/root": "12.1.1",
77
77
  "@types/node": "20.14.2",
78
78
  "typescript": "5.4.5"
79
79
  }