added tests for node

This commit is contained in:
Ken Struys 2014-03-14 11:25:23 -07:00
parent dd004c2ee5
commit 1a9ace859a
3 changed files with 67 additions and 2 deletions

View file

@ -1,6 +1,7 @@
from __future__ import absolute_import
import jsonschema
import simplejson
import pytest
import time
from plumbum import local
@ -75,6 +76,59 @@ def func():
yield dummy_git_repo
@pytest.yield_fixture
def node_pre_commit_git_repo(dummy_git_repo):
local.path(C.MANIFEST_FILE).write("""
-
id: foo
name: Foo
entry: foo
language: node
""")
add_and_commit()
local.path('package.json').write(simplejson.dumps({
'name': 'foo',
'version': '0.0.1',
'bin': {
'foo': './bin/main.js'
},
}))
bin_dir = local.path('bin')
bin_dir.mkdir()
with local.cwd(bin_dir):
local.path('main.js').write(
"""#!/usr/bin/env node
console.log('Hello World');
""")
add_and_commit()
yield dummy_git_repo
@pytest.fixture
def config_for_node_pre_commit_git_repo(node_pre_commit_git_repo):
config = {
'repo': node_pre_commit_git_repo,
'sha': git.get_head_sha(node_pre_commit_git_repo),
'hooks': [{
'id': 'foo',
'files': '*.js',
}],
}
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
return config
@pytest.fixture
def config_for_python_pre_commit_git_repo(python_pre_commit_git_repo):
config = {

View file

@ -43,7 +43,7 @@ def test_install_python_repo_in_env(python_pre_commit_git_repo, config_for_pytho
@pytest.mark.integration
def test_run_a_hook_omg(config_for_python_pre_commit_git_repo):
def test_run_a_python_hook(config_for_python_pre_commit_git_repo):
repo = Repository(config_for_python_pre_commit_git_repo)
repo.install()
ret = repo.run_hook('foo', [])
@ -52,6 +52,15 @@ def test_run_a_hook_omg(config_for_python_pre_commit_git_repo):
assert ret[1] == 'Hello World\n'
@pytest.mark.skipif(True, reason="TODO: make this test not super slow")
def test_run_a_node_hook(config_for_node_pre_commit_git_repo):
repo = Repository(config_for_node_pre_commit_git_repo)
repo.install()
ret = repo.run_hook('foo', [])
assert ret[0] == 0
assert ret[1] == 'Hello World\n'
@pytest.fixture
def mock_repo_config():
config = {
@ -83,3 +92,5 @@ def test_languages(config_for_python_pre_commit_git_repo):
repo = Repository(config_for_python_pre_commit_git_repo)
assert repo.languages == set(['python'])