Skip to content

Commit

Permalink
Test for node require
Browse files Browse the repository at this point in the history
  • Loading branch information
puremourning committed Mar 6, 2017
1 parent da342f7 commit b507fed
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
37 changes: 26 additions & 11 deletions ycmd/tests/javascript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,29 @@ def IsolatedYcmd( test ):
started, no .ycm_extra_conf.py loaded, etc).
Do NOT attach it to test generators but directly to the yielded tests."""
@functools.wraps( test )
def Wrapper( *args, **kwargs ):
old_server_state = handlers._server_state
app = SetUpApp()
try:
with CurrentWorkingDirectory( PathToTestFile() ):
test( app, *args, **kwargs )
finally:
StopCompleterServer( app, 'javascript' )
handlers._server_state = old_server_state
return Wrapper
return IsolatedYcmdInDirectory( PathToTestFile() )


def IsolatedYcmdInDirectory( directory ):
"""Defines a decorator to be attached to tests of this package. This decorator
passes a unique ycmd application as a parameter running in the directory
supplied. It should be used on tests that change the server state in a
irreversible way (ex: a semantic subserver is stopped or restarted) or expect
a clean state (ex: no semantic subserver started, no .ycm_extra_conf.py
loaded, etc).
Do NOT attach it to test generators but directly to the yielded tests."""
def Decorator( test ):
@functools.wraps( test )
def Wrapper( *args, **kwargs ):
old_server_state = handlers._server_state
app = SetUpApp()
try:
with CurrentWorkingDirectory( directory ):
test( app, *args, **kwargs )
finally:
StopCompleterServer( app, 'javascript' )
handlers._server_state = old_server_state
return Wrapper

return Decorator
31 changes: 29 additions & 2 deletions ycmd/tests/javascript/get_completions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
from pprint import pformat
import requests

from ycmd.tests.javascript import PathToTestFile, SharedYcmd
from ycmd.tests.test_utils import BuildRequest, CompletionEntryMatcher
from ycmd.tests.javascript import ( PathToTestFile, SharedYcmd,
IsolatedYcmdInDirectory )
from ycmd.tests.test_utils import ( BuildRequest, CompletionEntryMatcher,
WaitUntilCompleterServerReady )
from ycmd.utils import ReadFile

# The following properties/methods are in Object.prototype, so are present
Expand Down Expand Up @@ -481,3 +483,28 @@ def GetCompletions_Unicode_InFile_test( app ):
} )
},
} )


@IsolatedYcmdInDirectory( PathToTestFile( 'node' ) )
def GetCompletions_ChangeStartColumn_test( app ):
WaitUntilCompleterServerReady( app, 'javascript' )
RunTest( app, {
'description': 'the completion_start_column is updated by tern',
'request': {
'filetype' : 'javascript',
'filepath' : PathToTestFile( 'node', 'node_test.js' ),
'line_num' : 1,
'column_num' : 17,
'force_semantic': True,
},
'expect': {
'response': requests.codes.ok,
'data': has_entries( {
'completions': contains(
CompletionEntryMatcher( '"path"', 'path' )
),
'completion_start_column': 14,
'errors': empty(),
} )
},
} )
5 changes: 5 additions & 0 deletions ycmd/tests/javascript/testdata/node/.tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": {
"node": {}
}
}
2 changes: 2 additions & 0 deletions ycmd/tests/javascript/testdata/node/node_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p = require( "path" )
p.jo

0 comments on commit b507fed

Please sign in to comment.