@@ -6,7 +6,12 @@ import {
66} from "../../utils/test-head" ;
77
88import readFixture from "./helpers/readFixture" ;
9- const { getSymbols, getEmptyLines, getOutOfScopeLocations } = selectors ;
9+ const {
10+ getSymbols,
11+ getEmptyLines,
12+ getOutOfScopeLocations,
13+ getSourceMetaData
14+ } = selectors ;
1015import getInScopeLines from "../../selectors/linesInScope" ;
1116
1217const threadClient = {
@@ -31,7 +36,8 @@ const threadClient = {
3136const sourceTexts = {
3237 "base.js" : "function base(boo) {}" ,
3338 "foo.js" : "function base(boo) { return this.bazz; } outOfScope" ,
34- "scopes.js" : readFixture ( "scopes.js" )
39+ "scopes.js" : readFixture ( "scopes.js" ) ,
40+ "reactComponent.js" : readFixture ( "reactComponent.js" )
3541} ;
3642
3743const evaluationResult = {
@@ -51,6 +57,26 @@ describe("ast", () => {
5157 expect ( emptyLines ) . toMatchSnapshot ( ) ;
5258 } ) ;
5359 } ) ;
60+ describe ( "setSourceMetaData" , ( ) => {
61+ it ( "should detect react components" , async ( ) => {
62+ const { dispatch, getState } = createStore ( threadClient ) ;
63+ const source = makeSource ( "reactComponent.js" ) ;
64+ await dispatch ( actions . newSource ( source ) ) ;
65+ await dispatch ( actions . loadSourceText ( { id : "reactComponent.js" } ) ) ;
66+
67+ const sourceMetaData = getSourceMetaData ( getState ( ) , source . id ) ;
68+ expect ( sourceMetaData ) . toEqual ( { isReactComponent : true } ) ;
69+ } ) ;
70+ it ( "should not give false positive on non react components" , async ( ) => {
71+ const { dispatch, getState } = createStore ( threadClient ) ;
72+ const source = makeSource ( "base.js" ) ;
73+ await dispatch ( actions . newSource ( source ) ) ;
74+ await dispatch ( actions . loadSourceText ( { id : "base.js" } ) ) ;
75+
76+ const sourceMetaData = getSourceMetaData ( getState ( ) , source . id ) ;
77+ expect ( sourceMetaData ) . toEqual ( { isReactComponent : false } ) ;
78+ } ) ;
79+ } ) ;
5480 describe ( "setSymbols" , ( ) => {
5581 describe ( "when the source is loaded" , ( ) => {
5682 it ( "should be able to set symbols" , async ( ) => {
0 commit comments