it('Test 040 : should have getBySize method returning resource with size specified or null', function () { expect(cfg.getStaticResources('windows', 'icon').getBySize(128)).toBe(null); expect(cfg.getStaticResources('windows', 'icon').getBySize(72)).toBeDefined(); expect(cfg.getStaticResources('windows', 'icon').getBySize(72).width).toBe(72); expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48)).toBeDefined(); expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48).height).toBe(48); });
it('should be a 400 error with a cause', function () { var cause = 'Unexpected character: \';\''; var e = new HttpError(HttpError.statusCodes.BAD_REQUEST, 'Invalid JSON', cause); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(400); expect(e.statusReason).toBe('Bad request'); expect(e.message).toBe('Invalid JSON'); expect(e.causes).toEqual([cause]); expect(e.toString()).toBe('HttpError: Invalid JSON'); });
it('should not trigger the log READOUT if no entries', function() { var data = new Buffer([0x0,0x0,0x0,0x0]); log.downloadLog(); expect(device.send.calls.any()).toBe(true); device.send.calls.reset(); device.emitter.emit([MODULE, LENGTH], data, MODULE.toString(16), LENGTH.toString(16)); expect(device.send.calls.any()).toBe(false); });
it('Test 019 : should map an empty directory', function () { mockFs.statMap[path.join(testRootDir, testSourceDir)] = testDirStats; mockFs.dirMap[path.join(testRootDir, testSourceDir)] = []; const dirMap = FileUpdater.mapDirectory(testRootDir, testSourceDir, ['**'], []); expect(Object.keys(dirMap)).toEqual(['']); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); });
it('Test 002 : should expose default levels as constants', function () { DEFAULT_LEVELS.forEach(function (level) { const constant = level.toUpperCase(); expect(CordovaLogger[constant]).toBeDefined(); expect(CordovaLogger[constant]).toBe(level); }); });
it('Test 012 : should remove and mkdir when source is a directory and target is a file', function () { const updated = FileUpdater.updatePathWithStats( testSourceDir, mockDirStats(), testTargetDir, mockFileStats(now)); expect(updated).toBe(true); expect(mockFs.cpPaths.length).toBe(0); expect(mockFs.rmPaths.length).toBe(1); expect(mockFs.mkdirPaths.length).toBe(1); expect(mockFs.rmPaths[0]).toBe(testTargetDir); expect(mockFs.mkdirPaths[0]).toBe(testTargetDir); });
it('Test 002 : should return new instance for every PluginManager.get call', function () { expect(PluginManager.get(FAKE_PLATFORM, FAKE_LOCATIONS)).toEqual(jasmine.any(PluginManager)); expect(PluginManager.get(FAKE_PLATFORM, FAKE_LOCATIONS)) .not.toBe(PluginManager.get(FAKE_PLATFORM, FAKE_LOCATIONS)); });
it('Test 023 : should include files that match include globs', function () { mockFs.statMap[testSourceDir] = testDirStats; mockFs.dirMap[testSourceDir] = [testSourceFile, testSourceFile2]; mockFs.statMap[path.join(testSourceDir, testSourceFile)] = testFileStats; mockFs.statMap[path.join(testSourceDir, testSourceFile2)] = testFileStats; const dirMap = FileUpdater.mapDirectory('', testSourceDir, [testSourceFile], []); expect(Object.keys(dirMap).sort()).toEqual(['', testSourceFile]); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); expect(dirMap[testSourceFile].subDir).toBe(testSourceDir); expect(dirMap[testSourceFile].stats).toBe(testFileStats); });
it('Test 010 : should copy when a file exists at source and not at target', function () { const updated = FileUpdater.updatePathWithStats( testSourceFile, mockFileStats(now), testTargetFile, null); expect(updated).toBe(true); expect(mockFs.cpPaths.length).toBe(1); expect(mockFs.rmPaths.length).toBe(0); expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]); });
it('Test 036 : should fetch platform-specific resources along with shared if platform parameter is specified', function () { expect(cfg.getStaticResources('android', 'icon').length).toBe(5); expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyDefined)).toBeTruthy(); expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).length).toBe(3); expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyUndefined)).toBeTruthy(); });
it('Test 008 : should copy when a file exists at source and target and target is newer ' + 'and forcing update', function () { const updated = FileUpdater.updatePathWithStats( testSourceFile, mockFileStats(oneHourAgo), testTargetFile, mockFileStats(now), { all: true }); expect(updated).toBe(true); expect(mockFs.cpPaths.length).toBe(1); expect(mockFs.rmPaths.length).toBe(0); expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]); });
it('should trigger the log READOUT specifying the correct number of entries to be notified for 0.05 notification progress', function() { var data = new Buffer([0x68,0x8,0x0,0x0]); log.downloadLog(); expect(device.send.calls.any()).toBe(true); device.send.calls.reset(); device.emitter.emit([MODULE, LENGTH], data, MODULE.toString(16), LENGTH.toString(16)); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0xb,0x6,0x68,0x8,0x0,0x0,0x6b,0x0,0x0,0x0])); });
it('Test 020 : should map a directory with a file', function () { mockFs.statMap[path.join(testRootDir, testSourceDir)] = testDirStats; mockFs.dirMap[path.join(testRootDir, testSourceDir)] = [testSourceFile]; mockFs.statMap[path.join(testRootDir, testSourceDir, testSourceFile)] = testFileStats; const dirMap = FileUpdater.mapDirectory(testRootDir, testSourceDir, ['**'], []); expect(Object.keys(dirMap).sort()).toEqual(['', testSourceFile]); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); expect(dirMap[testSourceFile].subDir).toBe(testSourceDir); expect(dirMap[testSourceFile].stats).toBe(testFileStats); });
it('Test 021 : should map a directory with a subdirectory', function () { mockFs.statMap[testSourceDir] = testDirStats; mockFs.dirMap[testSourceDir] = [testSubDir]; mockFs.statMap[path.join(testSourceDir, testSubDir)] = testDirStats; mockFs.dirMap[path.join(testSourceDir, testSubDir)] = []; const dirMap = FileUpdater.mapDirectory('', testSourceDir, ['**'], []); expect(Object.keys(dirMap).sort()).toEqual(['', testSubDir]); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); expect(dirMap[testSubDir].subDir).toBe(testSourceDir); expect(dirMap[testSubDir].stats).toBe(testDirStats); });
it('Test 009 : should copy when a file exists at source and target and source is newer', function () { const updated = FileUpdater.updatePathWithStats( testSourceFile, mockFileStats(now), testTargetFile, mockFileStats(oneHourAgo)); expect(updated).toBe(true); expect(mockFs.cpPaths.length).toBe(1); expect(mockFs.rmPaths.length).toBe(0); expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]); });