From beeb94dee77c7f46282995c9d87b200a3166be03 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 13:46:35 +0200 Subject: [PATCH 01/22] Add JS Based GHA Reporter --- test/unit/GithubActionsReporter.js | 59 ++++++++++++++++++++++++++++++ test/unit/jest.config.js | 1 + 2 files changed, 60 insertions(+) create mode 100644 test/unit/GithubActionsReporter.js diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js new file mode 100644 index 00000000000000..3e11760f4af693 --- /dev/null +++ b/test/unit/GithubActionsReporter.js @@ -0,0 +1,59 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * 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' ); + +const newLine = /\n/g; +const encodedNewLine = '%0A'; +const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/; + +class GithubActionReporter { + async onRunComplete( _contexts, _aggregatedResults ) { + const messages = getMessages( _aggregatedResults?.testResults ); + + for ( const message of messages ) { + process.stderr.write( message + '\n' ); + } + } +} + +function getMessages( results ) { + if ( ! results ) return []; + + return results.reduce( + flatMap( ( { testFilePath, testResults } ) => + testResults + .filter( ( r ) => r.status === 'failed' ) + .reduce( + flatMap( ( r ) => r.failureMessages ), + [] + ) + .map( ( m ) => m.replace( newLine, encodedNewLine ) ) + .map( ( m ) => lineAndColumnInStackTrace.exec( m ) ) + //.filter((m): m is RegExpExecArray => m !== null) + .map( + ( [ message, line, col ] ) => + `::error file=${ testFilePath },line=${ line },col=${ col }::${ message }` + ) + ), + [] + ); +} + +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 ) ); +// } + +module.exports = GithubActionReporter; diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js index 346c2f288efd44..ae8f631d5f997c 100644 --- a/test/unit/jest.config.js +++ b/test/unit/jest.config.js @@ -43,4 +43,5 @@ module.exports = { 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname', ], + reporters: [ 'default', '/test/unit/GithubActionsReporter.js' ], }; From a4c33b51b136010295baeaaea7fc5ada34b95ea2 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 13:50:16 +0200 Subject: [PATCH 02/22] Make it TS --- package-lock.json | 215 +++++++++++++++++- package.json | 2 + test/tsconfig.json | 20 ++ ...nsReporter.js => GithubActionsReporter.ts} | 35 ++- tsconfig.json | 3 +- 5 files changed, 247 insertions(+), 28 deletions(-) create mode 100644 test/tsconfig.json rename test/unit/{GithubActionsReporter.js => GithubActionsReporter.ts} (53%) diff --git a/package-lock.json b/package-lock.json index eac22935047415..161a9cc95fa299 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3434,13 +3434,214 @@ } }, "@jest/test-result": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-24.9.0.tgz", - "integrity": "sha512-XEFrHbBonBJ8dGp2JmF8kP/nQI/ImPpygKHwQ/SY+es59Z3L5PI4Qb9TQQMAEeYsThG1xF0k6tmG0tIKATNiiA==", + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-26.6.2.tgz", + "integrity": "sha512-5O7H5c/7YlojphYNrK02LlDIV2GNPYisKwHm2QTKjNZeEzezCbwYs9swJySv2UfPMyZ0VdsmMv7jIlD/IKYQpQ==", + "dev": true, "requires": { - "@jest/console": "^24.9.0", - "@jest/types": "^24.9.0", - "@types/istanbul-lib-coverage": "^2.0.0" + "@jest/console": "^26.6.2", + "@jest/types": "^26.6.2", + "@types/istanbul-lib-coverage": "^2.0.0", + "collect-v8-coverage": "^1.0.0" + }, + "dependencies": { + "@jest/console": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/console/-/console-26.6.2.tgz", + "integrity": "sha512-IY1R2i2aLsLr7Id3S6p2BA82GNWryt4oSvEXLAKc+L2zdi89dSkE8xC1C+0kpATG4JhBJREnQOH7/zmccM2B0g==", + "dev": true, + "requires": { + "@jest/types": "^26.6.2", + "@types/node": "*", + "chalk": "^4.0.0", + "jest-message-util": "^26.6.2", + "jest-util": "^26.6.2", + "slash": "^3.0.0" + } + }, + "@jest/types": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", + "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^15.0.0", + "chalk": "^4.0.0" + } + }, + "@types/istanbul-reports": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.0.tgz", + "integrity": "sha512-nwKNbvnwJ2/mndE9ItP/zc2TCzw6uuodnF4EHYWD+gCQDVBuRQL5UzbZD0/ezy1iKsFU2ZQiDqg4M9dN4+wZgA==", + "dev": true, + "requires": { + "@types/istanbul-lib-report": "*" + } + }, + "@types/stack-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz", + "integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==", + "dev": true + }, + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "dev": true + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "graceful-fs": { + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", + "dev": true + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "jest-message-util": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-26.6.2.tgz", + "integrity": "sha512-rGiLePzQ3AzwUshu2+Rn+UMFk0pHN58sOG+IaJbk5Jxuqo3NYO1U2/MIR4S1sKgsoYSXSzdtSa0TgrmtUwEbmA==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@jest/types": "^26.6.2", + "@types/stack-utils": "^2.0.0", + "chalk": "^4.0.0", + "graceful-fs": "^4.2.4", + "micromatch": "^4.0.2", + "pretty-format": "^26.6.2", + "slash": "^3.0.0", + "stack-utils": "^2.0.2" + } + }, + "jest-util": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-26.6.2.tgz", + "integrity": "sha512-MDW0fKfsn0OI7MS7Euz6h8HNDXVQ0gaM9uW6RjfDmd1DAFcaxX9OqIakHIqhbnmF08Cf2DLDG+ulq8YQQ0Lp0Q==", + "dev": true, + "requires": { + "@jest/types": "^26.6.2", + "@types/node": "*", + "chalk": "^4.0.0", + "graceful-fs": "^4.2.4", + "is-ci": "^2.0.0", + "micromatch": "^4.0.2" + } + }, + "micromatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", + "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.2.3" + } + }, + "picomatch": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz", + "integrity": "sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg==", + "dev": true + }, + "pretty-format": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", + "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "dev": true, + "requires": { + "@jest/types": "^26.6.2", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^17.0.1" + } + }, + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + }, + "stack-utils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.3.tgz", + "integrity": "sha512-gL//fkxfWUsIlFL2Tl42Cl6+HFALEaB1FU76I/Fy+oZjRreP7OPMXFlGbxM7NQsI0ZpUfw76sHnv0WNYuTb7Iw==", + "dev": true, + "requires": { + "escape-string-regexp": "^2.0.0" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } } }, "@jest/test-sequencer": { @@ -38142,7 +38343,6 @@ "integrity": "sha512-oCj8FiZ3U0hTP4aSui87P4L4jC37BtQwUMqk+zk/b11FR19BJDeZsZAvIHutWnmtw7r85UmR3CEWZ0HWU2mAlw==", "requires": { "@babel/code-frame": "^7.0.0", - "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", "@types/stack-utils": "^1.0.1", "chalk": "^2.0.1", @@ -39703,7 +39903,6 @@ "@jest/console": "^24.9.0", "@jest/fake-timers": "^24.9.0", "@jest/source-map": "^24.9.0", - "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", "callsites": "^3.0.0", "chalk": "^2.0.1", diff --git a/package.json b/package.json index bfb7291ce44ab8..db774bd5bcb921 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 00000000000000..1648b94b5b6de4 --- /dev/null +++ b/test/tsconfig.json @@ -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" + ] +} diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.ts similarity index 53% rename from test/unit/GithubActionsReporter.js rename to test/unit/GithubActionsReporter.ts index 3e11760f4af693..a35378da49e0e6 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.ts @@ -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( @@ -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 }` @@ -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; diff --git a/tsconfig.json b/tsconfig.json index 72d6dc72c2d39d..6464aef99e443f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,7 +30,8 @@ { "path": "packages/token-list" }, { "path": "packages/url" }, { "path": "packages/warning" }, - { "path": "packages/wordcount" } + { "path": "packages/wordcount" }, + { "path": "test" }, ], "files": [] } From adf6a331825945667252cba69b1e3ef842c14932 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 13:55:03 +0200 Subject: [PATCH 03/22] Add dummy unit test --- test/unit/test/index.test.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/unit/test/index.test.js diff --git a/test/unit/test/index.test.js b/test/unit/test/index.test.js new file mode 100644 index 00000000000000..f52c8b19e43f7d --- /dev/null +++ b/test/unit/test/index.test.js @@ -0,0 +1,5 @@ +describe( 'My test', () => { + test( 'A equals B', () => { + expect( 'a' ).toBe( 'b' ); + } ); +} ); From 87c162d69c0bd23002061c7bc6d3ef90525fc375 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 13:55:50 +0200 Subject: [PATCH 04/22] Revert "Make it TS" This reverts commit a4c33b51b136010295baeaaea7fc5ada34b95ea2. --- package-lock.json | 215 +----------------- package.json | 2 - test/tsconfig.json | 20 -- ...nsReporter.ts => GithubActionsReporter.js} | 35 +-- tsconfig.json | 3 +- 5 files changed, 28 insertions(+), 247 deletions(-) delete mode 100644 test/tsconfig.json rename test/unit/{GithubActionsReporter.ts => GithubActionsReporter.js} (53%) diff --git a/package-lock.json b/package-lock.json index 161a9cc95fa299..eac22935047415 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3434,214 +3434,13 @@ } }, "@jest/test-result": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-26.6.2.tgz", - "integrity": "sha512-5O7H5c/7YlojphYNrK02LlDIV2GNPYisKwHm2QTKjNZeEzezCbwYs9swJySv2UfPMyZ0VdsmMv7jIlD/IKYQpQ==", - "dev": true, + "version": "24.9.0", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-24.9.0.tgz", + "integrity": "sha512-XEFrHbBonBJ8dGp2JmF8kP/nQI/ImPpygKHwQ/SY+es59Z3L5PI4Qb9TQQMAEeYsThG1xF0k6tmG0tIKATNiiA==", "requires": { - "@jest/console": "^26.6.2", - "@jest/types": "^26.6.2", - "@types/istanbul-lib-coverage": "^2.0.0", - "collect-v8-coverage": "^1.0.0" - }, - "dependencies": { - "@jest/console": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/console/-/console-26.6.2.tgz", - "integrity": "sha512-IY1R2i2aLsLr7Id3S6p2BA82GNWryt4oSvEXLAKc+L2zdi89dSkE8xC1C+0kpATG4JhBJREnQOH7/zmccM2B0g==", - "dev": true, - "requires": { - "@jest/types": "^26.6.2", - "@types/node": "*", - "chalk": "^4.0.0", - "jest-message-util": "^26.6.2", - "jest-util": "^26.6.2", - "slash": "^3.0.0" - } - }, - "@jest/types": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", - "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "dev": true, - "requires": { - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^15.0.0", - "chalk": "^4.0.0" - } - }, - "@types/istanbul-reports": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.0.tgz", - "integrity": "sha512-nwKNbvnwJ2/mndE9ItP/zc2TCzw6uuodnF4EHYWD+gCQDVBuRQL5UzbZD0/ezy1iKsFU2ZQiDqg4M9dN4+wZgA==", - "dev": true, - "requires": { - "@types/istanbul-lib-report": "*" - } - }, - "@types/stack-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz", - "integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==", - "dev": true - }, - "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", - "dev": true - }, - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "requires": { - "fill-range": "^7.0.1" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true - }, - "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "requires": { - "to-regex-range": "^5.0.1" - } - }, - "graceful-fs": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==", - "dev": true - }, - "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true - }, - "jest-message-util": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-26.6.2.tgz", - "integrity": "sha512-rGiLePzQ3AzwUshu2+Rn+UMFk0pHN58sOG+IaJbk5Jxuqo3NYO1U2/MIR4S1sKgsoYSXSzdtSa0TgrmtUwEbmA==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "@jest/types": "^26.6.2", - "@types/stack-utils": "^2.0.0", - "chalk": "^4.0.0", - "graceful-fs": "^4.2.4", - "micromatch": "^4.0.2", - "pretty-format": "^26.6.2", - "slash": "^3.0.0", - "stack-utils": "^2.0.2" - } - }, - "jest-util": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-26.6.2.tgz", - "integrity": "sha512-MDW0fKfsn0OI7MS7Euz6h8HNDXVQ0gaM9uW6RjfDmd1DAFcaxX9OqIakHIqhbnmF08Cf2DLDG+ulq8YQQ0Lp0Q==", - "dev": true, - "requires": { - "@jest/types": "^26.6.2", - "@types/node": "*", - "chalk": "^4.0.0", - "graceful-fs": "^4.2.4", - "is-ci": "^2.0.0", - "micromatch": "^4.0.2" - } - }, - "micromatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", - "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", - "dev": true, - "requires": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" - } - }, - "picomatch": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz", - "integrity": "sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg==", - "dev": true - }, - "pretty-format": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", - "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", - "dev": true, - "requires": { - "@jest/types": "^26.6.2", - "ansi-regex": "^5.0.0", - "ansi-styles": "^4.0.0", - "react-is": "^17.0.1" - } - }, - "react-is": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true - }, - "slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true - }, - "stack-utils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.3.tgz", - "integrity": "sha512-gL//fkxfWUsIlFL2Tl42Cl6+HFALEaB1FU76I/Fy+oZjRreP7OPMXFlGbxM7NQsI0ZpUfw76sHnv0WNYuTb7Iw==", - "dev": true, - "requires": { - "escape-string-regexp": "^2.0.0" - } - }, - "to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "requires": { - "is-number": "^7.0.0" - } - } + "@jest/console": "^24.9.0", + "@jest/types": "^24.9.0", + "@types/istanbul-lib-coverage": "^2.0.0" } }, "@jest/test-sequencer": { @@ -38343,6 +38142,7 @@ "integrity": "sha512-oCj8FiZ3U0hTP4aSui87P4L4jC37BtQwUMqk+zk/b11FR19BJDeZsZAvIHutWnmtw7r85UmR3CEWZ0HWU2mAlw==", "requires": { "@babel/code-frame": "^7.0.0", + "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", "@types/stack-utils": "^1.0.1", "chalk": "^2.0.1", @@ -39903,6 +39703,7 @@ "@jest/console": "^24.9.0", "@jest/fake-timers": "^24.9.0", "@jest/source-map": "^24.9.0", + "@jest/test-result": "^24.9.0", "@jest/types": "^24.9.0", "callsites": "^3.0.0", "chalk": "^2.0.1", diff --git a/package.json b/package.json index db774bd5bcb921..bfb7291ce44ab8 100644 --- a/package.json +++ b/package.json @@ -89,8 +89,6 @@ "@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", diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index 1648b94b5b6de4..00000000000000 --- a/test/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "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" - ] -} diff --git a/test/unit/GithubActionsReporter.ts b/test/unit/GithubActionsReporter.js similarity index 53% rename from test/unit/GithubActionsReporter.ts rename to test/unit/GithubActionsReporter.js index a35378da49e0e6..3e11760f4af693 100644 --- a/test/unit/GithubActionsReporter.ts +++ b/test/unit/GithubActionsReporter.js @@ -5,30 +5,27 @@ * LICENSE file in the root directory of this source tree. */ -/** - * External dependencies - */ -import type { AggregatedResult, TestResult } from '@jest/test-result'; -import { BaseReporter, Context } from '@jest/reporters'; +// import type {AggregatedResult, TestResult} from '@jest/test-result'; +// import type { Reporter, Context } from '@jest/reporters'; +// import type {Context} from './types'; + +// const { flatMap } = require( 'lodash' ); const newLine = /\n/g; const encodedNewLine = '%0A'; const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/; -export default class GithubActionReporter extends BaseReporter { - onRunComplete( - _contexts?: Set< Context >, - aggregatedResults?: AggregatedResult - ): void { - const messages = getMessages( aggregatedResults?.testResults ); +class GithubActionReporter { + async onRunComplete( _contexts, _aggregatedResults ) { + const messages = getMessages( _aggregatedResults?.testResults ); for ( const message of messages ) { - this.log( message ); + process.stderr.write( message + '\n' ); } } } -function getMessages( results: Array< TestResult > | undefined ) { +function getMessages( results ) { if ( ! results ) return []; return results.reduce( @@ -41,7 +38,7 @@ function getMessages( results: Array< TestResult > | undefined ) { ) .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 }` @@ -51,6 +48,12 @@ function getMessages( results: Array< TestResult > | undefined ) { ); } -function flatMap< In, Out >( map: ( x: In ) => Array< Out > ) { - return ( out: Array< Out >, entry: In ) => out.concat( ...map( entry ) ); +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 ) ); +// } + +module.exports = GithubActionReporter; diff --git a/tsconfig.json b/tsconfig.json index 6464aef99e443f..72d6dc72c2d39d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,8 +30,7 @@ { "path": "packages/token-list" }, { "path": "packages/url" }, { "path": "packages/warning" }, - { "path": "packages/wordcount" }, - { "path": "test" }, + { "path": "packages/wordcount" } ], "files": [] } From d7b38eddda1aceff2012a02fed14b695320a2f24 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 14:03:29 +0200 Subject: [PATCH 05/22] Minor cleanup --- test/unit/GithubActionsReporter.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index 3e11760f4af693..cc49cac3afc865 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -5,12 +5,6 @@ * 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' ); - const newLine = /\n/g; const encodedNewLine = '%0A'; const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/; @@ -52,8 +46,4 @@ 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 ) ); -// } - module.exports = GithubActionReporter; From 6e3aaf6cbb1ea7a9c9456c92ca169382ccabbaa3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 16:16:54 +0200 Subject: [PATCH 06/22] Ignore ESLint --- test/unit/GithubActionsReporter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index cc49cac3afc865..798bd61ec6dd5e 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -14,7 +14,8 @@ class GithubActionReporter { const messages = getMessages( _aggregatedResults?.testResults ); for ( const message of messages ) { - process.stderr.write( message + '\n' ); + // eslint-disable-next-line no-console + console.log( message ); } } } From 61f6b083c9a3dc93d4ab4183eb6fa02007351525 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 17:37:01 +0200 Subject: [PATCH 07/22] Fix Node 12 issue --- test/unit/GithubActionsReporter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index 798bd61ec6dd5e..7d4a07183bdd67 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -11,7 +11,10 @@ const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/; class GithubActionReporter { async onRunComplete( _contexts, _aggregatedResults ) { - const messages = getMessages( _aggregatedResults?.testResults ); + if ( ! _aggregatedResults ) { + return; + } + const messages = getMessages( _aggregatedResults.testResults ); for ( const message of messages ) { // eslint-disable-next-line no-console From 52a24a233c99a2ff1bdfb4e01ac04c87769fd191 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 18:13:53 +0200 Subject: [PATCH 08/22] Try removing the GITHUB_WORKSPACE path --- test/unit/GithubActionsReporter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index 7d4a07183bdd67..d3480cd5bb6d4a 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -39,7 +39,10 @@ function getMessages( results ) { //.filter((m): m is RegExpExecArray => m !== null) .map( ( [ message, line, col ] ) => - `::error file=${ testFilePath },line=${ line },col=${ col }::${ message }` + `::error file=${ testFilePath.replace( + process.env.GITHUB_WORKSPACE + '/', + '' + ) },line=${ line },col=${ col }::${ message }` ) ), [] From ea464c2f61f21572704106bbd0b156beb45e3cc3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 19:58:22 +0200 Subject: [PATCH 09/22] Don't be so greedy --- test/unit/GithubActionsReporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index d3480cd5bb6d4a..2d4b1b2d0d9ddc 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -7,7 +7,7 @@ const newLine = /\n/g; const encodedNewLine = '%0A'; -const lineAndColumnInStackTrace = /^.*:([0-9]+):([0-9]+).*$/; +const lineAndColumnInStackTrace = /^.*?:([0-9]+):([0-9]+).*$/; class GithubActionReporter { async onRunComplete( _contexts, _aggregatedResults ) { From 5d3e37844d8463a8db368803129dcaf5ffe7c334 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 21 Apr 2021 20:14:24 +0200 Subject: [PATCH 10/22] Revert "Try removing the GITHUB_WORKSPACE path" This reverts commit 52a24a233c99a2ff1bdfb4e01ac04c87769fd191. --- test/unit/GithubActionsReporter.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index 2d4b1b2d0d9ddc..7d26e233090277 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -39,10 +39,7 @@ function getMessages( results ) { //.filter((m): m is RegExpExecArray => m !== null) .map( ( [ message, line, col ] ) => - `::error file=${ testFilePath.replace( - process.env.GITHUB_WORKSPACE + '/', - '' - ) },line=${ line },col=${ col }::${ message }` + `::error file=${ testFilePath },line=${ line },col=${ col }::${ message }` ) ), [] From 9962fa292572b1b4ba5866ac0c9445e9acab5bba Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 13:14:45 +0200 Subject: [PATCH 11/22] Mention the Jest PR the reporter is based on --- test/unit/GithubActionsReporter.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/GithubActionsReporter.js index 7d26e233090277..fff642911c5051 100644 --- a/test/unit/GithubActionsReporter.js +++ b/test/unit/GithubActionsReporter.js @@ -1,3 +1,10 @@ +/** + * Based on https://github.com/facebook/jest/pull/11320. + * + * We might be able to remove this file once the Jest PR is merged, and a + * version of Jest that includes the GithubActionsReporter is released. + */ + /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * From 753981fe9631ea76fa804e92f6c28c3f0d8c897f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 13:15:50 +0200 Subject: [PATCH 12/22] Move to ./config, kebab-case --- .../github-actions-reporter.js} | 0 test/unit/jest.config.js | 5 ++++- 2 files changed, 4 insertions(+), 1 deletion(-) rename test/unit/{GithubActionsReporter.js => config/github-actions-reporter.js} (100%) diff --git a/test/unit/GithubActionsReporter.js b/test/unit/config/github-actions-reporter.js similarity index 100% rename from test/unit/GithubActionsReporter.js rename to test/unit/config/github-actions-reporter.js diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js index ae8f631d5f997c..47467b8484489d 100644 --- a/test/unit/jest.config.js +++ b/test/unit/jest.config.js @@ -43,5 +43,8 @@ module.exports = { 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname', ], - reporters: [ 'default', '/test/unit/GithubActionsReporter.js' ], + reporters: [ + 'default', + '/test/unit/config/github-actions-reporter.js', + ], }; From 9e83a1b37ec47fda455246652f5a9bb86b116372 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 13:16:44 +0200 Subject: [PATCH 13/22] Plural, to match filename --- test/unit/config/github-actions-reporter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/config/github-actions-reporter.js b/test/unit/config/github-actions-reporter.js index fff642911c5051..2ae06ddb494120 100644 --- a/test/unit/config/github-actions-reporter.js +++ b/test/unit/config/github-actions-reporter.js @@ -16,7 +16,7 @@ const newLine = /\n/g; const encodedNewLine = '%0A'; const lineAndColumnInStackTrace = /^.*?:([0-9]+):([0-9]+).*$/; -class GithubActionReporter { +class GithubActionsReporter { async onRunComplete( _contexts, _aggregatedResults ) { if ( ! _aggregatedResults ) { return; @@ -57,4 +57,4 @@ function flatMap( fn ) { return ( out, entry ) => out.concat( ...fn( entry ) ); } -module.exports = GithubActionReporter; +module.exports = GithubActionsReporter; From 68dfa7ecaae325c9c0f1a986fd030f5423e99f0f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 16:25:20 +0200 Subject: [PATCH 14/22] Bail early if not in GHA --- test/unit/config/github-actions-reporter.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/config/github-actions-reporter.js b/test/unit/config/github-actions-reporter.js index 2ae06ddb494120..f3d774dd03edb5 100644 --- a/test/unit/config/github-actions-reporter.js +++ b/test/unit/config/github-actions-reporter.js @@ -18,6 +18,10 @@ const lineAndColumnInStackTrace = /^.*?:([0-9]+):([0-9]+).*$/; class GithubActionsReporter { async onRunComplete( _contexts, _aggregatedResults ) { + if ( ! process.env.GITHUB_ACTIONS ) { + return; + } + if ( ! _aggregatedResults ) { return; } From e17d77e982d1288f1d194d3d6e8b0b8ff73610c5 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 16:56:13 +0200 Subject: [PATCH 15/22] Revert "Add dummy unit test" This reverts commit adf6a331825945667252cba69b1e3ef842c14932. --- test/unit/test/index.test.js | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test/unit/test/index.test.js diff --git a/test/unit/test/index.test.js b/test/unit/test/index.test.js deleted file mode 100644 index f52c8b19e43f7d..00000000000000 --- a/test/unit/test/index.test.js +++ /dev/null @@ -1,5 +0,0 @@ -describe( 'My test', () => { - test( 'A equals B', () => { - expect( 'a' ).toBe( 'b' ); - } ); -} ); From 6a0ba19edc72fb9b232443cd3cb01402599083ca Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 16:59:47 +0200 Subject: [PATCH 16/22] Restore null check --- test/unit/config/github-actions-reporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/config/github-actions-reporter.js b/test/unit/config/github-actions-reporter.js index f3d774dd03edb5..9a8f292beb80ce 100644 --- a/test/unit/config/github-actions-reporter.js +++ b/test/unit/config/github-actions-reporter.js @@ -47,7 +47,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 !== null ) .map( ( [ message, line, col ] ) => `::error file=${ testFilePath },line=${ line },col=${ col }::${ message }` From 9afeae2b75696aa072d7c7065570240e3f82182a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 20:30:54 +0200 Subject: [PATCH 17/22] Move reporter to shared location in packages/scripts --- .../scripts/config/jest-github-actions-reporter.js | 0 test/unit/jest.config.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename test/unit/config/github-actions-reporter.js => packages/scripts/config/jest-github-actions-reporter.js (100%) diff --git a/test/unit/config/github-actions-reporter.js b/packages/scripts/config/jest-github-actions-reporter.js similarity index 100% rename from test/unit/config/github-actions-reporter.js rename to packages/scripts/config/jest-github-actions-reporter.js diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js index 47467b8484489d..84277c929d8171 100644 --- a/test/unit/jest.config.js +++ b/test/unit/jest.config.js @@ -45,6 +45,6 @@ module.exports = { ], reporters: [ 'default', - '/test/unit/config/github-actions-reporter.js', + 'packages/scripts/config/jest-github-actions-reporter.js', ], }; From 414085e1e48b48441a5abf05695b09e183088fca Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 20:53:59 +0200 Subject: [PATCH 18/22] Add GHA reporter to jest-e2e.config.js --- packages/scripts/config/jest-e2e.config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/scripts/config/jest-e2e.config.js b/packages/scripts/config/jest-e2e.config.js index 05b10123a7b87e..9714664ca7f530 100644 --- a/packages/scripts/config/jest-e2e.config.js +++ b/packages/scripts/config/jest-e2e.config.js @@ -20,6 +20,10 @@ const jestE2EConfig = { setupFilesAfterEnv: [ 'expect-puppeteer' ], testMatch: [ '**/specs/**/*.[jt]s', '**/?(*.)spec.[jt]s' ], testPathIgnorePatterns: [ '/node_modules/' ], + reporters: [ + 'default', + path.join( __dirname, 'jest-github-actions-reporter.js' ), + ], }; if ( ! hasBabelConfig() ) { From 1996153a79cafab914f7fe543192d34c9c925332 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 21:00:48 +0200 Subject: [PATCH 19/22] Add GHA reporter to jest-unit.config.js --- packages/scripts/config/jest-unit.config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/scripts/config/jest-unit.config.js b/packages/scripts/config/jest-unit.config.js index 3244e163925d61..a5ad97acd1c00f 100644 --- a/packages/scripts/config/jest-unit.config.js +++ b/packages/scripts/config/jest-unit.config.js @@ -10,6 +10,10 @@ const { hasBabelConfig } = require( '../utils' ); const jestUnitConfig = { preset: '@wordpress/jest-preset-default', + reporters: [ + 'default', + path.join( __dirname, 'jest-github-actions-reporter.js' ), + ], }; if ( ! hasBabelConfig() ) { From f98d6c7024e95695c46feec049c7c8b65cb4f86f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 21:20:53 +0200 Subject: [PATCH 20/22] Scripts: Add Changelog entry --- packages/scripts/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index f928b4c2bc8a40..1aeba8b878c476 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Include a Jest Reporter that formats test results for GitHub Actions annotations ([#31041](https://github.com/WordPress/gutenberg/pull/31041)). + ### Breaking Changes - Rename `format-js` script to `format` ([#30240](https://github.com/WordPress/gutenberg/pull/30240)). From e7a5c2233351e3de33d003ab0332edf9fa66b195 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 22 Apr 2021 21:25:36 +0200 Subject: [PATCH 21/22] REVERT ME: e2e test failure --- .../e2e-tests/specs/editor/various/inserting-blocks.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js index 498cc94cef17f5..5f6cd99c24c722 100644 --- a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js @@ -112,7 +112,7 @@ describe( 'Inserting blocks', () => { // Verify vertical traversal at offset. This has been buggy in the past // where verticality on a blank newline would skip into previous block. - await page.keyboard.type( 'Foo' ); + await page.keyboard.type( 'Bar' ); await page.keyboard.press( 'ArrowUp' ); await page.keyboard.press( 'ArrowUp' ); await pressKeyTimes( 'Delete', 6 ); From b45e10298a36e19379a34807c24b105672a6f05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Fri, 23 Apr 2021 08:30:01 +0200 Subject: [PATCH 22/22] Update packages/e2e-tests/specs/editor/various/inserting-blocks.test.js --- .../e2e-tests/specs/editor/various/inserting-blocks.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js index 5f6cd99c24c722..498cc94cef17f5 100644 --- a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js @@ -112,7 +112,7 @@ describe( 'Inserting blocks', () => { // Verify vertical traversal at offset. This has been buggy in the past // where verticality on a blank newline would skip into previous block. - await page.keyboard.type( 'Bar' ); + await page.keyboard.type( 'Foo' ); await page.keyboard.press( 'ArrowUp' ); await page.keyboard.press( 'ArrowUp' ); await pressKeyTimes( 'Delete', 6 );