How to use getVersionNumber method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

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

getVersionNumber.test.js

Source: getVersionNumber.test.js Github

copy
1// @ts-check
2"use strict";
3
4describe("getVersionNumber", () => {
5  const { getVersionNumber } = require("../../windows/test-app");
6
7  test("handles arbitrary version number formats", () => {
8    expect(getVersionNumber("0")).toBe(0);
9    expect(getVersionNumber("1")).toBe(1);
10    expect(getVersionNumber("11")).toBe(11);
11
12    expect(getVersionNumber("0.0")).toBe(0);
13    expect(getVersionNumber("0.1")).toBe(1);
14    expect(getVersionNumber("1.0")).toBe(100);
15    expect(getVersionNumber("1.1")).toBe(101);
16
17    expect(getVersionNumber("0.0.0")).toBe(0);
18    expect(getVersionNumber("0.0.1")).toBe(1);
19    expect(getVersionNumber("0.1.0")).toBe(100);
20    expect(getVersionNumber("0.1.1")).toBe(101);
21    expect(getVersionNumber("1.0.0")).toBe(10000);
22    expect(getVersionNumber("1.0.1")).toBe(10001);
23    expect(getVersionNumber("1.1.0")).toBe(10100);
24    expect(getVersionNumber("1.1.1")).toBe(10101);
25
26    expect(getVersionNumber("0.0.0.0")).toBe(0);
27    expect(getVersionNumber("0.0.0.1")).toBe(1);
28    expect(getVersionNumber("0.0.1.0")).toBe(100);
29    expect(getVersionNumber("0.0.1.1")).toBe(101);
30    expect(getVersionNumber("0.1.0.0")).toBe(10000);
31    expect(getVersionNumber("0.1.0.1")).toBe(10001);
32    expect(getVersionNumber("0.1.1.0")).toBe(10100);
33    expect(getVersionNumber("0.1.1.1")).toBe(10101);
34    expect(getVersionNumber("1.0.0.0")).toBe(1000000);
35    expect(getVersionNumber("1.0.0.1")).toBe(1000001);
36    expect(getVersionNumber("1.0.1.0")).toBe(1000100);
37    expect(getVersionNumber("1.0.1.1")).toBe(1000101);
38    expect(getVersionNumber("1.1.0.0")).toBe(1010000);
39    expect(getVersionNumber("1.1.0.1")).toBe(1010001);
40    expect(getVersionNumber("1.1.1.0")).toBe(1010100);
41    expect(getVersionNumber("1.1.1.1")).toBe(1010101);
42
43    expect(getVersionNumber("1.0.0-rc.1")).toBe(10000);
44  });
45});
46
Full Screen

Version.js

Source: Version.js Github

copy
1import React from 'react';
2import { connect } from 'react-redux';
3
4import * as actions from '../../_redux/actions';
5
6import styles from './Version.scss';
7
8const mapDispatchToProps = {
9  getVersionNumber: actions.getVersionNumber,
10  postVersion: actions.postVersion
11};
12
13const Version = ({ data, getVersionNumber, onVersionItemClick, postVersion }) => {
14
15  const handleSelect = (item) => {
16    postVersion({ version: item.commit });
17    onVersionItemClick();
18    getVersionNumber(item.version);
19  }
20
21  return (
22    <div className={styles['version']}>
23      {
24        data.map(item => {
25          return (
26            <div 
27              key={`id--${item.version}`}
28              className={styles['version__item']}
29              onClick={() => handleSelect(item)}
30              >
31              <span>{item.version}</span>
32            </div>
33        )})
34      }
35    </div>
36  )
37}
38
39export default connect(null, mapDispatchToProps)(Version);
Full Screen

ReleaseChart.js

Source: ReleaseChart.js Github

copy
1import React, { PropTypes, Component } from 'react';
2import _ from 'lodash';
3import moment from 'moment';
4import Humanize from 'humanize-plus';
5import semver from 'semver';
6
7import PackageDivider from './PackageDivider';
8import ChartItem from './ChartItem';
9
10require('../../node_modules/chartist/dist/chartist.min.css');
11import '../../assets/stylesheets/charts.scss';
12
13export default class ReleaseChart extends Component {
14
15  render () {
16    const { releases } = this.props;
17    if (!releases || !releases.length) return null;
18
19    const keys = releases.map((release)=>moment(release.date).format('MMMM YYYY'));
20    const firstVersion = this.getVersionNumber(_.first(releases));
21    const lastVersion = this.getVersionNumber(_.last(releases));
22
23    return (
24      <div className='chart'>
25        <PackageDivider text='Releases' />
26        <div className='chart-block'>
27          {_.map(releases, (release, index)=>(
28            <ChartItem
29              item={this.calculateChartNumber(release, firstVersion, lastVersion)}
30              label={release.version}
31              key={index}
32            />
33          ))}
34        </div>
35      </div>
36    );
37  }
38
39  calculateChartNumber (current, min, max) {
40    const currentVersion = this.getVersionNumber(current);
41
42    const percentages = {
43      date: this.percentAlongRange(currentVersion.date, min.date, max.date),
44      major: this.percentAlongRange(currentVersion.major, 0, max.major),
45      minor: this.percentAlongRange(currentVersion.minor, 0, max.minor),
46      patch: this.percentAlongRange(currentVersion.patch, 0, max.patch),
47    };
48
49    return {
50      date: percentages.date,
51      value: (percentages.major + percentages.minor + percentages.patch) / 3,
52    }
53  }
54
55  getVersionNumber (release) {
56    return {
57      date: new Date(release.date).getTime(),
58      major: semver.major(release.version) || 0,
59      minor: semver.minor(release.version) || 0,
60      patch: semver.patch(release.version) || 0,
61    };
62  }
63
64  percentAlongRange (x, a, b) {
65    return (x-a) / (b-a);
66  }
67}
68
69ReleaseChart.propTypes = {
70  releases: PropTypes.array,
71};
72
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)