Skip to content

Commit c8884c5

Browse files
committed
fixed release workflow and added cypress example
1 parent 30509c6 commit c8884c5

File tree

14 files changed

+15350
-1
lines changed

14 files changed

+15350
-1
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
- name: Release
4444
run: npm run release.ci -- ${{github.event.inputs.releaseType}}
4545
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ reports/
77
.DS_Store
88
yarn.lock
99
*.tgz
10+
11+
videos/
12+
screenshots/
13+
downloads/
14+
*.ndjson
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"json": {
3+
"enabled": true
4+
},
5+
"messages": {
6+
"enabled": false
7+
},
8+
"stepDefinitions": ["cypress/e2e/[filepath].step.{js,ts}"]
9+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const report = require("multiple-cucumber-html-reporter");
2+
const dayjs = require("dayjs");
3+
const fs = require("fs");
4+
5+
const data = fs.readFileSync("./reports/cypress-report.json", {
6+
encoding: "utf8",
7+
flag: "r",
8+
});
9+
const runInfo = JSON.parse(data);
10+
11+
const osName = () => {
12+
switch (runInfo["osName"]) {
13+
case "win32":
14+
return "windows";
15+
case "linux":
16+
return "ubuntu";
17+
default:
18+
console.log("Undefined OS");
19+
}
20+
};
21+
22+
const browserName = () => {
23+
switch (runInfo["browserName"]) {
24+
case "chrome":
25+
return "Chrome";
26+
case "firefox":
27+
return "Firefox";
28+
case "edge":
29+
return "Edge";
30+
case "webkit":
31+
return "Safari";
32+
default:
33+
console.log("Undefined Browser");
34+
}
35+
};
36+
37+
report.generate({
38+
jsonDir: "./reports/cucumber-json",
39+
reportPath: "./reports",
40+
metadata: {
41+
browser: {
42+
name: browserName(),
43+
version: runInfo["browserVersion"],
44+
},
45+
platform: {
46+
name: osName(),
47+
version: runInfo["osVersion"],
48+
},
49+
},
50+
customData: {
51+
title: "Run Info",
52+
data: [
53+
{ label: "Project", value: "Sample " },
54+
{ label: "Release", value: "1.0.0" },
55+
{ label: "Cypress Version", value: runInfo["cypressVersion"] },
56+
{ label: "Node Version", value: runInfo["nodeVersion"] },
57+
{
58+
label: "Execution Start Time",
59+
value: dayjs(runInfo["startedTestsAt"]).format(
60+
"YYYY-MM-DD HH:mm:ss.SSS"
61+
),
62+
},
63+
{
64+
label: "Execution End Time",
65+
value: dayjs(runInfo["endedTestsAt"]).format("YYYY-MM-DD HH:mm:ss.SSS"),
66+
},
67+
],
68+
},
69+
pageTitle: "Sample",
70+
reportName: "Sample",
71+
displayDuration: true,
72+
displayReportTime: true,
73+
});

examples/cypress/cypress.config.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const { defineConfig } = require("cypress");
2+
const fs = require("fs");
3+
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
4+
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");
5+
6+
function createReportJsonMeta(results) {
7+
fs.writeFileSync(
8+
"./reports/generated/results.json",
9+
JSON.stringify(
10+
{
11+
browserName: results.browserName,
12+
browserVersion: results.browserVersion,
13+
osName: results.osName,
14+
osVersion: results.osVersion,
15+
nodeVersion: results.config.resolvedNodeVersion,
16+
cypressVersion: results.cypressVersion,
17+
startedTestsAt: results.startedTestsAt,
18+
endedTestsAt: results.endedTestsAt,
19+
},
20+
null,
21+
"\t"
22+
)
23+
);
24+
}
25+
async function setupNodeEvents(on, config) {
26+
await preprocessor.addCucumberPreprocessorPlugin(on, config);
27+
28+
on("file:preprocessor", browserify.default(config));
29+
on("after:run", async (results) => {
30+
if (results) {
31+
createReportJsonMeta(results);
32+
let sourcePath = "./reports/cucumber-json";
33+
let oldExtension = "cucumber.json";
34+
let newExtension =
35+
results.browserName + "." + new Date().getTime() + ".json";
36+
fs.readdir(sourcePath, (err, files) => {
37+
if (err) {
38+
cy.log("Issue in the file reading");
39+
return;
40+
}
41+
42+
files.forEach((file) => {
43+
const oldFilePath = `${sourcePath}/${file}`;
44+
45+
if (file.endsWith(`.${oldExtension}`)) {
46+
const newFilePath = `${sourcePath}/${file.replace(
47+
`.${oldExtension}`,
48+
`.${newExtension}`
49+
)}`;
50+
fs.rename(oldFilePath, newFilePath, (err) => {
51+
if (err) {
52+
cy.log("Issue in the file renaming");
53+
}
54+
});
55+
}
56+
});
57+
});
58+
}
59+
});
60+
61+
return config;
62+
}
63+
64+
module.exports = defineConfig({
65+
e2e: {
66+
specPattern: "cypress/e2e/**/*.feature",
67+
setupNodeEvents,
68+
defaultCommandTimeout: 60000,
69+
pageLoadTimeout: 60000,
70+
video: false,
71+
reporter: "json",
72+
},
73+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Gmail Opening
2+
3+
Scenario: Gmail
4+
5+
Given I open the gmail
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference types="Cypress"/>
2+
3+
import { Given } from "@badeball/cypress-cucumber-preprocessor";
4+
5+
Given("I open the gmail", function () {
6+
cy.visit("https://mail.google.com");
7+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Google Opening
2+
3+
Scenario: Google
4+
5+
Given I open the google
6+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="cypress" />
2+
3+
import { Given } from "@badeball/cypress-cucumber-preprocessor";
4+
5+
// Import the necessary modules
6+
7+
Given("I open the google", function () {
8+
cy.visit("https://www.google.co.in");
9+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

0 commit comments

Comments
 (0)