Skip to content

Commit e0f5f2e

Browse files
committed
Add infrastructure to avoid hacky comment/uncomment testing code
1 parent bbbff08 commit e0f5f2e

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/CommandLineOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface MultiProjectOptions {
1717
cwd: string
1818
output: string
1919
indexedProjects: Set<string>
20+
shouldIndexFile?: (filename: string) => boolean
2021
}
2122

2223
/** Configuration options to index a single TypeScript project. */

src/FileIndexer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ export class FileIndexer {
3939
this.workingDirectoryRegExp = new RegExp(options.cwd, 'g')
4040
}
4141
public index(): void {
42-
// Uncomment below if you want to skip certain files for local development.
43-
// if (!this.sourceFile.fileName.includes('infer-relation')) {
44-
// return
45-
// }
42+
if (this.options.shouldIndexFile?.(this.sourceFile.fileName) === false) {
43+
return
44+
}
4645
this.emitSourceFileOccurrence()
4746
this.visit(this.sourceFile)
4847
}

src/main.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function isUpdateSnapshot(): boolean {
1515
return process.argv.includes('--update-snapshots')
1616
}
1717

18+
const onlyFile = process.env['ONLY']
19+
const onlyAbsoluteFilename = onlyFile ? join(process.cwd(), onlyFile) : ''
20+
1821
const snapshotNodeModules = join(process.cwd(), 'snapshots', 'node_modules')
1922
if (!fs.existsSync(snapshotNodeModules)) {
2023
throw new Error(
@@ -34,16 +37,14 @@ interface PackageJson {
3437
packageManager?: string
3538
}
3639
for (const snapshotDirectory of snapshotDirectories) {
37-
// Uncomment below if you want to skip certain tests for local development.
38-
// if (!snapshotDirectory.includes('syntax')) {
39-
// continue
40-
// }
4140
const inputRoot = join(inputDirectory, snapshotDirectory)
4241
const outputRoot = join(outputDirectory, snapshotDirectory)
4342
if (!fs.statSync(inputRoot).isDirectory()) {
4443
continue
4544
}
46-
test(snapshotDirectory, () => {
45+
const testFunction =
46+
onlyFile && !onlyAbsoluteFilename.startsWith(inputRoot) ? test.skip : test
47+
testFunction(snapshotDirectory, () => {
4748
const packageJsonPath = path.join(inputRoot, 'package.json')
4849
const packageJson = JSON.parse(
4950
fs.readFileSync(packageJsonPath).toString()
@@ -61,6 +62,12 @@ for (const snapshotDirectory of snapshotDirectories) {
6162
progressBar: false,
6263
indexedProjects: new Set(),
6364
globalCaches: true,
65+
shouldIndexFile: filename => {
66+
if (onlyFile) {
67+
return filename === onlyAbsoluteFilename
68+
}
69+
return true
70+
},
6471
})
6572
if (inferTsconfig) {
6673
fs.rmSync(tsconfigJsonPath)

0 commit comments

Comments
 (0)