How to use initialSpec method in tracetest

Best JavaScript code snippet using tracetest

PackageJsonUpdater.ts

Source:PackageJsonUpdater.ts Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.2// See LICENSE in the project root for license information.3import colors from 'colors/safe';4import * as semver from 'semver';5import { RushConfiguration } from '../api/RushConfiguration';6import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager';7import { InstallManagerFactory } from './InstallManagerFactory';8import { VersionMismatchFinder } from './versionMismatch/VersionMismatchFinder';9import { PurgeManager } from './PurgeManager';10import { Utilities } from '../utilities/Utilities';11import { DependencyType, PackageJsonDependency } from '../api/PackageJsonEditor';12import { RushGlobalFolder } from '../api/RushGlobalFolder';13import { RushConfigurationProject } from '../api/RushConfigurationProject';14import { VersionMismatchFinderEntity } from './versionMismatch/VersionMismatchFinderEntity';15import { VersionMismatchFinderProject } from './versionMismatch/VersionMismatchFinderProject';16import { RushConstants } from './RushConstants';17import { InstallHelpers } from './installManager/InstallHelpers';18/**19 * The type of SemVer range specifier that is prepended to the version20 */21export const enum SemVerStyle {22 Exact = 'exact',23 Caret = 'caret',24 Tilde = 'tilde',25 Passthrough = 'passthrough'26}27/**28 * Options for adding a dependency to a particular project.29 */30export interface IPackageJsonUpdaterRushAddOptions {31 /**32 * The projects whose package.jsons should get updated33 */34 projects: RushConfigurationProject[];35 /**36 * The name of the dependency to be added37 */38 packageName: string;39 /**40 * The initial version specifier.41 * If undefined, the latest version will be used (that doesn't break ensureConsistentVersions).42 * If specified, the latest version meeting the SemVer specifier will be used as the basis.43 */44 initialVersion: string | undefined;45 /**46 * Whether or not this dependency should be added as a devDependency or a regular dependency.47 */48 devDependency: boolean;49 /**50 * If specified, other packages that use this dependency will also have their package.json's updated.51 */52 updateOtherPackages: boolean;53 /**54 * If specified, "rush update" will not be run after updating the package.json file(s).55 */56 skipUpdate: boolean;57 /**58 * If specified, "rush update" will be run in debug mode.59 */60 debugInstall: boolean;61 /**62 * The style of range that should be used if the version is automatically detected.63 */64 rangeStyle: SemVerStyle;65 /**66 * The variant to consider when performing installations and validating shrinkwrap updates.67 */68 variant?: string | undefined;69}70/**71 * Configuration options for adding or updating a dependency in a single project72 */73export interface IUpdateProjectOptions {74 /**75 * The project which will have its package.json updated76 */77 project: VersionMismatchFinderEntity;78 /**79 * The name of the dependency to be added or updated in the project80 */81 packageName: string;82 /**83 * The new SemVer specifier that should be added to the project's package.json84 */85 newVersion: string;86 /**87 * The type of dependency that should be updated. If left empty, this will be auto-detected.88 * If it cannot be auto-detected an exception will be thrown.89 */90 dependencyType?: DependencyType;91}92/**93 * A helper class for managing the dependencies of various package.json files.94 * @internal95 */96export class PackageJsonUpdater {97 private _rushConfiguration: RushConfiguration;98 private _rushGlobalFolder: RushGlobalFolder;99 public constructor(rushConfiguration: RushConfiguration, rushGlobalFolder: RushGlobalFolder) {100 this._rushConfiguration = rushConfiguration;101 this._rushGlobalFolder = rushGlobalFolder;102 }103 /**104 * Adds a dependency to a particular project. The core business logic for "rush add".105 */106 public async doRushAdd(options: IPackageJsonUpdaterRushAddOptions): Promise<void> {107 const {108 projects,109 packageName,110 initialVersion,111 devDependency,112 updateOtherPackages,113 skipUpdate,114 debugInstall,115 rangeStyle,116 variant117 } = options;118 const implicitlyPinned: Map<string, string> =119 this._rushConfiguration.getImplicitlyPreferredVersions(variant);120 const purgeManager: PurgeManager = new PurgeManager(this._rushConfiguration, this._rushGlobalFolder);121 const installManagerOptions: IInstallManagerOptions = {122 debug: debugInstall,123 allowShrinkwrapUpdates: true,124 bypassPolicy: false,125 noLink: false,126 fullUpgrade: false,127 recheckShrinkwrap: false,128 networkConcurrency: undefined,129 collectLogFile: false,130 variant: variant,131 maxInstallAttempts: RushConstants.defaultMaxInstallAttempts,132 pnpmFilterArguments: []133 };134 const installManager: BaseInstallManager = InstallManagerFactory.getInstallManager(135 this._rushConfiguration,136 this._rushGlobalFolder,137 purgeManager,138 installManagerOptions139 );140 const version: string = await this._getNormalizedVersionSpec(141 projects,142 installManager,143 packageName,144 initialVersion,145 implicitlyPinned.get(packageName),146 rangeStyle147 );148 console.log();149 console.log(colors.green(`Updating projects to use `) + packageName + '@' + colors.cyan(version));150 console.log();151 const allPackageUpdates: IUpdateProjectOptions[] = [];152 for (const project of projects) {153 const currentProjectUpdate: IUpdateProjectOptions = {154 project: new VersionMismatchFinderProject(project),155 packageName,156 newVersion: version,157 dependencyType: devDependency ? DependencyType.Dev : undefined158 };159 this.updateProject(currentProjectUpdate);160 const otherPackageUpdates: IUpdateProjectOptions[] = [];161 if (this._rushConfiguration.ensureConsistentVersions || updateOtherPackages) {162 // we need to do a mismatch check163 const mismatchFinder: VersionMismatchFinder = VersionMismatchFinder.getMismatches(164 this._rushConfiguration,165 {166 variant: variant167 }168 );169 const mismatches: string[] = mismatchFinder.getMismatches().filter((mismatch) => {170 return !projects.find((proj) => proj.packageName === mismatch);171 });172 if (mismatches.length) {173 if (!updateOtherPackages) {174 throw new Error(175 `Adding '${packageName}@${version}' to ${project.packageName}` +176 ` causes mismatched dependencies. Use the "--make-consistent" flag to update other packages to use` +177 ` this version, or do not specify a SemVer range.`178 );179 }180 // otherwise we need to go update a bunch of other projects181 const mismatchedVersions: string[] | undefined = mismatchFinder.getVersionsOfMismatch(packageName);182 if (mismatchedVersions) {183 for (const mismatchedVersion of mismatchedVersions) {184 for (const consumer of mismatchFinder.getConsumersOfMismatch(packageName, mismatchedVersion)!) {185 if (consumer instanceof VersionMismatchFinderProject) {186 otherPackageUpdates.push({187 project: consumer,188 packageName: packageName,189 newVersion: version190 });191 }192 }193 }194 }195 }196 }197 this.updateProjects(otherPackageUpdates);198 allPackageUpdates.push(currentProjectUpdate, ...otherPackageUpdates);199 }200 for (const { project } of allPackageUpdates) {201 if (project.saveIfModified()) {202 console.log(colors.green('Wrote ') + project.filePath);203 }204 }205 if (!skipUpdate) {206 console.log();207 console.log(colors.green('Running "rush update"'));208 console.log();209 try {210 await installManager.doInstallAsync();211 } finally {212 purgeManager.deleteAll();213 }214 }215 }216 /**217 * Updates several projects' package.json files218 */219 public updateProjects(projectUpdates: IUpdateProjectOptions[]): void {220 for (const update of projectUpdates) {221 this.updateProject(update);222 }223 }224 /**225 * Updates a single project's package.json file226 */227 public updateProject(options: IUpdateProjectOptions): void {228 let { dependencyType } = options;229 const { project, packageName, newVersion } = options;230 const oldDependency: PackageJsonDependency | undefined = project.tryGetDependency(packageName);231 const oldDevDependency: PackageJsonDependency | undefined = project.tryGetDevDependency(packageName);232 const oldDependencyType: DependencyType | undefined = oldDevDependency233 ? oldDevDependency.dependencyType234 : oldDependency235 ? oldDependency.dependencyType236 : undefined;237 dependencyType = dependencyType || oldDependencyType || DependencyType.Regular;238 project.addOrUpdateDependency(packageName, newVersion, dependencyType!);239 }240 /**241 * Selects an appropriate version number for a particular package, given an optional initial SemVer spec.242 * If ensureConsistentVersions, tries to pick a version that will be consistent.243 * Otherwise, will choose the latest semver matching the initialSpec and append the proper range style.244 * @param projects - the projects which will have their package.json's updated245 * @param packageName - the name of the package to be used246 * @param initialSpec - a semver pattern that should be used to find the latest version matching the spec247 * @param implicitlyPinnedVersion - the implicitly preferred (aka common/primary) version of the package in use248 * @param rangeStyle - if this version is selected by querying registry, then this range specifier is prepended to249 * the selected version.250 */251 private async _getNormalizedVersionSpec(252 projects: RushConfigurationProject[],253 installManager: BaseInstallManager,254 packageName: string,255 initialSpec: string | undefined,256 implicitlyPinnedVersion: string | undefined,257 rangeStyle: SemVerStyle258 ): Promise<string> {259 console.log(colors.gray(`Determining new version for dependency: ${packageName}`));260 if (initialSpec) {261 console.log(`Specified version selector: ${colors.cyan(initialSpec)}`);262 } else {263 console.log(`No version selector was specified, so the version will be determined automatically.`);264 }265 console.log();266 // determine if the package is a project in the local repository and if the version exists267 const localProject: RushConfigurationProject | undefined = this._tryGetLocalProject(268 packageName,269 projects270 );271 // if ensureConsistentVersions => reuse the pinned version272 // else, query the registry and use the latest that satisfies semver spec273 if (initialSpec && implicitlyPinnedVersion && initialSpec === implicitlyPinnedVersion) {274 console.log(275 colors.green('Assigning "') +276 colors.cyan(initialSpec) +277 colors.green(278 `" for "${packageName}" because it matches what other projects are using in this repo.`279 )280 );281 return initialSpec;282 }283 if (this._rushConfiguration.ensureConsistentVersions && !initialSpec && implicitlyPinnedVersion) {284 console.log(285 `Assigning the version range "${colors.cyan(implicitlyPinnedVersion)}" for "${packageName}" because` +286 ` it is already used by other projects in this repo.`287 );288 return implicitlyPinnedVersion;289 }290 await InstallHelpers.ensureLocalPackageManager(291 this._rushConfiguration,292 this._rushGlobalFolder,293 RushConstants.defaultMaxInstallAttempts294 );295 const useWorkspaces: boolean = !!(296 this._rushConfiguration.pnpmOptions && this._rushConfiguration.pnpmOptions.useWorkspaces297 );298 const workspacePrefix: string = 'workspace:';299 // Trim 'workspace:' notation from the spec, since we're going to be tweaking the range300 if (useWorkspaces && initialSpec && initialSpec.startsWith(workspacePrefix)) {301 initialSpec = initialSpec.substring(workspacePrefix.length).trim();302 }303 let selectedVersion: string | undefined;304 let selectedVersionPrefix: string = '';305 if (initialSpec && initialSpec !== 'latest') {306 console.log(colors.gray('Finding versions that satisfy the selector: ') + initialSpec);307 console.log();308 if (localProject !== undefined) {309 const version: string = localProject.packageJson.version;310 if (semver.satisfies(version, initialSpec)) {311 // For workspaces, assume that specifying the exact version means you always want to consume312 // the local project. Otherwise, use the exact local package version313 if (useWorkspaces) {314 selectedVersion = initialSpec === version ? '*' : initialSpec;315 selectedVersionPrefix = workspacePrefix;316 } else {317 selectedVersion = version;318 }319 } else {320 throw new Error(321 `The dependency being added ("${packageName}") is a project in the local Rush repository, ` +322 `but the version specifier provided (${initialSpec}) does not match the local project's version ` +323 `(${version}). Correct the version specifier, omit a version specifier, or include "${packageName}" as a ` +324 `cyclicDependencyProject if it is intended for "${packageName}" to come from an external feed and not ` +325 'from the local Rush repository.'326 );327 }328 } else {329 console.log(`Querying registry for all versions of "${packageName}"...`);330 let commandArgs: string[];331 if (this._rushConfiguration.packageManager === 'yarn') {332 commandArgs = ['info', packageName, 'versions', '--json'];333 } else {334 commandArgs = ['view', packageName, 'versions', '--json'];335 }336 const allVersions: string = Utilities.executeCommandAndCaptureOutput(337 this._rushConfiguration.packageManagerToolFilename,338 commandArgs,339 this._rushConfiguration.commonTempFolder340 );341 let versionList: string[];342 if (this._rushConfiguration.packageManager === 'yarn') {343 versionList = JSON.parse(allVersions).data;344 } else {345 versionList = JSON.parse(allVersions);346 }347 console.log(colors.gray(`Found ${versionList.length} available versions.`));348 for (const version of versionList) {349 if (semver.satisfies(version, initialSpec)) {350 selectedVersion = initialSpec;351 console.log(`Found a version that satisfies ${initialSpec}: ${colors.cyan(version)}`);352 break;353 }354 }355 if (!selectedVersion) {356 throw new Error(357 `Unable to find a version of "${packageName}" that satisfies` +358 ` the version specifier "${initialSpec}"`359 );360 }361 }362 } else {363 if (!this._rushConfiguration.ensureConsistentVersions) {364 console.log(365 colors.gray(366 `The "ensureConsistentVersions" policy is NOT active, so we will assign the latest version.`367 )368 );369 console.log();370 }371 if (localProject !== undefined) {372 // For workspaces, assume that no specified version range means you always want to consume373 // the local project. Otherwise, use the exact local package version374 if (useWorkspaces) {375 selectedVersion = '*';376 selectedVersionPrefix = workspacePrefix;377 } else {378 selectedVersion = localProject.packageJson.version;379 }380 } else {381 console.log(`Querying NPM registry for latest version of "${packageName}"...`);382 let commandArgs: string[];383 if (this._rushConfiguration.packageManager === 'yarn') {384 commandArgs = ['info', packageName, 'dist-tags.latest', '--silent'];385 } else {386 commandArgs = ['view', `${packageName}@latest`, 'version'];387 }388 selectedVersion = Utilities.executeCommandAndCaptureOutput(389 this._rushConfiguration.packageManagerToolFilename,390 commandArgs,391 this._rushConfiguration.commonTempFolder392 ).trim();393 }394 console.log();395 console.log(`Found latest version: ${colors.cyan(selectedVersion!)}`);396 }397 console.log();398 let reasonForModification: string = '';399 if (selectedVersion !== '*') {400 switch (rangeStyle) {401 case SemVerStyle.Caret: {402 selectedVersionPrefix += '^';403 reasonForModification = ' because the "--caret" flag was specified';404 break;405 }406 case SemVerStyle.Exact: {407 reasonForModification = ' because the "--exact" flag was specified';408 break;409 }410 case SemVerStyle.Tilde: {411 selectedVersionPrefix += '~';412 break;413 }414 case SemVerStyle.Passthrough: {415 break;416 }417 default: {418 throw new Error(`Unexpected SemVerStyle ${rangeStyle}.`);419 }420 }421 }422 const normalizedVersion: string = selectedVersionPrefix + selectedVersion;423 console.log(424 colors.gray(`Assigning version "${normalizedVersion}" for "${packageName}"${reasonForModification}.`)425 );426 return normalizedVersion;427 }428 private _collectAllDownstreamDependencies(429 project: RushConfigurationProject430 ): Set<RushConfigurationProject> {431 const allProjectDownstreamDependencies: Set<RushConfigurationProject> =432 new Set<RushConfigurationProject>();433 const collectDependencies: (rushProject: RushConfigurationProject) => void = (434 rushProject: RushConfigurationProject435 ) => {436 for (const downstreamDependencyProject of rushProject.downstreamDependencyProjects) {437 const foundProject: RushConfigurationProject | undefined =438 this._rushConfiguration.projectsByName.get(downstreamDependencyProject);439 if (!foundProject) {440 continue;441 }442 if (foundProject.cyclicDependencyProjects.has(rushProject.packageName)) {443 continue;444 }445 if (!allProjectDownstreamDependencies.has(foundProject)) {446 allProjectDownstreamDependencies.add(foundProject);447 collectDependencies(foundProject);448 }449 }450 };451 collectDependencies(project);452 return allProjectDownstreamDependencies;453 }454 /**455 * Given a package name, this function returns a {@see RushConfigurationProject} if the package is a project456 * in the local Rush repo and is not marked as cyclic for any of the projects.457 *458 * @remarks459 * This function throws an error if adding the discovered local project as a dependency460 * would create a dependency cycle, or if it would be added to multiple projects.461 */462 private _tryGetLocalProject(463 packageName: string,464 projects: RushConfigurationProject[]465 ): RushConfigurationProject | undefined {466 const foundProject: RushConfigurationProject | undefined =467 this._rushConfiguration.projectsByName.get(packageName);468 if (foundProject === undefined) {469 return undefined;470 }471 if (projects.length > 1) {472 throw new Error(473 `"rush add" does not support adding a local project as a dependency to multiple projects at once.`474 );475 }476 const project: RushConfigurationProject = projects[0];477 if (project.cyclicDependencyProjects.has(foundProject.packageName)) {478 return undefined;479 }480 // Are we attempting to add this project to itself?481 if (project === foundProject) {482 throw new Error(483 'Unable to add a project as a dependency of itself unless the dependency is listed as a cyclic dependency ' +484 `in rush.json. This command attempted to add "${foundProject.packageName}" as a dependency of itself.`485 );486 }487 // Are we attempting to create a cycle?488 const downstreamDependencies: Set<RushConfigurationProject> =489 this._collectAllDownstreamDependencies(project);490 if (downstreamDependencies.has(foundProject)) {491 throw new Error(492 `Adding "${foundProject.packageName}" as a direct or indirect dependency of ` +493 `"${project.packageName}" would create a dependency cycle.`494 );495 }496 return foundProject;497 }...

Full Screen

Full Screen

Integration-test.js

Source:Integration-test.js Github

copy

Full Screen

1jest.autoMockOff();2var initialSpec = {3 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},4 extenders:{p2:{base:'p1',ref:'p0',angle:7.1600000000000055,len:5,speed:0.04}},5 rotaries:{p1:'p2'},6 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},7};8var mouseMoveEventLog = [{handlerName:'onMouseMove',eventData:{x:36,y:22.9}}];9// make a four bar from the rotary10var State0_State14_State4_State6_State0 = {11 initialSpec: {12 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},13 extenders:{p2:{base:'p1',ref:'p0',angle:1.5000000000000007,len:5,speed:1}},14 rotaries:{p1:'p2'},15 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},16 },17 finalSpec: {18 points:{19 p0:{p1:{len:1}},20 p1:{p0:{len:1},p2:{len:5}},21 p2:{p1:{len:5},p4:{len:17.71089208411792}},22 p3:{p4:{len:15.273833834371775}},23 p4:{p2:{len:17.71089208411792},p3:{len:15.273833834371775}}24 },25 extenders:{p2:{base:'p1',ref:'p0',angle:1.5000000000000007,len:5,speed:1}},26 rotaries:{p1:'p2'},27 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'},p3:{x:17.1,y:-1.2,id:'p3'}},28 },29 eventLog: [{handlerName:'onMouseMove',eventData:{x:-0.1,y:5}},{handlerName:'onMouseDown',eventData:{x:-0.1,y:5}},{handlerName:'onMouseUp',eventData:{x:-0.1,y:5}},{handlerName:'onMouseMove',eventData:{x:15.6,y:14}},{handlerName:'onMouseDown',eventData:{x:15.6,y:14}},{handlerName:'onMouseUp',eventData:{x:15.6,y:14}},{handlerName:'onMouseMove',eventData:{x:17.1,y:-1.2}},{handlerName:'onMouseDown',eventData:{x:17.1,y:-1.2}},{handlerName:'onMouseUp',eventData:{x:17.1,y:-1.2}},{handlerName:'onMouseMove',eventData:{x:33.3,y:1.3}}],30};31// add a segment and delete it32var deleteSpec = {33 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},34 extenders:{p2:{base:'p1',ref:'p0',angle:13.900000000000063,len:5,speed:1}},35 rotaries:{p1:'p2'},36 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},37};38var State0_State14_State4_State6_State0_State14_State4_State0 = {39 initialSpec: deleteSpec,40 finalSpec: deleteSpec,41 eventLog: [{handlerName:'onMouseMove',eventData:{x:1.4,y:5.5}},{handlerName:'onMouseDown',eventData:{x:1.4,y:5.5}},{handlerName:'onMouseUp',eventData:{x:1.4,y:5.5}},{handlerName:'onMouseMove',eventData:{x:9.9,y:13.6}},{handlerName:'onMouseDown',eventData:{x:9.9,y:13.6}},{handlerName:'onMouseUp',eventData:{x:9.9,y:13.6}},{handlerName:'onMouseMove',eventData:{x:14.6,y:1.7}},{handlerName:'onMouseDown',eventData:{x:14.6,y:1.7}},{handlerName:'onMouseUp',eventData:{x:14.6,y:1.7}},{handlerName:'onMouseMove',eventData:{x:10.4,y:13.2}},{handlerName:'onMouseDown',eventData:{x:10.4,y:13.2}},{handlerName:'onMouseUp',eventData:{x:10.4,y:13.2}},{handlerName:'onKeyDown',eventData:68},{handlerName:'onKeyPress',eventData:100},{handlerName:'onKeyUp',eventData:68},{handlerName:'onMouseMove',eventData:{x:35.9,y:-13.8}}],42};43// make a four bar with coupler44var State0_State14_State4_State6_State0_State9_State0 = {45 initialSpec: {46 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},47 extenders:{p2:{base:'p1',ref:'p0',angle:7.299999999999982,len:5,speed:1}},48 rotaries:{p1:'p2'},49 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},50 },51 finalSpec: {52 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5},p4:{len:12.564522752030888},p5:{len:9.936616918299022}},p3:{p4:{len:10.165136496870073}},p4:{p2:{len:12.564522752030888},p3:{len:10.165136496870073},p5:{len:16.32482771731451}},p5:{p4:{len:16.32482771731451},p2:{len:9.936616918299022}}},53 extenders:{p2:{base:'p1',ref:'p0',angle:7.299999999999982,len:5,speed:1}},54 rotaries:{p1:'p2'},55 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'},p3:{x:16.7,y:-0.2,id:'p3'}},56 },57 eventLog: [{handlerName:'onMouseMove',eventData:{x:3.1,y:4.3}},{handlerName:'onMouseDown',eventData:{x:3.1,y:4.3}},{handlerName:'onMouseUp',eventData:{x:3.1,y:4.3}},{handlerName:'onMouseMove',eventData:{x:14,y:9.6}},{handlerName:'onMouseDown',eventData:{x:14,y:9.6}},{handlerName:'onMouseUp',eventData:{x:14,y:9.6}},{handlerName:'onMouseMove',eventData:{x:16.7,y:-0.2}},{handlerName:'onMouseDown',eventData:{x:16.7,y:-0.2}},{handlerName:'onMouseUp',eventData:{x:16.7,y:-0.2}},{handlerName:'onMouseMove',eventData:{x:7.9,y:6}},{handlerName:'onMouseDown',eventData:{x:7.9,y:6}},{handlerName:'onMouseUp',eventData:{x:7.9,y:6}},{handlerName:'onMouseMove',eventData:{x:6.5,y:-4.9}},{handlerName:'onMouseDown',eventData:{x:6.5,y:-4.9}},{handlerName:'onMouseUp',eventData:{x:6.5,y:-4.9}},{handlerName:'onMouseMove',eventData:{x:35.2,y:0}}],58};59// make a five bar with two rotaries60var State0_State1_State0_State11_State0_State11_State0_State14_State4_State5_State0 = {61 initialSpec: {62 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},63 extenders:{p2:{base:'p1',ref:'p0',angle:7.99999999999998,len:5,speed:1}},64 rotaries:{p1:'p2'},65 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},66 },67 finalSpec: {68 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5},p6:{len:13.550305595766215}},p3:{p4:{len:1}},p4:{p3:{len:1},p5:{len:5}},p5:{p4:{len:5},p6:{len:12.16552506059644}},p6:{p2:{len:13.550305595766215},p5:{len:12.16552506059644}}},69 extenders:{p2:{base:'p1',ref:'p0',angle:7.99999999999998,len:5,speed:1},p5:{base:'p4',ref:'p3',angle:0.9272952180016122,speed:1,len:5}},70 rotaries:{p1:'p2',p4:'p5'},71 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'},p3:{x:13.3,y:-1.2,id:'p3'},p4:{x:12.3,y:-1.2,id:'p4'}},72 },73 eventLog: [{handlerName:'onMouseMove',eventData:{x:12.3,y:-1.2}},{handlerName:'onMouseDown',eventData:{x:12.3,y:-1.2}},{handlerName:'onMouseUp',eventData:{x:12.3,y:-1.2}},{handlerName:'onKeyDown',eventData:27},{handlerName:'onKeyUp',eventData:27},{handlerName:'onKeyDown',eventData:82},{handlerName:'onKeyPress',eventData:114},{handlerName:'onKeyUp',eventData:82},{handlerName:'onKeyDown',eventData:82},{handlerName:'onKeyPress',eventData:114},{handlerName:'onMouseDown',eventData:{x:12.3,y:-1.2}},{handlerName:'onMouseUp',eventData:{x:12.3,y:-1.2}},{handlerName:'onKeyDown',eventData:82},{handlerName:'onKeyPress',eventData:114},{handlerName:'onKeyDown',eventData:82},{handlerName:'onKeyPress',eventData:114},{handlerName:'onKeyUp',eventData:82},{handlerName:'onMouseMove',eventData:{x:15.4,y:2.6}},{handlerName:'onMouseDown',eventData:{x:15.4,y:2.6}},{handlerName:'onMouseUp',eventData:{x:15.4,y:2.6}},{handlerName:'onMouseMove',eventData:{x:-0.6,y:5}},{handlerName:'onMouseDown',eventData:{x:-0.6,y:5}},{handlerName:'onMouseUp',eventData:{x:-0.6,y:5}},{handlerName:'onMouseMove',eventData:{x:9.7,y:13.6}},{handlerName:'onMouseDown',eventData:{x:9.7,y:13.6}},{handlerName:'onMouseUp',eventData:{x:9.7,y:13.6}},{handlerName:'onMouseMove',eventData:{x:35.9,y:12.3}}],74};75// make a four bar, then move around ground points76var State0_State14_State4_State6_State0_State7_State0_State3_State0 = {77 initialSpec: {78 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},79 extenders:{p2:{base:'p1',ref:'p0',angle:14.150000000000066,len:5,speed:1}},80 rotaries:{p1:'p2'},81 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},82 },83 finalSpec: {84 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5},p4:{len:13.524215351034957}},p3:{p4:{len:11.237882362794158}},p4:{p2:{len:13.524215351034957},p3:{len:11.237882362794158}}},85 extenders:{p2:{base:'p1',ref:'p0',angle:14.150000000000066,len:5,speed:1}},86 rotaries:{p1:'p2'},87 groundPoints:{p0:{x:0.8,y:2.5,id:'p0'},p1:{x:-0.2,y:2.5,id:'p1'},p3:{x:-17.5,y:3.3,id:'p3'}},88 },89 eventLog: [{handlerName:'onMouseMove',eventData:{x:0.2,y:5.1}},{handlerName:'onMouseDown',eventData:{x:0.2,y:5.1}},{handlerName:'onMouseUp',eventData:{x:0.2,y:5.1}},{handlerName:'onMouseMove',eventData:{x:12.2,y:10.7}},{handlerName:'onMouseDown',eventData:{x:12.2,y:10.7}},{handlerName:'onMouseUp',eventData:{x:12.2,y:10.7}},{handlerName:'onMouseMove',eventData:{x:14.5,y:-0.3}},{handlerName:'onMouseDown',eventData:{x:14.5,y:-0.3}},{handlerName:'onMouseUp',eventData:{x:14.5,y:-0.3}},{handlerName:'onMouseMove',eventData:{x:-0.2,y:-0.5}},{handlerName:'onMouseDown',eventData:{x:-0.2,y:-0.5}},{handlerName:'onMouseMove',eventData:{x:-0.2,y:2.5}},{handlerName:'onMouseUp',eventData:{x:-0.2,y:2.5}},{handlerName:'onMouseMove',eventData:{x:14.9,y:-0.7}},{handlerName:'onMouseDown',eventData:{x:14.9,y:-0.7}},{handlerName:'onMouseMove',eventData:{x:-17.5,y:3.3}},{handlerName:'onMouseUp',eventData:{x:-17.5,y:3.3}},{handlerName:'onMouseMove',eventData:{x:34.4,y:-3.1}}],90};91// make a four bar from the canvas92var State0_State1_State2_State0 = {93 initialSpec: {94 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},95 extenders:{p2:{base:'p1',ref:'p0',angle:7.84999999999998,len:5,speed:1}},96 rotaries:{p1:'p2'},97 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},98 },99 finalSpec: {100 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5},p4:{len:18.463637150668838}},p3:{p4:{len:14.023551618616446}},p4:{p2:{len:18.463637150668838},p3:{len:14.023551618616446}}},101 extenders:{p2:{base:'p1',ref:'p0',angle:7.84999999999998,len:5,speed:1}},102 rotaries:{p1:'p2'},103 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'},p3:{x:19.2,y:4.5,id:'p3'}},104 },105 eventLog: [{handlerName:'onMouseMove',eventData:{x:19.2,y:4.5}},{handlerName:'onMouseDown',eventData:{x:19.2,y:4.5}},{handlerName:'onMouseUp',eventData:{x:19.2,y:4.5}},{handlerName:'onMouseMove',eventData:{x:13.7,y:17.4}},{handlerName:'onMouseDown',eventData:{x:13.7,y:17.4}},{handlerName:'onMouseUp',eventData:{x:13.7,y:17.4}},{handlerName:'onMouseMove',eventData:{x:0.4,y:5.2}},{handlerName:'onMouseDown',eventData:{x:0.4,y:5.2}},{handlerName:'onMouseUp',eventData:{x:0.4,y:5.2}},{handlerName:'onMouseMove',eventData:{x:33.2,y:1.5}}],106};107// select a rotary and move it around108var State0_State7_State8_State7_State0 = {109 initialSpec: {110 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},111 extenders:{p2:{base:'p1',ref:'p0',angle:7.549999999999981,len:5,speed:1}},112 rotaries:{p1:'p2'},113 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},114 },115 finalSpec: {116 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},117 extenders:{p2:{base:'p1',ref:'p0',angle:7.549999999999981,len:5,speed:1}},118 rotaries:{p1:'p2'},119 groundPoints:{p0:{x:3.5,y:1,id:'p0'},p1:{x:2.5,y:1,id:'p1'}},120 },121 eventLog: [{handlerName:'onMouseMove',eventData:{x:0,y:0.1}},{handlerName:'onMouseDown',eventData:{x:0,y:0.1}},{handlerName:'onMouseUp',eventData:{x:0,y:0.1}},{handlerName:'onMouseDown',eventData:{x:0,y:0.1}},{handlerName:'onMouseMove',eventData:{x:2.5,y:1}},{handlerName:'onMouseUp',eventData:{x:2.5,y:1}},{handlerName:'onMouseMove',eventData:{x:31.2,y:-4.6}}],122};123// make four bar from canvas and rotary124var State0_State1_State13_State0 = {125 initialSpec: {126 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5}}},127 extenders:{p2:{base:'p1',ref:'p0',angle:7.249999999999982,len:5,speed:1}},128 rotaries:{p1:'p2'},129 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'}},130 },131 finalSpec: {132 points:{p0:{p1:{len:1}},p1:{p0:{len:1},p2:{len:5}},p2:{p1:{len:5},p4:{len:15.020110003172254}},p3:{p4:{len:14.467895493125459}},p4:{p2:{len:15.020110003172254},p3:{len:14.467895493125459}}},133 extenders:{p2:{base:'p1',ref:'p0',angle:7.249999999999982,len:5,speed:1}},134 rotaries:{p1:'p2'},135 groundPoints:{p0:{x:1,y:0,id:'p0'},p1:{x:0,y:0,id:'p1'},p3:{x:11,y:1.3,id:'p3'}},136 },137 eventLog: [{handlerName:'onMouseMove',eventData:{x:11,y:1.3}},{handlerName:'onMouseDown',eventData:{x:11,y:1.3}},{handlerName:'onMouseUp',eventData:{x:11,y:1.3}},{handlerName:'onMouseMove',eventData:{x:3,y:4.2}},{handlerName:'onMouseDown',eventData:{x:3,y:4.2}},{handlerName:'onMouseUp',eventData:{x:3,y:4.2}},{handlerName:'onMouseMove',eventData:{x:12.4,y:15.7}},{handlerName:'onMouseDown',eventData:{x:12.4,y:15.7}},{handlerName:'onMouseUp',eventData:{x:12.4,y:15.7}},{handlerName:'onMouseMove',eventData:{x:34.6,y:-10.5}}],138};139describe('state behaviors and transitions', function() {140 function runTest(desc, initialSpec, eventLog, finalSpec) {141 var testFunct = function () {142 var Linkage = require('../Linkage.js');143 var UI = require('../ui/UI.js');144 var UIState = require('../ui/UIState');145 // copy the initial spec (we expect the linkage to mutate it)146 var linkage = new Linkage(JSON.parse(JSON.stringify(initialSpec)));147 var initialState = UIState.getInitialPausedState(linkage);148 var ui = new UI(initialState, null, []);149 eventLog.forEach(event => ui[event.handlerName](event.eventData));150 expect(ui.state.linkage.spec).toEqual(finalSpec);151 };152 if (desc === 'State0_State14_State4_State6_State0') {153 findTriangles(initialSpec);154 console.log('');155 findTriangles(finalSpec);156 iit(desc, testFunct);157 } else {158 it(desc, testFunct);159 }160 }161 runTest(162 'should do nothing if nothing happens',163 initialSpec,164 [],165 initialSpec166 );167 runTest(168 'should do nothing if only the mouse moves',169 initialSpec,170 mouseMoveEventLog,171 initialSpec172 );173 // mising 10, 12, 13, 15174 var pathTests = {175 State0_State14_State4_State6_State0,176 State0_State14_State4_State6_State0_State14_State4_State0,177 State0_State14_State4_State6_State0_State9_State0,178 State0_State1_State0_State11_State0_State11_State0_State14_State4_State5_State0,179 State0_State14_State4_State6_State0_State7_State0_State3_State0,180 State0_State1_State2_State0,181 State0_State7_State8_State7_State0,182 State0_State1_State13_State0,183 };184 Object.keys(pathTests).forEach(name => {185 runTest(186 name,187 pathTests[name].initialSpec,188 pathTests[name].eventLog,189 pathTests[name].finalSpec190 );191 });192});193function _addSolution(solutionMap, p1ID, p2ID, p3ID, solutionIndex) {194 if (!solutionMap[p1ID]) {195 solutionMap[p1ID] = {};196 }197 if (!solutionMap[p1ID][p2ID]) {198 solutionMap[p1ID][p2ID] = {};199 }200 solutionMap[p1ID][p2ID][p3ID] = solutionIndex;201 if (!solutionMap[p2ID]) {202 solutionMap[p2ID] = {};203 }204 if (!solutionMap[p2ID][p1ID]) {205 solutionMap[p2ID][p1ID] = {};206 }207 solutionMap[p2ID][p1ID][p3ID] = solutionIndex ? 0 : 1;208}209function findTriangles(spec) {210 var solutionMap = {};211 Object.keys(spec.points).forEach(p0id => {212 if (spec.rotaries[p0id]) {213 return;214 }215 Object.keys(spec.points[p0id]).forEach(p1id => {216 Object.keys(spec.points[p1id]).forEach(p2id => {217 if (!spec.rotaries[p2id] && p0id !== p2id) {218 console.log('triangle:', p0id, p2id, p1id);219 if (!solutionMap[p0id]) {220 _addSolution(solutionMap, p0id, p2id, p1id, 0);221 }222 }223 })224 })225 });226 spec.solutionMap = solutionMap;227}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetesting = require('tracetesting');2var trace = tracetesting.initialSpec();3var tracetesting = require('tracetesting');4var trace = tracetesting.trace();5var tracetesting = require('tracetesting');6var trace = tracetesting.trace();7var tracetesting = require('tracetesting');8var trace = tracetesting.trace();9var tracetesting = require('tracetesting');10var trace = tracetesting.trace();11var tracetesting = require('tracetesting');12var trace = tracetesting.trace();13var tracetesting = require('tracetesting');14var trace = tracetesting.trace();15var tracetesting = require('tracetesting');16var trace = tracetesting.trace();17var tracetesting = require('tracetesting');18var trace = tracetesting.trace();19var tracetesting = require('tracetesting');20var trace = tracetesting.trace();21var tracetesting = require('tracetesting');22var trace = tracetesting.trace();23var tracetesting = require('tracetesting');24var trace = tracetesting.trace();25var tracetesting = require('tracetesting');26var trace = tracetesting.trace();27var tracetesting = require('tracetesting');28var trace = tracetesting.trace();

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2tracetest.initialSpec('test', 'spec1', 'spec2', 'spec3');3var tracetest = require('tracetest');4tracetest.trace('spec1', 'spec2', 'spec3');5var tracetest = require('tracetest');6tracetest.trace('spec2', 'spec3');7var tracetest = require('tracetest');8tracetest.trace('spec3');9var tracetest = require('tracetest');10tracetest.trace('spec4');11var tracetest = require('tracetest');12tracetest.trace('spec5');13var tracetest = require('tracetest');14tracetest.trace('spec6');15var tracetest = require('tracetest');16tracetest.trace('spec7');17var tracetest = require('tracetest');18tracetest.trace('spec8');19var tracetest = require('tracetest');20tracetest.trace('spec9');21var tracetest = require('tracetest');22tracetest.trace('spec10');23var tracetest = require('tracetest');24tracetest.trace('spec11');

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var trace = tracetest.initialSpec('trace');3var trace = tracetest.initialSpec('trace', 'test');4var trace = tracetest.initialSpec('trace', 'test', 'test');5var trace = tracetest.initialSpec('trace', 'test', 'test', 'test');6var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test');7var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test');8var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test', 'test');9var tracetest = require('tracetest');10var trace = tracetest.initialSpec('trace');11var trace = tracetest.initialSpec('trace', 'test');12var trace = tracetest.initialSpec('trace', 'test', 'test');13var trace = tracetest.initialSpec('trace', 'test', 'test', 'test');14var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test');15var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test');16var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test', 'test');17var tracetest = require('tracetest');18var trace = tracetest.initialSpec('trace');19var trace = tracetest.initialSpec('trace', 'test');20var trace = tracetest.initialSpec('trace', 'test', 'test');21var trace = tracetest.initialSpec('trace', 'test', 'test', 'test');22var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test');23var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test');24var trace = tracetest.initialSpec('trace', 'test', 'test', 'test', 'test', 'test', '

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var spec = tracetest.initialSpec();3spec.addTest('test1', 'test1 description');4spec.addTest('test2', 'test2 description');5spec.addTest('test3', 'test3 description');6spec.addTest('test4', 'test4 description');7spec.addTest('test5', 'test5 description');8spec.addTest('test6', 'test6 description');9spec.addTest('test7', 'test7 description');10spec.addTest('test8', 'test8 description');11spec.addTest('test9', 'test9 description');12spec.addTest('test10', 'test10 description');13spec.addTest('test11', 'test11 description');14spec.addTest('test12', 'test12 description');15spec.addTest('test13', 'test13 description');16spec.addTest('test14', 'test14 description');17spec.addTest('test15', 'test15 description');18spec.addTest('test16', 'test16 description');19spec.addTest('test17', 'test17 description');20spec.addTest('test18', 'test18 description');21spec.addTest('test19', 'test19 description');22spec.addTest('test20', 'test20 description');23spec.addTest('test21', 'test21 description');24spec.addTest('test22', 'test22 description');25spec.addTest('test23', 'test23 description');26spec.addTest('test24', 'test24 description');27spec.addTest('test25', 'test25 description');28spec.addTest('test26', 'test26 description');29spec.addTest('test27', 'test27 description');30spec.addTest('test28', 'test28 description');31spec.addTest('test29', 'test29 description');32spec.addTest('test30', 'test30 description');33spec.addTest('test31', 'test31 description');34spec.addTest('test32', 'test32 description');35spec.addTest('test33', 'test33 description');36spec.addTest('test34', 'test34 description');37spec.addTest('test35', 'test35 description');38spec.addTest('test36', 'test36 description');39spec.addTest('test37', 'test37 description');40spec.addTest('test38', 'test38 description');41spec.addTest('test39', 'test39 description');

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var testSpec = tracetest.initialSpec();3console.log(testSpec);4var tracetest = require('tracetest');5tracetest.run();6var tracetest = require('tracetest');7var testSpec = tracetest.initialSpec();8testSpec.testName = "My custom test name";9tracetest.run(testSpec);10var tracetest = require('tracetest');11var testSpec = tracetest.initialSpec();12testSpec.testName = "My custom test name";13tracetest.run(testSpec, function(){14 console.log("my custom test function");15});16var tracetest = require('tracetest');17var testSpec = tracetest.initialSpec();18testSpec.testName = "My custom test name";19tracetest.run(testSpec, function(){20 console.log("my custom test function");21}, function(){22 console.log("my custom callback function");23});24var tracetest = require('tracetest');25var testSpec = tracetest.initialSpec();26testSpec.testName = "My custom test name";27tracetest.run(testSpec, function(){28 console.log("my custom test function");29}, function(){30 console.log("my custom callback function");31}, function(err){32 console.log("my custom error handler function");33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var initialSpec = tracetest.initialSpec();3initialSpec.setSpec('Test case name', 'test case description');4var assert = tracetest.assert();5assert.assert('assertion name', 'assertion description', 'result of assertion');6var result = tracetest.result();7result.getResults();8var finalSpec = tracetest.finalSpec();9finalSpec.setSpec('Test case name', 'test case description');10var end = tracetest.end();11end.end();12var endTestSuite = tracetest.endTestSuite();13endTestSuite.endTestSuite();14var report = tracetest.report();15report.getReport();16var save = tracetest.save();17save.saveReport();18var saveAndUpload = tracetest.saveAndUpload();19saveAndUpload.saveAndUploadReport();20var upload = tracetest.upload();21upload.uploadReport();22var reset = tracetest.reset();23reset.resetReport();24var get = tracetest.get();25get.getReport();26var getReport = tracetest.getReport();

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest.js');2var fs = require('fs');3var specFile = process.argv[2] || tracetest.defaultSpecFile;4tracetest.initialSpec(specFile, function(err, test) {5 if (err) {6 console.log('error creating test case: ' + err);7 } else {8 console.log('test case created, running');9 test.run(function(err, results) {10 if (err) {11 console.log('error running test case: ' + err);12 } else {13 console.log('test case completed');14 console.log('results:');15 console.log(results);16 }17 });18 }19});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful