const assertDoesNotThrow = async (opts?: { shouldStartApplicatinThrow: boolean }) => { assert.deepEqual(logger.traceOutput, ""); applicationManager.startApplication = async (appData: Mobile.IApplicationData) => { if (opts && opts.shouldStartApplicatinThrow) { throw error; } isStartApplicationCalled = true; }; await applicationManager.tryStartApplication(applicationData); assert.isFalse(isStartApplicationCalled, "startApplication must not be called when there's an error."); assert.isTrue(logger.traceOutput.indexOf("Throw!") !== -1, "Error message must be shown in trace output."); assert.isTrue(logger.traceOutput.indexOf("Unable to start application") !== -1, "'Unable to start application' must be shown in trace output."); };
it('recognizes valid and invalid url parameter combinations according to provided rules', ()=>{ assert.isTrue( validateParameters({ studyId:'someString', sampleId:'someString' }, [ 'studyId', ['sampleId', 'caseId']]).isValid ); assert.isTrue( validateParameters({ studyId:'someString', caseId:'someString' }, [ 'studyId', ['sampleId', 'caseId']]).isValid ); assert.isFalse( validateParameters({ studyId:'someString', sampleId:'' }, [ 'studyId', ['sampleId', 'caseId']]).isValid, 'non zero length string required' ) assert.isFalse( validateParameters({ studyId:'someString', sampleId:'' }, [ 'param1', ['sampleId', 'caseId']]).isValid, 'non zero length string required' ) assert.isFalse( validateParameters({ sampleId:'' }, [ 'studyId', ['sampleId', 'caseId']]).isValid, 'missing parameter recognized' ) });
return (() => { let fs: IFileSystem = this.testInjector.resolve("fs"); let projectDir = path.join(tempFolder, projectName); let appDirectoryPath = path.join(projectDir, "app"); let platformsDirectoryPath = path.join(projectDir, "platforms"); let tnsProjectFilePath = path.join(projectDir, "package.json"); let tnsModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME, constants.TNS_CORE_MODULES_NAME); let packageJsonContent = fs.readJson(tnsProjectFilePath).wait(); let options = this.testInjector.resolve("options"); assert.isTrue(fs.exists(appDirectoryPath).wait()); assert.isTrue(fs.exists(platformsDirectoryPath).wait()); assert.isTrue(fs.exists(tnsProjectFilePath).wait()); assert.isTrue(fs.exists(tnsModulesPath).wait()); assert.isFalse(fs.isEmptyDir(appDirectoryPath).wait()); assert.isTrue(fs.isEmptyDir(platformsDirectoryPath).wait()); let actualAppId = packageJsonContent["nativescript"].id; let expectedAppId = appId; assert.equal(actualAppId, expectedAppId); let tnsCoreModulesRecord = packageJsonContent["dependencies"][constants.TNS_CORE_MODULES_NAME]; assert.isTrue(tnsCoreModulesRecord !== null); let sourceDir = projectSourceDirectory || options.copyFrom; let expectedFiles = fs.enumerateFilesInDirectorySync(sourceDir); let actualFiles = fs.enumerateFilesInDirectorySync(appDirectoryPath); assert.isTrue(actualFiles.length >= expectedFiles.length, "Files in created project must be at least as files in app dir."); _.each(expectedFiles, file => { let relativeToProjectDir = helpers.getRelativeToRootPath(sourceDir, file); let filePathInApp = path.join(appDirectoryPath, relativeToProjectDir); assert.isTrue(fs.exists(filePathInApp).wait(), `File ${filePathInApp} does not exist.`); }); // assert dependencies and devDependencies are copied from template to real project let sourcePackageJsonContent = fs.readJson(path.join(sourceDir, "package.json")).wait(); let missingDeps = _.difference(_.keys(sourcePackageJsonContent.dependencies), _.keys(packageJsonContent.dependencies)); let missingDevDeps = _.difference(_.keys(sourcePackageJsonContent.devDependencies), _.keys(packageJsonContent.devDependencies)); assert.deepEqual(missingDeps, [], `All dependencies from template must be copied to project's package.json. Missing ones are: ${missingDeps.join(", ")}.`); assert.deepEqual(missingDevDeps, [], `All devDependencies from template must be copied to project's package.json. Missing ones are: ${missingDevDeps.join(", ")}.`); // assert App_Resources are prepared correctly let appResourcesDir = path.join(appDirectoryPath, "App_Resources"); let appResourcesContents = fs.readDirectory(appResourcesDir).wait(); assert.deepEqual(appResourcesContents, ["Android", "iOS"], "Project's app/App_Resources must contain Android and iOS directories."); }).future<void>()();
it("should verify IsOffline", function() { let reason: any = { code: "ENOENT" }; assert.isTrue(Utils.IsOffline(reason)); reason = { code: "ENOTFOUND" }; assert.isTrue(Utils.IsOffline(reason)); reason = { code: "EAI_AGAIN" }; assert.isTrue(Utils.IsOffline(reason)); let reason2: any = { statusCode: "ENOENT" }; assert.isTrue(Utils.IsOffline(reason2)); reason2 = { statusCode: "ENOTFOUND" }; assert.isTrue(Utils.IsOffline(reason2)); reason2 = { statusCode: "EAI_AGAIN" }; assert.isTrue(Utils.IsOffline(reason2)); reason = { code: "404" }; assert.isFalse(Utils.IsOffline(reason)); });
it('should trigger gpio on updating schedule', function () { const clock = sinon.useFakeTimers(new Date(2016, 8, 20, 10, 0, 0).getTime()); const gpioController = new MockGpioController(); const controller = new ScheduleController(gpioController, new Schedule()); assert.equal(gpioController.state, false); const schedule = new Schedule(); schedule.includeHour(10); controller.updateSchedule(schedule); assert.equal(gpioController.state, true); clock.tick(61 * 60 * 1000); assert.isFalse(gpioController.state); clock.restore(); });
it("should verify TeamServices origin remote", function() { const repoName: string = "gitrepo"; const repoPath: string = path.join(__dirname, TEST_REPOS_FOLDER, repoName, DOT_GIT_FOLDER); const gc: GitContext = new GitContext(repoPath, DOT_GIT_FOLDER); assert.equal(gc.CurrentBranch, "jeyou/approved-pr"); assert.equal(gc.CurrentRef, "refs/heads/jeyou/approved-pr"); assert.isFalse(gc.IsSsh); assert.isTrue(gc.IsTeamFoundation); assert.isTrue(gc.IsTeamServices); assert.equal(gc.RemoteUrl, "https://account.visualstudio.com/DefaultCollection/teamproject/_git/gitrepo"); assert.equal(gc.RepositoryParentFolder, path.join(__dirname, TEST_REPOS_FOLDER, repoName)); assert.equal(gc.RepoFolder, repoPath); assert.isUndefined(gc.TeamProjectName); //For Git repositories, teamproject comes from vsts/info (not remoteUrl) assert.equal(gc.Type, RepositoryType.GIT); });
const assertIsCalled = async (methodName: string): Promise<void> => { const instance: any = new InvokeBeforeDecoratorsTest(); assert.isFalse(instance.isInvokeBeforeMethodCalled); const expectedResult = 1; assert.deepEqual(await instance[methodName](expectedResult), expectedResult); assert.isTrue(instance.isInvokeBeforeMethodCalled); instance.invokedBeforeCount = 0; for (let iteration = 0; iteration < 10; iteration++) { instance.isInvokeBeforeMethodCalled = false; assert.deepEqual(await instance[methodName](iteration), iteration); assert.isTrue(instance.isInvokeBeforeMethodCalled); assert.deepEqual(instance.invokedBeforeCount, iteration + 1); } };
test('calling dependencies() starts analysis', () => { const config = new ProjectConfig({ root: `test-fixtures/analyzer-data`, entrypoint: 'entrypoint.html', fragments: [ 'a.html', 'b.html', ], sources: ['a.html', 'b.html', 'entrypoint.html'], }); const analyzer = new BuildAnalyzer(config); assert.isFalse(analyzer.started); analyzer.dependencies().pipe(new NoopStream()); assert.isTrue(analyzer.started); });
PRIMITIVE_MARKS.forEach((mark) => { const spec = { "data": {"url": "data/barley.json"}, "mark": mark, "encoding": { "x": {"aggregate": "sum", "field": "yield", "type": "quantitative"}, "y": {"field": "variety", "type": "nominal"}, "color": {"aggregate": "count", "field": "*", "type": "quantitative"} }, "config": { "mark": {"stacked": stacked} } }; assert.isNull(stack(spec.mark, spec.encoding as any, spec.config)); assert.isFalse(isStacked(spec as any)); });
it("should verify 'collection in the domain' case insensitivity in repositoryInfo to RepositoryInfo constructor for azure", function() { let repoInfo: RepositoryInfo = new RepositoryInfo("https://test.azure.com/account/teamproject/_git/repositoryName"); assert.equal(repoInfo.Host, "test.azure.com"); assert.equal(repoInfo.Account, "account"); assert.isTrue(repoInfo.IsTeamServices); assert.isTrue(repoInfo.IsTeamFoundation); // To properly test 'collection in the domain' case insensitivity, ensure the collection name is a different case than the account (e.g., 'ACCOUNT' versus 'account') const repositoryInfo: any = { "serverUrl": "https://test.azure.com", "collection": { "id": "5e082e28-e8b2-4314-9200-629619e91098", "name": "ACCOUNT", "url": "https://test.azure.com/account/_apis/projectCollections/5e082e28-e8b2-4314-9200-629619e91098" }, "repository": { "id": "cc015c05-de20-4e3f-b3bc-3662b6bc0e42", "name": "repositoryName", "url": "https://test.azure.com/account/_apis/git/repositories/cc015c05-de20-4e3f-b3bc-3662b6bc0e42", "project": { "id": "ecbf2301-0e62-4b0d-a12d-1992f2ea95a8", "name": "teamproject", "description": "Our team project", "url": "https://test.azure.com/account/_apis/projects/ecbf2301-0e62-4b0d-a12d-1992f2ea95a8", "state": 1, "revision": 14558 }, "remoteUrl": "https://test.azure.com/account/teamproject/_git/repositoryName" } }; repoInfo = new RepositoryInfo(repositoryInfo); assert.equal(repoInfo.Host, "test.azure.com"); assert.equal(repoInfo.Account, "account"); assert.equal(repoInfo.AccountUrl, "https://test.azure.com/account"); assert.equal(repoInfo.CollectionId, "5e082e28-e8b2-4314-9200-629619e91098"); // CollectionName should maintain the same case as in the JSON assert.equal(repoInfo.CollectionName, "ACCOUNT"); // CollectionUrl should not contain the collection name since this is an azure-backed/test.azure.com account & collection name are the same (case insensitive) assert.equal(repoInfo.CollectionUrl, "https://test.azure.com/account"); assert.isTrue(repoInfo.IsTeamServices); assert.isTrue(repoInfo.IsTeamFoundation); assert.isFalse(repoInfo.IsTeamFoundationServer); assert.equal(repoInfo.RepositoryId, "cc015c05-de20-4e3f-b3bc-3662b6bc0e42"); assert.equal(repoInfo.RepositoryName, "repositoryName"); assert.equal(repoInfo.RepositoryUrl, "https://test.azure.com/account/teamproject/_git/repositoryName"); assert.equal(repoInfo.TeamProject, "teamproject"); assert.equal(repoInfo.TeamProjectUrl, "https://test.azure.com/account/teamproject"); });