How to use createCommitStatus method in qawolf

Best JavaScript code snippet using qawolf

autoupdater.test.js

Source:autoupdater.test.js Github

copy

Full Screen

1const autoupdater = require("../src/autoupdater");2jest.mock("@actions/core");3async function expectError(callback, expected) {4 let error;5 try {6 await callback();7 } catch (e) {8 error = e;9 }10 expect(error).toEqual(expected);11}12function createOctokitMock({ prs = [], repos, pulls }) {13 const checksMock = {14 listForRef: jest.fn().mockReturnValue(15 new Promise((resolve) =>16 resolve({17 data: {18 check_runs: [],19 },20 })21 )22 ),23 };24 const reposMock = {25 createCommitStatus: jest.fn(),26 getStatusChecksProtection: jest.fn().mockReturnValue(27 new Promise((resolve) =>28 resolve({29 data: { contexts: [] },30 })31 )32 ),33 ...repos,34 };35 const pullsMock = {36 updateBranch: jest.fn(),37 list: jest38 .fn()39 .mockReturnValue(new Promise((resolve) => resolve({ data: prs }))),40 ...pulls,41 };42 return {43 repos: reposMock,44 pulls: pullsMock,45 checks: checksMock,46 };47}48function createGithubMock({ octokit = {}, context = {} } = {}) {49 const contextMock = {50 repo: jest.mock(),51 ...context,52 };53 const octokitMock = {54 pulls: {55 updateBranch: jest.fn(),56 list: jest57 .fn()58 .mockReturnValue(new Promise((resolve) => resolve({ data: [] }))),59 },60 ...octokit,61 };62 return {63 context: contextMock,64 getOctokit: jest.fn().mockReturnValue(octokitMock),65 };66}67describe("autoupdater", () => {68 it("should throw an error if the GITHUB_TOKEN is falsey", () => {69 const githubMock = createGithubMock();70 return expectError(71 () => autoupdater(githubMock),72 new Error("GITHUB_TOKEN must be set")73 );74 });75 it("should make the octokit call to update the correct prs", async () => {76 const repo = { repo: "repo", owner: "owner" };77 const context = { repo, ref: "ref", eventName: "push" };78 const prs = [79 {80 labels: [{ name: "autoupdate" }],81 head: { ref: "head-ref0", sha: "head-sha0" },82 base: { ref: "base-ref0" },83 number: 0,84 },85 {86 labels: [],87 head: { ref: "head-ref1", sha: "head-sha1" },88 base: { ref: "base-ref1" },89 number: 1,90 },91 {92 labels: [{ name: "autoupdate" }, { name: "other" }],93 head: { ref: "head-ref2", sha: "head-sha2" },94 base: { ref: "base-ref2" },95 number: 2,96 },97 {98 labels: [{ name: "other" }],99 head: { ref: "head-ref3", sha: "head-sha3" },100 base: { ref: "base-ref3" },101 number: 3,102 },103 ];104 const octokitMock = createOctokitMock({ prs });105 const githubMock = createGithubMock({ context, octokit: octokitMock });106 await autoupdater(githubMock, { GITHUB_TOKEN: "GITHUB_TOKEN" });107 expect(octokitMock.pulls.list).toHaveBeenCalledTimes(1);108 expect(octokitMock.pulls.list).toHaveBeenCalledWith({109 ...repo,110 base: "ref",111 state: "open",112 });113 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledTimes(2);114 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledWith({115 ...repo,116 pull_number: 0,117 });118 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledWith({119 ...repo,120 pull_number: 2,121 });122 });123 it("should update commit statuses to reflect errors updating", async () => {124 const repo = { repo: "repo", owner: "owner" };125 const context = { repo, ref: "ref", eventName: "push" };126 const prs = [127 {128 labels: [{ name: "autoupdate" }],129 head: { ref: "head-ref0", sha: "head-sha0" },130 base: { ref: "base-ref" },131 number: 0,132 },133 {134 labels: [],135 head: { ref: "head-ref1", sha: "head-sha1" },136 base: { ref: "base-ref" },137 number: 1,138 },139 {140 labels: [{ name: "autoupdate" }, { name: "other" }],141 head: { ref: "head-ref2", sha: "head-sha2" },142 base: { ref: "base-ref" },143 number: 2,144 },145 {146 labels: [{ name: "other" }],147 head: { ref: "head-ref3", sha: "head-sha3" },148 base: { ref: "base-ref" },149 number: 3,150 },151 ];152 const pullsMock = {153 updateBranch: jest154 .fn()155 .mockRejectedValueOnce(new Error("My Error"))156 .mockResolvedValue(),157 };158 const octokitMock = createOctokitMock({ prs, pulls: pullsMock });159 const githubMock = createGithubMock({ context, octokit: octokitMock });160 await autoupdater(githubMock, { GITHUB_TOKEN: "GITHUB_TOKEN" });161 expect(octokitMock.repos.createCommitStatus).toHaveBeenCalledTimes(4);162 // head-sha0 fails163 expect(octokitMock.repos.createCommitStatus).toHaveBeenCalledWith({164 ...repo,165 context: "autoupdate from base-ref",166 description: "Updating",167 sha: "head-sha0",168 state: "pending",169 });170 expect(octokitMock.repos.createCommitStatus).toHaveBeenCalledWith({171 ...repo,172 context: "autoupdate from base-ref",173 description:174 "There was an error. Check the action output for more information.",175 sha: "head-sha0",176 state: "error",177 });178 // head-sha2 success179 expect(octokitMock.repos.createCommitStatus).toHaveBeenCalledWith({180 ...repo,181 context: "autoupdate from base-ref",182 description: "Updating",183 sha: "head-sha2",184 state: "pending",185 });186 expect(octokitMock.repos.createCommitStatus).toHaveBeenCalledWith({187 ...repo,188 context: "autoupdate from base-ref",189 description: "Successfully updated",190 sha: "head-sha2",191 state: "success",192 });193 expect(octokitMock.pulls.list).toHaveBeenCalledTimes(1);194 expect(octokitMock.pulls.list).toHaveBeenCalledWith({195 ...repo,196 base: "ref",197 state: "open",198 });199 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledTimes(2);200 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledWith({201 ...repo,202 pull_number: 0,203 });204 expect(octokitMock.pulls.updateBranch).toHaveBeenCalledWith({205 ...repo,206 pull_number: 2,207 });208 });...

Full Screen

Full Screen

create-status.test.ts

Source:create-status.test.ts Github

copy

Full Screen

...7 }).then((instance) => {8 octokit = instance;9 });10 });11 it("octokit.rest.repos.createCommitStatus()", () => {12 return Promise.all([13 octokit.rest.repos.createCommitStatus({14 owner: "octokit-fixture-org",15 repo: "create-status",16 sha: "0000000000000000000000000000000000000001",17 state: "failure",18 target_url: "https://example.com",19 description: "create-status failure test",20 context: "example/1",21 }),22 octokit.rest.repos.createCommitStatus({23 owner: "octokit-fixture-org",24 repo: "create-status",25 sha: "0000000000000000000000000000000000000001",26 state: "success",27 target_url: "https://example.com",28 description: "create-status success test",29 context: "example/2",30 }),31 ])32 .then(() => {33 return octokit.rest.repos.listCommitStatusesForRef({34 owner: "octokit-fixture-org",35 repo: "create-status",36 ref: "0000000000000000000000000000000000000001",...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

...7 }8 const statusArgs1 = context.repo({sha: context.payload.after, context: "great-app"});9 const statusArgs2 = context.repo({sha: context.payload.after, context: "great-app-2"});10 const statusArgs3 = context.repo({sha: context.payload.after, context: "great-app-3"});11 await context.octokit.repos.createCommitStatus({state: "pending", description: "started 1", ...statusArgs1});12 await context.octokit.repos.createCommitStatus({state: "pending", description: "started 2", ...statusArgs2});13 await context.octokit.repos.createCommitStatus({state: "pending", description: "started 3", ...statusArgs3});14 await delay(10000);15 await context.octokit.repos.createCommitStatus({state: "success", description: "AOK BOSS 1", ...statusArgs1});16 context.octokit.repos.createCommitStatus({state: "failure", description: "AOK BOSS 2", ...statusArgs2});17 context.octokit.repos.createCommitStatus({state: "success", description: "AOK BOSS 3", ...statusArgs3});18 });19};20function delay(ms: number) {21 return new Promise( resolve => setTimeout(resolve, ms) );...

Full Screen

Full Screen

createCommitStatuses.js

Source:createCommitStatuses.js Github

copy

Full Screen

1module.exports = async ({ github, context, solutionNamesString }) => {2 console.log(solutionNamesString)3 let solutionNamesArray = solutionNamesString.split(",")4 await solutionNamesArray.forEach(createCommitStatus)5 async function createCommitStatus(solutionName) {6 let contextToUse = "build-deploy-" + solutionName7 await github.rest.repos.createCommitStatus({8 owner: context.repo.owner,9 repo: context.repo.repo,10 sha: context.payload.pull_request.head.sha,11 context: contextToUse,12 state: "pending"13 })14 }...

Full Screen

Full Screen

create-commit-status.js

Source:create-commit-status.js Github

copy

Full Screen

...17 } catch (error) {18 console.error(error);19 }20};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createCommitStatus } = require("qawolf");2const { createCommitStatus } = require("qawolf");3const { createCommitStatus } = require("qawolf");4const { createCommitStatus } = require("qawolf");5const { createCommitStatus } = require("qawolf");6SyntaxError: Unexpected token {7const { createCommitStatus } = require("qawolf");8SyntaxError: Unexpected token {9const { createCommitStatus } = require("qawolf");10SyntaxError: Unexpected token {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createCommitStatus } = require("qawolf");2const { GITHUB_TOKEN } = process.env;3(async () => {4 await createCommitStatus({5 });6})();7 githubToken: ${{ secrets.GITHUB_TOKEN }}8 githubToken: ${{ secrets.GITHUB_TOKEN }}

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 qawolf 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