示例#1
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Upload local copy of source archive to speed up tests
    local_cache = '~/.vagrant.d/cache/fabtools/node-v%s.tar.gz' % nodejs.DEFAULT_VERSION
    if os.path.exists(local_cache):
        put(local_cache)

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') == None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) == None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
示例#2
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') is None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json',
                     contents=json.dumps({
                         'name': 'nodetest',
                         'version': '1.0.0',
                         'dependencies': {
                             'underscore': '1.4.2'
                         }
                     }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
示例#3
0
def install_nodejs():
    """
    Test low level API
    """

    from fabtools import nodejs
    from fabtools import require
    from fabtools.files import is_file

    # Install Node.js from source
    if nodejs.version() != nodejs.DEFAULT_VERSION:
        nodejs.install_from_source()

    assert is_file('/usr/local/bin/node')
    assert nodejs.version() == nodejs.DEFAULT_VERSION

    # Install / uninstall global package
    if not nodejs.package_version('underscore'):
        nodejs.install_package('underscore', version='1.4.2')

    assert nodejs.package_version('underscore') == '1.4.2'
    assert is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    nodejs.uninstall_package('underscore')

    assert nodejs.package_version('underscore') is None
    assert not is_file('/usr/local/lib/node_modules/underscore/underscore.js')

    # Install / uninstall local package
    if not nodejs.package_version('underscore', local=True):
        nodejs.install_package('underscore', version='1.4.2', local=True)

    assert is_file('node_modules/underscore/underscore.js')
    assert nodejs.package_version('underscore', local=True) == '1.4.2'

    nodejs.uninstall_package('underscore', local=True)

    assert nodejs.package_version('underscore', local=True) is None
    assert not is_file('node_modules/underscore/underscore.js')

    # Install dependencies from package.json file
    require.directory('nodetest')
    with cd('nodetest'):
        require.file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        nodejs.install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert nodejs.package_version('underscore', local=True) == '1.4.2'
示例#4
0
def test_install_dependencies_from_package_json_file(nodejs, testdir):

    from fabtools.nodejs import install_dependencies, package_version, uninstall_package

    with cd(testdir):
        require_file(
            "package.json",
            contents=json.dumps({"name": "nodetest", "version": "1.0.0", "dependencies": {"underscore": "1.4.2"}}),
        )

        install_dependencies()

        assert is_file("node_modules/underscore/underscore.js")
        assert package_version("underscore", local=True) == "1.4.2"

        uninstall_package("underscore", local=True)
示例#5
0
def test_install_dependencies_from_package_json_file(nodejs, testdir):

    from fabtools.nodejs import install_dependencies, package_version, uninstall_package

    with cd(testdir):
        require_file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert package_version('underscore', local=True) == '1.4.2'

        uninstall_package('underscore', local=True)
示例#6
0
def test_install_dependencies_from_package_json_file(nodejs, testdir):

    from fabtools.nodejs import install_dependencies, package_version, uninstall_package

    with cd(testdir):
        require_file('package.json', contents=json.dumps({
            'name': 'nodetest',
            'version': '1.0.0',
            'dependencies': {
                'underscore': '1.4.2'
            }
        }))

        install_dependencies()

        assert is_file('node_modules/underscore/underscore.js')
        assert package_version('underscore', local=True) == '1.4.2'

        uninstall_package('underscore', local=True)
示例#7
0
def ensure_packages_node():
    nodejs.install_dependencies(npm='yarn')