@domain-first/project-structure 5.1.0 → 5.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/dist/index.cjs +18 -1
- package/dist/index.js +18 -1
- package/dist/integrations/testcontainers.d.ts +6 -0
- package/package.json +1 -1
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;
|
|
@@ -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
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
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[]>;
|