Skip to content

Commit

Permalink
Make it TS
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Apr 21, 2021
1 parent beeb94d commit a4c33b5
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 28 deletions.
215 changes: 207 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
"@babel/plugin-syntax-jsx": "7.12.13",
"@babel/runtime-corejs3": "7.13.10",
"@babel/traverse": "7.13.0",
"@jest/reporters": "^26.6.2",
"@jest/test-result": "^26.6.2",
"@octokit/rest": "16.26.0",
"@octokit/webhooks": "7.1.0",
"@storybook/addon-a11y": "6.2.5",
Expand Down
20 changes: 20 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "ES6",
"lib": [ "ES6", "ES2020.string" ],
"rootDir": ".",

// These scripts aren't published and packages don't depend on them.
// Don't generate types, this is strictly for validation.
"incremental": true,
"declaration": true,
"declarationMap": true,
"outDir": ".cache"
},
"files": [
"./unit/GithubActionsReporter.ts"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
* LICENSE file in the root directory of this source tree.
*/

// import type {AggregatedResult, TestResult} from '@jest/test-result';
// import type { Reporter, Context } from '@jest/reporters';
// import type {Context} from './types';

// const { flatMap } = require( 'lodash' );
/**
* External dependencies
*/
import type { AggregatedResult, TestResult } from '@jest/test-result';
import { BaseReporter, Context } from '@jest/reporters';

const newLine = /\n/g;
const encodedNewLine = '%0A';
const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/;

class GithubActionReporter {
async onRunComplete( _contexts, _aggregatedResults ) {
const messages = getMessages( _aggregatedResults?.testResults );
export default class GithubActionReporter extends BaseReporter {
onRunComplete(
_contexts?: Set< Context >,
aggregatedResults?: AggregatedResult
): void {
const messages = getMessages( aggregatedResults?.testResults );

for ( const message of messages ) {
process.stderr.write( message + '\n' );
this.log( message );
}
}
}

function getMessages( results ) {
function getMessages( results: Array< TestResult > | undefined ) {
if ( ! results ) return [];

return results.reduce(
Expand All @@ -38,7 +41,7 @@ function getMessages( results ) {
)
.map( ( m ) => m.replace( newLine, encodedNewLine ) )
.map( ( m ) => lineAndColumnInStackTrace.exec( m ) )
//.filter((m): m is RegExpExecArray => m !== null)
.filter( ( m ): m is RegExpExecArray => m !== null )
.map(
( [ message, line, col ] ) =>
`::error file=${ testFilePath },line=${ line },col=${ col }::${ message }`
Expand All @@ -48,12 +51,6 @@ function getMessages( results ) {
);
}

function flatMap( fn ) {
return ( out, entry ) => out.concat( ...fn( entry ) );
function flatMap< In, Out >( map: ( x: In ) => Array< Out > ) {
return ( out: Array< Out >, entry: In ) => out.concat( ...map( entry ) );
}

// function flatMap< In, Out >( map: ( x: In ) => Array< Out > ) {
// return ( out: Array< Out >, entry: In ) => out.concat( ...map( entry ) );
// }

module.exports = GithubActionReporter;
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
{ "path": "packages/token-list" },
{ "path": "packages/url" },
{ "path": "packages/warning" },
{ "path": "packages/wordcount" }
{ "path": "packages/wordcount" },
{ "path": "test" },
],
"files": []
}

0 comments on commit a4c33b5

Please sign in to comment.