diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4d67b79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +--- +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['16'] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js v${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Enable Corepack + run: corepack enable + - name: Install dependencies + run: yarn install --immutable + - name: Build + run: yarn run build + - name: Run Tests + run: | + yarn run test + yarn run test:invalid + yarn run test:reporter + + timeout-minutes: 10 diff --git a/.gitignore b/.gitignore index 42859a2..8cf4d69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,23 @@ +# yarn +# See https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored. +.pnp.* .yarnclean -.yarn/cache +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions + +# npm packages +node_modules + build build-test dist -.idea reports -node_modules *.log package-lock.json lib lib-test +.idea diff --git a/.mocharc.json b/.mocharc.json index 8fcc375..8d0605a 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,5 +1,5 @@ { "require": "./register.js", "reporter": "spec", - "ui": "tdd" + "ui": "bdd" } \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..2ab3d4b --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v16.20.2 diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz deleted file mode 100644 index 342e6fd..0000000 Binary files a/.yarn/install-state.gz and /dev/null differ diff --git a/.yarnrc.yml b/.yarnrc.yml index 3fb7653..3186f3f 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -1,3 +1 @@ nodeLinker: node-modules - -yarnPath: /users/rpii/.yarn/releases/yarn-3.6.1.cjs diff --git a/README.md b/README.md index 4889c00..b3812d9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - # wdio-html-nice-reporter +# wdio-html-nice-reporter A reporter for webdriver.io which generates a nice HTML report. The name is silly but provides integration with webdriverio @@ -12,7 +12,7 @@ Note: if you are not getting your report generated in the cucumber or jasmine te "report": "node node_modules/wdio-html-nice-reporter/lib/makeReport.js master-report.html 'reports/html-reports/'", ``` If you do this you do not need to create a ReportAggregator in your wdio.config.ts -### Bug fix: json write wasnt awaited for correctly +### Bug fix: json write was not awaited for correctly ### Great new improvement: no more out of memory errors due to json.stringify @@ -103,7 +103,7 @@ onComplete: function (exitCode, config, capabilities, results) { ### To use a logger for debugging A new feature for developers is to add a log4js logger to see detailed debug output. See the test/reporter.spec.js for configuration options. -If you dont want to use the logging, include in your project @log4js-node/log4js-api and you can quiet all debugging. +If you don't want to use the logging, include in your project @log4js-node/log4js-api and you can quiet all debugging. via: const log4js = require('@log4js-node/log4js-api'); @@ -113,7 +113,7 @@ via: ### To generate a pdf file from this report -Requires an additional plugin to keep the support lightweight for those that dont want it. +Requires an additional plugin to keep the support lightweight for those that don't want it. see [@rpii/wdio-html-reporter-pdf](https://www.npmjs.com/package/@rpii/wdio-html-reporter-pdf) @@ -123,6 +123,4 @@ see [@rpii/wdio-html-reporter-pdf](https://www.npmjs.com/package/@rpii/wdio-html ## browserName -This must be set manually. Its not available at config time since the browser object doesnt exist until you start a session. - - +This must be set manually. It is not available at config time since the browser object doesn't exist until you start a session. diff --git a/package.json b/package.json index 273fa9c..6758489 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,9 @@ "clean:build": "rimraf ./lib", "clean:reports": "rimraf ./reports", "clean:logs": "rimraf ./logs", - "test": "cd test ;tsc", + "test": "cd test; tsc", "test:invalid": "mocha ./lib/test/invalid.test.spec.js", - "test:reporter": "mocha ./lib/test/reporter.spec.js", - "test:nested": "mocha ./test/nested.test.spec.ts" + "test:reporter": "mocha ./lib/test/reporter.spec.js" }, "repository": { "type": "git", diff --git a/test/invalid.test.spec.js b/test/invalid.test.spec.js deleted file mode 100644 index 59939d6..0000000 --- a/test/invalid.test.spec.js +++ /dev/null @@ -1,153 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -var fs_extra_1 = require("fs-extra"); -var path_1 = require("path"); -var chai_1 = require("chai"); -var index_js_1 = require("../src/index.js"); -var testdata_js_1 = require("./testdata.js"); -var log4js = require('log4js'); -log4js.configure({ - appenders: { - fileLog: { - type: 'file', - filename: "logs/console.log" - }, - 'out': { - type: 'stdout', - layout: { - type: "colored" - } - } - }, - categories: { - file: { appenders: ['fileLog'], level: 'debug' }, - "default": { appenders: ['out', 'fileLog'], level: 'debug' } - } -}); -var logger = log4js.getLogger("default"); -var reportAggregator; -var htmlReporter = new index_js_1.HtmlReporter({ - outputDir: './reports/html-reports/invalid/', - filename: 'report.html', - reportTitle: 'Unit Test Report Title', - showInBrowser: false, - browserName: "dummy", - LOG: logger, - collapseTests: true, - useOnAfterCommandForScreenshot: false -}); -describe('HtmlReporter', function () { - before(function () { - reportAggregator = new index_js_1.ReportAggregator({ - debug: false, - outputDir: './reports/html-reports/invalid/', - filename: 'master-report.html', - reportTitle: 'Master Report', - browserName: "test browser", - showInBrowser: true, - collapseTests: false, - LOG: logger, - useOnAfterCommandForScreenshot: false - }); - reportAggregator.clean(); - }); - // - // describe('on create', function () { - // it('should verify initial properties', function () { - // expect(Array.isArray(htmlReporter.suiteUids)).to.equal(true); - // expect(htmlReporter.suiteUids.length).to.equal(0); - // expect(Array.isArray(htmlReporter.suites)).to.equal(true); - // expect(htmlReporter.suites.length).to.deep.equal(0); - // expect(htmlReporter.indents).to.equal(0); - // expect(htmlReporter.suiteIndents).to.deep.equal({}); - // expect(htmlReporter.defaultTestIndent).to.equal(' '); - // expect(htmlReporter.metrics).to.deep.equal({ - // passed: 0, - // skipped: 0, - // failed: 0, - // start: 0, - // end: 0, - // duration: 0 - // }); - // }) - // }); - describe('onRunnerStart', function () { - before(function () { - htmlReporter.onRunnerStart(testdata_js_1.RUNNER); - }); - //This will fail. - it('set cid test', function () { - (0, chai_1.expect)(htmlReporter._currentCid).to.equal("0-0"); - }); - }); - describe('onRunnerEnd', function () { - it('should call htmlOutput method', function () { - var _this = this; - (function () { return __awaiter(_this, void 0, void 0, function () { - var reportFile; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, htmlReporter.onRunnerEnd(testdata_js_1.RUNNER)]; - case 1: - _a.sent(); - reportFile = path_1["default"].join(process.cwd(), htmlReporter.options.outputDir, encodeURIComponent(htmlReporter._currentSuiteUid), encodeURIComponent(htmlReporter._currentCid), htmlReporter.options.filename); - (0, chai_1.expect)(fs_extra_1["default"].existsSync(reportFile)).to.equal(true); - //wipe out output - fs_extra_1["default"].emptyDirSync(path_1["default"].join(process.cwd(), htmlReporter.options.outputDir, encodeURIComponent(htmlReporter._currentSuiteUid), encodeURIComponent(htmlReporter._currentCid))); - return [2 /*return*/]; - } - }); - }); })(); - }); - it('should invoke the reportAggregator', function () { - var _this = this; - (function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, reportAggregator.createReport()]; - case 1: - _a.sent(); - (0, chai_1.expect)(fs_extra_1["default"].existsSync(reportAggregator.reportFile)).to.equal(true); - return [2 /*return*/]; - } - }); - }); })(); - }); - }); -}); diff --git a/test/nested.test.spec.js b/test/nested.test.spec.js deleted file mode 100644 index 7c69154..0000000 --- a/test/nested.test.spec.js +++ /dev/null @@ -1,134 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -var fs_extra_1 = require("fs-extra"); -var log4js = require('log4js'); -var chai_1 = require("chai"); -var index_js_1 = require("../src/index.js"); -log4js.configure({ - appenders: { - fileLog: { - type: 'file', - filename: "logs/console.log" - }, - 'out': { - type: 'stdout', - layout: { - type: "colored" - } - } - }, - categories: { - file: { appenders: ['fileLog'], level: 'debug' }, - "default": { appenders: ['out', 'fileLog'], level: 'debug' } - } -}); -var logger = log4js.getLogger("default"); -var reportAggregator; -var htmlReporter = new index_js_1.HtmlReporter({ - outputDir: './reports/html-reports/', - filename: 'report.html', - reportTitle: 'Unit Test Report Title', - showInBrowser: false, - browserName: "dummy", - LOG: logger, - collapseTests: true, - useOnAfterCommandForScreenshot: false -}); -reportAggregator = new index_js_1.ReportAggregator({ - debug: false, - outputDir: './reports/html-reports', - filename: 'master-report.html', - reportTitle: 'Master Report', - browserName: "test browser", - showInBrowser: true, - collapseTests: false, - LOG: logger, - useOnAfterCommandForScreenshot: false -}); -reportAggregator.clean(); -describe('Suite 1', function () { - describe('Suite 2', function () { - it('test 1', function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - console.log('test 1 block'); - return [2 /*return*/]; - }); - }); }); - it('test 2', function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - console.log('test 2 block'); - return [2 /*return*/]; - }); - }); }); - }); - describe('Suite 3', function () { - it('test 3', function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - console.log('test 3 block'); - return [2 /*return*/]; - }); - }); }); - describe('Suite 4', function () { - describe('Suite 5', function () { - it('test 5', function () { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - console.log('test 5 block'); - return [2 /*return*/]; - }); - }); }); - }); - }); - }); -}); -function after() { - var _this = this; - (function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, reportAggregator.createReport()]; - case 1: - _a.sent(); - (0, chai_1.expect)(fs_extra_1["default"].existsSync(reportAggregator.reportFile)).to.equal(true); - return [2 /*return*/]; - } - }); - }); })(); -} -; -after(); diff --git a/test/nested.test.spec.ts b/test/nested.test.spec.ts index e2f891a..ce61d00 100644 --- a/test/nested.test.spec.ts +++ b/test/nested.test.spec.ts @@ -1,88 +1 @@ -import fs from 'fs-extra'; -import path from 'path'; -import log4js from 'log4js' ; -import {expect} from 'chai'; -import {HtmlReporter, ReportGenerator, ReportAggregator} from '../src/index.js'; - -log4js.configure({ // configure to use all types in different files. - appenders: { - fileLog: { - type: 'file', - filename: "logs/console.log" - }, - 'out': { - type: 'stdout', - layout: { - type: "colored" - }, - } - }, - categories: { - file: {appenders: ['fileLog'], level: 'debug'}, - default: {appenders: ['out', 'fileLog'], level: 'debug'} - } -}); - -let logger = log4js.getLogger("default") ; -let reportAggregator : ReportAggregator; - -let htmlReporter = new HtmlReporter({ - - outputDir: './reports/html-reports/', - filename: 'report.html', - reportTitle: 'Unit Test Report Title', - showInBrowser: false, - browserName: "dummy", - LOG : logger, - collapseTests: true, - useOnAfterCommandForScreenshot: false -}); - -reportAggregator = new ReportAggregator({ - debug: false, - outputDir: './reports/html-reports', - filename: 'master-report.html', - reportTitle: 'Master Report', - browserName : "test browser", - showInBrowser: true, - collapseTests: false, - LOG : logger, - useOnAfterCommandForScreenshot: false -}); -reportAggregator.clean(); - -describe('Suite 1', () => { - - describe('Suite 2', () => { - it('test 1', async () => { - console.log('test 1 block'); - }); - - it('test 2', async () => { - console.log('test 2 block'); - }); - }); - - describe('Suite 3', () => { - it('test 3', async () => { - console.log('test 3 block'); - }); - - describe('Suite 4', () => { - describe('Suite 5', () => { - it('test 5', async() => { - console.log('test 5 block'); - }); - }); - }); - }); -}); - -function after () { - (async () => { - await reportAggregator.createReport(); - expect(fs.existsSync(reportAggregator.reportFile)).to.equal(true); - })(); -}; - -after() ; \ No newline at end of file +// FIXME: Assert the report is created once. diff --git a/test/reporter.spec.js b/test/reporter.spec.js deleted file mode 100644 index 114ad93..0000000 --- a/test/reporter.spec.js +++ /dev/null @@ -1,234 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (g && (g = 0, op[0] && (_ = 0)), _) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -var fs_extra_1 = require("fs-extra"); -var path_1 = require("path"); -var log4js = require('log4js'); -var chai_1 = require("chai"); -var index_js_1 = require("../src/index.js"); -var testdata_js_1 = require("./testdata.js"); -log4js.configure({ - appenders: { - fileLog: { - type: 'file', - filename: "logs/html-reporter.log", - maxLogSize: 5000000, - level: 'debug' - }, - debugLog: { - type: 'file', - filename: "logs/debug-html-reporter.log", - maxLogSize: 5000000, - level: 'debug' - }, - out: { - type: 'stdout', - layout: { - type: "pattern", - pattern: "%[[%p]%] - %10.-100f{2} | %7.12l:%7.12o - %[%m%]" - } - }, - filterOut: { - type: 'stdout', - layout: { - type: "pattern", - pattern: "%[[%p]%] - %10.-100f{2} | %7.12l:%7.12o - %[%m%]" - }, - level: 'info' - } - }, - categories: { - file: { appenders: ['fileLog'], level: 'info' }, - "default": { appenders: ['fileLog'], level: 'info' }, - debug: { appenders: ['debugLog'], level: 'debug' } - } -}); -var logger = log4js.getLogger("debug"); -var reportAggregator; -var htmlReporter = new index_js_1.HtmlReporter({ - outputDir: './reports/html-reports/valid', - filename: 'report.html', - reportTitle: 'Unit Test Report Title', - LOG: logger, - browserName: "dummy" -}); -describe('HtmlReporter', function () { - before(function () { - reportAggregator = new index_js_1.ReportAggregator({ - outputDir: './reports/html-reports/valid', - filename: 'master-report.html', - reportTitle: 'Master Report', - browserName: "test browser", - LOG: logger - }); - reportAggregator.clean(); - }); - describe('on create', function () { - it('should verify initial properties', function () { - (0, chai_1.expect)(htmlReporter._suiteUids.size).to.deep.equal(0); - (0, chai_1.expect)(htmlReporter._indents).to.equal(0); - (0, chai_1.expect)(htmlReporter._suiteIndents).to.deep.equal({}); - (0, chai_1.expect)(htmlReporter.defaultTestIndent).to.equal(' '); - (0, chai_1.expect)(htmlReporter.metrics).to.deep.equal({ - passed: 0, - skipped: 0, - failed: 0, - duration: 0 - }); - }); - }); - describe('onRunnerStart', function () { - before(function () { - htmlReporter.onRunnerStart(testdata_js_1.RUNNER); - }); - it('should set cid', function () { - (0, chai_1.expect)(htmlReporter._currentCid).to.equal(testdata_js_1.RUNNER.cid); - }); - }); - describe('onSuiteStart', function () { - before(function () { - htmlReporter.onSuiteStart(testdata_js_1.SUITES[0]); - }); - it('should add to suiteUids', function () { - (0, chai_1.expect)(htmlReporter._suiteUids.size).to.equal(1); - // expect(htmlReporter._suiteUids[0]).to.equal('Foo test1') - (0, chai_1.expect)(htmlReporter._currentSuiteUid).to.equal('Foo test1'); - }); - it('should increase suiteIndents', function () { - (0, chai_1.expect)(htmlReporter._suiteIndents['Foo test1']).to.equal(1); - }); - }); - describe('onTestStart', function () { - before(function () { - htmlReporter.onTestStart(testdata_js_1.SUITES[0].tests[0]); - }); - }); - describe('onTestPass', function () { - before(function () { - htmlReporter.onTestPass(testdata_js_1.SUITES[0].tests[0]); - }); - it('should increase metrics.passed by 1', function () { - (0, chai_1.expect)(htmlReporter.metrics.passed).to.equal(1); - }); - after(function () { - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[0]); - }); - }); - describe('onTestStart', function () { - before(function () { - htmlReporter.onTestStart(testdata_js_1.SUITES[0].tests[1]); - }); - }); - describe('onTestFail', function () { - before(function () { - htmlReporter.onTestFail(testdata_js_1.SUITES[0].tests[1]); - }); - it('should increase metrics.failed by 1', function () { - (0, chai_1.expect)(htmlReporter.metrics.failed).to.equal(1); - }); - after(function () { - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[1]); - }); - }); - describe('onTestStart', function () { - before(function () { - htmlReporter.onTestStart(testdata_js_1.SUITES[0].tests[2]); - }); - }); - describe('onTestSkip', function () { - before(function () { - htmlReporter.onTestSkip(testdata_js_1.SUITES[0].tests[2]); - }); - it('should increase metrics.skipped by 1', function () { - (0, chai_1.expect)(htmlReporter.metrics.skipped).to.equal(1); - }); - after(function () { - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[2]); - }); - }); - describe('onTestEnd', function () { - before(function () { - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[0]); - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[1]); - htmlReporter.onTestEnd(testdata_js_1.SUITES[0].tests[2]); - }); - }); - describe('onSuiteEnd', function () { - before(function () { - htmlReporter.onSuiteEnd(testdata_js_1.SUITES[0]); - }); - it('should decrease indents', function () { - (0, chai_1.expect)(htmlReporter._indents).to.equal(0); - }); - it('should add the suite to the suites array', function () { - (0, chai_1.expect)(htmlReporter._suiteUids.size).to.equal(1); - }); - }); - describe('onRunnerEnd', function () { - it('should call htmlOutput method', function () { - var _this = this; - (function () { return __awaiter(_this, void 0, void 0, function () { - var reportFile; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, htmlReporter.onRunnerEnd(testdata_js_1.RUNNER)]; - case 1: - _a.sent(); - reportFile = path_1["default"].join(process.cwd(), htmlReporter.options.outputDir, encodeURIComponent(htmlReporter._currentSuiteUid), encodeURIComponent(htmlReporter._currentCid), htmlReporter.options.filename); - (0, chai_1.expect)(fs_extra_1["default"].existsSync(reportFile)).to.equal(true); - return [2 /*return*/]; - } - }); - }); })(); - }); - it('should invoke the reportAggregator', function () { - var _this = this; - (function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, reportAggregator.createReport()]; - case 1: - _a.sent(); - (0, chai_1.expect)(fs_extra_1["default"].existsSync(reportAggregator.reportFile)).to.equal(true); - return [2 /*return*/]; - } - }); - }); })(); - }); - }); -}); diff --git a/test/reporter.spec.ts b/test/reporter.spec.ts index 21972c2..919b1b4 100644 --- a/test/reporter.spec.ts +++ b/test/reporter.spec.ts @@ -63,10 +63,8 @@ let reportAggregator = new ReportAggregator({ }); reportAggregator.clean(); -suite('HtmlReporter', async () => { - - - test('on create should verify initial properties', async () => { +describe('HtmlReporter', async () => { + it('on create should verify initial properties', async () => { expect(htmlReporter._suiteUids.size).to.deep.equal(0); expect(htmlReporter._indents).to.equal(0); expect(htmlReporter._suiteIndents).to.deep.equal({}); @@ -78,11 +76,13 @@ suite('HtmlReporter', async () => { duration: 0 }); }); - test('onRunnerStart should set cid', async () => { + + it('onRunnerStart should set cid', async () => { htmlReporter.onRunnerStart(RUNNER); expect(htmlReporter._currentCid).to.equal(RUNNER.cid); }); - test('onSuiteStart should add to suiteUids', async () => { + + it('onSuiteStart should add to suiteUids', async () => { htmlReporter.onSuiteStart(SUITES[0]) expect(htmlReporter._suiteUids.size).to.equal(1); // expect(htmlReporter._suiteUids[0]).to.equal('Foo test1') @@ -90,56 +90,57 @@ suite('HtmlReporter', async () => { expect(htmlReporter._suiteIndents['Foo test1']).to.equal(1) }); - test('onTestStart', async () => { + it('onTestStart', async () => { htmlReporter.onTestStart(SUITES[0].tests[0]) }); - test('onTestPass', async () => { + + it('onTestPass', async () => { htmlReporter.onTestPass(SUITES[0].tests[0]) expect(htmlReporter.metrics.passed).to.equal(1) htmlReporter.onTestEnd(SUITES[0].tests[0]) }); - test('onTestStart', async () => { + it('onTestStart', async () => { htmlReporter.onTestStart(SUITES[0].tests[1]) }); - test('onTestFail', async () => { + + it('onTestFail', async () => { htmlReporter.onTestFail(SUITES[0].tests[1]) expect(htmlReporter.metrics.failed).to.equal(1) htmlReporter.onTestEnd(SUITES[0].tests[1]) }); - test('onTestStart', async () => { + it('onTestStart', async () => { htmlReporter.onTestStart(SUITES[0].tests[2]) }); - test('onTestSkip', async () => { + + it('onTestSkip', async () => { htmlReporter.onTestSkip(SUITES[0].tests[2]) expect(htmlReporter.metrics.skipped).to.equal(1) htmlReporter.onTestEnd(SUITES[0].tests[2]) }); - test('onTestEnd', async () => { + it('onTestEnd', async () => { htmlReporter.onTestEnd(SUITES[0].tests[0]); htmlReporter.onTestEnd(SUITES[0].tests[1]); htmlReporter.onTestEnd(SUITES[0].tests[2]); }); - - test('onSuiteEnd', async () => { + describe('onSuiteEnd', async () => { htmlReporter.onSuiteEnd(SUITES[0]) - test('should decrease indents', async () => { + it('should decrease indents', async () => { expect(htmlReporter._indents).to.equal(0) }); - test('should add the suite to the suites array', async () => { + it('should add the suite to the suites array', async () => { expect(htmlReporter._suiteUids.size).to.equal(1) }) }); - test('call reportAggregator', async () => { + it('call reportAggregator', async () => { await htmlReporter.onRunnerEnd(RUNNER); await reportAggregator.createReport(); expect(fs.existsSync(reportAggregator.reportFile)).to.equal(true); }); - }); diff --git a/test/testdata.ts b/test/testdata.ts index a4dce02..302434a 100644 --- a/test/testdata.ts +++ b/test/testdata.ts @@ -52,7 +52,7 @@ export const SUITES : SuiteStats[] = [ state : 'passed', "start": new Date("2021-06-11T01:28:24.778Z"), "_duration":9009, - "cid":"0-0", + // "cid":"0-0", "fullTitle":"full foo", "parent": "login test valid logins suite", }, @@ -140,216 +140,3 @@ export const SUITES : SuiteStats[] = [ }], } ] - -export const SUITES_MULTIPLE_ERRORS : SuiteStats[] = [ - { - cid : SUITE_UIDS[0], - uid : SUITE_UIDS[0], - title : SUITE_UIDS[0].slice(0, -1), - type : "suite", - file: "dummy", - hooks: [], - tests : [ - //@ts-ignore - { - cid : 'foo1', - uid : 'foo1', - title : 'foo', - state : 'passed', - }, - //@ts-ignore - { - cid : 'bar1', - uid : 'bar1', - title : 'bar', - state : 'passed', - } - ], - }, - { - cid : SUITE_UIDS[1], - uid : SUITE_UIDS[1], - title : SUITE_UIDS[1].slice(0, -1), - type : "suite", - file: "dummy", - hooks: [], - tests : [ - //@ts-ignore - { - cid : 'some test1', - uid : 'some test1', - title : 'some test', - state : 'passed', - }, - { - cid : 'a failed test', - uid : 'a failed test', - title : 'a test with two failures', - state : 'failed', - - errors : [ - - { - "name": "Error", - "message": "expected the party on the first part to be the party on the first part", - "stack": "First failed stack trace", - //@ts-ignore - "type": "Error" - }, - - //@ts-ignore - { - name: "Error", - message : 'expected the party on the second part to be the party on the second part', - stack : 'Second failed stack trace', - //@ts-ignore - type: "Error" - } - ] - } - ], - }, -] - -export const SUITES_NO_TESTS : SuiteStats[] = [ - //@ts-ignore - { - cid : SUITE_UIDS[0], - uid: SUITE_UIDS[0], - title: SUITE_UIDS[0].slice(0, -1), - file: "dummy", - tests: [], - suites: [], - hooks: [] - }, -] - -export const SUITES_NO_TESTS_WITH_HOOK_ERROR : SuiteStats[] = [ - { - cid : SUITE_UIDS[0], - uid: SUITE_UIDS[0], - title: SUITE_UIDS[0].slice(0, -1), - file: "dummy", - tests: [], - suites: [], - hooks: [ - //@ts-ignore - { - uid : 'a failed hook2', - title : 'a failed hook', - state : 'failed', - error : { - name: "Error", - message : 'expected foo to equal bar', - stack : 'Failed test stack trace' - } - }] - }, -] -export const SUITES_NESTED : SuiteStats[] = [ -{ - "cid" : "Foo test1", - "uid": "Foo test1", - "title": "Foo test", - "type": "suite", - "hooks": [], - "start": "2019-04-13T00:10:05.191Z", - "end": "2019-04-13T00:10:15.191Z", - "tests": [ - { - "type": "test", - "cid": "foo1", - "uid": "foo1", - "title": "foo", - "state": "passed", - "start": "2021-06-11T01:28:24.778Z", - "_duration": 9009, - "cid": "0-0", - "fullTitle": "full foo", - "parent": "login test valid logins suite" - }, - { - "cid": "bar1", - "uid": "bar1", - "title": "bar", - "state": "failed", - "start": "2021-06-11T01:28:24.778Z", - "_duration": 15809, - "events": [ - { - "type": "log", - "value": "Show Login Screen" - }, - { - "message": "Expected to be displayed but it is not", - "stack": "Error: Expected to be displayed but it is not\n at timer.catch.e (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\webdriverio\\build\\commands\\browser\\waitUntil.js:69:15)\n at Browser.runCommand (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\@wdio\\sync\\build\\wrapCommand.js:31:24)\n at Browser. (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\@wdio\\sync\\build\\wrapCommand.js:53:31)\n at Proxy. (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\chai-webdriverio\\dist\\assertions\\displayed.js:35:20)\n at Proxy.methodWrapper (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\chai\\lib\\chai\\utils\\addMethod.js:57:25)\n at LoginPage.displayed [as assertInvalidCredentials] (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\test\\pages/login.page.js:112:51)\n at LoginPage.assertion [as login] (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\test\\pages/login.page.js:89:9)\n at LoginPage.login [as loginFn] (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\test\\pages/login.page.js:98:14)\n at module.exports.loginFn [as fn] (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\test\\specs/login2.spec.js:29:23)\n at module.exports.runCase (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\@rpii\\wdio-data-driven\\lib\\wdio-data-driven.js:92:22)\n at module.exports.forCasesInSpreadsheet (C:\\Users\\rpii\\Development\\micro-magic-web-e2e-test\\node_modules\\@rpii\\wdio-data-driven\\lib\\wdio-data-driven.js:71:18)", - "type": "Error" - }, - { - "type": "screenshot", - "value": "test\\test.png" - } - ] - } - ], - "suites": [ - { - "cid" : "nested Foo test1", - "uid": "nested Foo test1", - "title": "Nested Foo test1", - "type": "suite", - "hooks": [], - "start": "2019-04-13T00:10:05.191Z", - "end": "2019-04-13T00:10:15.191Z", - "tests": [ - { - "type": "test", - "cid": "foo1", - "uid": "foo1", - "title": "foo", - "state": "passed", - "start": "2021-06-11T01:28:24.778Z", - "_duration": 9009, - "cid": "0-0", - "fullTitle": "full foo", - "parent": "login test valid logins suite" - } - ] - }, - { - "cid" : "Nested Foo test2", - "uid": "Nested Foo test2", - "title": "Nested Foo test2", - "type": "suite", - "hooks": [], - "start": "2019-04-13T00:10:05.191Z", - "end": "2019-04-13T00:10:15.191Z", - "tests": [], - "suites": [ - { - "cid" : "Foo test2", - "uid": "Foo test2", - "title": "nested Foo test2", - "type": "suite", - "hooks": [], - "start": "2019-04-13T00:10:05.191Z", - "end": "2019-04-13T00:10:15.191Z", - "tests": [ - { - "type": "test", - "cid": "foo1", - "uid": "foo1", - "title": "foo", - "state": "passed", - "start": "2021-06-11T01:28:24.778Z", - "_duration": 9009, - "fullTitle": "full foo", - "parent": "login test valid logins suite" - } - ] - } - ] - } - ] - } -] diff --git a/test/tsconfig.json b/test/tsconfig.json index 678043c..86801d2 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -20,7 +20,8 @@ "@rpii/wdio-report-events", "@types/chai", "@types/mocha" - ] + ], + "skipLibCheck": true }, "include": [ "../test/*.ts" diff --git a/yarn.lock b/yarn.lock index 85c16bb..cd9427b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4873,11 +4873,11 @@ __metadata: "typescript@patch:typescript@^5.1.3#~builtin": version: 5.1.3 - resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin::version=5.1.3&hash=5da071" + resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin::version=5.1.3&hash=ad5954" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 6f0a9dca6bf4ce9dcaf4e282aade55ef4c56ecb5fb98d0a4a5c0113398815aea66d871b5611e83353e5953a19ed9ef103cf5a76ac0f276d550d1e7cd5344f61e + checksum: 32a25b2e128a4616f999d4ee502aabb1525d5647bc8955e6edf05d7fbc53af8aa98252e2f6ba80bcedfc0260c982b885f3c09cfac8bb65d2924f3133ad1e1e62 languageName: node linkType: hard