Skip to content

Commit

Permalink
spring cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Nov 9, 2021
1 parent a11d83c commit deb3af8
Show file tree
Hide file tree
Showing 20 changed files with 10,387 additions and 219 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"env": {
"es6": true,
"node": true
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Manual NPM Publish

on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type - major, minor or patch'
required: true
default: 'patch'
distTag:
description: 'NPM tag (e.g. use "next" to release a test version)'
required: true
default: 'latest'

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: 'main'
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 14.x
- name: NPM Setup
run: |
npm set registry "https://registry.npmjs.org/"
npm set //registry.npmjs.org/:_authToken $NPM_TOKEN
npm whoami
- name: Git Setup
run: |
git config --global user.email "community@webdriver.io"
git config --global user.name "WebdriverIO Release Bot"
- name: Install Dependencies
run: npm ci
- name: Build Project
run: npm run build
env:
NODE_ENV: production
- name: Release
run: npm run release:ci -- ${{github.event.inputs.releaseType}}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Test

on:
push:
branches:
- main
pull_request:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 16
- run: npm ci
- run: npm run build --if-present
- run: npm test
env:
CI: true
- uses: actions/upload-artifact@v2
if: failure()
with:
name: wdio-logs
path: ./test/*.log
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ node_modules

# Optional REPL history
.node_repl_history
package-lock.json
yarn.lock
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.13.0
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

118 changes: 58 additions & 60 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const WdioReporter = require('@wdio/reporter').default
const assert = require('assert')
const WdioReporter = require('@wdio/reporter').default;
const assert = require('assert');

/**
* @typedef {Object} SuiteStats
Expand Down Expand Up @@ -50,7 +48,7 @@ const assert = require('assert')

class WdioTeamcityReporter extends WdioReporter {
static escape (str) {
if (!str) return ''
if (!str) return '';
return str
.toString()
.replace(/\|/g, '||')
Expand All @@ -61,71 +59,71 @@ class WdioTeamcityReporter extends WdioReporter {
.replace(/\u0085/g, '|x') // next line
.replace(/\u2028/g, '|l') // line separator
.replace(/\u2029/g, '|p') // paragraph separator
.replace(/'/g, '|\'')
.replace(/'/g, '|\'');
}

static bool (value, fallback) {
return typeof value === 'boolean' ? value : fallback
return typeof value === 'boolean' ? value : fallback;
}

static number (value, fallback) {
return typeof value === 'number' ? value : fallback
return typeof value === 'number' ? value : fallback;
}

static string (value, fallback) {
return typeof value === 'string' ? value : fallback
return typeof value === 'string' ? value : fallback;
}

constructor (reporterOptions) {
const r = WdioTeamcityReporter
const r = WdioTeamcityReporter;
const params = {
captureStandardOutput: r.bool(reporterOptions.captureStandardOutput, false),
flowId: r.bool(reporterOptions.flowId, true),
message: r.string(reporterOptions.message, '[title]'),
stdout: true,
writeStream: process.stdout
}
const options = Object.assign(reporterOptions, params)
writeStream: process.stdout,
};
const options = Object.assign(reporterOptions, params);

super(options)
super(options);
}

/**
* @param {SuiteStats} suiteStats
*/
onSuiteStart (suiteStats) {
this._m('##teamcity[testSuiteStarted name=\'{name}\' flowId=\'{id}\']', suiteStats)
this._m('##teamcity[testSuiteStarted name=\'{name}\' flowId=\'{id}\']', suiteStats);
}

/**
* @param {TestStats} testStats
*/
onTestStart (testStats) {
this._m('##teamcity[testStarted name=\'{name}\' captureStandardOutput=\'{capture}\' flowId=\'{id}\']', testStats)
this._m('##teamcity[testStarted name=\'{name}\' captureStandardOutput=\'{capture}\' flowId=\'{id}\']', testStats);
}

/**
* @param {TestStats} testStats
*/
onTestEnd (testStats) {
if (testStats.state === 'skipped') return
this._m('##teamcity[testFinished name=\'{name}\' duration=\'{ms}\' flowId=\'{id}\']', testStats)
if (testStats.state === 'skipped') return;
this._m('##teamcity[testFinished name=\'{name}\' duration=\'{ms}\' flowId=\'{id}\']', testStats);
}

/**
* @param {TestStats} testStats
*/
onTestFail (testStats) {
const { escape, number } = WdioTeamcityReporter
const specFileRetryAttempts = number(this.runnerStat.config.specFileRetryAttempts, 0)
const specFileRetries = number(this.runnerStat.config.specFileRetries, 0)
const attempt = escape(`${specFileRetryAttempts}/${specFileRetries}`)
const { escape, number } = WdioTeamcityReporter;
const specFileRetryAttempts = number(this.runnerStat.config.specFileRetryAttempts, 0);
const specFileRetries = number(this.runnerStat.config.specFileRetries, 0);
const attempt = escape(`${specFileRetryAttempts}/${specFileRetries}`);

if (specFileRetryAttempts === specFileRetries) {
// ##teamcity[testFailed type='comparisonFailure' name='test2' message='failure message' details='message and stack trace' expected='expected value' actual='actual value']
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', testStats)
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', testStats);
} else {
this._m(`##teamcity[message name='{name}' text='attempt ${attempt} failed: {error}' flowId='{id}']`, testStats)
this._m(`##teamcity[message name='{name}' text='attempt ${attempt} failed: {error}' flowId='{id}']`, testStats);
}
}

Expand All @@ -134,80 +132,80 @@ class WdioTeamcityReporter extends WdioReporter {
*/
onHookEnd (hookStats) {
if (hookStats.state === 'failed') {
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', hookStats)
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', hookStats);
}
}

/**
* @param {TestStats} testStats
*/
onTestSkip (testStats) {
this._m('##teamcity[testIgnored name=\'{name}\' message=\'skipped\' flowId=\'{id}\']', testStats)
this._m('##teamcity[testIgnored name=\'{name}\' message=\'skipped\' flowId=\'{id}\']', testStats);
}

/**
* @param {SuiteStats} suiteStats
*/
onSuiteEnd (suiteStats) {
const pendingTests = Object.values(suiteStats.tests).filter(test => test.state === 'pending')
const pendingTests = Object.values(suiteStats.tests).filter(test => test.state === 'pending');
pendingTests.forEach(testStat => {
testStat.error = testStat.error || {
message: 'Test is considered as failed, as it is still "pending" on suite end.',
stack: ''
}
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', testStat)
})
stack: '',
};
this._m('##teamcity[testFailed name=\'{name}\' message=\'{error}\' details=\'{stack}\' flowId=\'{id}\']', testStat);
});

this._m('##teamcity[testSuiteFinished name=\'{name}\' flowId=\'{id}\']', suiteStats)
this._m('##teamcity[testSuiteFinished name=\'{name}\' flowId=\'{id}\']', suiteStats);
}

/**
* @param {string} template
* @param {TestStats | SuiteStats} stats
*/
_m (template, stats) {
assert(stats != null, '_m(): missing stats argument')
assert(stats != null, '_m(): missing stats argument');

if (!this.options.flowId) {
template = template.replace(' flowId=\'{id}\'', '')
template = template.replace(' flowId=\'{id}\'', '');
}

const fragment = pattern => {
switch (pattern) {
case '{capture}':
return this.options.captureStandardOutput ? 'true' : 'false'
case '{id}':
return this.runnerStat.sessionId + '/' + stats.cid
case '{ms}':
return stats._duration
case '{name}':
var name = this.options.message
if (name.includes('[browser]')) name = name.replace(/\[browser\]/g, this._v())
if (name.includes('[title]')) name = name.replace(/\[title\]/g, stats.title)
return name
case '{state}':
return stats.state
case '{error}':
return stats.error.message
case '{stack}':
return stats.error.stack
default:
return ''
case '{capture}':
return this.options.captureStandardOutput ? 'true' : 'false';
case '{id}':
return this.runnerStat.sessionId + '/' + stats.cid;
case '{ms}':
return stats._duration;
case '{name}': {
let name = this.options.message;
if (name.includes('[browser]')) name = name.replace(/\[browser\]/g, this._v());
if (name.includes('[title]')) name = name.replace(/\[title\]/g, stats.title);
return name;
} case '{state}':
return stats.state;
case '{error}':
return stats.error.message;
case '{stack}':
return stats.error.stack;
default:
return '';
}
}
};

const m = template.replace(/\{[a-z]+\}/gi, m =>
WdioTeamcityReporter.escape(fragment(m)))
WdioTeamcityReporter.escape(fragment(m)));

this.write(m + '\n')
this.write(m + '\n');
}

_v () {
// @see https://github.com/webdriverio/webdriverio/blob/v6.10.5/packages/webdriver/src/types.ts#L215
const { browserName, browserVersion, version } = this.runnerStat.capabilities
return `${browserName} ${browserVersion || version}`
const { browserName, browserVersion, version } = this.runnerStat.capabilities;
return `${browserName} ${browserVersion || version}`;
}
}

module.exports.default = WdioTeamcityReporter
module.exports.reporterName = 'teamcity'
module.exports.default = WdioTeamcityReporter;
module.exports.reporterName = 'teamcity';
Loading

0 comments on commit deb3af8

Please sign in to comment.