Skip to content

Commit 87e205d

Browse files
committed
wip - discard: test suite generation scripts
1 parent 0d72c4d commit 87e205d

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import Directory from '../../@internal/Directory';
2+
import File from '../../@internal/File';
3+
import FilesystemPath from '../../@internal/FilesystemPath';
4+
5+
interface TestCompanionCreationResult {
6+
created: boolean;
7+
pathForTestFile: string;
8+
}
9+
10+
// take a given file path and generate a stub for a test suite
11+
function createAndSaveTestCompanionForUnitWith(
12+
givenAbsolutePath: string,
13+
): TestCompanionCreationResult {
14+
const componentsOfAbsolutePath = givenAbsolutePath.split('/');
15+
const fileNameWithExtension = componentsOfAbsolutePath.pop() ?? '';
16+
const [fileName, fileExtension] = fileNameWithExtension.split('.');
17+
18+
if (
19+
!fileName || !fileExtension
20+
) throw new Error(`Could not parse file name and extension from: ${givenAbsolutePath}`); // eslint-disable-line no-restricted-syntax -- "@/library/Attempt is not accessible outside of src"
21+
22+
const testFileName = `${fileName}.test.${fileExtension}`;
23+
const absolutePathToTestCompanion = [...componentsOfAbsolutePath, testFileName].join('/');
24+
const symbolName = 'someSymbol';
25+
26+
const contentsOfTestCompanion = `import {
27+
describe,
28+
} from 'vitest';
29+
30+
import {
31+
${symbolName},
32+
} from './${fileNameWithExtension}';
33+
34+
describe.todo(${symbolName});
35+
`;
36+
37+
const pathToTestCompanion = FilesystemPath.parsedFrom(absolutePathToTestCompanion);
38+
const pathToDirectoryOfTestCompanion = FilesystemPath.parsedFrom(pathToTestCompanion.dir);
39+
40+
if (
41+
!File.doesExistAt(pathToDirectoryOfTestCompanion)
42+
) Directory.createAt(pathToDirectoryOfTestCompanion);
43+
44+
const testCompanionShouldBeCreated = !File.doesExistAt(pathToTestCompanion);
45+
46+
if (
47+
testCompanionShouldBeCreated
48+
) File.write({
49+
contents: contentsOfTestCompanion,
50+
to : pathToTestCompanion,
51+
});
52+
53+
return {
54+
created : testCompanionShouldBeCreated,
55+
pathForTestFile: absolutePathToTestCompanion,
56+
};
57+
}
58+
59+
const inputPath = process.argv[2];
60+
61+
if (!inputPath) {
62+
console.error('Usage: npx jiti scripts/generate-stub-for-test-suite.ts <path-to-source-file.ts>');
63+
process.exit(1);
64+
}
65+
66+
// eslint-disable-next-line no-restricted-syntax -- "@/library/Attempt is not accessible outside of src"
67+
try {
68+
const result = createAndSaveTestCompanionForUnitWith(inputPath);
69+
70+
const messageForResult = result.created
71+
? `Created test stub: ${result.pathForTestFile}`
72+
: `Test file already exists: ${result.pathForTestFile}`;
73+
74+
console.log(messageForResult);
75+
}
76+
catch (err) {
77+
console.error('Error:', (err as Error).message);
78+
process.exit(1);
79+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {
2+
describe,
3+
} from 'vitest';
4+
5+
import {
6+
toSharkUIOutput_Image_Description_all,
7+
} from './all.ts';
8+
9+
describe.todo(toSharkUIOutput_Image_Description_all);

tsconfig.node.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"vitest/**/*",
88
"cypress/eslint.config.*",
99
"cypress/package.d.ts",
10+
"scripts/**/*"
1011
],
1112
"compilerOptions": {
1213
"noEmit": true,

0 commit comments

Comments
 (0)