def test_ls_ext_deps_come_before_local(): fs = FakeFileSystem() fs.create_dir('plugins/portals') # local deps deplist = "fileupload\nunderscore\n" fs.create_file('plugins/portals/dependencies', deplist) # external deps package = { 'dependencies': { 'fileupload': '/some/url', 'underscore': '/other/url' } } fs.create_file('plugins/portals/package.json', json.dumps(package)) fs.create_dir('plugins/portals/node_modules/fileupload/src') fs.create_dir('plugins/portals/node_modules/underscore/src') scan_path = ScanPath(fs, 'plugins') paths = scan_path.ls('portals') assert paths == [ 'plugins/portals/node_modules/fileupload', 'plugins/portals/node_modules/underscore', 'plugins/common/fileupload', 'plugins/common/underscore', 'plugins/portals' ]
def test_create_file_without_all_parent_dirs_throws_error(): fs = FakeFileSystem() with raises(IOError): dependency_file_content = 'something' fs.create_file('/plugins/portals/dependencies', dependency_file_content)
def test_create_files_same_dir(): fs = FakeFileSystem() fs.create_dir('test-dir') fs.create_file('test-dir/hi.txt', 'hi') fs.create_file('test-dir/hello.txt', 'hello') with fs.open('test-dir/hi.txt') as f: assert f.read() == 'hi' with fs.open('test-dir/hello.txt') as f: assert f.read() == 'hello'
def test_create_dir_and_file(): fs = FakeFileSystem() fs.create_dir('/plugins/portals') dependency_file_content = 'fileupload\nunderscore\n' fs.create_file('/plugins/portals/dependencies', dependency_file_content) with fs.open('/plugins/portals/dependencies') as f: dependency_names = f.read().splitlines() assert dependency_names[0] == 'fileupload'
def test_paths_with_extension_when_flat_dir(): fs = FakeFileSystem() fs.create_dir('test-dir') fs.create_file('test-dir/hi.txt') fs.create_file('test-dir/hello.js') fs.create_file('test-dir/hello.txt') fs.create_file('test-dir/something.css') fs.create_file('test-dir/.gitignore') paths = fs.paths_with_extension('test-dir', 'txt') assert paths == ['test-dir/hi.txt', 'test-dir/hello.txt']
def test_ls_when_package_json_without_external_deps(): fs = FakeFileSystem() fs.create_dir('plugins/portals') package = { 'name': 'portal' } fs.create_file('plugins/portals/package.json', json.dumps(package)) scan_path = ScanPath(fs, 'plugins') paths = scan_path.ls('portals') assert paths == [ 'plugins/portals' ]
def test_ls_local_deps(): fs = FakeFileSystem() fs.create_dir('plugins/portals') deplist = "fileupload\nunderscore\n" fs.create_file('plugins/portals/dependencies', deplist) scan_path = ScanPath(fs, 'plugins') paths = scan_path.ls('portals') assert paths == [ 'plugins/common/fileupload', 'plugins/common/underscore', 'plugins/portals' ]
def test_ls_when_package_json_with_external_dep_without_src_folder(): fs = FakeFileSystem() fs.create_dir('plugins/portals') package = { 'dependencies': { 'fileupload': '/some/url' } } fs.create_file('plugins/portals/package.json', json.dumps(package)) fs.create_dir('plugins/portals/node_modules/fileupload') scan_path = ScanPath(fs, 'plugins') paths = scan_path.ls('portals') assert paths == [ 'plugins/portals' ]
def test_paths_with_extension_when_nested_dirs(): fs = FakeFileSystem() fs.create_dir('test-dir') fs.create_file('test-dir/hi.txt') fs.create_dir('test-dir/src') fs.create_file('test-dir/src/hello.js') fs.create_dir('test-dir/docs') fs.create_file('test-dir/docs/hello.txt') fs.create_file('test-dir/.gitignore') paths = fs.paths_with_extension('test-dir', 'txt') assert paths == ['test-dir/hi.txt', 'test-dir/docs/hello.txt']
def test_ls_when_package_json_with_external_deps(): fs = FakeFileSystem() fs.create_dir('plugins/portals') package = """{ "dependencies": { "zn-underscore": "/other/url", "apples": "/other/url", "fileupload": "/some/url" } }""" fs.create_file('plugins/portals/package.json', package) fs.create_dir('plugins/portals/node_modules/zn-underscore/src') fs.create_dir('plugins/portals/node_modules/apples/src') fs.create_dir('plugins/portals/node_modules/fileupload/src') scan_path = ScanPath(fs, 'plugins') paths = scan_path.ls('portals') assert paths == [ 'plugins/portals/node_modules/zn-underscore', 'plugins/portals/node_modules/apples', 'plugins/portals/node_modules/fileupload', 'plugins/portals' ]