@domain-first/project-structure 5.1.0 → 5.1.2

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
@@ -1420,6 +1420,16 @@ test('connects to the database in the container', () => {
1420
1420
  expect(process.env.DATABASE_URL).toBe(inject('databaseUrl'));
1421
1421
  });
1422
1422
  `;
1423
+ const excludeFromUnitTests = (content)=>{
1424
+ const exclude = /(exclude:\s*\[\s*\.\.\.configDefaults\.exclude\b[^\]]*?)(,?)(\s*)\]/;
1425
+ if (!exclude.test(content)) return;
1426
+ const entry = `'${integrationFolder}/**'`;
1427
+ return content.replace(exclude, (_, items, comma, whitespace)=>{
1428
+ const indent = whitespace.includes('\n') ? /\n([ \t]*)[^\n]*$/.exec(items)?.[1] : void 0;
1429
+ const separator = void 0 === indent ? ', ' : `,\n${indent}`;
1430
+ return `${items}${separator}${entry}${comma}${whitespace}]`;
1431
+ }).replace('// Playwright runs end-to-end specs\n', '// Playwright runs end-to-end specs, test:integration runs integration ones\n');
1432
+ };
1423
1433
  const testcontainers_stageFile = (filePath, content)=>{
1424
1434
  const file = new File(filePath);
1425
1435
  if (!file.exists || file.data !== content) file.data = content;
@@ -1435,7 +1445,7 @@ const addTestcontainers = async ()=>{
1435
1445
  };
1436
1446
  const selected = await addPackageScripts(manifestFile, testcontainersScripts);
1437
1447
  const withPrisma = new File(external_node_path_default().resolve(root, config.rootFolder, 'shared/infrastructure/prisma/prisma.config.ts')).exists;
1438
- const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply']}` : void 0;
1448
+ const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply'].replace(' --advance-ref db', '')}` : void 0;
1439
1449
  const folder = external_node_path_default().join(root, integrationFolder);
1440
1450
  testcontainers_stageFile(external_node_path_default().join(folder, 'vitest.config.ts'), testcontainersVitestConfig(Boolean(dependencies['@domain-first/handlers-next'])));
1441
1451
  testcontainers_stageFile(external_node_path_default().join(folder, 'global-setup.ts'), testcontainersGlobalSetup(migrationCommand));
@@ -1443,7 +1453,14 @@ const addTestcontainers = async ()=>{
1443
1453
  const example = new File(external_node_path_default().join(folder, 'database/database.spec.ts'));
1444
1454
  if (!example.exists) example.data = testcontainers_exampleSpec;
1445
1455
  const unitConfig = new File(external_node_path_default().join(root, 'vitest.config.ts'));
1446
- const excludedFromUnitTests = !unitConfig.exists || unitConfig.data.includes(integrationFolder);
1456
+ let excludedFromUnitTests = !unitConfig.exists || unitConfig.data.includes(integrationFolder);
1457
+ if (!excludedFromUnitTests) {
1458
+ const excluded = excludeFromUnitTests(unitConfig.data);
1459
+ if (excluded) {
1460
+ unitConfig.update(excluded);
1461
+ excludedFromUnitTests = true;
1462
+ }
1463
+ }
1447
1464
  const missing = [
1448
1465
  'vitest',
1449
1466
  'testcontainers',
package/dist/index.js CHANGED
@@ -1038,6 +1038,16 @@ test('connects to the database in the container', () => {
1038
1038
  expect(process.env.DATABASE_URL).toBe(inject('databaseUrl'));
1039
1039
  });
1040
1040
  `;
1041
+ const excludeFromUnitTests = (content)=>{
1042
+ const exclude = /(exclude:\s*\[\s*\.\.\.configDefaults\.exclude\b[^\]]*?)(,?)(\s*)\]/;
1043
+ if (!exclude.test(content)) return;
1044
+ const entry = `'${integrationFolder}/**'`;
1045
+ return content.replace(exclude, (_, items, comma, whitespace)=>{
1046
+ const indent = whitespace.includes('\n') ? /\n([ \t]*)[^\n]*$/.exec(items)?.[1] : void 0;
1047
+ const separator = void 0 === indent ? ', ' : `,\n${indent}`;
1048
+ return `${items}${separator}${entry}${comma}${whitespace}]`;
1049
+ }).replace('// Playwright runs end-to-end specs\n', '// Playwright runs end-to-end specs, test:integration runs integration ones\n');
1050
+ };
1041
1051
  const testcontainers_stageFile = (filePath, content)=>{
1042
1052
  const file = new File(filePath);
1043
1053
  if (!file.exists || file.data !== content) file.data = content;
@@ -1053,7 +1063,7 @@ const addTestcontainers = async ()=>{
1053
1063
  };
1054
1064
  const selected = await addPackageScripts(manifestFile, testcontainersScripts);
1055
1065
  const withPrisma = new File(node_path.resolve(root, config.rootFolder, 'shared/infrastructure/prisma/prisma.config.ts')).exists;
1056
- const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply']}` : void 0;
1066
+ const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply'].replace(' --advance-ref db', '')}` : void 0;
1057
1067
  const folder = node_path.join(root, integrationFolder);
1058
1068
  testcontainers_stageFile(node_path.join(folder, 'vitest.config.ts'), testcontainersVitestConfig(Boolean(dependencies['@domain-first/handlers-next'])));
1059
1069
  testcontainers_stageFile(node_path.join(folder, 'global-setup.ts'), testcontainersGlobalSetup(migrationCommand));
@@ -1061,7 +1071,14 @@ const addTestcontainers = async ()=>{
1061
1071
  const example = new File(node_path.join(folder, 'database/database.spec.ts'));
1062
1072
  if (!example.exists) example.data = testcontainers_exampleSpec;
1063
1073
  const unitConfig = new File(node_path.join(root, 'vitest.config.ts'));
1064
- const excludedFromUnitTests = !unitConfig.exists || unitConfig.data.includes(integrationFolder);
1074
+ let excludedFromUnitTests = !unitConfig.exists || unitConfig.data.includes(integrationFolder);
1075
+ if (!excludedFromUnitTests) {
1076
+ const excluded = excludeFromUnitTests(unitConfig.data);
1077
+ if (excluded) {
1078
+ unitConfig.update(excluded);
1079
+ excludedFromUnitTests = true;
1080
+ }
1081
+ }
1065
1082
  const missing = [
1066
1083
  'vitest',
1067
1084
  'testcontainers',
@@ -4,4 +4,10 @@ export declare const testcontainersScripts: {
4
4
  export declare const testcontainersVitestConfig: (inlineHandlersNext: boolean) => string;
5
5
  export declare const testcontainersGlobalSetup: (migrationCommand?: string) => string;
6
6
  export declare const testcontainersSetupEnv = "import 'dotenv/config';\nimport { inject } from 'vitest';\n\n// Runs before each spec's imports: development implementations get the .env\n// config, and DATABASE_URL points to the container instead of the one from .env.\nif (process.env.NODE_ENV !== 'development') {\n throw new Error(\n `Integration specs need NODE_ENV=development to wire development implementations, got \"${process.env.NODE_ENV}\"`\n );\n}\n\nprocess.env.DATABASE_URL = inject('databaseUrl');\n";
7
+ /**
8
+ * Adds the integration folder to `test.exclude` of the unit test config.
9
+ * The array is found by `...configDefaults.exclude`, which coverage
10
+ * excludes don't use. Returns `undefined` for configs of another shape.
11
+ */
12
+ export declare const excludeFromUnitTests: (content: string) => string | undefined;
7
13
  export declare const addTestcontainers: () => Promise<string[]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "5.1.0",
4
+ "version": "5.1.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",