Skip to content

Commit

Permalink
Feat/add solution (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
syzzana committed Nov 18, 2023
1 parent c2e6f19 commit db712c4
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**/node_modules/*
node_modules/
test-results/
playwright-report
dist/

# IDE
.idea

# System Files
.DS_Store
Thumbs.db
{"mode":"full","isActive":false}
26 changes: 26 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/stylistic",
"prettier",
],
parser: "@typescript-eslint/parser",
root: true,
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/no-explicit-any": 0,
"no-console": 0,
"no-restricted-syntax": [
"error",
{
selector: "CallExpression[calle.property.name='only']",
message: "We don't wan to leave .only on our tests 😱",
},
{
selector: "CallExpression[callee.name='validateJsonSchema'][arguments.length!=3]",
message: "We don't want to commit validateJsonSchema(*,*,*,true)😎",
},
],
},
};
22 changes: 10 additions & 12 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
branches: ["main", "test/*"]
pull_request:
branches: [ "main" ]
branches: ["main", "test/*"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -23,14 +23,12 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "18.x"

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- name: Install dependencies
run: npm install
- name: Run tests with dummy data
run: npm test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
node_modules/
dist/
/test-results/
/playwright-report/
/playwright/.cache/
package-lock.json
.DS_Store
/test-results
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Playwright Specific
node_modules/
test-results/
playwright-report
dist/
# IDE - VSCode
.idea

# System Files
.DS_Store
Thumbs.db
{"mode":"full","isActive":false}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": false,
"printWidth": 120
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# indent-list-reporter
Playwright list reporter with colorful terminal and indentation

Playwright list reporter with colorful terminal and indentation
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "indent-list-reporter",
"version": "1.0.0",
"description": "Playwright list reporter for terminal with colors and indentation'",
"main": "./dist/src/indent-list-reporter.js",
"type": "module",
"homepage": "https://github.com/syzzana/indent-list-reporter/blob/main/README.md",
"scripts": {
"test": "npx playwright test",
"compile": "tsc",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write",
"prepare": "npm run compile",
"pretest": "npm run compile"
},
"keywords": [
"reporter"
],
"author": "Syzana Bicaj",
"license": "MIT",
"dependencies": {
"playwright": "^1.39.0",
"@playwright/test": "^1.39.0",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"chalk": "^5.3.0",
"dotenv": "^16.3.1",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"node-fetch": "^3.3.2",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
}
}
14 changes: 14 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "@playwright/test";

export default defineConfig({
testDir: "tests",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [["./dist/src/indent-list-reporter.js"]],
use: {
ignoreHTTPSErrors: true,
trace: "off",
},
});
70 changes: 70 additions & 0 deletions src/TestsPerSpecFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { TestStatus } from "@playwright/test";

export interface TestCaseData {
id: string;
title: string;
status: TestStatus;
line: number;
column: number;
duration: number;
}

export class SuiteTestCases {
private suiteDescription: string;
tests: TestCaseData[];

constructor(suiteDescription: string) {
this.suiteDescription = suiteDescription;
this.tests = [];
}

getSuiteDescription() {
return this.suiteDescription;
}

setSuiteDescription(suiteDescription: string) {
this.suiteDescription = suiteDescription;
}

getTests() {
return this.tests;
}

setTests(tests: TestCaseData[]) {
this.tests = tests;
}

addTestCase(test: TestCaseData) {
this.tests.push(test);
}
}

export class TestsPerSpecFile {
private specName: string;
private suiteTests: SuiteTestCases[];

constructor(specName: string) {
this.specName = specName;
this.suiteTests = [];
}

setTestCases(testCases: SuiteTestCases[]) {
this.suiteTests = testCases;
}

setSpecName(specName: string) {
this.specName = specName;
}

getSpecName() {
return this.specName;
}

getSuiteTests() {
return this.suiteTests;
}

addTestCases(testCase: SuiteTestCases) {
this.suiteTests.push(testCase);
}
}
120 changes: 120 additions & 0 deletions src/indent-list-reporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { TestCase, TestResult, Reporter, FullResult, Suite, FullConfig } from "@playwright/test/reporter";
import { SuiteTestCases, TestCaseData, TestsPerSpecFile } from "./TestsPerSpecFile";
import {
filterDuplicateSpecNames,
getFileNameOrParentSuite,
howToReadTestResults,
lineBreak,
log,
logFailedTests,
logSummary,
logTestResults,
StatusCounter,
} from "./testResults";
import chalk from "chalk";
import { TestStatus } from "@playwright/test";
import { TestError } from "playwright/types/testReporter";

interface TerminalColors {
specFileName: string;
suiteDescription: string;
}

interface IndentListReporterOptions {
isDimmed: boolean;
baseColors: TerminalColors;
isJenkins: boolean; //TODO implement colors for jenkins terminal
isGithubActions: boolean; //TODO implement colors for github actions terminal
}

export type TestCaseError = {
error: TestError;
titlePath: string[];
}

class IndentListReporter implements Reporter {
private _options: IndentListReporterOptions;
allTests: TestsPerSpecFile[] = [];
passed = 0;
failed = 0;
skipped = 0;
interrupted = 0;
timedOut = 0;
failedTests: TestCaseError[] = [];
constructor(options: IndentListReporterOptions) {
this._options = options;
}

printsToStdio() {
return true;
}

onBegin(config: FullConfig, suite: Suite) {
howToReadTestResults();
log(`${chalk.cyanBright.bgBlack("TEST RESULTS\n")}`);
const numberOfTests = chalk.whiteBright(suite.allTests().length);
const numberOfWorkers = chalk.whiteBright(config.workers.valueOf());
const testInfo = `Running ${numberOfTests} tests using ${numberOfWorkers} workers\n`;
console.log(chalk.gray(testInfo));
}

onTestEnd(test: TestCase, result: TestResult) {
const currentFileName = getFileNameOrParentSuite(test.titlePath(), false, true);
const currentParentSuite = getFileNameOrParentSuite(test.titlePath(), true, false);
const testCase: TestCaseData = {
id: test.id,
title: test.title,
line: test.location.line,
column: test.location.column,
status: result.status,
duration: result.duration,
};
const testsPerSpecFile = new TestsPerSpecFile(currentFileName);
const suiteTestCases = new SuiteTestCases(currentParentSuite);
suiteTestCases.addTestCase(testCase);
testsPerSpecFile.addTestCases(suiteTestCases);
this.allTests.push(testsPerSpecFile);
this.increaseTestStatusCounter(result.status);
if (result.status === "failed") {
const testCaseError: TestCaseError = {
error: result.error,
titlePath: test.titlePath(),
}
this.failedTests.push(testCaseError);
}
}

onEnd(result: FullResult) {
const myTests = filterDuplicateSpecNames(this.allTests);
logTestResults(myTests);
const statusCounter: StatusCounter = {
passed: this.passed,
failed: this.failed,
skipped: this.skipped,
interrupted: this.interrupted,
timedOut: this.timedOut,
};
if (this.failedTests.length > 0) {
log(chalk.bgBlack.italic.red("FAILED TESTS:"));
logFailedTests(this.failedTests);
}
log(lineBreak);
logSummary(result.duration, statusCounter);
}

increaseTestStatusCounter(test: TestStatus) {
if (test === "passed") {
this.passed++;
} else if (test === "failed") {
this.failed++;
} else if (test === "timedOut") {
this.timedOut++;
} else if (test === "skipped") {
this.skipped++;
} else if (test === "interrupted") {
this.interrupted++;
}
}
}

export default IndentListReporter;
Loading

0 comments on commit db712c4

Please sign in to comment.