Skip to content

Commit cac25e3

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

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

src/CommandLineOptions.ts

+1
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

+30-4
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
}
@@ -172,6 +171,14 @@ export class FileIndexer {
172171
: sym?.declarations || []
173172
for (const declaration of declarations) {
174173
let scipSymbol = this.scipSymbol(declaration)
174+
if (scipSymbol.value === 'local 4') {
175+
console.log({
176+
node: node.getText(),
177+
kind: ts.SyntaxKind[node.kind],
178+
kind2: ts.SyntaxKind[node.parent.kind],
179+
kind3: ts.SyntaxKind[node.parent.parent.kind],
180+
})
181+
}
175182

176183
if (
177184
((ts.isIdentifier(node) && ts.isNewExpression(node.parent)) ||
@@ -399,6 +406,25 @@ export class FileIndexer {
399406
}
400407
return this.cached(node, package_)
401408
}
409+
410+
if (
411+
node?.parent?.parent &&
412+
ts.isIdentifier(node) &&
413+
ts.isMethodDeclaration(node.parent) &&
414+
node.parent.name === node &&
415+
ts.isObjectLiteralExpression(node.parent.parent)
416+
) {
417+
const tpe = this.assignedType.get(node.parent.parent)
418+
const property = tpe?.getProperty(node.getText())
419+
console.log({
420+
node: node.getText(),
421+
tpe: tpe && this.checker.typeToString(tpe),
422+
})
423+
if (property?.declarations && property.declarations.length > 0) {
424+
return this.cached(node, this.scipSymbol(property.declarations[0]))
425+
}
426+
}
427+
402428
if (
403429
ts.isPropertyAssignment(node) ||
404430
ts.isShorthandPropertyAssignment(node)

src/main.test.ts

+12-5
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)