Skip to content

Commit 1a9ace8

Browse files
committed
added tests for node
1 parent dd004c2 commit 1a9ace8

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

pre_commit/languages/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def install_environment():
3232

3333
with python.in_env() as python_env:
3434
python_env.run('pip install nodeenv')
35-
python_env.run('nodeenv {0}'.format(NODE_ENV))
35+
python_env.run('nodeenv --jobs 4 {0}'.format(NODE_ENV))
3636

3737
with in_env(python_env) as node_env:
3838
node_env.run('npm install -g')

tests/conftest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
import jsonschema
4+
import simplejson
45
import pytest
56
import time
67
from plumbum import local
@@ -75,6 +76,59 @@ def func():
7576
yield dummy_git_repo
7677

7778

79+
@pytest.yield_fixture
80+
def node_pre_commit_git_repo(dummy_git_repo):
81+
local.path(C.MANIFEST_FILE).write("""
82+
-
83+
id: foo
84+
name: Foo
85+
entry: foo
86+
language: node
87+
""")
88+
89+
add_and_commit()
90+
91+
local.path('package.json').write(simplejson.dumps({
92+
'name': 'foo',
93+
'version': '0.0.1',
94+
'bin': {
95+
'foo': './bin/main.js'
96+
},
97+
}))
98+
99+
bin_dir = local.path('bin')
100+
101+
bin_dir.mkdir()
102+
103+
with local.cwd(bin_dir):
104+
local.path('main.js').write(
105+
"""#!/usr/bin/env node
106+
107+
console.log('Hello World');
108+
""")
109+
110+
add_and_commit()
111+
112+
yield dummy_git_repo
113+
114+
115+
@pytest.fixture
116+
def config_for_node_pre_commit_git_repo(node_pre_commit_git_repo):
117+
config = {
118+
'repo': node_pre_commit_git_repo,
119+
'sha': git.get_head_sha(node_pre_commit_git_repo),
120+
'hooks': [{
121+
'id': 'foo',
122+
'files': '*.js',
123+
}],
124+
}
125+
126+
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
127+
128+
return config
129+
130+
131+
78132
@pytest.fixture
79133
def config_for_python_pre_commit_git_repo(python_pre_commit_git_repo):
80134
config = {

tests/repository_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_install_python_repo_in_env(python_pre_commit_git_repo, config_for_pytho
4343

4444

4545
@pytest.mark.integration
46-
def test_run_a_hook_omg(config_for_python_pre_commit_git_repo):
46+
def test_run_a_python_hook(config_for_python_pre_commit_git_repo):
4747
repo = Repository(config_for_python_pre_commit_git_repo)
4848
repo.install()
4949
ret = repo.run_hook('foo', [])
@@ -52,6 +52,15 @@ def test_run_a_hook_omg(config_for_python_pre_commit_git_repo):
5252
assert ret[1] == 'Hello World\n'
5353

5454

55+
@pytest.mark.skipif(True, reason="TODO: make this test not super slow")
56+
def test_run_a_node_hook(config_for_node_pre_commit_git_repo):
57+
repo = Repository(config_for_node_pre_commit_git_repo)
58+
repo.install()
59+
ret = repo.run_hook('foo', [])
60+
61+
assert ret[0] == 0
62+
assert ret[1] == 'Hello World\n'
63+
5564
@pytest.fixture
5665
def mock_repo_config():
5766
config = {
@@ -83,3 +92,5 @@ def test_languages(config_for_python_pre_commit_git_repo):
8392
repo = Repository(config_for_python_pre_commit_git_repo)
8493
assert repo.languages == set(['python'])
8594

95+
96+

0 commit comments

Comments
 (0)