Skip to content

Commit 72fa629

Browse files
committed
wip - discard: test suite generation scripts
1 parent d4a3d99 commit 72fa629

File tree

3 files changed

+84
-0
lines changed

3 files changed

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