Best JavaScript code snippet using argos
app.js
Source:app.js
1import React from "react";2import SelectBranch from "./select-branch";3import TabButtons from "./tabs-buttons";4import BranchOverView from './branch-overview';5import CypressCi from "./cypress-ci";6import ScreenshotDiffsTab from "./screenshot-diffs-tab";7import { TABS } from "./constants";8const vscode = acquireVsCodeApi();9const sendMessage = message => {10 vscode.postMessage(message);11};12class App extends React.Component {13 state = {14 showTab: TABS.overview,15 currentBranchName: null,16 screenshotDiffs: {files: [], unapproved: 0},17 branchList : [],18 cypressData: [],19 pullRequestUrl: null20 };21 setMessage(message) {22 this.setState({ message });23 }24 setCypressBuild(data) {25 if (data.type === 'COMPLETED') {26 this.setState({ cypressData: data.data || [] });27 }28 }29 closePanel() {30 vscode.postMessage({31 messageId: "quit",32 text: "Lets close the extension as user asked so."33 });34 }35 componentDidMount() {36 sendMessage({messageId: 'get-current-branch-info'});37 sendMessage({messageId: 'get-branch-list'});38 this.messageListener = window.addEventListener("message", event => {39 const message = event.data;40 const {data} = event.data;41 console.log("Received data from shell : " + message.messageId, message);42 switch (message.messageId) {43 case "retried":44 this.setMessage("Cant run more than one window. !");45 break;46 case "set-cypress-builds":47 this.setCypressBuild(data);48 break;49 case 'set-branch-info':50 this.pupulateBranch(message.data.branchInfo.branchName);51 break;52 case 'set-screenshot-diffs':53 this.setScreenshotDiffs(message.data);54 break;55 case 'set-branch-list':56 this.setBranchList(message.data);57 break;58 case 'set-pull-request':59 this.setBranchPR(message.data);60 break;61 }62 });63 }64 componentWillUnmount() {65 window.removeEventListener(this.messageListener);66 }67 setBranchPR({pullRequest, link}) {68 this.setState({69 branchPullRequest: pullRequest,70 pullRequestUrl: link71 });72 }73 sendHttpRequest({url, body}) {74 sendMessage({messageId: 'send-http-post-request', data: {url, body, requestId: Math.random()}});75 }76 setBranchList(list) {77 this.setState(({branchList}) => ({78 branchList: Array.from(new Set(list.concat(branchList)))79 }));80 }81 pupulateBranch(branch){82 this.setState(({branchList}) => ({83 currentBranchName: branch,84 branchList: Array.from(new Set([...branchList, branch]))85 }));86 this.setBranch(branch);87 }88 setBranch(branchName) {89 this.setState({ currentBranchName: branchName });90 }91 selectTab(tabName) {92 this.setState({ showTab: tabName });93 }94 getScreenshotDiffs(branchName){95 sendMessage({messageId: 'get-screenshot-diffs', data: {branchName}});96 }97 getCypressBuilds(){98 sendMessage({messageId: 'get-cypress-builds', data: {branchName: this.state.currentBranchName}});99 }100 openUrl(url){101 sendMessage({messageId: 'open-url', data: {url}});102 }103 getBranchDetails(branchName) {104 sendMessage({messageId: 'get-pull-request', data: {branchName}});105 }106 openFile(data){107 sendMessage({messageId: 'open-file', data});108 }109 setScreenshotDiffs(screenshotDiffs) {110 this.setState({screenshotDiffs});111 }112 triggerCypressBuild() {113 sendMessage({114 messageId: "get-trigger-cypress-build",115 data: { branchName: this.state.currentBranchName }116 });117 }118 setScreenshotDiffs(screenshotDiffs) {119 this.setState({ screenshotDiffs });120 }121 render() {122 const {123 showTab,124 currentBranchName,125 screenshotDiffs,126 branchList,127 branchPullRequest,128 pullRequestUrl129 } = this.state;130 const callbacks = {131 selectBranch: branchName => this.setBranch(branchName),132 selectTab: tabname => this.selectTab(tabname),133 getBranchDetails: branchName => this.getBranchDetails(branchName),134 getScreenshotDiffs: () => this.getScreenshotDiffs(currentBranchName),135 openUrl: url => this.openUrl(url),136 sendHttpRequest: ({ url, body }) => this.sendHttpRequest({ url, body }),137 openFile: url => this.openFile(url),138 triggerCypressBuild: () => this.triggerCypressBuild(),139 getCypressBuilds: () => this.getCypressBuilds()140 };141 const getTab = () => {142 switch (showTab) {143 case TABS.overview:144 return (145 <BranchOverView146 openUrl={callbacks.openUrl}147 selectedBranch={currentBranchName}148 getBranchDetails={callbacks.getBranchDetails}149 pullRequestUrl={pullRequestUrl}150 branchPullRequest={branchPullRequest}151 />152 );153 case TABS.cypressCi:154 return (155 <CypressCi156 data={this.state.cypressData}157 currentBranchName={this.state.currentBranchName}158 callBack={callbacks.triggerCypressBuild}159 getCypressBuilds={callbacks.getCypressBuilds}160 />161 );162 case TABS.screenshotDiffs:163 return (164 <ScreenshotDiffsTab165 branchName={currentBranchName}166 screenshotDiffs={screenshotDiffs}167 getScreenshotDiffs={callbacks.getScreenshotDiffs}168 openUrl={callbacks.openUrl}169 sendHttpRequest={callbacks.sendHttpRequest}170 openFile={callbacks.openFile}171 />172 );173 case TABS.ciLogs:174 return <div>Integration helper logs</div>;175 }176 };177 return (178 <div id="app">179 <SelectBranch180 selectBranch={callbacks.selectBranch}181 currentBranch={currentBranchName}182 list={branchList}183 />184 <TabButtons selectTab={callbacks.selectTab} selectedTab={showTab} />185 <div className="selected-tab-container">{getTab()}</div>186 </div>187 );188 }189}...
resolveBuild.test.js
Source:resolveBuild.test.js
1import request from 'supertest'2import { useDatabase, noGraphqlError } from 'server/test/utils'3import factory from 'server/test/factory'4import graphqlMiddleware from '../middleware'5describe('GraphQL', () => {6 useDatabase()7 describe('resolveBuild', () => {8 let build9 let user10 let screenshot211 beforeEach(async () => {12 user = await factory.create('User')13 const repository = await factory.create('Repository')14 await factory.create('UserRepositoryRight', {15 userId: user.id,16 repositoryId: repository.id,17 })18 build = await factory.create('Build', {19 repositoryId: repository.id,20 })21 const screenshot1 = await factory.create('Screenshot', {22 name: 'email_deleted',23 })24 screenshot2 = await factory.create('Screenshot', {25 name: 'email_deleted',26 })27 const screenshot3 = await factory.create('Screenshot', {28 name: 'email_added',29 })30 await factory.create('ScreenshotDiff', {31 buildId: build.id,32 baseScreenshotId: screenshot1.id,33 compareScreenshotId: screenshot2.id,34 score: 0,35 })36 await factory.create('ScreenshotDiff', {37 buildId: build.id,38 baseScreenshotId: screenshot1.id,39 compareScreenshotId: screenshot2.id,40 score: 0.3,41 })42 await factory.create('ScreenshotDiff', {43 buildId: build.id,44 baseScreenshotId: screenshot3.id,45 compareScreenshotId: screenshot3.id,46 score: 0,47 })48 })49 it('should sort the diffs by score', async () => {50 const res = await request(graphqlMiddleware())51 .post('/')52 .send({53 query: `{54 build(id: ${build.id}) {55 screenshotDiffs {56 baseScreenshot {57 name58 }59 compareScreenshot {60 name61 }62 score63 }64 }65 }`,66 })67 noGraphqlError(res)68 expect(res.status).toBe(200)69 const { screenshotDiffs } = res.body.data.build70 expect(screenshotDiffs).toEqual([71 {72 baseScreenshot: {73 name: 'email_deleted',74 },75 compareScreenshot: {76 name: 'email_deleted',77 },78 score: 0.3,79 },80 {81 baseScreenshot: {82 name: 'email_added',83 },84 compareScreenshot: {85 name: 'email_added',86 },87 score: 0,88 },89 {90 baseScreenshot: {91 name: 'email_deleted',92 },93 compareScreenshot: {94 name: 'email_deleted',95 },96 score: 0,97 },98 ])99 })100 it('should also display transitioning diffs', async () => {101 await factory.create('ScreenshotDiff', {102 buildId: build.id,103 baseScreenshotId: null,104 compareScreenshotId: screenshot2.id,105 score: null,106 })107 await request(graphqlMiddleware())108 .post('/')109 .send({110 query: `{111 build(id: ${build.id}) {112 screenshotDiffs {113 baseScreenshot {114 name115 }116 compareScreenshot {117 name118 }119 score120 }121 }122 }`,123 })124 .expect(noGraphqlError)125 .expect(res => {126 const { screenshotDiffs } = res.body.data.build127 expect(screenshotDiffs).toEqual([128 {129 baseScreenshot: null,130 compareScreenshot: {131 name: 'email_deleted',132 },133 score: null,134 },135 {136 baseScreenshot: {137 name: 'email_deleted',138 },139 compareScreenshot: {140 name: 'email_deleted',141 },142 score: 0.3,143 },144 {145 baseScreenshot: {146 name: 'email_added',147 },148 compareScreenshot: {149 name: 'email_added',150 },151 score: 0,152 },153 {154 baseScreenshot: {155 name: 'email_deleted',156 },157 compareScreenshot: {158 name: 'email_deleted',159 },160 score: 0,161 },162 ])163 })164 .expect(200)165 })166 })...
index.js
Source:index.js
1import React from "react";2import ScreenshotDiffItem from "./diff-item.js";3class ScreenshotDiffs extends React.Component {4 loadDataForBranch(){5 this.props.getScreenshotDiffs(this.props.branchName);6 }7 componentDidMount() {8 this.loadDataForBranch();9 }10 componentDidUpdate(prevProps) {11 if (prevProps.currentBranchName !== this.props.currentBranchName) {12 this.loadDataForBranch();13 }14 }15 render() {16 const {screenshotDiffs, openUrl, sendHttpRequest, openFile} = this.props;17 return <div id="screenshot-diffs-tab">18 <ul>19 {20 screenshotDiffs.files.length ? screenshotDiffs.files.map(diff => (21 <li className='file-screenshot-diff-group'>22 <ul>23 {24 diff.screenshots.map(diff => <ScreenshotDiffItem25 diff={diff}26 openUrl={openUrl}27 sendHttpRequest={sendHttpRequest}28 openFile={openFile}29 />)30 }31 </ul>32 </li>33 )) : "No screenshot diffs found."34 }35 </ul>36 </div>;37 }38}...
Using AI Code Generation
1var argos = require('argos');2 if (error) {3 console.log(error);4 } else {5 console.log(result);6 }7});
Using AI Code Generation
1var argos = require('argos');2var screenshotDiffs = argos.screenshotDiffs;3var config = require('./config.json');4var diffs = screenshotDiffs(config);5diffs.then(function(result){6console.log(result);7});8{9 "viewport": {10 },11}
Using AI Code Generation
1const screenshotDiffs = require('argos-ci').screenshotDiffs;2const path = require('path');3const fs = require('fs');4const rimraf = require('rimraf');5const diffDir = path.join(__dirname, 'diffs');6rimraf.sync(diffDir);7fs.mkdirSync(diffDir);8screenshotDiffs({9 screenshotsDir: path.join(__dirname, 'screenshots'),10 baselineDir: path.join(__dirname, 'baseline'),11})12.then(function (results) {13 console.log(results);14})15.catch(function (err) {16 console.error(err);17});18{19 "scripts": {20 },21 "dependencies": {22 }23}
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!!