@@ -11,6 +11,8 @@ import { formatGitHubActionAnnotation } from './github-annotations';
1111import { dashesSeparator , formatCSSAssertError , formatWarningsAssertError } from './format-asserts' ;
1212import noopPlugin from './noop-plugin' ;
1313
14+ const emitGitHubAnnotations = process . env . GITHUB_ACTIONS && process . env . ENABLE_ANNOTATIONS_FOR_NODE === 'true' && process . env . ENABLE_ANNOTATIONS_FOR_OS === 'true' ;
15+
1416type TestCaseOptions = {
1517 // Debug message
1618 message ?: string ,
@@ -40,7 +42,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
4042 if ( currentPlugin . postcss !== true ) {
4143 hasErrors = true ;
4244
43- if ( process . env . GITHUB_ACTIONS ) {
45+ if ( emitGitHubAnnotations ) {
4446 console . log ( formatGitHubActionAnnotation (
4547 'postcss flag not set to "true" on exported plugin object' ,
4648 'error' ,
@@ -57,7 +59,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
5759 if ( ! plugin . postcssPlugin || typeof plugin . postcssPlugin !== 'string' ) {
5860 hasErrors = true ;
5961
60- if ( process . env . GITHUB_ACTIONS ) {
62+ if ( emitGitHubAnnotations ) {
6163 console . log ( formatGitHubActionAnnotation (
6264 'plugin name not set via "postcssPlugin"' ,
6365 'error' ,
@@ -74,7 +76,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
7476 if ( ! packageInfo . keywords . includes ( 'postcss-plugin' ) ) {
7577 hasErrors = true ;
7678
77- if ( process . env . GITHUB_ACTIONS ) {
79+ if ( emitGitHubAnnotations ) {
7880 console . log ( formatGitHubActionAnnotation (
7981 'package.json does not include "postcss-plugin" keyword' ,
8082 'error' ,
@@ -90,7 +92,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
9092 if ( ! packageInfo . name . startsWith ( 'postcss-' ) && ! packageInfo . name . startsWith ( '@csstools/postcss-' ) ) {
9193 hasErrors = true ;
9294
93- if ( process . env . GITHUB_ACTIONS ) {
95+ if ( emitGitHubAnnotations ) {
9496 console . log ( formatGitHubActionAnnotation (
9597 'plugin name in package.json does not start with "postcss-"' ,
9698 'error' ,
@@ -106,7 +108,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
106108 if ( Object . keys ( Object ( packageInfo . dependencies ) ) . includes ( 'postcss' ) && ! ( 'postcssTapeSelfTest' in currentPlugin ) ) {
107109 hasErrors = true ;
108110
109- if ( process . env . GITHUB_ACTIONS ) {
111+ if ( emitGitHubAnnotations ) {
110112 console . log ( formatGitHubActionAnnotation (
111113 'postcss should only be a peer and/or dev dependency' ,
112114 'error' ,
@@ -154,14 +156,14 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
154156 hasErrors = true ;
155157 expected = false ;
156158
157- if ( process . env . GITHUB_ACTIONS ) {
159+ if ( emitGitHubAnnotations ) {
158160 console . log ( formatGitHubActionAnnotation (
159- `${ testCaseLabel } \n\nmissing or broken "expect" file: "${ expectFilePath } "` ,
161+ `${ testCaseLabel } \n\nmissing or broken "expect" file: "${ path . parse ( expectFilePath ) . base } "` ,
160162 'error' ,
161163 { file : testFilePath , line : 1 , col : 1 } ,
162164 ) ) ;
163165 } else {
164- console . error ( `\n${ testCaseLabel } \n\nmissing or broken "expect" file: "${ expectFilePath } "\n\n${ dashesSeparator } ` ) ;
166+ console . error ( `\n${ testCaseLabel } \n\nmissing or broken "expect" file: "${ path . parse ( expectFilePath ) . base } "\n\n${ dashesSeparator } ` ) ;
165167 }
166168 }
167169
@@ -195,7 +197,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
195197 } catch ( err ) {
196198 hasErrors = true ;
197199
198- if ( process . env . GITHUB_ACTIONS ) {
200+ if ( emitGitHubAnnotations ) {
199201 console . log ( formatGitHubActionAnnotation (
200202 formatCSSAssertError ( testCaseLabel , testCaseOptions , err , true ) ,
201203 'error' ,
@@ -216,7 +218,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
216218 } catch ( err ) {
217219 hasErrors = true ;
218220
219- if ( process . env . GITHUB_ACTIONS ) {
221+ if ( emitGitHubAnnotations ) {
220222 console . log ( formatGitHubActionAnnotation (
221223 `${ testCaseLabel } \n\nbroken source map: ${ JSON . stringify ( result . map . toJSON ( ) . sources ) } ` ,
222224 'error' ,
@@ -252,7 +254,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
252254 } catch ( _ ) {
253255 hasErrors = true ;
254256
255- if ( process . env . GITHUB_ACTIONS ) {
257+ if ( emitGitHubAnnotations ) {
256258 console . log ( formatGitHubActionAnnotation (
257259 `${ testCaseLabel } \n\nresult was not parsable with PostCSS.` ,
258260 'error' ,
@@ -287,7 +289,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
287289 } catch ( err ) {
288290 hasErrors = true ;
289291
290- if ( process . env . GITHUB_ACTIONS ) {
292+ if ( emitGitHubAnnotations ) {
291293 console . log ( formatGitHubActionAnnotation (
292294 'testing older PostCSS:\n' + formatCSSAssertError ( testCaseLabel , testCaseOptions , err , true ) ,
293295 'error' ,
@@ -308,7 +310,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
308310 } catch ( err ) {
309311 hasErrors = true ;
310312
311- if ( process . env . GITHUB_ACTIONS ) {
313+ if ( emitGitHubAnnotations ) {
312314 console . log ( formatGitHubActionAnnotation (
313315 formatWarningsAssertError ( testCaseLabel , testCaseOptions , result . warnings ( ) . length , testCaseOptions . warnings , true ) ,
314316 'error' ,
0 commit comments