Skip to content

Commit 7320dd5

Browse files
committed
Detect and mark Typescript test modules
1 parent ee2949c commit 7320dd5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Add "Test" label for modules that contain tests and test-related implementations
2+
3+
MATCH (m:Module)
4+
WITH m
5+
,(m.globalFqn contains '/__tests__/') OR
6+
(m.globalFqn contains '/test/') OR
7+
(m.globalFqn contains '/tests/') AS isInTestFolder
8+
,(m.globalFqn contains '/__mocks__/') OR
9+
(m.globalFqn contains '/mock/') OR
10+
(m.globalFqn contains '/mocks/') AS isInMockFolder
11+
,(m.globalFqn ENDS WITH '.test.' + m.extension) OR
12+
(m.globalFqn ENDS WITH '/test.' + m.extension) OR
13+
(m.globalFqn ENDS WITH 'Test.' + m.extension) AS isTestExtension
14+
,(m.globalFqn ENDS WITH '.spec.' + m.extension) OR
15+
(m.globalFqn ENDS WITH '/spec.' + m.extension) OR
16+
(m.globalFqn ENDS WITH 'Spec.' + m.extension) AS isSpecificationExtension
17+
//,(m.globalFqn contains 'test') AS isTestMentioned // for debugging
18+
WITH *
19+
,(isTestExtension OR isSpecificationExtension) AS isTest
20+
,isInMockFolder AS isMock
21+
,(isInTestFolder AND NOT isInMockFolder AND NOT isTestExtension AND NOT isSpecificationExtension) AS isTestRelated
22+
WITH *
23+
,CASE WHEN isTest THEN [1] ELSE [] END AS nonEmptyIfTest
24+
,CASE WHEN isMock THEN [1] ELSE [] END AS nonEmptyIfMock
25+
,CASE WHEN isTestRelated THEN [1] ELSE [] END AS nonEmptyIfTestRelated
26+
// Set labels "Test", "Mock" or "TestRelated" and the property "testMarkerInteger" (default=0) to filter projections.
27+
// Numeric properties are required by projections using Neo4j's graph data science library.
28+
SET m.testMarkerInteger = 0
29+
FOREACH (x in nonEmptyIfTest | SET m:Test, m.testMarkerInteger = 1)
30+
FOREACH (x in nonEmptyIfMock | SET m:Mock, m.testMarkerInteger = 2)
31+
FOREACH (x in nonEmptyIfTestRelated | SET m:TestRelated, m.testMarkerInteger = 3)
32+
RETURN isTest, isMock, isTestRelated
33+
,isInTestFolder, isInMockFolder, isTestExtension, isSpecificationExtension
34+
//,isTestMentioned // for debugging
35+
,count(DISTINCT m.globalFqn) AS numberOfModules
36+
,collect(DISTINCT m.globalFqn)[0..4] AS examples

scripts/prepareAnalysis.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ execute_cypher "${CYPHER_DIR}/Create_Typescript_index_for_name.cypher"
5555
# Preparation - Enrich Graph for Typescript by adding "module" and "name" properties
5656
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Index_module_name.cypher"
5757
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_module_properties.cypher"
58+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Mark_test_modules.cypher"
5859

5960
# Preparation - Enrich Graph for Typescript by adding a name properties
6061
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_projects.cypher"

0 commit comments

Comments
 (0)