Best JavaScript code snippet using best
metrics.test.js
Source: metrics.test.js
...181 t.is(latest.id, t.context.snapshot.id);182 t.is(latest.userId, t.context.user.id);183 await snapshot.destroy();184});185test.serial('fetchComparison() returns comparison of week apart snapshots', async t => {186 const STAR_DIFFERENCE = 3;187 const FORK_DIFFERENCE = 10;188 const VIEW_DIFFERENCE = 6;189 const CLONE_DIFFERENCE = 2;190 const [snapshot] = await userSnapshots(t.context.user.id);191 const alteredSnapshot = _.cloneDeep(snapshot);192 alteredSnapshot.metrics.map(repo => {193 repo.stars -= STAR_DIFFERENCE;194 repo.forks -= FORK_DIFFERENCE;195 repo.views -= VIEW_DIFFERENCE;196 repo.clones -= CLONE_DIFFERENCE;197 return repo;198 });199 const previousSnapshot = await createSnapshot(200 {201 metrics: alteredSnapshot.metrics,202 userId: t.context.user.id,203 createdAt: moment().subtract(WEEK_IN_DAYS, 'days'),204 },205 {206 returning: true,207 },208 );209 const comparison = await fetchComparison(t.context.user.id);210 const expectedRepoNames = REPOS211 .filter(repo => repo.selected)212 .map(repo => repo.name);213 const actualRepoNames = comparison.map(repo => repo.name);214 t.deepEqual(actualRepoNames, expectedRepoNames);215 t.true(comparison.length > 0);216 comparison.forEach(repo => t.deepEqual(Object.keys(repo), REPO_KEYS));217 comparison.forEach(repo => {218 t.deepEqual(Object.keys(repo), REPO_KEYS);219 Object.keys(repo).filter(key => key !== 'name').forEach(key => {220 t.deepEqual(Object.keys(repo[key]), COMPARISON_KEYS);221 });222 });223 t.true(comparison.every(repo => repo.stars.difference === STAR_DIFFERENCE));224 t.true(comparison.every(repo => repo.forks.difference === FORK_DIFFERENCE));225 t.true(comparison.every(repo => repo.views.difference === VIEW_DIFFERENCE));226 t.true(comparison.every(repo => repo.clones.difference === CLONE_DIFFERENCE));227 await previousSnapshot.destroy();228});229test.serial('fetchComparison() returns comparison based on selected metric types', async t => {230 const [snapshot] = await userSnapshots(t.context.user.id);231 const previousSnapshot = await createSnapshot(232 {233 metrics: snapshot.metrics,234 userId: t.context.user.id,235 createdAt: moment().subtract(WEEK_IN_DAYS, 'days'),236 },237 {238 returning: true,239 },240 );241 const UNSELECTED_METRIC_TYPES = new Set(['views', 'forks']);242 const ALTERED_METRIC_TYPES = _.cloneDeep(METRIC_TYPES).map(metricType => {243 if (UNSELECTED_METRIC_TYPES.has(metricType.name)) {244 metricType.selected = false;245 }246 return metricType;247 });248 await setUserMetricTypes(t.context.user, ALTERED_METRIC_TYPES);249 const comparison = await fetchComparison(t.context.user.id);250 t.true(comparison.length > 0);251 const actualRepoNames = comparison.map(repo => repo.name);252 const expectedRepoNames = REPOS253 .filter(repo => repo.selected)254 .map(repo => repo.name);255 t.deepEqual(actualRepoNames, expectedRepoNames);256 const EXPECTED_REPO_KEYS = REPO_KEYS.filter(key => !UNSELECTED_METRIC_TYPES.has(key));257 comparison.forEach(repo => t.deepEqual(Object.keys(repo), EXPECTED_REPO_KEYS));258 comparison.forEach(repo => {259 t.deepEqual(Object.keys(repo), EXPECTED_REPO_KEYS);260 Object.keys(repo).filter(key => key !== 'name').forEach(key => {261 t.deepEqual(Object.keys(repo[key]), COMPARISON_KEYS);262 });263 });264 await previousSnapshot.destroy();265});266test.serial('fetchComparison() returns null without sufficient snapshots', async t => {267 const comparison = await fetchComparison(t.context.user.id);268 t.is(comparison, null);...
queues.test.js
Source: queues.test.js
...34 sinon.assert.calledWith(ingest, user.id);35 t.deepEqual(jobResult, SNAPSHOT);36 ingest.restore();37});38test.serial('sendEmailWorker calls metrics.fetchComparison() and email.send()', async t => {39 const fetchComparison = sinon.stub(metrics, 'fetchComparison');40 fetchComparison.returns(Promise.resolve(WEEKLY_METRICS));41 const send = sinon.stub(email, 'send');42 send.returns(Promise.resolve(SENDGRID_SUCCESS));43 const jobResult = await sendEmailWorker(job);44 t.true(fetchComparison.calledOnce);45 t.true(send.calledOnce);46 sinon.assert.calledWith(fetchComparison, user.id);47 sinon.assert.calledWith(send, {48 user,49 metrics: WEEKLY_METRICS,50 date: moment().format('LL'),51 });52 t.deepEqual(jobResult, SENDGRID_SUCCESS);...
ComparisonResult.js
Source: ComparisonResult.js
...30 if (this.timer) {31 clearTimeout(this.timer);32 }33 }34 fetchComparison() {35 this.props.getComparison(this.props.research.comparisonID);36 }37 formatTime(time) {38 if (time > 9) {39 return _.toString(time);40 }41 return `0${time}`;42 }43 renderProgress() {44 const {comparison} = this.props;45 if (comparison.finished || !comparison.total) {46 return null;47 }48 const percentage = Math.min(100 * _.round(comparison.processed / comparison.total, 2), 100);...
Check out the latest blogs from LambdaTest on this topic:
LambdaTest has recently received two notable awards from the leading business software directory FinancesOnline after their experts were impressed with our test platform’s capabilities in accelerating one’s development process.
The layout of a web page is one of the most important features of a web page. It can affect the traffic inflow by a significant margin. At times, a designer may come up with numerous layout ideas and sometimes he/she may struggle the entire day to come up with one. Moreover, design becomes even more important when it comes to ensuring cross browser compatibility.
Chrome is hands down the most used browsers by developers and users alike. It is the primary reason why there is such a solid chrome community and why there is a huge list of Chrome Extensions targeted at developers.
In a startup, the major strength of the people is that they are multitaskers. Be it anything, the founders and the core team wears multiple hats and takes complete responsibilities to get the ball rolling. From designing to deploying, from development to testing, everything takes place under the hawk eyes of founders and the core members.
We are in the era of the ‘Heads down’ generation. Ever wondered how much time you spend on your smartphone? Well, let us give you an estimate. With over 2.5 billion smartphone users, an average human spends approximately 2 Hours 51 minutes on their phone every day as per ComScore’s 2017 report. The number increases by an hour if we include the tab users as well!
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!