@elevate_security/browser-test-cli
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "@elevate_security/browser-test-cli", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Run browser tests with Ghost Inspector and GitHub", | ||
@@ -14,3 +14,3 @@ "main": "src/index.js", | ||
"test": "jest", | ||
"lint": "eslint ." | ||
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint ." | ||
}, | ||
@@ -21,11 +21,12 @@ "license": "Apache-2.0", | ||
"isomorphic-fetch": "^3.0.0", | ||
"octokit": "^3.1.2" | ||
"octokit": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.56.0", | ||
"eslint": "^9.2.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-license-header": "^0.6.1", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.1.1" | ||
"prettier": "^3.2.5" | ||
} | ||
} |
# browser-test-cli | ||
[![build](https://github.com/ElevateSecurity/browser-test-cli/actions/workflows/build.yml/badge.svg)](https://github.com/ElevateSecurity/browser-test-cli/actions/workflows/build.yml) | ||
[![NPM Version (with dist tag)](https://img.shields.io/npm/v/%40elevate_security%2Fbrowser-test-cli/latest)](https://www.npmjs.com/package/@elevate_security/browser-test-cli) | ||
@@ -5,0 +5,0 @@ |
@@ -0,1 +1,6 @@ | ||
/* | ||
* Copyright Mimecast Services Limited or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
const fetch = require("isomorphic-fetch") | ||
@@ -2,0 +7,0 @@ |
@@ -0,1 +1,6 @@ | ||
/* | ||
* Copyright Mimecast Services Limited or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
exports.DEFAULT_CONFIG = require("./default-config.js") |
#!/usr/bin/env node | ||
/* | ||
* Copyright Mimecast Services Limited or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
const GhostInspector = require("ghost-inspector") | ||
@@ -10,3 +15,3 @@ const { Octokit } = require("octokit") | ||
ghostInspectorFacade, | ||
githubFacade, | ||
scmFacade, | ||
suiteId, | ||
@@ -33,3 +38,3 @@ startUrl, | ||
await githubFacade.postGitHubStatus({ | ||
await scmFacade.postStatus({ | ||
state: "pending", | ||
@@ -55,3 +60,3 @@ description: "Browser tests running", | ||
if (!allPassing) { | ||
await githubFacade.postGitHubStatus({ | ||
await scmFacade.postStatus({ | ||
state: "failure", | ||
@@ -62,3 +67,3 @@ description: `Browser tests failed (${countFailing} / ${testResults.length})`, | ||
} else { | ||
await githubFacade.postGitHubStatus({ | ||
await scmFacade.postStatus({ | ||
state: "success", | ||
@@ -80,2 +85,6 @@ description: `Browser tests passed (${countPassing} / ${testResults.length})`, | ||
const isFeatureBranch = () => { | ||
// Special config value of `["*"]` indicates all branches are main branches | ||
if (mainBranches.includes("*")) { | ||
return false | ||
} | ||
return !mainBranches.includes(branchName) | ||
@@ -121,2 +130,8 @@ } | ||
const log = { | ||
stderr(...args) { | ||
console.error(...args) | ||
}, | ||
} | ||
;(async () => { | ||
@@ -127,19 +142,4 @@ if (require.main !== module) { | ||
const log = { | ||
stderr(...args) { | ||
console.error(...args) | ||
}, | ||
} | ||
try { | ||
const { | ||
SUITE_ID, | ||
START_URL, | ||
GI_API_KEY, | ||
BRANCH_NAME, | ||
GITHUB_TOKEN, | ||
COMMIT_ID, | ||
REPO_OWNER, | ||
REPO_NAME, | ||
} = demandEnvVars( | ||
const { SUITE_ID, START_URL, GI_API_KEY, BRANCH_NAME, COMMIT_ID } = demandEnvVars( | ||
"SUITE_ID", | ||
@@ -149,6 +149,3 @@ "START_URL", | ||
"BRANCH_NAME", | ||
"GITHUB_TOKEN", | ||
"COMMIT_ID", | ||
"REPO_OWNER", | ||
"REPO_NAME", | ||
) | ||
@@ -159,22 +156,6 @@ | ||
const ghostInspectorClient = GhostInspector(GI_API_KEY) | ||
const githubClient = new Octokit({ auth: GITHUB_TOKEN, request: { fetch } }) | ||
const postGitHubStatus = ({ state, description, resultUrl }) => { | ||
return githubClient.request("POST /repos/{owner}/{repo}/statuses/{sha}", { | ||
owner: REPO_OWNER, | ||
repo: REPO_NAME, | ||
sha: COMMIT_ID, | ||
state, | ||
target_url: resultUrl, | ||
description, | ||
context: "browser-tests", | ||
headers: { | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
}, | ||
}) | ||
} | ||
await run({ | ||
ghostInspectorFacade: ghostInspectorClient, | ||
githubFacade: { postGitHubStatus }, | ||
scmFacade: createScmFacade(), | ||
suiteId: SUITE_ID, | ||
@@ -192,1 +173,30 @@ startUrl: START_URL, | ||
})() | ||
function createScmFacade() { | ||
const { GITHUB_TOKEN } = process.env | ||
if (GITHUB_TOKEN) { | ||
log.stderr("No GITHUB_TOKEN provided, no SCM statuses will be published") | ||
return { postStatus: () => {} } | ||
} | ||
const { COMMIT_ID, REPO_OWNER, REPO_NAME } = demandEnvVars("COMMIT_ID", "REPO_OWNER", "REPO_NAME") | ||
const githubClient = new Octokit({ auth: GITHUB_TOKEN, request: { fetch } }) | ||
const postStatus = ({ state, description, resultUrl }) => { | ||
return githubClient.request("POST /repos/{owner}/{repo}/statuses/{sha}", { | ||
owner: REPO_OWNER, | ||
repo: REPO_NAME, | ||
sha: COMMIT_ID, | ||
state, | ||
target_url: resultUrl, | ||
description, | ||
context: "browser-tests", | ||
headers: { | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
}, | ||
}) | ||
} | ||
return { postStatus } | ||
} |
@@ -0,6 +1,11 @@ | ||
/* | ||
* Copyright Mimecast Services Limited or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
const { run } = require("./run-browser-tests") | ||
describe("run-browser-tests", () => { | ||
it("posts the correct GitHub status when tests pass", async () => { | ||
const postGitHubStatus = jest.fn() | ||
it("posts the correct SCM status when tests pass", async () => { | ||
const postStatus = jest.fn() | ||
await run({ | ||
@@ -34,4 +39,4 @@ ghostInspectorFacade: { | ||
}, | ||
githubFacade: { | ||
postGitHubStatus, | ||
scmFacade: { | ||
postStatus, | ||
}, | ||
@@ -49,3 +54,3 @@ suiteId: "SuiteId", | ||
expect(postGitHubStatus).toHaveBeenCalledWith({ | ||
expect(postStatus).toHaveBeenCalledWith({ | ||
state: "pending", | ||
@@ -55,3 +60,3 @@ description: "Browser tests running", | ||
}) | ||
expect(postGitHubStatus).toHaveBeenLastCalledWith({ | ||
expect(postStatus).toHaveBeenLastCalledWith({ | ||
state: "success", | ||
@@ -63,4 +68,4 @@ description: "Browser tests passed (2 / 2)", | ||
it("posts the correct GitHub status when tests fail", async () => { | ||
const postGitHubStatus = jest.fn() | ||
it("posts the correct SCM status when tests fail", async () => { | ||
const postStatus = jest.fn() | ||
await run({ | ||
@@ -94,4 +99,4 @@ ghostInspectorFacade: { | ||
}, | ||
githubFacade: { | ||
postGitHubStatus, | ||
scmFacade: { | ||
postStatus, | ||
}, | ||
@@ -109,3 +114,3 @@ suiteId: "SuiteId", | ||
expect(postGitHubStatus).toHaveBeenCalledWith({ | ||
expect(postStatus).toHaveBeenCalledWith({ | ||
state: "pending", | ||
@@ -115,3 +120,3 @@ description: "Browser tests running", | ||
}) | ||
expect(postGitHubStatus).toHaveBeenLastCalledWith({ | ||
expect(postStatus).toHaveBeenLastCalledWith({ | ||
state: "failure", | ||
@@ -118,0 +123,0 @@ description: "Browser tests failed (1 / 2)", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23791
362
2
6
6
Updatedoctokit@^3.2.0